From fac4915cb7fd15f098b453a17ec55950dd374a67 Mon Sep 17 00:00:00 2001 From: Quintine <15965533+Quintine@users.noreply.github.com> Date: Mon, 16 Nov 2026 17:18:04 +1100 Subject: [PATCH] Preserve Basic Emperor gifts while Sandtrout waits --- docs/CURRENT_STATUS.md | 9 + docs/EMPEROR_ALLIANCE_TIMING.md | 19 +++ docs/RULE_DECISIONS.md | 6 + game/engine.ts | 6 +- game/reference.ts | 2 +- ...ror-auction-gift-waiting-sandtrout.test.ts | 160 ++++++++++++++++++ ...ror-opening-gift-waiting-sandtrout.test.ts | 123 ++++++++++++++ 7 files changed, 321 insertions(+), 4 deletions(-) create mode 100644 tests/emperor-auction-gift-waiting-sandtrout.test.ts create mode 100644 tests/emperor-opening-gift-waiting-sandtrout.test.ts diff --git a/docs/CURRENT_STATUS.md b/docs/CURRENT_STATUS.md index d3584fde..c736cbd8 100644 --- a/docs/CURRENT_STATUS.md +++ b/docs/CURRENT_STATUS.md @@ -17,6 +17,15 @@ open mode gates. ## Current checkpoint and work +**Basic Emperor gifts while Sandtrout waits — 16 November. Prototyped / +Partial.** Supported opening, ordinary auction and Richese cache gift windows +remain available after an actual Sandtrout draw and a subsequent Ecaz +Ambassador alliance. Allow, cancellation, original funding and the human-before- +bot opening survive; Advanced and other module guards remain. Eight related +unit files pass 43 cases, including both Richese auction methods. Complete +games, broader combinations and deployed acceptance remain open. +[Scope](EMPEROR_ALLIANCE_TIMING.md#basic-opening-and-auction-gifts-with-waiting-sandtrout--16-november-2026). + **Basic actions with waiting Sandtrout — 16 November. Prototyped / Partial.** An actual Ix Spice draw no longer disables supported No-Field reveal, direct bribes or Emperor gifts during Extortion. The original choice, payment and diff --git a/docs/EMPEROR_ALLIANCE_TIMING.md b/docs/EMPEROR_ALLIANCE_TIMING.md index 44669286..dd1bce10 100644 --- a/docs/EMPEROR_ALLIANCE_TIMING.md +++ b/docs/EMPEROR_ALLIANCE_TIMING.md @@ -1,5 +1,24 @@ # Emperor alliance gift timing +## Basic opening and auction gifts with waiting Sandtrout — 16 November 2026 + +**Prototyped / Partial.** A waiting Sandtrout no longer suppresses an +otherwise supported Basic Emperor gift at an Ix phase opening, before an +ordinary auction payment, or before a Richese cache sale settles. Sandtrout +still breaks alliances when drawn; the gift requires a later mutual alliance. +The gift, Karama response and Continue retain the original opening or sale and +committed funding. The existing neutral opportunity before the last bot pass +is also available at the opening. These remain the provisional online timing +interpretations described below, not new publisher rulings. Advanced and other +module guards are unchanged. + +[Opening journeys](../tests/emperor-opening-gift-waiting-sandtrout.test.ts) +and [auction journeys](../tests/emperor-auction-gift-waiting-sandtrout.test.ts) +draw Sandtrout, form the Ecaz/Emperor alliance through an Ambassador and use +actual actions through Allow, cancellation and continuation. They stage the +unopened Spice order, force positions, cards and auction wallets. Wider +combinations, complete games and deployed acceptance remain open. + ## Basic Extortion gift with waiting Sandtrout — 16 November 2026 **Prototyped / Partial.** In the existing supported Basic Extortion decision, diff --git a/docs/RULE_DECISIONS.md b/docs/RULE_DECISIONS.md index aa83585c..61797aeb 100644 --- a/docs/RULE_DECISIONS.md +++ b/docs/RULE_DECISIONS.md @@ -1,5 +1,11 @@ # Rule decision index +## Basic Emperor gifts with waiting Sandtrout — 16 November 2026 + +The existing provisional phase-opening and auction gift opportunities apply +after Sandtrout when a new mutual alliance has formed. This extends the existing +online ordering, not the publisher's ruling. [Scope](EMPEROR_ALLIANCE_TIMING.md#basic-opening-and-auction-gifts-with-waiting-sandtrout--16-november-2026). + ## Basic mixed-deck Emperor gifts at Ix openings — 16 November 2026 The existing provisional opening-gift and final-bot-pass ordering extends to diff --git a/game/engine.ts b/game/engine.ts index 4195a262..77b65429 100644 --- a/game/engine.ts +++ b/game/engine.ts @@ -19219,7 +19219,7 @@ function emperorAuctionGiftSignature(g: Game): string { function beginEmperorRicheseAuctionGift(g: Game, quote: Extract, bank = false): boolean { if (g.advanced || g.status !== 'playing' || g.phase !== 3 || g.richeseAuction?.source !== 'cache' || g.techTokens || g.strongholdCards || g.leaderSkills || g.homeworlds || - g.discoveryEnabled || g.sandtrout || g.coalitionState || g.ecazTreachery || + g.discoveryEnabled || g.coalitionState || g.ecazTreachery || g.pendingEmperorAuctionGift || g.response || g.decision || g.phaseOpening || g.truthtrance || g.pendingKarama || g.pendingTreacheryDiscard || g.pendingRicheseGift || g.pendingNullentropy || g.pendingRicheseBetrayal || g.pendingNexusEmperorSellerPurchase || @@ -19238,7 +19238,7 @@ function beginEmperorAuctionGift(g: Game) { (g.advanced ? g.expansions.length !== 0 || g.players.some(seat => !['atreides', 'beneGesserit', 'emperor', 'fremen', 'guild', 'harkonnen'].includes(seat.faction)) : g.expansions.length > 0 && !selectedPhaseModuleRoster(g)) || g.techTokens || g.strongholdCards || g.leaderSkills || g.homeworlds || (g.advanced && g.nexusCards) || - g.discoveryEnabled || g.sandtrout || g.coalitionState || g.pendingEmperorAuctionGift || + g.discoveryEnabled || (g.advanced && g.sandtrout) || g.coalitionState || g.pendingEmperorAuctionGift || g.response || g.phaseOpening || g.truthtrance || g.pendingKarama || g.pendingTreacheryDiscard || g.pendingRicheseGift || g.pendingNullentropy || g.currentAuctionSale || g.richeseAuction || g.ixAuction || @@ -30827,7 +30827,7 @@ function emperorPhaseOpeningGiftSignature(g: Game, opening: {passed: string[]; i function emperorPhaseOpeningGiftPublicEligible(g: Game, p: Player): boolean { if (g.status !== 'playing' || !g.expansions.includes('ix') || !selectedPhaseModuleRoster(g) || g.techTokens || g.strongholdCards || g.leaderSkills || g.homeworlds || - g.discoveryEnabled || g.sandtrout || g.coalitionState || + g.discoveryEnabled || (g.advanced && g.sandtrout) || g.coalitionState || !g.phaseOpening || !g.amalWindowOpen || g.response || g.decision || g.truthtrance || g.pendingKarama || g.pendingKull || g.pendingTreacheryDiscard || g.battle || g.pendingRicheseGift || g.pendingNullentropy || g.pendingShipment || g.pendingGuildTransport || diff --git a/game/reference.ts b/game/reference.ts index 6d3c83b3..696c893e 100644 --- a/game/reference.ts +++ b/game/reference.ts @@ -297,7 +297,7 @@ export const RULE_TOPICS: RuleTopic[] = [ 'Open Bribes beneath the table. Choose a non-allied faction and a positive whole amount, then use the named Pay button. The amount is public and leaves your supply immediately. A message or promise alone does not pay spice.', 'The recipient keeps paid spice separately until the next Mentat opening. A payment after the current opening waits for next turn’s opening. Your incoming bribes are shown separately from your spendable supply; they cannot fund bids, shipments or another bribe yet.', 'A waiting Sandtrout does not prevent the supported Basic bribe interruption windows.', - 'During a supported Basic Extortion decision, a waiting Sandtrout does not prevent the Emperor gifting spice to an ally formed after the Sandtrout draw.', + 'During supported Basic phase openings, auction payments, Richese cache sales and Extortion decisions, a waiting Sandtrout does not prevent the Emperor gifting spice to an ally formed after the Sandtrout draw.', 'You may pay out of turn when no decision or response is pending, including during Mentat after opening collection. In supported Basic games with classic or selected native expansion factions, direct bribes can also interrupt a normal auction-payment decision, Atreides auction inspection, Fremen allied-revival grant, ordinary Fremen or Ixian movement response, or CHOAM movement decision. Supported Basic Ix and Moritani games also allow payments during the Amal opening or an Extortion choice. The original parent and its passes remain pending. You cannot bribe yourself or your ally, or while Inflation shows Double. Emperor gifts to allies use their own power controls.', 'Your payment limit excludes reserved spending and preserves binding Truthtrance answers. If an alliance, pending decision or available supply changes, recheck the recipient and amount. A rejected payment does not change the game.', 'In the Basic group preview, group allies are excluded from ordinary bribes and nonallied deals. Existing agreements remain recorded and can be released; a deferred bribe to a newly allied recipient stays pending while it is unavailable, subject to its original deadline.', diff --git a/tests/emperor-auction-gift-waiting-sandtrout.test.ts b/tests/emperor-auction-gift-waiting-sandtrout.test.ts new file mode 100644 index 00000000..bc579302 --- /dev/null +++ b/tests/emperor-auction-gift-waiting-sandtrout.test.ts @@ -0,0 +1,160 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import { applyAction, createGame, joinGame, newPlayer, viewGame, type Action, type Game } from '../game/engine'; +import { territory } from '../game/board'; +import { beforeIxSpiceDraw, orderIxSpiceCards } from './fixture-ix-spice-cards'; +import { nextSemutaNexusTradeNativeStep } from './fixture-semuta-nexus-trade'; + +const act = (game: Game, actor: string, action: Action) => applyAction(game, actor, action); +function seat(game: Game, id: string) { const player = game.players.find(p => p.id === id); assert.ok(player); return player; } +const clean = (game: Game) => !game.response && !game.decision && !game.phaseOpening && !game.truthtrance && !game.pendingTreacheryDiscard; +function cards(game: Game) { + const ids = [...game.deck, ...game.discard, ...(game.richeseCache ?? []), ...(game.richeseRemoved ?? []), + ...(game.auction?.cards.slice(game.auction.index + Number(game.currentAuctionSale?.origin === 'normal')) ?? []), + ...(game.ixAuction?.cards ?? []), ...game.players.flatMap(p => p.hand)].map(card => card.id).sort(); + assert.equal(new Set(ids).size, ids.length); return ids; +} +function advance(state: Game, until: (game: Game) => boolean): Game { + let game = state; + for (let n = 0; n < 2000; n++) { + if (until(game)) return game; + assert.notEqual(game.status, 'finished', 'Native journey must reach the auction'); + if (game.status === 'setup' && game.setupStage === 'forces' && seat(game, 'ecaz').reserves === 20) + game = act(game, 'ecaz', { type: 'ecazSetup', placements: { 'imperial_basin:9': 6 } }); + else if (game.decision?.kind === 'ecazPlacement' && !game.response && !game.phaseOpening) + game = act(game, 'ecaz', { type: 'decision', decline: true }); + else { + const next = nextSemutaNexusTradeNativeStep(game); + game = act(game, next.actor, next.action); + } + } + throw Error('Native journey did not reach its auction boundary'); +} +function passResponse(state: Game): Game { + let game = state; + while (game.response) { + const player = game.players.find(p => !game.response!.passed.includes(p.id)); assert.ok(player); + game = act(game, player.id, { type: 'passResponse' }); + } + return game; +} +/** A real first-turn Sandtrout breaks alliances. An Ecaz Ambassador then forms + * the Emperor alliance; a land-only second Spice Blow leaves Sandtrout waiting. + * Unopened Spice order, conserved board forces, cards and wallets are staged. */ +function alliance() { + let game = createGame('AUCTION-SANDTROUT', newPlayer('ecaz', 'Ecaz', 'ecaz'), false, ['choam', 'ix', 'ecaz']); + for (const faction of ['emperor', 'richese', 'choam', 'atreides'] as const) + joinGame(game, newPlayer(faction, faction, faction)); + for (const p of game.players) game = act(game, p.id, { type: 'ready' }); + game = act(game, 'ecaz', { type: 'start' }); + game = advance(game, g => g.status === 'playing'); + const original = cards(game); + for (const p of game.players) { p.reserves += Object.values(p.forces).reduce((a, b) => a + b, 0); p.forces = {}; } + game = advance(game, beforeIxSpiceDraw); orderIxSpiceCards(game, ['sandtrout', 'land']); + game = advance(game, g => g.phase === 4 && !g.response && !g.phaseOpening && g.decision?.kind === 'ecazPlacement'); + assert.equal(game.sandtrout, true); + const location = ['habbanya_ridge_sietch', 'sietch_tabr', 'carthag', 'arrakeen', 'tueks_sietch'] + .map(id => ({ territory: id, sector: territory(id).sectors.find(s => s !== game.storm) })) + .find((row): row is { territory: string; sector: number } => row.sector !== undefined); + assert.ok(location); + const token = game.ecazAmbassadors!.tokens.find(row => row.effect === 'ecaz'); assert.ok(token); + game = act(game, 'ecaz', { type: 'decision', token: token.id, territory: location.territory }); + game = advance(game, g => g.phase === 5 && clean(g) && g.active === 'emperor'); + game = act(game, 'emperor', { type: 'ship', amount: 1, ...location }); + game = advance(game, g => !g.response && g.pendingAmbassador?.stage === 'offer'); + const event = game.pendingAmbassador!.event; + game = act(game, 'ecaz', { type: 'decision', event, trigger: true, beneficiary: 'ecaz', choice: 'alliance' }); + game = act(game, 'emperor', { type: 'decision', event, accept: true }); + game = act(game, 'ecaz', { type: 'decision', event, loan: false }); + assert.equal(seat(game, 'ecaz').ally, 'emperor'); assert.equal(seat(game, 'emperor').ally, 'ecaz'); + game = advance(game, g => g.turn === 2 && beforeIxSpiceDraw(g)); + orderIxSpiceCards(game, ['land', 'land']); + game = advance(game, g => g.phase === 3 && g.phaseOpening?.initialize === true); + assert.equal(game.sandtrout, true); + assert.equal(seat(game, 'ecaz').ally, 'emperor'); + // Leave room for a purchased card and allocate a distinct physical Karama to the countering seat. + for (const p of game.players) game.deck.push(...p.hand.splice(0)); + const index = game.deck.findIndex(card => card.effect === 'karama'); assert.ok(index >= 0); + const [counter] = game.deck.splice(index, 1); seat(game, 'atreides').hand.push(counter); + seat(game, 'ecaz').spice = 7; seat(game, 'emperor').spice = 8; + assert.deepEqual(cards(game), original); + return { game, counter: counter.id, original }; +} +function fixture(source: 'onceAround' | 'silent' | 'ordinary') { + const result = alliance(); let game = result.game; + if (source !== 'ordinary') { + game = advance(game, g => g.decision?.kind === 'richeseCache'); + const card = game.richeseCache![0]; assert.ok(card); + game = act(game, 'richese', { type: 'decision', event: game.richeseBidding!.event, card: card.id, method: source, + ...(source === 'onceAround' ? { direction: 'clockwise' as const } : {}) }); + game = act(game, 'emperor', { type: 'pledgeAid', amount: 1 }); + let bid = false; + for (let n = 0; !game.pendingEmperorAuctionGift && n < 300; n++) { + const lot = game.richeseAuction; + if (lot && !lot.outcome && !game.response && !game.decision && lot.method === 'onceAround' && lot.active) { + const buyer = lot.active === 'ecaz' && !bid; + game = act(game, lot.active, { type: 'richeseBid', event: lot.event, amount: buyer ? 3 : null, + ...(buyer ? { allyPayment: 1 } : {}) }); + if (buyer) bid = true; + } else if (lot && !lot.outcome && !game.response && !game.decision && lot.method === 'silent') { + const actor = lot.eligible.find(id => !Object.hasOwn(lot.sealed, id)); assert.ok(actor); + const buyer = actor === 'ecaz' && !bid; + game = act(game, actor, { type: 'richeseBid', event: lot.event, amount: buyer ? 3 : 0, + ...(buyer ? { allyPayment: 1 } : {}) }); + if (buyer) bid = true; + } else { const next = nextSemutaNexusTradeNativeStep(game); game = act(game, next.actor, next.action); } + } + assert.ok(bid); assert.ok(game.pendingEmperorAuctionGift, 'The original cache sale exposes an Emperor opportunity'); + return { ...result, game, card: card.id }; + } + game = advance(game, g => g.phase === 3 && !!g.auction && !g.richeseAuction && clean(g)); + while (game.auction!.active !== 'ecaz') game = act(game, game.auction!.active, { type: 'passBid' }); + const card = game.auction!.cards[game.auction!.index].id; + game = act(game, 'emperor', { type: 'pledgeAid', amount: 1 }); + game = act(game, 'ecaz', { type: 'bid', amount: 3, allyPayment: 1 }); + for (let n = 0; game.auction && !game.response && !game.decision && n < 15; n++) + game = act(game, game.auction.active, { type: 'passBid' }); + assert.equal(game.decision?.kind, 'auctionPayment'); + assert.ok(game.pendingEmperorAuctionGift, 'The original ordinary auction exposes an Emperor opportunity'); + return { ...result, game, card }; +} + +for (const source of ['onceAround', 'silent', 'ordinary'] as const) for (const cancel of [false, true]) void test( + `Basic ${source} auction Emperor gift with genuine waiting Sandtrout ${cancel ? 'cancels' : 'allows'} and continues`, () => { + const f = fixture(source), before = structuredClone(f.game); + const offer = viewGame(f.game, 'emperor').emperorAuctionGift; assert.ok(offer); + assert.equal(offer.recipient, 'ecaz'); + assert.equal(before.aid.emperor?.amount, 1); + if (source === 'ordinary') { + assert.equal(before.auction?.bid, 3); assert.equal(before.auction?.allyPayment, 1); + } else assert.ok(before.richeseFunding?.ecaz); + let game = act(f.game, 'emperor', { type: 'emperorGift', amount: 2 }); + if (cancel) { + game = act(game, 'atreides', { type: 'card', mode: 'cancel', card: f.counter }); + if (game.pendingKull) game = act(game, 'choam', { type: 'kullDecision', event: game.pendingKull.event, decline: true }); + while (game.pendingTreacheryDiscard?.reaction?.stage === 'offer') { + const reaction = game.pendingTreacheryDiscard.reaction; + const player = game.players.find(p => !reaction.passed.includes(p.id)); assert.ok(player); + game = act(game, player.id, { type: 'semutaPass', event: game.pendingTreacheryDiscard.batch.event }); + } + } else game = passResponse(game); + assert.equal(game.sandtrout, true); + assert.equal(seat(game, 'ecaz').spice, seat(before, 'ecaz').spice + (cancel ? 0 : 2)); + assert.equal(seat(game, 'emperor').spice, seat(before, 'emperor').spice - (cancel ? 0 : 2)); + assert.deepEqual(game.richeseAuction, before.richeseAuction); assert.deepEqual(game.auction, before.auction); + assert.deepEqual(game.richeseFunding, before.richeseFunding); assert.deepEqual(game.aid, before.aid); + assert.equal(viewGame(game, 'emperor').emperorAuctionGift?.event, offer.event); + game = act(game, 'emperor', { type: 'emperorAuctionGiftContinue', event: offer.event }); + if (game.decision?.kind === 'auctionPayment') game = act(game, 'ecaz', { type: 'decision', karama: false }); + game = passResponse(game); + assert.ok(seat(game, 'ecaz').hand.some(card => card.id === f.card)); + assert.equal(seat(game, 'ecaz').spice, seat(before, 'ecaz').spice + (cancel ? 0 : 2) - 2); + assert.equal(game.aid.emperor?.amount ?? 0, 0); + if (source === 'ordinary') + assert.equal(seat(game, 'emperor').spice, seat(before, 'emperor').spice - (cancel ? 0 : 2) + 3); + else { + assert.equal(seat(game, 'emperor').spice, seat(before, 'emperor').spice - (cancel ? 0 : 2)); + assert.equal(seat(game, 'richese').spice, seat(before, 'richese').spice + 3); + } + assert.equal(game.sandtrout, true); assert.deepEqual(cards(game), f.original); + }); diff --git a/tests/emperor-opening-gift-waiting-sandtrout.test.ts b/tests/emperor-opening-gift-waiting-sandtrout.test.ts new file mode 100644 index 00000000..803c5813 --- /dev/null +++ b/tests/emperor-opening-gift-waiting-sandtrout.test.ts @@ -0,0 +1,123 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import { applyAction, createGame, joinGame, newPlayer, viewGame, type Action, type Game } from '../game/engine'; +import { territory } from '../game/board'; +import { botActions, runBots } from '../game/bots'; +import { DIFFICULTIES } from '../game/bot-profiles'; +import { beforeIxSpiceDraw, orderIxSpiceCards } from './fixture-ix-spice-cards'; +import { nextStrongholdFactionsNativeStep } from './fixture-stronghold-factions'; +import { truthTurnAmalInventory as inventory } from './fixture-truth-turn-amal'; + +const act = (game: Game, id: string, action: Action) => applyAction(game, id, action); +function seat(game: Game, id: string) { + const player = game.players.find(row => row.id === id); assert.ok(player); return player; +} +function advance(game: Game, until: (state: Game) => boolean): Game { + for (let n = 0; n < 2000; n++) { + if (until(game)) return game; + assert.notEqual(game.status, 'finished'); + if (game.status === 'setup' && game.setupStage === 'forces' && seat(game, 'ecaz').reserves === 20) + game = act(game, 'ecaz', {type:'ecazSetup', placements:{'imperial_basin:9':6}}); + else if (game.decision?.kind === 'ecazPlacement' && !game.response && !game.phaseOpening) + game = act(game, 'ecaz', {type:'decision', decline:true}); + else { + const next = nextStrongholdFactionsNativeStep(game); assert.ok(next, `No continuation at ${game.phase}/${game.decision?.kind}`); + game = act(game, next.actor, next.action); + } + } + throw Error('Did not reach the requested native opening'); +} +function passResponses(game: Game): Game { + for (let n = 0; game.response && n < 20; n++) { + const actor = game.players.find(player => !game.response!.passed.includes(player.id)); assert.ok(actor); + game = act(game, actor.id, {type:'passResponse'}); + } + assert.equal(game.response, null); return game; +} + +/** Original public Basic Ecaz/Ix setup, real Sandtrout draw and actual Ecaz + * Ambassador alliance before the next opening. Only the unopened Spice prefix, + * conserved initial board forces and the counter card's physical custody are + * staged; neither the waiting flag nor the alliance is installed directly. */ +function fixture() { + let game = createGame('OPENINGSANDTROUT', newPlayer('ecaz','Ecaz','ecaz'), false, ['ecaz','ix']); + for (const id of ['emperor','atreides','guild'] as const) joinGame(game, newPlayer(id,id,id)); + for (const player of game.players) game = act(game, player.id, {type:'ready'}); + game = act(game, 'ecaz', {type:'start'}); + game = advance(game, state => state.status === 'playing'); + for (const player of game.players) { + player.reserves += Object.values(player.forces).reduce((sum, count) => sum + count, 0); + player.forces = {}; + } + game = advance(game, beforeIxSpiceDraw); + orderIxSpiceCards(game, ['sandtrout','land']); + game = advance(game, state => state.phase === 4 && !state.response && !state.phaseOpening && state.decision?.kind === 'ecazPlacement'); + assert.equal(game.sandtrout, true); + const spot = ['habbanya_ridge_sietch','sietch_tabr','carthag','arrakeen','tueks_sietch'] + .map(id => ({territory:id, sector:territory(id).sectors.find(sector => sector !== game.storm)})) + .find((row): row is {territory:string; sector:number} => row.sector !== undefined); + assert.ok(spot); + const ambassador = game.ecazAmbassadors!.tokens.find(row => row.effect === 'ecaz'); assert.ok(ambassador); + game = act(game, 'ecaz', {type:'decision', token:ambassador.id, territory:spot.territory}); + game = advance(game, state => !state.response && state.decision?.kind === 'ecazPlacement'); + game = act(game, 'ecaz', {type:'decision', decline:true}); + game = advance(game, state => state.phase === 5 && state.active === 'emperor' && !state.response && !state.decision && !state.phaseOpening); + game = act(game, 'emperor', {type:'ship', amount:1, territory:spot.territory, sector:spot.sector}); + game = advance(game, state => !state.response && state.pendingAmbassador?.stage === 'offer'); + const event = game.pendingAmbassador!.event; + game = act(game, 'ecaz', {type:'decision', event, trigger:true, beneficiary:'ecaz', choice:'alliance'}); + game = act(game, 'emperor', {type:'decision', event, accept:true}); + assert.equal(game.pendingAmbassador?.stage, 'loan'); + game = act(game, 'ecaz', {type:'decision', event, loan:false}); + assert.equal(seat(game, 'ecaz').ally, 'emperor'); assert.equal(seat(game, 'emperor').ally, 'ecaz'); + game = advance(game, state => state.phase === 6 && !!state.phaseOpening); + assert.equal(game.sandtrout, true); assert.ok(game.phaseOpening); + const original = inventory(game), guild = seat(game, 'guild'); + let counter = guild.hand.find(card => card.effect === 'karama'); + if (!counter) { + const source = game.players.find(player => player.id !== 'guild' && player.hand.some(card => card.effect === 'karama'))?.hand ?? game.deck; + const index = source.findIndex(card => card.effect === 'karama'); assert.ok(index >= 0); + if (guild.hand.length >= 4) game.deck.push(guild.hand.pop()!); + [counter] = source.splice(index, 1); guild.hand.push(counter); + } + assert.deepEqual(inventory(game), original); + game = act(game, 'emperor', {type:'ready'}); + game = act(game, 'ecaz', {type:'ready'}); + return {game, original, counter:counter.id}; +} + +for (const cancel of [false, true]) void test(`Basic phase-opening gift with waiting Sandtrout ${cancel ? 'cancels' : 'settles'} and resumes`, () => { + const f = fixture(), before = structuredClone(f.game), opening = structuredClone(f.game.phaseOpening); + const owner = seat(f.game, 'emperor').spice, ally = seat(f.game, 'ecaz').spice; + assert.ok(owner >= 1); + assert.deepEqual(viewGame(f.game, 'emperor').emperorPhaseOpeningGift, {recipient:'ecaz', maximum:owner}); + assert.equal(viewGame(f.game, 'ecaz').emperorPhaseOpeningGift, null); + assert.equal(viewGame(f.game, 'guild').emperorPhaseOpeningGift, null); + let game = act(f.game, 'emperor', {type:'emperorGift', amount:1}); + assert.equal(game.response?.kind, 'emperorGift'); assert.equal(game.phaseOpening, null); + game = cancel ? act(game, 'guild', {type:'card', card:f.counter, mode:'cancel'}) : passResponses(game); + assert.deepEqual(game.phaseOpening, opening); + assert.equal(game.phase, before.phase); assert.equal(game.turn, before.turn); + assert.equal(seat(game, 'emperor').spice, owner - Number(!cancel)); + assert.equal(seat(game, 'ecaz').spice, ally + Number(!cancel)); + assert.equal(game.sandtrout, true); assert.deepEqual(inventory(game), f.original); + game = act(game, 'atreides', {type:'ready'}); + game = act(game, 'guild', {type:'ready'}); + assert.notEqual(game.phase, before.phase); assert.equal(game.sandtrout, true); +}); + +void test('all bot levels preserve the human Emperor opening opportunity while Sandtrout waits', () => { + const f = fixture(); + const initial = act(f.game, 'atreides', {type:'ready'}); + for (const difficulty of DIFFICULTIES) { + let game = structuredClone(initial); seat(game, 'guild').bot = difficulty; + const priority = viewGame(game, 'emperor').emperorPhaseOpeningPriority; + assert.ok(priority?.canContinue); assert.equal(priority.recipient, 'ecaz'); + assert.ok(!botActions(viewGame(game, 'guild')).some(action => action.type === 'ready')); + const waiting = runBots(game, 2); assert.deepEqual(waiting.phaseOpening, game.phaseOpening); + game = act(game, 'emperor', {type:'emperorPhaseOpeningContinue', event:priority.event}); + const action = botActions(viewGame(game, 'guild')).find(row => row.type === 'ready'); + assert.ok(action, difficulty); game = act(game, 'guild', action); + assert.notEqual(game.phase, initial.phase); assert.equal(game.sandtrout, true); + } +});