Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions app/javascript/Domain/ImperialGameCoordinator.js
Original file line number Diff line number Diff line change
Expand Up @@ -719,9 +719,7 @@ export default class ImperialGameCoordinator {
this.endOfInvestorTurn(player);
}

// If there is one available action, it is the skip action and doesn't
// count as a real action.
if (this.availableActions.size <= 1) {
if ([...this.availableActions].every((action) => action.type !== 'bondPurchase')) {
this.annotatedLog.push(
Action.playerAutoSkipsBondPurchase({
player: this.currentPlayerName,
Expand Down Expand Up @@ -1983,6 +1981,30 @@ export default class ImperialGameCoordinator {
for (const bondPurchase of this.bondPurchasesFromAllNations()) {
this.availableActions.add(bondPurchase);
}

if ([...this.availableActions].every((action) => action.type !== 'bondPurchase')) {
this.annotatedLog.push(
Action.playerAutoSkipsBondPurchase({
player: this.currentPlayerName,
bondNation: this.currentNation,
}),
);
this.currentNation = this.nextNation(this.currentNation);
this.currentPlayerName = this.nations.get(
this.currentNation,
).controller;
this.advanceInvestorCard();

for (const availableAction of this.availableActions) {
if (availableAction.type === 'skipBondPurchase') {
this.log.push(availableAction);
this.availableActions.delete(availableAction);
}
}
for (const rondelAction of this.availableRondelActions(this.currentNation)) {
this.availableActions.add(rondelAction);
}
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions app/javascript/Domain/Tests/ImperialGameCoordinator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4625,6 +4625,18 @@ describe('imperial', () => {
expect(game.currentNation).toEqual(Nation.FR);
expect(game.currentPlayerName).toEqual('player1');
});

test('when a player does not have enough money to buy a bond, skip their invest turn', () => {
const game = newGame();
game.players.player2.cash = 0;
game.players.player2.bonds.clear();

game.tick(Action.rondel({ nation: Nation.AH, cost: 0, slot: 'investor' }));

// This is an awkward way to assert that we're not in a bond purchase round
expect([...game.availableActions].every((action) => action.type !== 'skipBondPurchase')).toEqual(true);
expect(game.currentPlayerName).toEqual('player2');
});
});

describe('undo', () => {
Expand Down
Loading