feat: resolve objective control and objective victory
This commit is contained in:
@@ -9,9 +9,11 @@ use BattleForge\Domain\Battlefield;
|
||||
use BattleForge\Domain\CombatEngine;
|
||||
use BattleForge\Domain\CombatException;
|
||||
use BattleForge\Domain\MatchState;
|
||||
use BattleForge\Domain\ObjectiveMarker;
|
||||
use BattleForge\Domain\Position;
|
||||
use BattleForge\Domain\Terrain;
|
||||
use BattleForge\Domain\UnitState;
|
||||
use BattleForge\Domain\VictoryCondition;
|
||||
use InvalidArgumentException;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@@ -973,4 +975,65 @@ final class CombatEngineTest extends TestCase
|
||||
|
||||
(new CombatEngine())->useAbility($match, 'scout-1', 'heal', new Position(0, 1));
|
||||
}
|
||||
|
||||
public function testEndTurnTalliesObjectiveControlAfterAFullRound(): void
|
||||
{
|
||||
$alpha = $this->unit('alpha-1', 'alpha', new Position(4, 4));
|
||||
$bravo = $this->unit('bravo-1', 'bravo', new Position(7, 7));
|
||||
$match = new MatchState(
|
||||
new Battlefield(8, 8),
|
||||
[$alpha, $bravo],
|
||||
'alpha',
|
||||
objectives: ['objective-1' => new ObjectiveMarker('objective-1', new Position(4, 4))],
|
||||
victoryCondition: VictoryCondition::HoldObjective,
|
||||
holdRoundsRequired: 2,
|
||||
);
|
||||
|
||||
$afterAlphaEnd = (new CombatEngine())->endTurn($match);
|
||||
$afterBravoEnd = (new CombatEngine())->endTurn($afterAlphaEnd);
|
||||
|
||||
self::assertSame(['alpha' => 1], $afterAlphaEnd->objectiveControl);
|
||||
self::assertSame(['alpha' => 1], $afterBravoEnd->objectiveControl);
|
||||
self::assertNull($afterBravoEnd->winnerTeamId);
|
||||
}
|
||||
|
||||
public function testEndTurnDeclaresWinnerWhenHoldRoundsReached(): void
|
||||
{
|
||||
$alpha = $this->unit('alpha-1', 'alpha', new Position(4, 4));
|
||||
$bravo = $this->unit('bravo-1', 'bravo', new Position(7, 7));
|
||||
$match = new MatchState(
|
||||
new Battlefield(8, 8),
|
||||
[$alpha, $bravo],
|
||||
'alpha',
|
||||
objectives: ['objective-1' => new ObjectiveMarker('objective-1', new Position(4, 4))],
|
||||
victoryCondition: VictoryCondition::HoldObjective,
|
||||
holdRoundsRequired: 1,
|
||||
objectiveControl: ['alpha' => 0],
|
||||
);
|
||||
|
||||
$afterAlphaEnd = (new CombatEngine())->endTurn($match);
|
||||
$afterBravoEnd = (new CombatEngine())->endTurn($afterAlphaEnd);
|
||||
|
||||
self::assertSame('alpha', $afterBravoEnd->winnerTeamId);
|
||||
self::assertSame(['alpha' => 1], $afterBravoEnd->objectiveControl);
|
||||
}
|
||||
|
||||
public function testEndTurnDoesNotAwardControlWhenNoTeamStandsOnTheObjective(): void
|
||||
{
|
||||
$alpha = $this->unit('alpha-1', 'alpha', new Position(0, 0));
|
||||
$bravo = $this->unit('bravo-1', 'bravo', new Position(7, 7));
|
||||
$match = new MatchState(
|
||||
new Battlefield(8, 8),
|
||||
[$alpha, $bravo],
|
||||
'alpha',
|
||||
objectives: ['objective-1' => new ObjectiveMarker('objective-1', new Position(4, 4))],
|
||||
victoryCondition: VictoryCondition::HoldObjective,
|
||||
holdRoundsRequired: 1,
|
||||
);
|
||||
|
||||
$next = (new CombatEngine())->endTurn($match);
|
||||
|
||||
self::assertSame([], $next->objectiveControl);
|
||||
self::assertNull($next->winnerTeamId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user