fix: guard invalid turn transitions

This commit is contained in:
Keith Solomon
2026-07-04 16:07:36 -05:00
parent acfbbf4a91
commit fef22d7b56
2 changed files with 132 additions and 5 deletions
+17
View File
@@ -93,8 +93,25 @@ final class CombatEngine
throw new CombatException('Matches require alpha and bravo teams.');
}
$livingTeams = ['alpha' => false, 'bravo' => false];
foreach ($match->units as $unit) {
if (!$unit->isDefeated()) {
$livingTeams[$unit->teamId] = true;
}
}
if (!$livingTeams['alpha'] || !$livingTeams['bravo']) {
throw new CombatException('Cannot end turn while a team is eliminated.');
}
$endingTeamId = $match->activeTeamId;
$nextTeamId = $endingTeamId === 'alpha' ? 'bravo' : 'alpha';
if ($nextTeamId === 'alpha' && $match->round === PHP_INT_MAX) {
throw new CombatException('Match round limit reached.');
}
$units = [];
foreach ($match->units as $unit) {