diff --git a/engine/src/decks.spec.ts b/engine/src/decks.spec.ts index 7bb572d..332e513 100644 --- a/engine/src/decks.spec.ts +++ b/engine/src/decks.spec.ts @@ -535,4 +535,34 @@ describe('shuffled power plant decks', () => { expect(replay.players.map((p) => p.money)).to.deep.equal(G.players.map((p) => p.money)); }); } + + it("marks the draw pile by the deck's own plug cards, not by plant 15", () => { + // Deck 1 has plug cards up to 16, and the shuffled decks mix in copies such as + // 16.1 and 15.2. Comparing the number with 15 showed those as ordinary cards. + const fresh = (deck: PowerPlantDeck) => + setup(5, { map: 'Germany', variant: 'recharged', powerPlantDeck: deck }, 'plug-flag'); + for (const deck of ['standard', 'deck1', 'shuffled', 'shuffledUnique'] as PowerPlantDeck[]) { + const dealt = visible(fresh(deck)).filter((pp) => pp.number != 99); + const plugAbove15 = dealt.find((pp) => pp.number > 15 && isPlugPlant(pp, deck)); + const ordinary = dealt.find((pp) => !isPlugPlant(pp, deck))!; + if (deck == 'standard') expect(plugAbove15, deck).to.equal(undefined); + else expect(plugAbove15, `${deck} deals a plug card above 15`).to.not.equal(undefined); + + for (const top of [plugAbove15, ordinary]) { + if (!top) continue; + const G = fresh(deck); + // Swap the chosen plant onto the top of the draw pile, wherever it was dealt. + for (const row of [G.actualMarket, G.futureMarket, G.powerPlantsDeck]) { + const at = row.findIndex((pp) => pp.number == top.number); + if (at >= 0) [row[at], G.powerPlantsDeck[0]] = [G.powerPlantsDeck[0], row[at]]; + } + const player = G.currentPlayers[0]; + G.players[player].availableMoves = availableMoves(G, G.players[player]); + const chosen = G.actualMarket[0].number; + const after = move(G, { name: MoveName.ChoosePowerPlant, data: chosen } as Move, player); + expect(after.powerPlantsDeck[0].number, deck).to.equal(top.number); + expect(after.nextCardWeak, `${deck}: ${top.number} on top`).to.equal(isPlugPlant(top, deck)); + } + } + }); }); diff --git a/engine/src/engine.ts b/engine/src/engine.ts index f26ef2c..b411511 100644 --- a/engine/src/engine.ts +++ b/engine/src/engine.ts @@ -597,7 +597,7 @@ export function setup( if (G.map.name == 'Middle East') { removePlantsForMiddleEastStep1(G); G.cardsLeft = G.powerPlantsDeck.length; - G.nextCardWeak = variant === 'recharged' && G.cardsLeft > 0 && G.powerPlantsDeck[0].number <= 15; + G.nextCardWeak = nextCardIsPlug(G); } // chooseRegions: start in the region draft instead of the auction. The map @@ -746,6 +746,18 @@ function advanceColorDraft(G: GameState) { } } +// The draw pile shows whether its top card has a plug on the back (Recharged only). +// Which plants are plug cards depends on the deck: Deck 1 has plugs up to 16, and the +// shuffled decks mix copies from every deck (16.1, 15.2, ...), so ask the deck rather +// than comparing the number with 15. +function nextCardIsPlug(G: GameState): boolean { + return ( + G.options.variant == 'recharged' && + G.powerPlantsDeck.length > 0 && + isPlugPlant(G.powerPlantsDeck[0], gameDeck(G.options)) + ); +} + export function stripSecret(G: GameState, player?: number): GameState { return { ...G, @@ -2028,7 +2040,7 @@ export function move( : move; G.cardsLeft = G.powerPlantsDeck.length; - G.nextCardWeak = G.options.variant == 'recharged' && G.cardsLeft > 0 && G.powerPlantsDeck[0].number <= 15; + G.nextCardWeak = nextCardIsPlug(G); updateClocks(G, move.poweringClock?.at ?? move.serverTime ?? move.time); if (move.poweringClock) { diff --git a/engine/src/sealed-bid-privacy.spec.ts b/engine/src/sealed-bid-privacy.spec.ts index d31c087..d2665b8 100644 --- a/engine/src/sealed-bid-privacy.spec.ts +++ b/engine/src/sealed-bid-privacy.spec.ts @@ -47,7 +47,9 @@ describe('sealed auction lastMove privacy', () => { } it('hides pending bids and passes from opponents and spectators, including revisions', async () => { - let { state, bidder, plant } = await opening(); + const opened = await opening(); + const { bidder, plant } = opened; + let { state } = opened; assertPrivate(state); const second = state.currentPlayers[0]; state = await wrapper.move(state, { name: MoveName.Pass, data: true }, second);