diff --git a/components/recruits.tsx b/components/recruits.tsx index aae98083..53e75eae 100644 --- a/components/recruits.tsx +++ b/components/recruits.tsx @@ -14,17 +14,18 @@ export function Recruits({ game, act, busy }: { if (!offer || game.status !== 'playing' || game.phase !== 4 || (!offer.active && !offer.play)) return null; const action = recruitsPlayAction(offer); + const plays = offer.active ? offer.plays ?? 1 : 0; return (

Recruits{offer.active ? ' · Active this turn' : ''}

{offer.active - ? 'Free revival rates are doubled for this turn. The ordinary force limit is seven; factions with unlimited revival keep that advantage.' + ? `Recruits has been played ${plays} ${plays === 1 ? 'time' : 'times'} this turn. Each play doubles the current free revival rates. The ordinary force limit is seven; factions with unlimited revival keep that advantage. Current rates are shown below.` : 'Play this card to double every faction’s free revival rate and raise the ordinary force limit to seven for this turn. Factions with unlimited revival keep that advantage.'}

Already completed revivals still count. Paid forces retain their normal prices, and special-force revival limits still apply.

Provisional late-play accounting: prior paid revivals keep their payments and count toward the total force limit, but only recorded free returns consume the doubled free allowance. No refund or retroactive reclassification. This is a first-version policy, not a publisher clarification or numerical user ruling.

- {game.homeworlds &&

Provisional current-rate composition: double the native free rate including its low-population bonus, capped by the seven-force total. Later separate requests recheck population and recorded free use; accepted returns keep their price. Normal and special counters retain native destinations and special-force limits.

} + {game.homeworlds &&

Provisional current-rate composition: each use doubles the native free rate including its low-population bonus, subject to the faction’s force limit. Later separate requests recheck population and recorded free use; accepted returns keep their price. Normal and special counters retain native destinations and special-force limits.

} @@ -42,7 +43,7 @@ export function Recruits({ game, act, busy }: { )} diff --git a/docs/BRIBE_CONTROLS.md b/docs/BRIBE_CONTROLS.md index 0fbe1751..9a48e311 100644 --- a/docs/BRIBE_CONTROLS.md +++ b/docs/BRIBE_CONTROLS.md @@ -1,5 +1,18 @@ # Ordinary bribe controls +## Basic worm ride and winner-card decisions — 16 November 2026 + +**Prototyped / Partial.** In supported clean Basic classic and selected native +faction profiles, a direct nonallied bribe may interrupt an original Fremen +worm-ride decision or a winner's optional battle-card retention decision. The +original decision, physical forces or cards, ride queue and original +continuation stay in place; recipient spice remains deferred to Mentat. +Uncommitted-spice and existing promise restrictions still apply. Optional +modules, competing pending transactions and other decision families remain +outside this initial scope. This digital interruption order is provisional, +not a publisher timing ruling. Runtime tests use a native worm ride and a +separate native battle, with one conserved shield swap for the latter. + ## Basic bribe with waiting Sandtrout — 16 November 2026 **Prototyped / Partial.** A waiting Sandtrout no longer blocks the existing diff --git a/docs/CURRENT_STATUS.md b/docs/CURRENT_STATUS.md index 8417ac7a..121a3553 100644 --- a/docs/CURRENT_STATUS.md +++ b/docs/CURRENT_STATUS.md @@ -17,6 +17,20 @@ open mode gates. ## Current checkpoint and work +**Bribes during worm rides and winner-card decisions — 16 November. +Prototyped / Partial.** Supported clean Basic games can pay a direct ordinary +bribe while a Fremen worm ride or winner card-retention decision waits; the +original decision and deferred recipient ledger remain intact. Other pending +decision families, optional modules, full games and deployment remain open. +[Scope](BRIBE_CONTROLS.md#basic-worm-ride-and-winner-card-decisions--16-november-2026). + +**Recovered Recruits replay — 16 November. Prototyped / Partial.** A player +who legally recovers the physical card can play it again in the same Revival; +each use provisionally doubles the current free rate again within the native +force limit. Semuta, earlier payments and the shared controls remain connected. +Other recovery routes, combinations, complete games and deployment remain open. +[Scope](RECRUITS_RUNTIME.md#replaying-a-recovered-card--16-november-2026). + **Current battle-choice Truthtrance and persistent notices — 16 November. Prototyped / Partial.** Supported combined current-turn questions can bind the current native battle chooser to a specific legal territory and opponent, with diff --git a/docs/RECRUITS_RUNTIME.md b/docs/RECRUITS_RUNTIME.md index 5219f248..87cbfe1d 100644 --- a/docs/RECRUITS_RUNTIME.md +++ b/docs/RECRUITS_RUNTIME.md @@ -6,6 +6,22 @@ Advanced faction setup. All three physical cards are present exactly once. Recruits, bounded Reinforcements and Harass & Withdraw have connected controls, AI and saved continuation; full interactions and publication remain gated. +## Replaying a recovered card — 16 November 2026 + +**Prototyped / Partial.** The actual Recruits card may be played again in the +same Revival after a legal recovery. Each physical play is discarded and uses +its own ordinary Semuta continuation when available. The latest player and a +public play count are recorded; older receipts without a count mean one play. + +The printed card does not identify a same-turn replay limit. As a provisional +interpretation of its doubling instruction, each additional play doubles the +current native free rate again, subject to the existing seven-force ordinary +limit and unlimited-faction rules. Previous returns and payments are preserved. +The connected Basic runtime fixture uses genuine auctions, Storm casualties, +Semuta recovery by another faction, a second play and an actual free return. +Other recovery routes, wider combinations, complete games and deployment remain +open. This is not a publisher ruling on multiple uses. + ## Native Fremen grant after play — 24 October 2026 The earlier later-grant guard is replaced by the symmetric current-rate @@ -43,7 +59,8 @@ user ruling or a newly retrieved publisher answer. Thus Atreides' actual two-free/one-paid return retains its two-spice payment and three total returns; after Recruits it may take two additional free forces under the seven total cap. Missing or inconsistent free-use ledgers, -pending declarations, unrelated later rate changes and same-turn replay remain guarded. +pending declarations and unrelated later rate changes remain guarded; same-turn +replay is now covered by the newer section above. The owned before-play panel and public active panel name this interpretation. Basic/Advanced before/after native smokes use a genuinely dealt card, an @@ -126,8 +143,8 @@ source review. No newly retrieved late-paid ruling is claimed. The scope permits activation before returns or after consistently recorded free/paid normal returns, once priority windows and transactions finish. -Unknown legacy usage, unrelated late-rate changes, same-turn replay after recovery -and other optional modules remain guarded, apart from clean classic Homeworlds +Unknown legacy usage, unrelated late-rate changes and other optional modules +remain guarded, apart from clean classic Homeworlds above or the separate clean classic/Ix/CHOAM [Tech/Advanced Stronghold composition](ECAZ_TREACHERY_RULES.md#original-phase-module-composition--16-october-2026). These are boundaries, not printed timing rules. diff --git a/docs/RULE_DECISIONS.md b/docs/RULE_DECISIONS.md index 98253997..9ac72224 100644 --- a/docs/RULE_DECISIONS.md +++ b/docs/RULE_DECISIONS.md @@ -1,5 +1,21 @@ # Rule decision index +## Bribes during worm rides and winner-card decisions — 16 November 2026 + +The existing provisional digital ordering for ordinary nonallied bribes now +includes supported clean Basic Fremen worm-ride and winner-card retention +decisions. The base rules p. 12 and November 2020 FAQ p. 9 establish bribes and +their deferred collection, not this online interruption priority. +[Scope](BRIBE_CONTROLS.md#basic-worm-ride-and-winner-card-decisions--16-november-2026). + +## Replaying Recruits — 16 November 2026 + +The printed Recruits effect gives no identified same-turn replay restriction. +When the physical card is legally recovered, a further play provisionally +doubles the current free rate again while retaining the normal total cap and +prior payments. This is an online composition, not a publisher ruling on +multiple uses. [Scope](RECRUITS_RUNTIME.md#replaying-a-recovered-card--16-november-2026). + ## Sapho and Great Maker voting — 16 November 2026 The printed first/last ordered-action effect extends to unanswered Great Maker diff --git a/game/engine.ts b/game/engine.ts index 3d1ea535..da1a4b6a 100644 --- a/game/engine.ts +++ b/game/engine.ts @@ -2959,6 +2959,8 @@ export type Game = { turn: number; player: string; card: typeof RECRUITS_CARD_ID; + /** Omitted by original receipts, which represent one play. */ + uses?: number; } | null; emperorExtra: Record; aid: Record; @@ -18273,6 +18275,18 @@ function basicBribeInterrupt(g: Game, p: Player): boolean { if (nativeRoster && !g.phaseOpening && !g.choamMarket && !g.ixAuction && !Object.entries(g).some(([key, value]) => key.startsWith('pending') && (Array.isArray(value) ? value.length > 0 : value !== null && value !== undefined && value !== false))) { + if (g.decision?.kind === 'wormRide' && !g.response && g.phase === 1) { + const rider = g.players.find(seat => seat.id === g.decision?.player); + const territory = g.decision.territory; + return rider?.faction === 'fremen' && Object.entries(rider.forces).some(([key, count]) => + count > 0 && splitLocation(key).territory === territory && splitLocation(key).sector !== g.storm); + } + if (g.decision?.kind === 'battleCards' && !g.response && g.phase === 6) { + const decision = g.decision, winner = g.players.find(seat => seat.id === decision.player); + return !!winner && g.lastBattleContext?.winner === winner.id && + g.lastBattleContext.territory === decision.territory && decision.cards.length > 0 && + decision.cards.every(card => winner.hand.some(held => held.id === card)); + } if (g.decision?.kind === 'auctionPayment' && !g.response) return g.phase === 3 && !!g.auction && !g.richeseAuction && !g.currentAuctionSale && g.auction.bidder === g.decision.player && !!g.auction.cards[g.auction.index]; @@ -20749,9 +20763,10 @@ function ecazTreacheryIntegrity(g: Game) { } if (g.recruits) { requireRule( - Object.keys(g.recruits).sort().join(',') === 'card,player,turn' && + ['card,player,turn', 'card,player,turn,uses'].includes(Object.keys(g.recruits).sort().join(',')) && g.recruits.card === RECRUITS_CARD_ID && g.recruits.turn === g.turn && + (g.recruits.uses === undefined || Number.isSafeInteger(g.recruits.uses) && g.recruits.uses >= 1) && g.players.some((player) => player.id === g.recruits!.player), 'The Recruits effect has a malformed or expired receipt.', ); @@ -20888,8 +20903,8 @@ function recruitsPlayBlock(g: Game, owner: Player, card: Card): string | null { return 'Recruits requires a supported independent-card profile: faction-only, all14 Skills with original World/phase modules, or existing native Homeworld compositions.'; if (g.status !== 'playing' || g.phase !== 4) return 'Play Recruits during Revival.'; - if (g.recruits?.turn === g.turn) - return 'Recruits is already active this turn; a recovered copy cannot be played again.'; + if (g.recruits?.turn === g.turn && (g.recruits.uses ?? 1) >= Number.MAX_SAFE_INTEGER) + return 'The Recruits play count cannot be increased further.'; const reserved = transferCardBlock(g, owner, card); if (reserved) return reserved; if (recruitsInteractionPending(g)) @@ -20917,7 +20932,7 @@ function recruitsPreview(g: Game, viewer: Player): RecruitsPreview | null { const active = g.recruits?.turn === g.turn; return { active, - ...(active ? { playedTurn: g.recruits!.turn, playedBy: g.recruits!.player } : {}), + ...(active ? { playedTurn: g.recruits!.turn, playedBy: g.recruits!.player, plays: g.recruits!.uses ?? 1 } : {}), play, rates: g.order.map((player) => { const target = getPlayer(g, player); @@ -46454,10 +46469,12 @@ function applyActionInner( requireRule(!blocked, blocked ?? 'Recruits is unavailable.'); discard(g, p, card.id); for (const player of g.players) player.freeForcesRevived ??= 0; - g.recruits = { turn: g.turn, player: p.id, card: RECRUITS_CARD_ID }; + const earlierUses = g.recruits?.turn === g.turn ? g.recruits.uses ?? 1 : 0; + g.recruits = { turn: g.turn, player: p.id, card: RECRUITS_CARD_ID, + ...(earlierUses ? { uses: earlierUses + 1 } : {}) }; log( g, - `${p.name} played Recruits. Current free revival rates are doubled and the ordinary force revival limit is seven for this turn.`, + `${p.name} played Recruits. Current free revival rates are doubled${earlierUses ? ' again' : ''} and the ordinary force revival limit is seven for this turn.`, { faction: p.faction, name: 'Recruits' }, ); if (execution === 'live' && independentRecruitsSemutaEnabled(g)) diff --git a/game/recruits.ts b/game/recruits.ts index 28d6d07a..91254d3d 100644 --- a/game/recruits.ts +++ b/game/recruits.ts @@ -1,5 +1,6 @@ /** A global card effect expires when the authoritative turn changes. */ -export type RecruitsEffect = Readonly<{ turn: number }>; +/** Legacy receipts omit uses and represent one physical play. */ +export type RecruitsEffect = Readonly<{ turn: number; uses?: number }>; export const RECRUITS_CARD_ID = 'ecaz-recruits' as const; export type RecruitsPlay = Readonly<{ type: 'card'; @@ -10,6 +11,7 @@ export type RecruitsPreview = Readonly<{ active: boolean; playedTurn?: number; playedBy?: string; + plays?: number; play: RecruitsPlay | null; rates: ReadonlyArray>; grantRevivalBlocked: string | null; @@ -73,11 +75,17 @@ export function recruitsRevivalAllowance( throw new RangeError(`${key} must be a nonnegative integer force count.`); const active = scope.recruits?.turn === scope.turn; + const uses = active ? scope.recruits?.uses ?? 1 : 0; + if (!Number.isSafeInteger(uses) || uses < 0 || (active && uses === 0)) + throw new RangeError('Active Recruits uses must be a positive safe integer.'); const limit = active ? Math.max(7, facts.currentLimit) : facts.currentLimit; const freeRate = facts.freeBlocked ? 0 : Math.min( - facts.currentFreeRate * (active ? 2 : 1), + // Each actual replay doubles the current rate again. Cap the exponent + // at 53: every supported input and cap is a safe nonnegative integer, + // so a larger power can never alter the capped result. + facts.currentFreeRate * 2 ** Math.min(uses, 53), facts.freeRateCap, limit, ); diff --git a/game/reference.ts b/game/reference.ts index 8529daf2..5c8f0d95 100644 --- a/game/reference.ts +++ b/game/reference.ts @@ -301,6 +301,7 @@ export const RULE_TOPICS: RuleTopic[] = [ 'In supported Advanced selected-deck auctions, the Emperor may gift spice before an allied ordinary purchase, Richese cache sale or Black Market sale. The original split remains: direct gifts are the buyer’s spice, while the Emperor’s pledged share goes to the bank. A promised funding update can be completed before continuing.', 'In supported classic Advanced games, the Emperor may share spice before a pending Guild shipment-rate response continues. Allowing or canceling the gift returns to the same rate decision and shipment.', '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.', + 'Supported clean Basic games also permit a direct bribe while a Fremen worm-ride choice or winner’s optional battle-card decision is pending. The decision and physical pieces remain in place, and the recipient collects the bribe at the original Mentat opening. Other interruption families and optional combinations remain partial.', '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.', 'A qualifying Bureaucrat may divert two spice to the Bank without reducing the payer’s cost. The remainder stays deferred. Unsupported combinations remain unavailable and do not imply an official rule prohibition.', @@ -6728,9 +6729,10 @@ export const RULE_TOPICS: RuleTopic[] = [ steps: [ 'The separate three-card variant includes Recruits, Reinforcements and Harass & Withdraw. It does not require the Ecaz faction. A development preview includes all three physical cards before setup; Recruits, bounded Reinforcements and Harass & Withdraw controls are connected.', 'The holder may play Recruits from its Revival panel. Discard the card once, then all players use the increased rates while this Revival phase remains open, including players who had already marked themselves ready. Completed returns still count toward their turn totals.', + 'If the actual card is legally recovered during the same Revival, its holder may play and discard it again. Provisionally, each play doubles the current free rate again; the ordinary seven-force limit, native unlimited advantages, prior returns and payments remain. The public panel shows the number of plays and resulting rates.', 'In a fresh Basic game with Richese, the CHOAM deck and these independent cards, Semuta Drug may claim Recruits or a used Hajr, Ghola, Harvester, Weather Control or Family Atomics immediately after another player discards it, including when other selected expansion factions are seated. With the Ix deck, clean Thumper, Amal and an Ixian ally’s privately discarded ordinary-auction replacement card can also be claimed before their original continuation. Supported battle cleanup, clean pre-leader Residual Poison, native Moritani allied retention, Ixian substitution, CHOAM sales and Worthless costs, clean Ambassador and Terror discards, completed Box searches, Distrans, simple Truthtrance and ordinary Ornithopter can also offer their discarded card. The original effect stays committed; other Semuta opportunities remain unfinished.', 'Atreides rises from two free forces to four; Fremen from three to six; Guild from one to two. The ordinary force limit becomes seven. Native unlimited CHOAM and Tleilaxu allowances remain unlimited, and their free rates become zero and four. Paid prices and separate elite limits still apply.', - 'Free prevention still prevents free returns. Prior paid ordinary returns now have a visibly provisional policy: preserve payment, deduct only recorded free returns from the doubled free allowance and all returns from the total cap. Two free plus one paid Atreides may take two more free without refund; this is not a numerical user ruling. Fremen may now grant after play under the same provisional current-rate policy, with its original Karama response settled before commitment. Missing/inconsistent ledgers, pending transactions and same-turn replay remain guarded.', + 'Free prevention still prevents free returns. Prior paid ordinary returns now have a visibly provisional policy: preserve payment, deduct only recorded free returns from the doubled free allowance and all returns from the total cap. Two free plus one paid Atreides may take two more free without refund; this is not a numerical user ruling. Fremen may now grant after play under the same provisional current-rate policy, with its original Karama response settled before commitment. Missing/inconsistent ledgers and pending transactions remain guarded.', 'Clean classic2–6 Basic/Advanced Homeworlds compose through the fresh independent36-card setup. Double current native free rates including low-population bonuses, within the seven-force total. Provisionally recheck population and recorded free use on each separate request: low Fremen may take7 together, but1 crossing high leaves5 further free and cannot buy a seventh without Tleilaxu. Original typed destinations and special-force limits stay. Other overlays/rosters, public activation and whole-mode acceptance remain unfinished.', 'Classic or selected Ix/CHOAM native/base rosters, including Homeworlds, may retain original unused Tech Tokens3–6 and/or Stronghold Cards2–6 Advanced. Setup, first-Storm Tech and actual end-Mentat custody remain original. Recruits changes current native free rates, not the once-per-phase Axlotl trigger/delayed payout. Harass returns are not free Revival.', 'Selected Ix/CHOAM native/base Basic/Advanced Worlds use original38/50 independent-card setup with optional original phase modules. Current native bonuses, typed deposits and accepted paid/free classifications stay. Ix keeps its multiple-Cyborg allowance; Tleilaxu and CHOAM remain unlimited rather than being reduced to seven. Other card/overlay/public-start gates remain.', diff --git a/tests/bribe-classic-decisions-runtime.test.ts b/tests/bribe-classic-decisions-runtime.test.ts new file mode 100644 index 00000000..e85b4711 --- /dev/null +++ b/tests/bribe-classic-decisions-runtime.test.ts @@ -0,0 +1,111 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import { viewGame, type Action, type Game } from '../game/engine'; +import { + actFremenRevivalGrant as actBattle, advanceFremenRevivalGrant as advanceBattle, + createFremenRevivalGrantFixture, fremenRevivalGrantClean, + fremenRevivalGrantInventory as battleInventory, fremenRevivalGrantPlayer as battlePlayer, +} from './fixture-fremen-revival-grant'; +import { + actSemutaDisasterWorm as actWorm, advanceSemutaDisasterWorm as advanceWorm, + allowSemutaDisasterWorm, createSemutaDisasterWormFixture, + semutaDisasterWormPlayer as wormPlayer, +} from './fixture-semuta-disaster-worm'; + +function rejected(game: Game, act: (game: Game, actor: string, action: Action) => Game, + actor: string, action: Action) { + const original = structuredClone(game); + assert.throws(() => act(game, actor, action)); + assert.deepEqual(game, original, 'A rejected bribe preserves its native parent and resources'); +} + +/** Actual public Basic selected-deck setup, purchase and original Fremen + * shipment; the natural second-turn worm and survival response create this + * ride. No decision, army, spice balance or phase is assigned by this test. */ +function wormRideSource() { + const fixture = createSemutaDisasterWormFixture({ advanced: false }); + let game = allowSemutaDisasterWorm(fixture.game); + game = advanceWorm(game, state => state.decision?.kind === 'wormRide' && + !state.response && !state.phaseOpening && !state.pendingTreacheryDiscard); + assert.equal(game.decision?.player, fixture.owner); + assert.equal(game.decision?.kind === 'wormRide' && game.decision.territory, 'funeral_plain'); + return {fixture, game}; +} + +void test('a Basic worm rider and another seat can negotiate while the original unpaid ride waits', () => { + const {fixture:f, game} = wormRideSource(); + const actor = f.spender, target = f.guild, originalDecision = structuredClone(game.decision); + const oldPurse = wormPlayer(game, actor).spice, oldCash = wormPlayer(game, target).spice; + const oldEscrow = wormPlayer(game, target).bribes; + assert.ok(oldPurse >= 4); assert.notEqual(wormPlayer(game, actor).ally, target); + assert.equal(viewGame(game, actor).bribeOptions.blocked, null); + rejected(game, actWorm, actor, {type:'bribe', target, amount:oldPurse + 1}); + rejected(game, actWorm, actor, {type:'bribe', target:actor, amount:1}); + const paid = actWorm(game, actor, {type:'bribe', target, amount:4}); + assert.deepEqual(paid.decision, originalDecision); + assert.deepEqual(paid.wormRides, game.wormRides); + assert.deepEqual(paid.spiceSequence, game.spiceSequence); + assert.equal(wormPlayer(paid, actor).spice, oldPurse - 4); + assert.equal(wormPlayer(paid, target).spice, oldCash); + assert.equal(wormPlayer(paid, target).bribes, oldEscrow + 4); + const decline: Action = {type:'decision', accept:false}; + const control = actWorm(game, f.owner, decline); + const continued = actWorm(paid, f.owner, decline); + assert.deepEqual(continued.decision, control.decision); + assert.deepEqual(continued.wormRides, control.wormRides); + assert.equal(wormPlayer(continued, target).bribes, oldEscrow + 4); +}); + +/** The original public Basic Fremen/Atreides invasion and real battle produce + * the winner's optional card disposal. One actually dealt Fremen card is + * exchanged with an original shield in another hand or the deck before battle + * when needed, conserving the physical cards and hand sizes. */ +function battleCardsSource() { + const f = createFremenRevivalGrantFixture(); + let game = structuredClone(f.beforeBattle); + const hand = battlePlayer(game, f.fremen).hand; + assert.ok(hand.length); + let shield = hand.find(card => card.kind === 'shield'); + if (!shield) { + const zone = [game.deck, ...game.players.filter(seat => seat.id !== f.fremen).map(seat => seat.hand)] + .find(cards => cards.some(card => card.kind === 'shield')); + assert.ok(zone); + const index = zone.findIndex(card => card.kind === 'shield'); + [hand[0], zone[index]] = [zone[index], hand[0]]; + shield = hand[0]; + } + const shieldId = shield.id, original = battleInventory(game); + game = actBattle(game, f.battleStep.actor, f.battleStep.action); + for (const step of f.plans) { + game = advanceBattle(game, state => !!state.battle && fremenRevivalGrantClean(state) && + !state.battle.preparation && (!state.battle.preLeader || state.battle.preLeader.closed)); + game = actBattle(game, step.actor, step.actor === f.fremen + ? {...step.action, defense:shieldId} : step.action); + } + game = advanceBattle(game, state => !state.response && !state.phaseOpening && + state.decision?.kind === 'battleCards'); + assert.equal(game.decision?.player, f.fremen); + assert.ok(game.decision?.kind === 'battleCards' && game.decision.cards.includes(shieldId)); + return {f, game, shield:shieldId, original}; +} + +void test('a Basic winner can retain the same played card after an out-of-turn bribe', () => { + const {f, game, shield, original} = battleCardsSource(); + const actor = f.observer, target = f.ally, decision = structuredClone(game.decision); + const purse = battlePlayer(game, actor).spice, cash = battlePlayer(game, target).spice; + const escrow = battlePlayer(game, target).bribes; + assert.ok(purse >= 1); assert.notEqual(battlePlayer(game, actor).ally, target); + assert.equal(viewGame(game, actor).bribeOptions.blocked, null); + rejected(game, actBattle, actor, {type:'bribe', target, amount:purse + 1}); + const paid = actBattle(game, actor, {type:'bribe', target, amount:1}); + assert.deepEqual(paid.decision, decision); + assert.deepEqual(paid.lastBattleContext, game.lastBattleContext); + assert.equal(battlePlayer(paid, actor).spice, purse - 1); + assert.equal(battlePlayer(paid, target).spice, cash); + assert.equal(battlePlayer(paid, target).bribes, escrow + 1); + assert.deepEqual(battleInventory(paid), original); + const retained = actBattle(paid, f.fremen, {type:'decision', discard:[]}); + assert.ok(battlePlayer(retained, f.fremen).hand.some(card => card.id === shield)); + assert.equal(battlePlayer(retained, target).bribes, escrow + 1); + assert.deepEqual(battleInventory(retained), original); +}); diff --git a/tests/recruits-controls.test.tsx b/tests/recruits-controls.test.tsx index bf98797e..fed88611 100644 --- a/tests/recruits-controls.test.tsx +++ b/tests/recruits-controls.test.tsx @@ -79,7 +79,7 @@ void test('late-paid controls allow provisional Recruits without refunding prior assert.equal(viewGame(free, 'at').revival.forcesRemaining, 2); }); -void test('missing and inconsistent ledgers, pending transactions, wrong phase and replay remain immutable guards', () => { +void test('missing and inconsistent ledgers, pending transactions, wrong phase and missing card remain immutable guards', () => { const paid = allowRevival(applyAction(ownerGame(), 'at', { type: 'revive', amount: 3 })); const missing = structuredClone(paid); delete missing.players[0].freeForcesRevived; @@ -90,16 +90,11 @@ void test('missing and inconsistent ledgers, pending transactions, wrong phase a const wrongPhase = ownerGame(); wrongPhase.phase = 5; const active = applyAction(ownerGame(), 'at', { type: 'card', card: 'ecaz-recruits' }); - const recovered = structuredClone(active); - const [card] = recovered.discard.splice(recovered.discard.findIndex((held) => held.id === 'ecaz-recruits'), 1); - assert.ok(card); - recovered.players[0].hand.push(card); for (const [label, g] of [ ['missing ledger', missing], ['inconsistent ledger', inconsistent], ['pending transaction', pending], ['wrong phase', wrongPhase], - ['already-active recovered copy', recovered], ] as const) { const before = structuredClone(g); const preview = viewGame(g, 'at').recruitsPreview; diff --git a/tests/recruits-replay-controls.test.tsx b/tests/recruits-replay-controls.test.tsx new file mode 100644 index 00000000..07872cd2 --- /dev/null +++ b/tests/recruits-replay-controls.test.tsx @@ -0,0 +1,91 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import { Children, createElement, isValidElement, type ReactElement, type ReactNode } from 'react'; +import { renderToStaticMarkup } from 'react-dom/server'; +import { Recruits } from '../components/recruits'; +import { Button } from '../components/ui/button'; +import { viewGame, type Action, type GameView } from '../game/engine'; +import { recruitsGame } from './fixture-recruits'; + +type ButtonProps = { onClick?: () => void; disabled?: boolean }; +function findButton(node: ReactNode): ReactElement | undefined { + for (const child of Children.toArray(node)) { + if (!isValidElement(child)) continue; + if (child.type === Button) return child as ReactElement; + const found = findButton((child.props as { children?: ReactNode }).children); + if (found) return found; + } +} + +/** The actual game view supplies the roster and legal card shape. The rates and + * replay offer are projected explicitly because this isolates the control from + * the independent engine implementation and its Semuta flow. */ +function replayView(): GameView { + const game = recruitsGame(false); + const owner = game.players.find(player => player.hand.some(card => card.id === 'ecaz-recruits'))!; + const view = viewGame(game, owner.id); + assert.ok(view.recruitsPreview?.play); + return { + ...view, + recruitsPreview: { + ...view.recruitsPreview, + active: true, + plays: 2, + play: {...view.recruitsPreview.play, blocked: null}, + rates: view.recruitsPreview.rates.map(rate => rate.player === 'tl' + ? {...rate, freeRate: 8, limit: 20} + : {...rate, freeRate: 7, limit: 7}), + }, + }; +} + +void test('a recovered physical Recruits exposes the server-approved replay and current rates', () => { + const game = replayView(), actions: Action[] = []; + const element = Recruits({ game, busy: false, act: action => actions.push(action) }); + assert.ok(element); + const html = renderToStaticMarkup(element); + assert.match(html, /played 2 times this turn/); + assert.match(html, /Each play doubles the current free revival rates/); + assert.match(html, />8<\/td>/); + assert.match(html, />Unlimited<\/td>/); + assert.match(html, /Play Recruits again · Discard card/); + const button = findButton(element); assert.ok(button); + assert.equal(button.props.disabled, false); + button.props.onClick?.(); + assert.deepEqual(actions, [{type:'card', card:'ecaz-recruits'}]); +}); + +void test('replay obeys busy and server block and never appears without a held offer', () => { + const original = replayView(), offer = original.recruitsPreview!; + const busyActions: Action[] = []; + const busy = Recruits({ game: original, busy: true, act: action => busyActions.push(action) }); + assert.ok(busy); + const busyButton = findButton(busy); assert.ok(busyButton); + assert.equal(busyButton.props.disabled, true); + busyButton.props.onClick?.(); + assert.deepEqual(busyActions, []); + + const blocked = {...original, recruitsPreview: {...offer, play: {...offer.play!, blocked:'Finish the current transaction.'}}}; + const blockedActions: Action[] = []; + const blockedElement = Recruits({ game: blocked, busy: false, act: action => blockedActions.push(action) }); + assert.ok(blockedElement); + assert.match(renderToStaticMarkup(blockedElement), /Finish the current transaction/); + const blockedButton = findButton(blockedElement); assert.ok(blockedButton); + assert.equal(blockedButton.props.disabled, true); + blockedButton.props.onClick?.(); + assert.deepEqual(blockedActions, []); + + const publicOnly = {...original, recruitsPreview: {...offer, play: null}}; + const html = renderToStaticMarkup(createElement(Recruits, {game:publicOnly, busy:false, act() {}})); + assert.match(html, /played 2 times this turn/); + assert.doesNotMatch(html, /Play Recruits again/); +}); + +void test('an active legacy projection without a play count displays one use', () => { + const game = replayView(), legacy = {...game.recruitsPreview!}; + delete legacy.plays; + const html = renderToStaticMarkup(createElement(Recruits, { + game: {...game, recruitsPreview: legacy}, busy:false, act() {}, + })); + assert.match(html, /played 1 time this turn/); +}); diff --git a/tests/recruits-replay.test.ts b/tests/recruits-replay.test.ts new file mode 100644 index 00000000..e61e38c5 --- /dev/null +++ b/tests/recruits-replay.test.ts @@ -0,0 +1,87 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import { applyAction, viewGame, type Game } from '../game/engine'; +import { recruitsPlayAction, recruitsRevivalAllowance, type RecruitsRevivalFacts } from '../game/recruits'; +import { + actSemutaRecruits as act, createSemutaRecruitsFixture as fixture, + semutaRecruitsInventory as inventory, semutaRecruitsPlayer as player, +} from './fixture-semuta-recruits'; + +const facts: RecruitsRevivalFacts = { + currentFreeRate: 2, currentLimit: 3, revived: 0, freeAllowanceUsed: 0, freeRateCap: 20, +}; + +void test('each actual Recruits use provisionally doubles the current native free rate, with one ordinary cap', () => { + const scope = (uses?: number) => ({ turn: 2, recruits: { turn: 2, ...(uses === undefined ? {} : { uses }) } }); + assert.equal(recruitsRevivalAllowance(scope(), facts).freeRate, 4, 'old receipt means one use'); + assert.equal(recruitsRevivalAllowance(scope(1), facts).freeRate, 4); + const second = recruitsRevivalAllowance(scope(2), facts); + assert.equal(second.freeRate, 7); + assert.equal(second.limit, 7, 'the normal seven-force limit does not multiply'); + const used = recruitsRevivalAllowance(scope(2), { ...facts, revived: 3, freeAllowanceUsed: 2 }); + assert.equal(used.remaining, 4); + assert.equal(used.freeRemaining, 4, 'earlier free and paid returns remain in their respective ledgers'); + const unlimited = recruitsRevivalAllowance(scope(2), { + ...facts, currentFreeRate: 4, currentLimit: 20, + }); + assert.equal(unlimited.freeRate, 16); + assert.equal(unlimited.limit, 20); + assert.equal(recruitsRevivalAllowance(scope(100), { ...facts, currentLimit: 20 }).freeRate, 20); + assert.equal(recruitsRevivalAllowance(scope(100), { ...facts, currentFreeRate: 0 }).freeRate, 0); + assert.equal(recruitsRevivalAllowance(scope(2), { ...facts, freeBlocked: true }).freeRate, 0); + assert.equal(recruitsRevivalAllowance(scope(2), { ...facts, revivalBlocked: true }).freeRemaining, 0); + assert.equal(recruitsRevivalAllowance({ turn: 3, recruits: { turn: 2, uses: 2 } }, facts).freeRate, 2); + for (const uses of [0, -1, 1.5, Number.NaN, Number.MAX_SAFE_INTEGER + 1]) + assert.throws(() => recruitsRevivalAllowance(scope(uses), facts), /positive safe integer/); +}); + +/** Genuine public Basic setup and normal auctions give the holder its real + * Semuta and the owner the physical Recruits. The real next Storm sends the + * owner's shipped group to the Tanks; no card or counter is injected. */ +void test('Semuta acquires and replays the same physical Recruits, retaining the first use and actual revival', () => { + const f = fixture(); + let game = act(f.game, f.owner, f.play); + let discard = game.pendingTreacheryDiscard; + assert.ok(discard?.reaction && discard.reaction.stage === 'offer'); + const firstEvent = discard.batch.event; + game = act(game, f.holder, { type: 'semutaCommit', event: firstEvent }); + if (game.pendingTreacheryDiscard?.reaction?.stage === 'select') + game = act(game, f.holder, { type: 'semutaSelect', event: firstEvent, card: 'ecaz-recruits' }); + assert.equal(game.pendingTreacheryDiscard, null); + assert.ok(player(game, f.holder).hand.some(card => card.id === 'ecaz-recruits')); + assert.equal(viewGame(game, f.owner).revival.freeRemaining, 4); + + const priorSpice = player(game, f.owner).spice; + game = act(game, f.owner, { type: 'revive', amount: 2, elite: 0 }); + assert.equal(player(game, f.owner).freeForcesRevived, 2); + assert.equal(player(game, f.owner).spice, priorSpice); + const replay = recruitsPlayAction(viewGame(game, f.holder).recruitsPreview); + assert.deepEqual(replay, f.play); + const before = structuredClone(game); + assert.throws(() => applyAction(game, f.owner, f.play), 'only the actual card holder may replay it'); + assert.deepEqual(game, before); + game = act(game, f.holder, f.play); + assert.equal(game.recruits?.uses, 2); + assert.equal(game.recruits?.player, f.holder); + discard = game.pendingTreacheryDiscard; + if (discard?.reaction?.stage === 'offer') { + const event = discard.batch.event; + assert.notEqual(event, firstEvent); + for (const seat of game.players) game = act(game, seat.id, { type: 'semutaPass', event }); + } + assert.equal(game.pendingTreacheryDiscard, null); + assert.equal(viewGame(game, f.owner).revival.limit, 7); + assert.equal(viewGame(game, f.owner).revival.freeRemaining, 5); + assert.equal(viewGame(game, f.owner).recruitsPreview?.plays, 2); + assert.equal(player(game, f.owner).freeForcesRevived, 2); + assert.equal(player(game, f.owner).spice, priorSpice); + assert.equal(game.discard.filter(card => card.id === 'ecaz-recruits').length, 1); + assert.equal(game.players.flatMap(seat => seat.hand).filter(card => card.id === 'ecaz-recruits').length, 0); + assert.deepEqual(inventory(game), f.originalInventory); + const restored = JSON.parse(JSON.stringify(game)) as Game; + assert.equal(viewGame(restored, f.owner).revival.freeRemaining, 5); + assert.equal(viewGame(restored, f.owner).recruitsPreview?.plays, 2); + game = act(game, f.owner, { type: 'revive', amount: 1, elite: 0 }); + assert.equal(player(game, f.owner).freeForcesRevived, 3); + assert.equal(player(game, f.owner).spice, priorSpice); +}); diff --git a/tests/semuta-recruits-basic.test.ts b/tests/semuta-recruits-basic.test.ts index 96092471..8eb0e46d 100644 --- a/tests/semuta-recruits-basic.test.ts +++ b/tests/semuta-recruits-basic.test.ts @@ -55,7 +55,7 @@ for (const claim of [false, true]) { assert.equal(resumed.discard.filter(card => card.id === SEMUTA_DRUG_ID).length, Number(claim)); assert.deepEqual(inventory(resumed), f.originalInventory); rejected(resumed, f.holder, {type: 'semutaCommit', event}); - if (claim) rejected(resumed, f.holder, f.play); + if (claim) assert.equal(viewGame(resumed, f.holder).recruitsPreview?.play?.blocked, null); const old = {reserves: player(resumed, f.owner).reserves, tanks: player(resumed, f.owner).tanks, spice: player(resumed, f.owner).spice}; const revived = act(resumed, f.owner, {type: 'revive', amount: 3, elite: 0});
Current revival rates
FactionFree rateForce limit