From 833f08c9de1fdfd62dbe40578656ed47e6029052 Mon Sep 17 00:00:00 2001 From: Eric Tillberg Date: Tue, 24 Dec 2024 11:00:17 -0500 Subject: [PATCH] fix auction nation advancing logic --- .../Domain/ImperialGameCoordinator.js | 14 ++-- app/javascript/Domain/Tests/Auction.test.js | 72 +++++++++++++++++-- app/javascript/Domain/auction.js | 7 +- 3 files changed, 83 insertions(+), 10 deletions(-) diff --git a/app/javascript/Domain/ImperialGameCoordinator.js b/app/javascript/Domain/ImperialGameCoordinator.js index 1fc568e5..1baee4d0 100644 --- a/app/javascript/Domain/ImperialGameCoordinator.js +++ b/app/javascript/Domain/ImperialGameCoordinator.js @@ -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': { diff --git a/app/javascript/Domain/Tests/Auction.test.js b/app/javascript/Domain/Tests/Auction.test.js index 60aa2085..4cf298ab 100644 --- a/app/javascript/Domain/Tests/Auction.test.js +++ b/app/javascript/Domain/Tests/Auction.test.js @@ -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', @@ -610,12 +610,76 @@ 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, + }), + ); + expect(game.availableActions).toEqual(expectedActions); }); }); diff --git a/app/javascript/Domain/auction.js b/app/javascript/Domain/auction.js index 1fab4464..90202f62 100644 --- a/app/javascript/Domain/auction.js +++ b/app/javascript/Domain/auction.js @@ -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': @@ -216,6 +216,11 @@ export default class Auction { break; } + return nations; + }; + + static advanceNation(game) { + const nations = this.nationsInOrder(game); const nationIndex = nations.indexOf(game.currentNation); game.currentNation = nations[nationIndex + 1];