Program: Fix an issue where PickGachiRule can end up in a state where no rules in the pool are valid

This commit is contained in:
OatmealDome 2024-08-11 13:48:57 -04:00
parent 8a34971659
commit 67d6a7c545

View File

@ -357,7 +357,7 @@ VersusRule PickGachiRule(GambitStageInfo stageInfo, GambitStageInfo lastStageInf
pool.AddRange(defaultGachiRulePool);
}
return GetRandomElementFromPool(pool, rule =>
bool IsRuleValid(VersusRule rule)
{
if (nextPhaseOverride != null)
{
@ -366,9 +366,26 @@ VersusRule PickGachiRule(GambitStageInfo stageInfo, GambitStageInfo lastStageInf
return false;
}
}
return rule != lastStageInfo.Rule;
}, random);
}
if (pool.All(r => !IsRuleValid(r)))
{
List<VersusRule> forbiddenRules = new List<VersusRule>()
{
lastStageInfo.Rule
};
if (nextPhaseOverride != null)
{
forbiddenRules.Add(nextPhaseOverride.GachiRule);
}
pool = defaultGachiRulePool.Except(forbiddenRules).ToList();
}
return GetRandomElementFromPool(pool, IsRuleValid, random);
}
int PickStage(GambitVersusPhase phase, GambitVersusPhase lastPhase, OverridePhase? nextPhaseOverride, VersusRule rule,