Skip to content

Commit

Permalink
Evasion almost works
Browse files Browse the repository at this point in the history
  • Loading branch information
xpmatteo committed Nov 8, 2023
1 parent b09e456 commit f2f1c55
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 32 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ image to appear. The parameters are:

# WIP

Must set the temporarySide to the opponent during evasion phases

# AI TESTS

- Early game
Expand All @@ -66,7 +68,6 @@ image to appear. The parameters are:

# TODO RULES

- evasion
- more cards
- cavalry bonus movement
- cavalry, chariot bonus combat
Expand Down
46 changes: 22 additions & 24 deletions src/ai/__snapshots__/mcts_player.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -51,38 +51,36 @@ exports[`2 on 2 1`] = `
`;

exports[`close combat from light to heavy 1`] = `
"-24/30: undefined -> Roman play one card -> 1
-24/30: PlayCard(Order Light Troops) -> Roman order 1 light units -> 1
-24/29: End phase -> Roman movement -> 1
-23/28: MacroCommand(Move [2,3] to [3,2]) -> Roman battle -> 1
"-21/30: undefined -> Roman play one card -> 1
-21/30: PlayCard(Order Light Troops) -> Roman order 1 light units -> 1
-21/29: End phase -> Roman movement -> 1
-20/28: MacroCommand(Move [2,3] to [3,2]) -> Roman battle -> 1
CHANCE/27: Close Combat from [3,2] to [2,2] -> Roman battle -> 5
-1/4: Close Combat from [3,2] to [2,2] -> Carthaginian retreat -> 2
1/4: Retreat [2,2] to [2,1] -> Roman advance after combat -> 2
0/1: Momentum advance [3,2] to [2,2] -> Roman battle -> 0
2/2: Skip Momentum Advance -> Roman battle -> 1
-3/3: Close Combat from [3,2] to [2,2] -> Carthaginian retreat -> 2
0/0: Retreat [2,2] to [3,1] -> Roman advance after combat -> 0
-8/8: Close Combat from [3,2] to [2,2] -> Roman attacker retreat -> 3
-3/3: Retreat [3,2] to [2,4] -> Roman battle -> 1
2/2: End phase -> Carthaginian play one card -> 1
3/3: Retreat [2,2] to [2,1] -> Roman advance after combat -> 2
1/1: Momentum advance [3,2] to [2,2] -> Roman battle -> 0
1/1: Skip Momentum Advance -> Roman battle -> 1
-5/6: Close Combat from [3,2] to [2,2] -> Roman attacker retreat -> 3
-2/2: Retreat [3,2] to [3,4] -> Roman battle -> 1
2/2: End phase -> Carthaginian play one card -> 1
-3/3: Retreat [3,2] to [1,4] -> Roman battle -> 1
3/3: End phase -> Carthaginian play one card -> 1
-4/4: Close Combat from [3,2] to [2,2] -> Roman attacker retreat -> 3
-2/2: Retreat [3,2] to [1,4] -> Roman battle -> 1
1/1: End phase -> Carthaginian play one card -> 0
-1/1: Retreat [3,2] to [3,4] -> Roman battle -> 1
1/1: End phase -> Carthaginian play one card -> 0
-1/1: Retreat [3,2] to [2,4] -> Roman battle -> 1
1/1: End phase -> Carthaginian play one card -> 0
3/3: Close Combat from [3,2] to [2,2] -> Carthaginian retreat -> 2
-3/3: Retreat [2,2] to [3,1] -> Roman advance after combat -> 2
-1/1: Momentum advance [3,2] to [2,2] -> Roman battle -> 0
-1/1: Skip Momentum Advance -> Roman battle -> 1
0/0: Retreat [2,2] to [2,1] -> Roman advance after combat -> 0
2/2: End phase -> Carthaginian play one card -> 1
-1/2: Retreat [3,2] to [2,4] -> Roman battle -> 1
0/1: End phase -> Carthaginian play one card -> 0
-7/7: Close Combat from [3,2] to [2,2] -> Roman battle -> 1
7/7: End phase -> Carthaginian play one card -> 1
6/6: PlayCard(Order Heavy Troops) -> Carthaginian order 1 heavy units -> 1
-9/9: Close Combat from [3,2] to [2,2] -> Roman attacker retreat -> 3
-3/3: Retreat [3,2] to [1,4] -> Roman battle -> 1
2/2: End phase -> Carthaginian play one card -> 1
-3/3: Retreat [3,2] to [3,4] -> Roman battle -> 1
3/3: End phase -> Carthaginian play one card -> 1
-3/3: Retreat [3,2] to [2,4] -> Roman battle -> 1
3/3: End phase -> Carthaginian play one card -> 1
0/1: Close Combat from [3,2] to [2,2] -> Carthaginian retreat -> 2
0/1: Retreat [2,2] to [3,1] -> Roman advance after combat -> 0
0/0: Retreat [2,2] to [2,1] -> Roman advance after combat -> 0
"
`;

Expand Down
2 changes: 1 addition & 1 deletion src/model/commands/EvadeCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export class EvadeCommand extends Command {
}

play(game) {
game.shiftPhase();
game.moveUnit(this.toHex, this.fromHex);
game.endPhase();
return [new DefenderEvasionEvent(this.toHex, this.fromHex)];
}

Expand Down
8 changes: 4 additions & 4 deletions src/model/phases/BattlePhase.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export class BattlePhase extends Phase {
}
attackingUnit.validCloseCombatTargets(attackingHex, game).forEach(defendingHex => {
const defendingUnit = game.unitAt(defendingHex);
// if (defendingUnit.canEvade(attackingUnit) && game.evasionPaths(defendingHex).length > 0) {
// commands.push(new AskOpponentIfTheyIntendToEvadeCommand(defendingHex, attackingHex));
// } else {
if (defendingUnit.canEvade(attackingUnit) && game.evasionPaths(defendingHex).length > 0) {
commands.push(new AskOpponentIfTheyIntendToEvadeCommand(defendingHex, attackingHex));
} else {
commands.push(new CloseCombatCommand(defendingHex, attackingHex));
// }
}
});
attackingUnit.validRangedCombatTargets(attackingHex, game).forEach(to => {
commands.push(new RangedCombatCommand(to, attackingHex));
Expand Down
4 changes: 2 additions & 2 deletions src/model/scenarios.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ export class HeavyVersusLightScenario extends Scenario {
board.placeUnit(hexOf(-1, 6), new units.RomanHeavyInfantry());
board.placeUnit(hexOf(0, 6), new units.RomanHeavyInfantry());

board.placeUnit(hexOf(0, 4), new units.CarthaginianLightInfantry());
board.placeUnit(hexOf(1, 4), new units.CarthaginianLightInfantry());
board.placeUnit(hexOf(0, 5), new units.CarthaginianLightInfantry());
board.placeUnit(hexOf(1, 5), new units.CarthaginianLightInfantry());
}
}

Expand Down

0 comments on commit f2f1c55

Please sign in to comment.