Skip to content

Commit

Permalink
fix auction nation advancing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Thrillberg committed Dec 24, 2024
1 parent 6371f9f commit ef4e627
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 10 deletions.
14 changes: 9 additions & 5 deletions app/javascript/Domain/ImperialGameCoordinator.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,16 @@ export default class ImperialGameCoordinator {
this.#undoHistory.undoToLastCheckpoint();

Object.assign(this, this.oldState);
if (
this.auction?.inAuction
&& this.auction.firstPlayerIndex !== Array.from(this.nations.keys()).indexOf(this.currentNation)
) {
this.auction.firstPlayerIndex -= 1;
if (this.auction?.inAuction) {
if (this.auction.firstPlayerIndex !== Array.from(this.nations.keys()).indexOf(this.currentNation)) {
if (this.auction.firstPlayerIndex === 0) {
this.auction.firstPlayerIndex = this.auction.order.length - 1;
} else {
this.auction.firstPlayerIndex -= 1;
}
}
}

return;
}
case 'bondPurchase': {
Expand Down
73 changes: 69 additions & 4 deletions app/javascript/Domain/Tests/Auction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,13 +526,13 @@ describe('auction', () => {
test('whole auction', () => {
const game = newGame();
const expectedActions = new Set([
Action.skipBondPurchase({ player: 't', nation: Nation2030.IN }),
Action.undo({ player: 'm' }),
Action.skipBondPurchase({ player: 't', nation: Nation2030.US }),
Action.undo({ player: 't' }),
]);
[2, 4, 6, 9, 12, 16].forEach((cost) => {
[2, 4, 6, 9].forEach((cost) => {
expectedActions.add(
Action.bondPurchase({
nation: Nation2030.IN,
nation: Nation2030.US,
cost,
tradeInValue: 0,
player: 't',
Expand Down Expand Up @@ -610,12 +610,77 @@ describe('auction', () => {
game.tick(
Action.undo({ player: 'm' }),
);
game.tick(
Action.bondPurchase({
player: 'm', cost: 9, nation: Nation2030.CN, tradeInValue: 0,
}),
);
game.tick(
Action.undo({ player: 'm' }),
);
game.tick(
Action.bondPurchase({
player: 'm', cost: 12, nation: Nation2030.CN, tradeInValue: 0,
}),
);

// India
// t
game.tick(
Action.bondPurchase({
player: 't', cost: 4, nation: Nation2030.IN, tradeInValue: 0,
}),
);
// f
game.tick(
Action.bondPurchase({
player: 'f', cost: 6, nation: Nation2030.IN, tradeInValue: 0,
}),
);
// m has insufficient funds
// e
game.tick(
Action.bondPurchase({
player: 'e', cost: 2, nation: Nation2030.IN, tradeInValue: 0,
}),
);

// Brazil
// f
game.tick(
Action.skipBondPurchase({ player: 'f', nation: Nation2030.BR }),
);
// m has insufficient funds
// e
game.tick(
Action.bondPurchase({
player: 'e', cost: 2, nation: Nation2030.BR, tradeInValue: 0,
}),
);
// t
game.tick(
Action.bondPurchase({
player: 't', cost: 4, nation: Nation2030.BR, tradeInValue: 0,
}),
);
game.tick(
Action.undo({ player: 't' }),
);
game.tick(
Action.bondPurchase({
player: 't', cost: 4, nation: Nation2030.BR, tradeInValue: 0,
}),
);
game.tick(
Action.undo({ player: 't' }),
);
game.tick(
Action.bondPurchase({
player: 't', cost: 4, nation: Nation2030.BR, tradeInValue: 0,
}),
);


Check failure on line 683 in app/javascript/Domain/Tests/Auction.test.js

View workflow job for this annotation

GitHub Actions / build (16.x)

More than 1 blank line not allowed
expect(game.availableActions).toEqual(expectedActions);
});
});
Expand Down
7 changes: 6 additions & 1 deletion app/javascript/Domain/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export default class Auction {
return game.currentPlayerName === this.order[this.firstPlayerIndex || 0];
}

static advanceNation(game) {
static nationsInOrder = (game) => {
let nations = [];
switch (game.baseGame) {
case 'imperial2030':
Expand Down Expand Up @@ -216,6 +216,11 @@ export default class Auction {
break;
}

return nations;
}

Check failure on line 220 in app/javascript/Domain/auction.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Missing semicolon

static advanceNation(game) {
const nations = this.nationsInOrder(game)

Check failure on line 223 in app/javascript/Domain/auction.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Missing semicolon
const nationIndex = nations.indexOf(game.currentNation);
game.currentNation = nations[nationIndex + 1];

Expand Down

0 comments on commit ef4e627

Please sign in to comment.