Skip to content

Commit

Permalink
Fix bug in attacker killed in battle back
Browse files Browse the repository at this point in the history
  • Loading branch information
xpmatteo committed Nov 5, 2023
1 parent 6825f56 commit 887521d
Showing 2 changed files with 22 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/model/commands/close_combat_command.js
Original file line number Diff line number Diff line change
@@ -52,8 +52,7 @@ export class CloseCombatCommand extends AbstractCombatCommand {
game.damageUnit(attackingUnit, totalDamage);
if (game.isUnitDead(attackingUnit)) {
events.push(new UnitKilledEvent(attackingUnit, attackingHex));
}
if (retreatHexes.length > 0) {
} else if (retreatHexes.length > 0) {
game.unshiftPhase(new AttackerRetreatPhase(attackingHex, retreatHexes));
}
}
21 changes: 21 additions & 0 deletions src/model/commands/close_combat_command.test.js
Original file line number Diff line number Diff line change
@@ -122,6 +122,27 @@ describe('defender cannot evade', () => {
});
});

describe('attacker killed, flags irrelevant', () => {
const defenderDice = Array(4).fill(RESULT_HEAVY).concat([RESULT_FLAG]);
let game = makeGame(new NullScenario(), diceReturning(
Array(5).fill(RESULT_LIGHT).concat(defenderDice)));
game.placeUnit(hexOf(1, 5), attacker);
game.placeUnit(hexOf(1, 4), defender);

const events = closeCombatCommand.play(game);

test('next phase', () => {
expect(game.currentPhase).toBeInstanceOf(PlayCardPhase);
expect(game.phases.length).toEqual(1);
});

test('attacker killed', () => {
expect(game.unitAt(hexOf(1, 4))).toBe(defender);
expect(game.unitAt(hexOf(1, 5))).toBeUndefined();
expect(game.killedUnitsOfSide(Side.ROMAN)).toEqual([attacker]);
});
});

describe('attacker retreats', () => {
let game = makeGame(new NullScenario(), diceReturning([
RESULT_LIGHT, RESULT_LIGHT,RESULT_LIGHT,RESULT_LIGHT,RESULT_LIGHT,

0 comments on commit 887521d

Please sign in to comment.