diff --git a/docs/CURRENT_STATUS.md b/docs/CURRENT_STATUS.md index 155299ff..cd7e337f 100644 --- a/docs/CURRENT_STATUS.md +++ b/docs/CURRENT_STATUS.md @@ -17,6 +17,25 @@ open mode gates. ## Current checkpoint and work +**Waiting Sandtrout and battle cards — 16 November. Prototyped / Partial.** +The ordinary waiting Spice effect no longer disables otherwise supported Mirror +Weapon, Stone Burner or independent Reinforcements use. Genuine Basic draws and +battle actions exercise card choices, physical costs and legal bot plans; card +locations and board forces are staged. Other optional combinations and deployed +acceptance remain open. [Mirror/Stone scope](MIRROR_WEAPON_ENGINE_AUDIT.md#waiting-sandtrout--16-november-2026), +[Reinforcements scope](REINFORCEMENTS_RUNTIME.md#waiting-sandtrout--16-november-2026). + +**Basic Richese reveal after Truthtrance facts — 16 November. Prototyped / +Partial.** Public current-fact questions no longer independently block a +supported reveal; mixed and future commitments remain uniformly guarded. +Original Guild-rate response and payment continue. Other interruption parents, +complete games and deployed acceptance remain open. +[Scope](RICHESE_NO_FIELD_RULES.md#basic-reveal-after-truthtrance-facts--16-november-2026). + +Nine related unit files pass 45 cases. Three older Reinforcements assertions +also failed at preceding commit `2cea251`; they now check the current legal +elite payment choices. These focused results do not certify complete modes. + **Basic Richese reveal during CHOAM free Revival — 16 November. Prototyped / Partial.** Supported voluntary reveals retain the original force request and CHOAM Allow/La La La decision. A Richese recipient reveals from current reserves diff --git a/docs/MIRROR_WEAPON_ENGINE_AUDIT.md b/docs/MIRROR_WEAPON_ENGINE_AUDIT.md index ed9eda31..5a61986e 100644 --- a/docs/MIRROR_WEAPON_ENGINE_AUDIT.md +++ b/docs/MIRROR_WEAPON_ENGINE_AUDIT.md @@ -4,6 +4,19 @@ The [24 October Basic native follow-up](#basic-native-e3-admission--24-october-2 **28 September ruling and runtime:** the user selected ordinary winner retention for the physical Mirror even when its copy activates Tooth or Artillery. This is an explicit product interpretation, not a located GF9 clarification. `game/effective-weapons.ts` keeps physical identity apart from copied attacks; the engine now connects copied Tooth/Stone choices, Stone comparison, custody, battle controls and legal AI in the bounded configuration. +## Waiting Sandtrout — 16 November 2026 + +**Prototyped / Partial.** Waiting Sandtrout no longer disables Mirror Weapon or +Stone Burner in otherwise supported games. The ordinary Ix Spice effect stays +active until its native worm resolution; it has no printed battle-card effect. +This supersedes the earlier Sandtrout guard below. Other module and allocation +guards remain unchanged. + +Focused Basic public-start cases draw the actual Sandtrout, then exercise both +weapons through selection, plans and settlement. Board forces and physical +card locations are staged. All four bot profiles submit legal candidate plans; +full combinations, complete games and deployed acceptance remain open. + ## Basic native E3 admission — 24 October 2026 **Prototyped / Partial.** Bare Basic CHOAM/Richese plus Ecaz/Moritani now uses diff --git a/docs/REINFORCEMENTS_RUNTIME.md b/docs/REINFORCEMENTS_RUNTIME.md index ebadb994..3c60d431 100644 --- a/docs/REINFORCEMENTS_RUNTIME.md +++ b/docs/REINFORCEMENTS_RUNTIME.md @@ -1,5 +1,15 @@ # Reinforcements battle prototype +## Waiting Sandtrout — 16 November 2026 + +**Prototyped / Partial.** An already drawn Sandtrout no longer blocks the +independent Reinforcements card in otherwise supported games. The Spice effect +remains waiting while the original three-reserve payment, slot choice and +battle settlement use their existing rules. The focused Basic public-start +cases draw Sandtrout and exercise both card slots with staged conserved forces +and card locations. Other module interactions, complete games and deployed +acceptance remain open. + The separate Ecaz Treachery Cards variant shuffles one physical Reinforcements card independently of choosing the Ecaz faction. Its bounded handler supports Basic/Advanced classic-faction tables, clean selected Ix and/or CHOAM native/base diff --git a/docs/RICHESE_NO_FIELD_RULES.md b/docs/RICHESE_NO_FIELD_RULES.md index 9262b222..6c0e8a5a 100644 --- a/docs/RICHESE_NO_FIELD_RULES.md +++ b/docs/RICHESE_NO_FIELD_RULES.md @@ -2,6 +2,21 @@ Audit date: 2026-09-06. This document distinguishes the printed token lifecycle from engine integration and unresolved combinations. It does not certify Richese, Homeworlds, or any other gated game mode. +## Basic reveal after Truthtrance facts — 16 November 2026 + +**Prototyped / Partial.** A public current-turn history containing only +current-fact Truthtrance questions no longer blocks an otherwise supported +voluntary No-Field interruption. Structured facts and freeform questions +declared as facts do not create future commitments. Questions with mixed or +future-action semantics remain uniformly fenced regardless of their answer, +and the original live promise safeguards still apply. The ordering follows the +existing provisional interpretation of the printed before-Battle permission. + +Focused genuine Basic questions cover both answers, recognized and unrecognized +freeform facts, a pending Guild rate and its native continuation. Physical +cards and unopened Spice order are staged. Other interruption parents, complete +games and deployed acceptance remain open. + ## Basic reveal during CHOAM free Revival — 16 November 2026 **Prototyped / Partial.** In supported Basic games Richese may reveal its diff --git a/game/engine.ts b/game/engine.ts index 162ff072..f916536d 100644 --- a/game/engine.ts +++ b/game/engine.ts @@ -19871,7 +19871,7 @@ function reinforcementsModeSupported(g: Game) { const nativeFamilies = !g.discoveries && !g.discoveryStash && !g.greatMaker && !g.semutaPreview && !g.kullPreview && !g.ecazOccupyPreview && g.expansions.length > 0 && independentCardRoster(g); - return !!g.ecazTreachery && recruitsModeSupported(g) && !g.sandtrout && + return !!g.ecazTreachery && recruitsModeSupported(g) && (nativeFamilies || (g.ecazOccupyPreview === true && ecazOccupyCompositionSupported(g)) || ((g.expansions.length === 0 || pairedEcaz) && g.players.every(player => { const expansion = faction(player.faction).expansion; diff --git a/game/mirror-weapon-mode.ts b/game/mirror-weapon-mode.ts index d0d68a7b..2a9a08e5 100644 --- a/game/mirror-weapon-mode.ts +++ b/game/mirror-weapon-mode.ts @@ -26,7 +26,7 @@ export function mirrorWeaponModeBlock(g: { if (g.expansions.includes('ecaz') && (!g.advanced || g.expansions.includes('ix')) && (g.techTokens || g.strongholdCards)) return 'This E3 Stone/Mirror combination with Tech Tokens or Stronghold Cards remains outside this profile.'; - if (g.homeworlds || g.nexusCards || g.leaderSkills || g.discoveries || g.sandtrout) + if (g.homeworlds || g.nexusCards || g.leaderSkills || g.discoveries) return 'Mirror Weapon with combined optional modules is still being integrated.'; return null; } diff --git a/game/reference.ts b/game/reference.ts index f44c5475..d3a84c28 100644 --- a/game/reference.ts +++ b/game/reference.ts @@ -1132,6 +1132,7 @@ export const RULE_TOPICS: RuleTopic[] = [ 'Richese has three No-Fields, numbered zero, three and five. A concealed token counts as one force. Only one may be deployed on Arrakis, and consecutive own or allied shipments cannot use the same token.', 'In Basic play, your own single concealed No-Field may provisionally ship into an ally’s territory if it can legally enter; move it and any paid accompanying forces out before your turn ends. Paid companions require the High Richese Homeworld power. If the marker remains, reveal it and send its newly materialized forces to Tanks under the provisional no-departure policy. A zero marker reveals but contributes no casualties. Existing physical forces and the ally are not part of that new-visitor loss. Paired markers keep their separate guards.', 'A normal No-Field shipment pays the one-force price. The concealed token moves like a force. Before Battle, Richese may reveal it voluntarily; a token involved in battle is revealed with the Battle Plan. Revelation brings the indicated forces from reserves, limited by what remains there.', + 'In supported Basic interruptions, a current-turn history of factual Truthtrance answers does not by itself block your reveal. Live promises and questions about future actions retain their existing safeguards.', 'In supported Basic games the voluntary reveal can also occur while CHOAM decides whether to prevent an already-declared free Revival. Reveal uses current reserves; the original Revival and CHOAM decision then continue once.', 'In supported Basic native games, voluntary revelation is also available during an Ix phase opening or selected auction and market decisions without replacing that decision. Other interruption windows remain unfinished.', 'In supported Basic games, your voluntary reveal can also interrupt a clean Emperor allied spice gift or extra-revival response, Tleilaxu revival-income response, Atreides Movement-phase Spice forecast without Bene Gesserit, or Guild’s own ordinary reserve-shipment rate response when the shipment enters a different territory from the marker. If Richese receives the extra revival, reveal from current reserves before that return. The original response and payment continue once; other interruptions remain guarded.', @@ -1359,7 +1360,10 @@ export const RULE_TOPICS: RuleTopic[] = [ : definition.card.effect === 'semutaDrug' ? 'In the explicit Richese development preview, every seat sees a neutral response to supported clean discards. A CHOAM & Richese game may include the Ix deck: Thumper pauses before worm/spice draw; Amal pauses after halving spice before opening resumes. Other public sources include ordinary cards, paid Box, Ornithopter, Distrans, definite ordinary Truthtrance answers including queued questions, supported shipment promises and battle answers before or after plan submission/reveal, four clean Sapho scopes, pre-leader Residual Poison, printed Karama canceling clean CHOAM Charity, Inflation or Bene Gesserit Charity, a clean printed Karama normal-auction purchase or winning-bid payment before lot settlement, a completed CHOAM card sale after its bank income, clean Kulon Worthless disposal before its movement bonus, proactive or reactive La La La disposal before blocking free revival, proactive or reactive Baliset before restricting movement, proactive Trip to Gamont before its ordinary/elite return or native No-Field reveal and capped recall, accepted Jubba Cloak before storm protection, and three battle batches. A private normal-auction or Black Market Ixian ally replacement also pauses before drawing, without showing its face until a holder commits; original payment and seller income settle once. Cache purchases cannot use native Ixian allied replacement. Ordinary definite Truthtrance answers pause even when another question stays reserved or the answer bound a supported shipment or unsubmitted battle-plan promise. Submitted/revealed plans bind no new promise, but their answers still offer Semuta without changing the plan. Under the user-selected exchange ruling, Commit may replace Semuta even at your faction hand limit: acquisition and Semuta disposal settle atomically, without increasing your completed hand. Reserved incoming cards still need room. For multiple eligible cards, inspect and select exactly one after commitment. Saved effects resume once. Other private discards, Karama uses, other reactive Worthless uses, inspected Residual Poison battles, nested responses, other pending rewards and wider interactions remain unfinished.' : 'Reference component only: this Richese card’s game actions are not enabled.', - ...(definition.card.effect === 'semutaDrug' ? [ + ...(['mirrorWeapon', 'stoneBurner'].includes(definition.card.effect ?? '') ? [ + 'A waiting Sandtrout does not prevent this card in an otherwise supported battle.', + ] : []), + ...(definition.card.effect === 'semutaDrug' ? [ 'In supported Basic Kull and Leader Skills games, with or without Nexus, the original Semuta claim or pass also follows a CHOAM or Ixian Ambassador discard, a clean Terror discard during a Fremen worm ride, or a completed Box search during an unsettled ordinary or Richese cache auction. The original Ambassador effect, worm queue or auction resumes once; other nested interactions remain provisional.', 'In supported Basic Moritani arrivals, Atomics may discard excess cards from Moritani and its ally. Semuta can privately select one card discarded by another player from that fresh batch. Losses, hand limits and Aftermath stay committed; the arrival resumes after claim or pass.', 'In fresh Basic games with Richese, classic opponents, the CHOAM deck and Tech Tokens, the existing Semuta preview is also enabled. Other module combinations remain separate; existing started games are not retrofitted.', @@ -6734,6 +6738,7 @@ export const RULE_TOPICS: RuleTopic[] = [ summary: 'Add two to battle strength while paying three own reserve counters into the Tanks when the physical card is revealed.', steps: [ 'In the independent Ecaz Treachery Cards variant, place your held Reinforcements card in either battle-card slot; it is neither a weapon nor a defense. A category Prescience answer is None, not the name of this card. One physical card cannot fill both slots.', + 'A waiting Sandtrout does not prevent Reinforcements in an otherwise supported battle.', 'Have three own forces in reserves when sealing. Classic/paired Ecaz/Moritani Basic/Advanced, clean selected Ix/CHOAM native/base rosters and explicitly selected native Advanced Occupy prototypes spend ordinary reserves first and then elite reserves, moving exactly three to corresponding Tanks subpools at resolution. These are the actual card holder’s reserves, not the variable ally’s pool; no extra forces arrive.', 'The normal-outcome score gains 2 without adding to the physical dial, spice support or on-board casualties. The card and its reserve cost are consumed even on a Traitor victory, a mutual Traitor result or a Lasgun/Shield explosion; successful Traitor calls still decide the outcome directly.', 'All-outcome payment and reserve transfer counting as battle losses remain provisional, not publisher rulings. The holder chooses an available ordinary/special reserve mix; older sealed plans without a choice retain normal-first payment. Same-plan Harass pays the original three-reserve fee before returns; returned reserves cannot fund it. In native Advanced Occupy, original/copied Stone ignores +2 normal score but still charges the fee. Basic Ecaz/Richese mixed-marker co-sides support the card; unprofiled armies and other card-specific limits remain guarded.', diff --git a/game/richese-reveal-interruption.ts b/game/richese-reveal-interruption.ts index f63ad143..cd10f016 100644 --- a/game/richese-reveal-interruption.ts +++ b/game/richese-reveal-interruption.ts @@ -29,12 +29,16 @@ export function richeseRevealInterruptSupported(g: Game): boolean { g.bureaucratPayments?.pending) return false; // A mixed Truthtrance answer can create a private residual only for some - // hidden facts. Fence the whole public turn's history uniformly before - // examining those ledgers, so this projected availability cannot reveal - // which private branch was required. + // hidden facts. Fence non-fact questions uniformly before examining those + // ledgers, so this projected availability cannot reveal which private branch + // was required. A publicly identified pure fact creates no future residual. // Historical saves without a complete public history retain their existing // interruption behavior; fresh games initialize an explicit empty history. - if (!Array.isArray(g.truthHistory) || g.truthHistory.some(entry => entry.turn === g.turn)) return false; + if (!Array.isArray(g.truthHistory) || g.truthHistory.some(entry => { + if (entry.turn !== g.turn) return false; + const question = entry.question; + return question?.kind !== 'fact' && !(question?.kind === 'freeform' && question.scope === 'fact'); + })) return false; // An ordinary Guild reserve shipment is independent of Richese's reserves // and marker when its destination is in a different territory. Its exact diff --git a/tests/basic-native-mirror-engine.test.ts b/tests/basic-native-mirror-engine.test.ts index 155636fc..ecb5716b 100644 --- a/tests/basic-native-mirror-engine.test.ts +++ b/tests/basic-native-mirror-engine.test.ts @@ -14,8 +14,9 @@ void test('bare Basic E3 and mixed native families admit Mirror without adding o players: (['ecaz', 'ixians', 'choam', 'richese', 'moritani', 'tleilaxu'] as const).map(faction => ({ faction })) } as const; assert.equal(mirrorWeaponModeBlock(native), null); assert.equal(mirrorWeaponModeBlock({ ...native, expansions: ['choam', 'ecaz'] }), null); - for (const selectedModule of ['homeworlds', 'nexusCards', 'leaderSkills', 'discoveries', 'sandtrout'] as const) + for (const selectedModule of ['homeworlds', 'nexusCards', 'leaderSkills', 'discoveries'] as const) assert.ok(mirrorWeaponModeBlock({ ...native, [selectedModule]: true })); + assert.equal(mirrorWeaponModeBlock({ ...native, sandtrout: true }), null); assert.ok(mirrorWeaponModeBlock({ ...native, techTokens: {} })); assert.ok(mirrorWeaponModeBlock({ ...native, expansions: ['choam', 'ecaz'], techTokens: {} })); assert.equal(mirrorWeaponModeBlock({ ...native, expansions: ['choam', 'ecaz'], advanced: true, techTokens: {} }), null); diff --git a/tests/mirror-weapon-waiting-sandtrout.test.ts b/tests/mirror-weapon-waiting-sandtrout.test.ts new file mode 100644 index 00000000..e8a729c5 --- /dev/null +++ b/tests/mirror-weapon-waiting-sandtrout.test.ts @@ -0,0 +1,124 @@ +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 { botActions } from '../game/bots'; +import { DIFFICULTIES } from '../game/bot-profiles'; +import { battlePlanCardOptions } from '../components/battle-preparation'; +import { beforeIxSpiceDraw, orderIxSpiceCards } from './fixture-ix-spice-cards'; +import { advanceSemutaNexusTrade } from './fixture-semuta-nexus-trade'; +import { finishBattleOutcomeWindow } from './fixture-battle-outcome-window'; + +const act = (g: Game, id: string, action: Action) => applyAction(g, id, action); +const seat = (g: Game, id: string) => { const p = g.players.find(row => row.id === id); assert.ok(p); return p; }; +const clean = (g: Game) => !g.response && !g.decision && !g.phaseOpening && !g.truthtrance && !g.pendingTreacheryDiscard; +function inventory(g: Game) { + const ids = [...g.deck, ...g.discard, ...(g.richeseCache ?? []), ...(g.richeseRemoved ?? []), + ...(g.auction?.cards.slice(g.auction.index) ?? []), ...(g.ixAuction?.cards ?? []), + ...g.players.flatMap(player => player.hand)].map(card => card.id).sort(); + assert.equal(new Set(ids).size, ids.length); return ids; +} + +/** Genuine Basic public setup and native first Spice Blow. Only unopened Spice + * order, physical board counters and held card locations are staged. */ +function fixture(kind: 'mirrorWeapon' | 'stoneBurner' = 'mirrorWeapon') { + let g = createGame('WAITINGMIRROR', newPlayer('p', 'Emperor', 'emperor'), false, ['ix', 'choam']); + joinGame(g, newPlayer('q', 'Guild', 'guild')); + joinGame(g, newPlayer('r', 'Richese', 'richese')); + for (const player of g.players) g = act(g, player.id, {type:'ready'}); + g = act(g, 'p', {type:'start'}); + g = advanceSemutaNexusTrade(g, state => state.status === 'playing'); + const cards = inventory(g); + g = advanceSemutaNexusTrade(g, beforeIxSpiceDraw); + orderIxSpiceCards(g, ['sandtrout', 'land']); + g = advanceSemutaNexusTrade(g, state => state.phase === 5 && clean(state)); + assert.equal(g.sandtrout, true); + assert.ok(g.log.some(entry => String(entry.text ?? '').includes('Sandtrout'))); + const position = g.storm === 5 ? {territory:'hagga_basin', sector:12} : {territory:'pasty_mesa', sector:5}; + for (const player of g.players) { + player.reserves += Object.values(player.forces).reduce((sum, amount) => sum + amount, 0); + player.forces = {}; + } + for (const id of ['p', 'q']) { seat(g, id).reserves -= 5; seat(g, id).forces[`${position.territory}:${position.sector}`] = 5; } + g = advanceSemutaNexusTrade(g, state => state.phase === 6 && clean(state)); + const choice = viewGame(g, g.active!).battleChoices.find(row => row.territory === position.territory); + assert.ok(choice); + g = act(g, choice.chooser, {type:'chooseBattle', territory:position.territory, + target:choice.chooser === choice.attacker ? choice.defender : choice.attacker}); + g = advanceSemutaNexusTrade(g, state => !!state.battle && !state.battle.preparation && + state.battle.preLeader?.closed !== false && clean(state)); + const place = (id: string, wanted: (card: Game['deck'][number]) => boolean) => { + const player = seat(g, id); + let card: Game['deck'][number] | undefined; + const cache = g.richeseCache?.findIndex(wanted) ?? -1; + if (cache >= 0) card = g.richeseCache!.splice(cache, 1)[0]; + else { + const fromDeck = g.deck.findIndex(wanted); + if (fromDeck >= 0) card = g.deck.splice(fromDeck, 1)[0]; + else { + const fromDiscard = g.discard.findIndex(wanted); + if (fromDiscard >= 0) card = g.discard.splice(fromDiscard, 1)[0]; + else { + const holder = g.players.find(row => row.hand.some(wanted)); assert.ok(holder); + card = holder.hand.splice(holder.hand.findIndex(wanted), 1)[0]; + } + } + } + assert.ok(card); + if (player.hand.length >= 4) g.deck.push(player.hand.shift()!); + player.hand.push(card); return card.id; + }; + const weapon = place('p', card => card.effect === kind); + const projectile = place('q', card => card.kind === 'projectile'); + assert.deepEqual(inventory(g), cards); + return { g, weapon, projectile, cards }; +} + +void test('waiting Sandtrout does not stop a physical Mirror from copying an ordinary attack', () => { + const f = fixture(), view = viewGame(f.g, 'p'); + assert.equal(f.g.sandtrout, true); + const mirror = seat(f.g, 'p').hand.find(card => card.id === f.weapon)!; + const options = battlePlanCardOptions(view, 'weapon', seat(f.g, 'p').leaders[0].id, '', ''); + assert.ok(options.some(option => option.id === mirror.id)); + for (const difficulty of DIFFICULTIES) { + const botView = viewGame(f.g, 'p'); botView.players.find(p => p.id === 'p')!.bot = difficulty; + const action = botActions(botView).find(row => row.type === 'battlePlan' && row.weapon === f.weapon); + assert.ok(action, difficulty); assert.doesNotThrow(() => act(f.g, 'p', action)); + } + let g = act(f.g, 'p', {type:'battlePlan', dial:2, support:0, + leader:seat(f.g, 'p').leaders[0].id, weapon:f.weapon}); + g = act(g, 'q', {type:'battlePlan', dial:2, support:0, + leader:seat(g, 'q').leaders[0].id, weapon:f.projectile}); + assert.equal(g.battle?.revealed, true); + for (const id of ['q', 'p']) g = act(g, id, {type:'traitorCall', call:false}); + g = finishBattleOutcomeWindow(g); + assert.equal(seat(g, 'p').leaders[0].dead, true); + assert.equal(seat(g, 'q').leaders[0].dead, true); + assert.ok(g.lastBattleContext?.winner); + assert.equal(g.sandtrout, true); + assert.deepEqual(inventory(g), f.cards); +}); + +void test('waiting Sandtrout does not stop Stone Burner from resolving an ordinary battle', () => { + const f = fixture('stoneBurner'), view = viewGame(f.g, 'p'); + assert.equal(f.g.sandtrout, true); + assert.ok(battlePlanCardOptions(view, 'weapon', seat(f.g, 'p').leaders[0].id, '', '') + .some(card => card.id === f.weapon)); + for (const difficulty of DIFFICULTIES) { + const botView = viewGame(f.g, 'p'); botView.players.find(p => p.id === 'p')!.bot = difficulty; + const action = botActions(botView).find(row => row.type === 'battlePlan' && row.weapon === f.weapon); + assert.ok(action, difficulty); assert.doesNotThrow(() => act(f.g, 'p', action)); + } + let g = act(f.g, 'p', {type:'battlePlan', dial:1, support:0, + leader:seat(f.g, 'p').leaders[0].id, weapon:f.weapon}); + g = act(g, 'q', {type:'battlePlan', dial:2, support:0, + leader:seat(g, 'q').leaders[0].id, weapon:f.projectile}); + assert.equal(g.decision?.kind, 'stoneBurner'); + g = act(g, 'p', {type:'decision', event:g.battle!.event, mode:'kill'}); + for (const id of ['q', 'p']) g = act(g, id, {type:'traitorCall', call:false}); + g = finishBattleOutcomeWindow(g); + assert.equal(seat(g, 'p').leaders[0].dead, true); + assert.equal(seat(g, 'q').leaders[0].dead, true); + assert.equal(g.lastBattleContext?.winner, 'p'); + assert.equal(g.sandtrout, true); + assert.deepEqual(inventory(g), f.cards); +}); diff --git a/tests/reinforcements-engine.test.ts b/tests/reinforcements-engine.test.ts index 68d9249b..61090274 100644 --- a/tests/reinforcements-engine.test.ts +++ b/tests/reinforcements-engine.test.ts @@ -46,7 +46,8 @@ void test('Reinforcements consumes exactly three own normal reserves in either c for (const advanced of [false, true]) for (const slot of ['weapon', 'defense'] as const) { const start = fixture(advanced); const owner = viewGame(start, 'a'); - assert.deepEqual(owner.battle?.reinforcements, { blocked: null, normal: 3, elite: 0 }); + assert.deepEqual(owner.battle?.reinforcements, { blocked: null, normal: 3, elite: 0, + eliteOptions: advanced ? [0, 1, 2, 3] : [0] }); assert.equal(viewGame(start, 'd').battle?.reinforcements, null); assert.equal(viewGame(start, 't').battle?.reinforcements, null); const privatePlan = applyAction(start, 'a', { @@ -75,7 +76,7 @@ void test('paired Ecaz/Moritani battles spend one physical Reinforcements cost w let g = harassWithdrawGame({ advanced, factions: [owner, owner === 'ecaz' ? 'moritani' : 'ecaz', 'atreides'] }); takeHarassCard(g, 'a', cardId); harassCustody(g); - assert.deepEqual(viewGame(g, 'a').battle?.reinforcements, { blocked: null, normal: 3, elite: 0 }); + assert.deepEqual(viewGame(g, 'a').battle?.reinforcements, { blocked: null, normal: 3, elite: 0, eliteOptions: [0] }); assert.equal(viewGame(g, 'd').battle?.reinforcements, null); g = applyAction(JSON.parse(JSON.stringify(g)) as Game, 'a', { type: 'battlePlan', dial: 1, support: advanced ? 1 : 0, @@ -129,7 +130,7 @@ void test('Reinforcements normal-first cost preserves elite subpool and is paid p.elites!.reserves = 2; p.elites!.tanks = 3; harassCustody(g); - assert.deepEqual(viewGame(g, 'a').battle?.reinforcements, { blocked: null, normal: 1, elite: 2 }); + assert.deepEqual(viewGame(g, 'a').battle?.reinforcements, { blocked: null, normal: 1, elite: 2, eliteOptions: [2] }); // Give Atreides the Emperor's selected leader as a real traitor, preserving the deck's identities. const target = 'emperor-0'; const old = g.players[1].traitors[0]; @@ -146,7 +147,7 @@ void test('Reinforcements normal-first cost preserves elite subpool and is paid assert.equal(done.discard.filter(c => c.id === cardId).length, 1); }); -void test('insufficient reserves and unsupported modules reject without mutating the original game', () => { +void test('insufficient reserves reject without mutating the original game', () => { const g = fixture(true); const p = g.players[0]; p.reserves = 2; @@ -156,11 +157,4 @@ void test('insufficient reserves and unsupported modules reject without mutating harassCustody(g); assert.match(viewGame(g, 'a').battle!.reinforcements!.blocked!, /three physical forces/); reject(g, 'a', { type: 'battlePlan', dial: 1, leader: 'emperor-0', weapon: cardId }, /three own forces/); - p.reserves = 15; - p.tanks = 0; - p.elites!.reserves = 5; - p.elites!.tanks = 0; - g.sandtrout = {} as Game['sandtrout']; - assert.throws(() => applyAction(g, 'a', - { type: 'battlePlan', dial: 1, leader: 'emperor-0', weapon: cardId }), RuleError); }); diff --git a/tests/reinforcements-waiting-sandtrout.test.ts b/tests/reinforcements-waiting-sandtrout.test.ts new file mode 100644 index 00000000..ed5a50c0 --- /dev/null +++ b/tests/reinforcements-waiting-sandtrout.test.ts @@ -0,0 +1,94 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import { applyAction, createGame, joinGame, newPlayer, viewGame, type Game, type Action } from '../game/engine'; +import { botActions } from '../game/bots'; +import { DIFFICULTIES } from '../game/bot-profiles'; +import { beforeIxSpiceDraw, orderIxSpiceCards } from './fixture-ix-spice-cards'; +import { advanceSemutaNexusTrade, nextSemutaNexusTradeNativeStep } from './fixture-semuta-nexus-trade'; + +const act = (g: Game, actor: string, action: Action) => applyAction(g, actor, action); +const seat = (g: Game, actor: string) => { const p = g.players.find(row => row.id === actor); assert.ok(p); return p; }; +const cards = (g: Game) => [...g.deck, ...g.discard, ...(g.auction?.cards.slice(g.auction.index) ?? []), + ...(g.ixAuction?.cards ?? []), ...g.players.flatMap(p => p.hand)].map(c => c.id).sort(); +const clean = (g: Game) => !g.response && !g.phaseOpening && !g.decision && !g.truthtrance && !g.pendingTreacheryDiscard; + +/** Real public Basic setup and Sandtrout draw. The unopened Spice prefix, + * later armies and one physical battle card are deliberately staged. */ +function fixture() { + let g = createGame('REINFORCEMENTSTROUT', newPlayer('a', 'Atreides', 'atreides'), false, ['ix']); + joinGame(g, newPlayer('e', 'Emperor', 'emperor')); + joinGame(g, newPlayer('g', 'Guild', 'guild')); + g = act(g, 'a', { type: 'moduleOption', module: 'ecazTreachery', enabled: true }); + for (const p of g.players) g = act(g, p.id, { type: 'ready' }); + g = act(g, 'a', { type: 'start' }); + g = advanceSemutaNexusTrade(g, state => state.status === 'playing'); + const inventory = cards(g); + g = advanceSemutaNexusTrade(g, beforeIxSpiceDraw); + orderIxSpiceCards(g, ['sandtrout', 'land', 'land']); + g = advanceSemutaNexusTrade(g, state => state.turn === 1 && state.phase === 5 && clean(state)); + assert.equal(g.sandtrout, true); + assert.ok(g.log.some(row => row.text.includes('Sandtrout broke all alliances'))); + assert.ok(g.players.every(p => p.ally === null)); + const territory = g.storm === 10 ? 'carthag' : 'arrakeen'; + const sector = territory === 'arrakeen' ? 10 : 11, location = `${territory}:${sector}`; + for (const p of g.players) { + p.reserves += Object.values(p.forces).reduce((sum, n) => sum + n, 0); + p.forces = {}; + } + for (const [id, amount] of [['a', 4], ['e', 2]] as const) { + const p = seat(g, id); p.reserves -= amount; p.forces[location] = amount; + } + const id = 'ecaz-reinforcements'; + const holder = g.players.find(p => p.hand.some(c => c.id === id)); + let card; + if (holder) card = holder.hand.splice(holder.hand.findIndex(c => c.id === id), 1)[0]; + else { + const pile = [g.deck, g.discard].find(source => source.some(c => c.id === id)); assert.ok(pile); + card = pile.splice(pile.findIndex(c => c.id === id), 1)[0]; + } + const owner = seat(g, 'a'); + if (owner.hand.length >= 4) g.deck.push(owner.hand.shift()!); + owner.hand.push(card); + assert.deepEqual(cards(g), inventory); + g = advanceSemutaNexusTrade(g, state => state.turn === 1 && state.phase === 6 && !state.battle && clean(state)); + const choice = viewGame(g, g.active!).battleChoices.find(row => row.territory === territory); assert.ok(choice); + g = act(g, choice.chooser, { type: 'chooseBattle', territory, + target: choice.chooser === choice.attacker ? choice.defender : choice.attacker }); + for (let n = 0; n < 100 && (!g.battle || g.battle.preparation || g.battle.preLeader?.closed === false || !clean(g)); n++) { + const step = nextSemutaNexusTradeNativeStep(g); g = act(g, step.actor, step.action); + } + assert.ok(g.battle && !g.battle.revealed && clean(g)); + assert.equal(g.sandtrout, true); + return { g, inventory, location }; +} + +for (const slot of ['weapon', 'defense'] as const) void test( + `Basic Reinforcements in the ${slot} slot remains usable while genuine Sandtrout waits`, () => { + const f = fixture(), before = structuredClone(f.g), owner = seat(f.g, 'a'), opponent = seat(f.g, 'e'); + const quote = viewGame(f.g, 'a').battle?.reinforcements; + assert.ok(quote); assert.equal(quote.blocked, null); assert.equal(quote.normal, 3); + for (const difficulty of DIFFICULTIES) { + const view = viewGame(f.g, 'a'); view.players.find(p => p.id === 'a')!.bot = difficulty; + const action = botActions(view).find(row => row.type === 'battlePlan'); assert.ok(action, difficulty); + assert.doesNotThrow(() => act(f.g, 'a', action), difficulty); + } + const ourLeader = owner.leaders.find(l => !l.dead && !l.usedAt); assert.ok(ourLeader); + const enemyLeader = opponent.leaders.find(l => !l.dead && !l.usedAt); assert.ok(enemyLeader); + let g = act(f.g, 'a', { type:'battlePlan', dial: 1, support: 0, leader:ourLeader.id, + weapon:slot === 'weapon' ? 'ecaz-reinforcements' : null, + defense:slot === 'defense' ? 'ecaz-reinforcements' : null }); + assert.deepEqual(f.g, before); + assert.equal(viewGame(g, 'e').battle!.plans.a, undefined); + g = act(g, 'e', { type:'battlePlan', dial:0, support:0, leader:enemyLeader.id }); + assert.equal(g.battle?.revealed, true); + for (let n = 0; n < 160 && (g.battle || !clean(g)); n++) { + const step = nextSemutaNexusTradeNativeStep(g); g = act(g, step.actor, step.action); + } + assert.equal(g.battle, null); assert.equal(g.sandtrout, true); + assert.equal(seat(g, 'a').reserves, owner.reserves - 3); + assert.ok(seat(g, 'a').tanks >= owner.tanks + 3); + assert.equal(g.discard.filter(c => c.id === 'ecaz-reinforcements').length, 1); + assert.deepEqual(cards(g), f.inventory); + for (const p of g.players) assert.equal(p.reserves + p.tanks + Object.values(p.forces).reduce((a,b) => a+b,0), 20); + }, +); diff --git a/tests/richese-reveal-after-fact.test.ts b/tests/richese-reveal-after-fact.test.ts new file mode 100644 index 00000000..285d83fb --- /dev/null +++ b/tests/richese-reveal-after-fact.test.ts @@ -0,0 +1,173 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import { createGame, joinGame, newPlayer, viewGame, type Game } from '../game/engine'; +import { botActions } from '../game/bots'; +import { DIFFICULTIES } from '../game/bot-profiles'; +import { richeseRevealInterruptSupported } from '../game/richese-reveal-interruption'; +import { actTruthMovementNativeEarly as act, nextTruthMovementNativeEarlyStep } from './fixture-truth-movement-native-early'; +import { truthMovementInventory as inventory } from './fixture-truth-movement'; + +const richese = 'richese', guild = 'guild', atreides = 'atreides'; +function player(game: Game, id: string) { + const seat = game.players.find(row => row.id === id); assert.ok(seat); return seat; +} +const clean = (game: Game) => !game.response && !game.decision && !game.phaseOpening && + !game.truthtrance && !game.pendingTreacheryDiscard; + +/** Original public Basic setup and native actions. Only an actual Truthtrance's + * held location and the order of unopened Spice cards are staged. */ +type QuestionMode = 'fact' | 'knownFreeform' | 'unknownFreeform' | 'future'; +function source(answer: 'yes' | 'no', mode: QuestionMode = 'fact') { + let game = createGame('REVEALAFTERFACT', newPlayer(richese, 'Richese', 'richese'), false, ['choam']); + joinGame(game, newPlayer(guild, 'Guild', 'guild')); + joinGame(game, newPlayer(atreides, 'Atreides', 'atreides')); + for (const seat of game.players) game = act(game, seat.id, { type: 'ready' }); + game = act(game, game.host, { type: 'start' }); + const reach = (until: (state: Game) => boolean) => { + for (let count = 0; count < 2000; count++) { + if (until(game)) return; + assert.notEqual(game.status, 'finished'); + const step = nextTruthMovementNativeEarlyStep(game, { + position: 'first', method: 'onceAround', direction: 'clockwise', keepUnbid: false, + }); + assert.ok(step, `Missing native action at ${game.turn}/${game.phase}/${game.decision?.kind}`); + game = act(game, step.actor, step.action); + } + throw Error('The genuine Basic parent was not reached'); + }; + reach(state => state.status === 'playing'); + const original = inventory(game); + for (const position of [0, 1]) { + const from = game.spiceDeck.findIndex((card, i) => i >= position && 'territory' in card && !card.discovery); + assert.ok(from >= position); [game.spiceDeck[position], game.spiceDeck[from]] = [game.spiceDeck[from], game.spiceDeck[position]]; + } + reach(state => state.turn === 1 && state.phase === 5 && state.active === richese && clean(state)); + const owner = player(game, richese), marker = owner.noField!.tokens.find(token => token.value === 3); + assert.ok(marker); assert.ok(owner.noFieldEvent); + game = act(game, richese, { type: 'ship', noField: marker.id, event: owner.noFieldEvent, + territory: 'polar_sink', sector: 0, allyPayment: 0 }); + reach(clean); + const asker = player(game, atreides); + let truth = asker.hand.find(card => card.effect === 'truthtrance'); + if (!truth) { + const held = game.players.find(seat => seat.id !== atreides && seat.hand.some(card => card.effect === 'truthtrance')); + if (held) { + const from = held.hand.findIndex(card => card.effect === 'truthtrance'); + truth = held.hand.splice(from, 1)[0]; + const replacement = asker.hand.pop(); + if (replacement) held.hand.push(replacement); + } else { + const from = game.deck.findIndex(card => card.effect === 'truthtrance'); assert.ok(from >= 0); + truth = game.deck.splice(from, 1)[0]; + if (asker.hand.length >= 4) game.deck.push(asker.hand.pop()!); + } + asker.hand.push(truth); + } + // Avoid creating a separate simultaneous Truthtrance order question. + for (const seat of game.players.filter(row => row.id !== atreides)) { + for (let i = seat.hand.length - 1; i >= 0; i--) if (seat.hand[i].effect === 'truthtrance') { + game.deck.push(...seat.hand.splice(i, 1)); + const replacement = game.deck.findIndex(card => card.effect !== 'truthtrance'); + assert.ok(replacement >= 0); seat.hand.push(game.deck.splice(replacement, 1)[0]); + } + } + assert.deepEqual(inventory(game), original); + game = act(game, atreides, { type: 'card', card: truth.id }); + while (game.truthtrance?.stage === 'priority') { + const seat = game.players.find(row => !game.truthtrance!.passed.includes(row.id)); assert.ok(seat); + game = act(game, seat.id, { type: 'truthPass' }); + } + assert.equal(game.truthtrance?.stage, 'ask'); + const fact = { kind: 'spice', compare: 'gte', value: answer === 'yes' ? 0 : Number.MAX_SAFE_INTEGER } as const; + const question = mode === 'future' + ? { kind: 'freeform', scope: 'currentTurn', target: guild, text: 'Will you ship six forces later this turn?' } + : mode === 'knownFreeform' + ? { kind: 'freeform', scope: 'fact', target: guild, text: `Do you have at least ${fact.value} spice?` } + : mode === 'unknownFreeform' + ? { kind: 'freeform', scope: 'fact', target: guild, text: 'Are you thinking of a sandworm right now?' } + : { kind: 'fact', target: guild, fact }; + game = act(game, atreides, { type: 'truthAsk', question }); + if (mode === 'fact' || mode === 'knownFreeform') assert.equal(viewGame(game, guild).truthAnswer, answer); + if (mode === 'unknownFreeform') assert.equal(viewGame(game, guild).truthAnswer, null); + game = act(game, guild, { type: 'truthAnswer', answer }); + reach(clean); + assert.equal(game.truthHistory!.at(-1)!.question.kind, mode === 'fact' ? 'fact' : 'freeform'); + assert.equal(game.truthHistory!.at(-1)!.answer, answer); + assert.deepEqual(inventory(game), original); + // A real held Karama keeps the Guild-rate response open for inspection. + if (!player(game, atreides).hand.some(card => card.effect === 'karama')) { + const holder = game.players.find(seat => seat.id !== atreides && seat.hand.some(card => card.effect === 'karama')); + const from = holder ? holder.hand : game.deck; + const index = from.findIndex(card => card.effect === 'karama'); assert.ok(index >= 0); + const card = from.splice(index, 1)[0]; + if (player(game, atreides).hand.length >= 4) from.push(player(game, atreides).hand.pop()!); + player(game, atreides).hand.push(card); + } + assert.deepEqual(inventory(game), original); + game = act(game, richese, { type: 'endMovement' }); + reach(state => state.phase === 5 && state.active === guild && clean(state) && !player(state, guild).shipped); + const event = player(game, richese).noFieldEvent; assert.ok(event); + game = act(game, guild, { type: 'ship', territory: 'arrakeen', sector: 10, amount: 3, allyPayment: 0 }); + assert.equal(game.response?.kind, 'guildRate'); assert.equal(game.pendingShipment?.player, guild); + return { game, event, marker: marker.id, original }; +} + +for (const answer of ['yes', 'no'] as const) void test( + `A public current-fact Truthtrance ${answer} allows Richese to reveal while Guild's original rate is pending`, () => { + const { game, event, marker, original } = source(answer), before = structuredClone(game); + assert.equal(viewGame(game, richese).richeseNoField?.canReveal, true); + const next = act(game, richese, { type: 'revealNoField', token: marker, event }); + assert.deepEqual(game, before); + assert.deepEqual(next.response, before.response); assert.deepEqual(next.pendingShipment, before.pendingShipment); + assert.deepEqual(next.truthHistory, before.truthHistory); + assert.equal(player(next, richese).noField?.deployed, null); + assert.equal(player(next, richese).forces['polar_sink:0'], 3); + assert.deepEqual(inventory(next), original); + let done = next; + for (let count = 0; done.response?.kind === 'guildRate' && count < done.players.length; count++) { + const seat = done.players.find(row => !done.response!.passed.includes(row.id)); assert.ok(seat); + done = act(done, seat.id, { type: 'passResponse' }); + } + assert.equal(done.pendingShipment, null); assert.equal(player(done, guild).forces['arrakeen:10'], 3); + assert.deepEqual(inventory(done), original); + }, +); + +void test('all four bot profiles can respond to the original rate after a factual answer and reveal', () => { + const { game, event, marker } = source('yes'); + const revealed = act(game, richese, { type: 'revealNoField', token: marker, event }); + for (const difficulty of DIFFICULTIES) { + const view = viewGame(revealed, atreides); view.players.find(seat => seat.id === atreides)!.bot = difficulty; + const action = botActions(view)[0]; assert.ok(action, difficulty); + assert.doesNotThrow(() => act(revealed, atreides, action), difficulty); + } +}); + +void test('a real current-turn freeform promise retains the public history fence', () => { + const { game, event, marker } = source('no', 'future'), before = structuredClone(game); + assert.equal(game.truthHistory!.at(-1)!.question.kind, 'freeform'); + assert.equal(richeseRevealInterruptSupported(game), false); + assert.equal(viewGame(game, richese).richeseNoField?.canReveal, false); + assert.throws(() => act(game, richese, { type: 'revealNoField', token: marker, event })); + assert.deepEqual(game, before); +}); + +for (const mode of ['knownFreeform', 'unknownFreeform'] as const) + for (const answer of ['yes', 'no'] as const) void test( + `A ${mode === 'knownFreeform' ? 'recognized' : 'unrecognized'} current-fact freeform ${answer} retains the reveal and Guild-rate continuation`, () => { + const { game, event, marker, original } = source(answer, mode); + const record = game.truthHistory!.at(-1)!; + assert.ok(record.question.kind === 'freeform'); + assert.equal(record.question.scope, 'fact'); + assert.equal(!!record.question.interpreted, mode === 'knownFreeform'); + assert.equal(viewGame(game, richese).richeseNoField?.canReveal, true); + let next = act(game, richese, { type: 'revealNoField', token: marker, event }); + assert.deepEqual(next.response, game.response); assert.deepEqual(next.pendingShipment, game.pendingShipment); + while (next.response?.kind === 'guildRate') { + const seat = next.players.find(row => !next.response!.passed.includes(row.id)); assert.ok(seat); + next = act(next, seat.id, { type: 'passResponse' }); + } + assert.equal(next.pendingShipment, null); assert.equal(player(next, guild).forces['arrakeen:10'], 3); + assert.deepEqual(inventory(next), original); + }, + );