From a2e7029a723a95a11bcbddf8854a7bfe52185563 Mon Sep 17 00:00:00 2001 From: Quintine <15965533+Quintine@users.noreply.github.com> Date: Mon, 16 Nov 2026 21:11:16 +1100 Subject: [PATCH] Connect Harkonnen Nexus to Ecaz Occupy --- components/game-table.tsx | 4 +- docs/CURRENT_STATUS.md | 13 +- docs/NEXUS_HARKONNEN_RULES.md | 24 ++- docs/RULE_DECISIONS.md | 14 +- game/engine.ts | 16 +- game/nexus-harkonnen-betrayal.ts | 24 ++- game/reference.ts | 6 +- tests/coalition-traitor-declarations.test.ts | 4 +- tests/nexus-harkonnen-moritani-reveal.test.ts | 136 ++++++++++++++++ tests/nexus-harkonnen-occupy-legacy.test.ts | 47 ++++++ tests/nexus-harkonnen-occupy-quote.test.ts | 114 ++++++++++++++ tests/nexus-harkonnen-occupy-runtime.test.ts | 146 ++++++++++++++++++ 12 files changed, 529 insertions(+), 19 deletions(-) create mode 100644 tests/nexus-harkonnen-moritani-reveal.test.ts create mode 100644 tests/nexus-harkonnen-occupy-legacy.test.ts create mode 100644 tests/nexus-harkonnen-occupy-quote.test.ts create mode 100644 tests/nexus-harkonnen-occupy-runtime.test.ts diff --git a/components/game-table.tsx b/components/game-table.tsx index 5c621f5b..5040e0ea 100644 --- a/components/game-table.tsx +++ b/components/game-table.tsx @@ -1499,8 +1499,8 @@ export function GameTable({ Harkonnen Nexus Betrayal development preview · cancel an actually declared native Harkonnen traitor call, return that physical card to the Traitor Deck, and draw one private replacement automatically at this turn’s Mentat Pause. Supported classic games and Advanced games with - one Ecaz or Moritani faction use Nexus alone. Ecaz Occupy battles retain their ordinary - Traitor call without this reaction. Native allied Karama counters finish first. Not complete + one Ecaz or Moritani faction use Nexus alone, including Ecaz Occupy battles. Native allied + Karama counters finish first. Not complete Harkonnen or certified Nexus rules.{' '} Preview rules and limits

diff --git a/docs/CURRENT_STATUS.md b/docs/CURRENT_STATUS.md index c04e38a2..c998e939 100644 --- a/docs/CURRENT_STATUS.md +++ b/docs/CURRENT_STATUS.md @@ -17,11 +17,20 @@ open mode gates. ## Current checkpoint and work +**Ecaz Occupy and canceled Traitor reveal — 16 November. Prototyped / +Partial.** Standalone Advanced Ecaz Occupy can bind the Harkonnen Nexus +reaction with either coalition lead and Harkonnen on either side. A Harkonnen +Traitor revealed before Nexus cancellation provisionally still prevents a +same-battle Moritani assassination. Simultaneous replacements, a real legacy +pending-source continuation, wider modules and complete games remain open. +Sixteen related unit files pass 107 cases. +[Scope](NEXUS_HARKONNEN_RULES.md#ecaz-occupy-and-revealed-moritani-traitor--16-november-2026). + **Advanced standalone Ecaz/Moritani Harkonnen Nexus — 16 November. Prototyped / Partial.** Fresh Nexus-only Advanced games with Harkonnen and one Ecaz or Moritani faction can use the existing declared-Traitor cancellation and -delayed private replacement. Ecaz Occupy battles retain their native call but -do not yet offer this reaction. Simultaneous Moritani replacement, wider module +delayed private replacement. The newer checkpoint above adds Ecaz Occupy +support. Simultaneous Moritani replacement, wider module combinations, complete games and deployment remain open. Eleven related unit files pass 73 cases, including Emperor purchase and Revival preservation. [Scope](NEXUS_HARKONNEN_RULES.md#advanced-standalone-ecaz-or-moritani--16-november-2026). diff --git a/docs/NEXUS_HARKONNEN_RULES.md b/docs/NEXUS_HARKONNEN_RULES.md index 9da8211a..bae61747 100644 --- a/docs/NEXUS_HARKONNEN_RULES.md +++ b/docs/NEXUS_HARKONNEN_RULES.md @@ -2,6 +2,26 @@ Source audit, 10 September 2026. This is a rules contract, not a runtime completion claim. The [common Nexus lifecycle](NEXUS_CARD_RULES.md) and existing expansion release gates still apply. The pending reaction-privacy question remains unresolved; this audit does not authorize a Betrayal reaction policy. +## Ecaz Occupy and revealed Moritani Traitor — 16 November 2026 + +**Prototyped / Partial.** The standalone Advanced Ecaz/Harkonnen Nexus +reaction now binds the actual Occupy coalition profile and lead. A Harkonnen +co-side voter calls directly, including when Ecaz owns the plan; an external +allied call retains its native Karama response. The public test journey uses +conserved staged forces and traitors, a real Nexus draw, battle, Use/Pass and +Mentat continuation for both leads and Harkonnen on either side. Previously +opened Basic pending sources retain their original source shape; the old-shape +helper case passes, while a real saved pending continuation remains unverified. + +The authorized revised Advanced source, physical page 35, requires no Traitor +to have been revealed before Moritani's Assassinate Leaders. The provisional +combined interpretation keeps that public fact when Harkonnen's subsequent +Nexus cancellation removes the call's battle outcome. An actual normal +Moritani loss confirms no assassination offer after this reveal; a no-reveal +control still offers it. The source does not explicitly adjudicate this +combination. Simultaneous Harkonnen/Moritani Mentat replacements, broader +modules, complete games and deployment remain open. + ## Advanced standalone Ecaz or Moritani — 16 November 2026 **Prototyped / Partial.** Fresh Advanced Nexus-only starts with Harkonnen, @@ -10,8 +30,8 @@ existing Betrayal reaction. Its native call, provisional neutral acknowledgement physical Traitor return and private Mentat replacement retain their existing continuation. Older games are not restamped. Ecaz Loyalty is excluded from the Traitor census; Moritani's retired identities remain outside the physical deck. -In an Ecaz Occupy battle, the native call continues without a Betrayal offer: -the existing source does not yet bind coalition voters. When Harkonnen and +At that checkpoint Ecaz Occupy retained its native call without a Betrayal +offer; the newer section above records the subsequent coalition support. When Harkonnen and Moritani replacements are both due, Harkonnen's draw precedes Moritani's; this online ordering is provisional and simultaneous obligations require further runtime proof. Leader Skills, Homeworlds, other modules, paired/mixed diff --git a/docs/RULE_DECISIONS.md b/docs/RULE_DECISIONS.md index dd139a17..c1bdbd93 100644 --- a/docs/RULE_DECISIONS.md +++ b/docs/RULE_DECISIONS.md @@ -1,10 +1,20 @@ # Rule decision index +## Ecaz Occupy and canceled Traitor reveal — 16 November 2026 + +The existing provisional Harkonnen reaction timing extends to standalone +Advanced Ecaz Occupy, preserving direct co-side calls. Under the provisional +combined interpretation of the supplied Advanced PDF physical page 35, +canceling a publicly revealed Traitor's battle effect does not undo the reveal +for Moritani's Assassinate Leaders condition. Neither interpretation is a new +publisher ruling. +[Scope](NEXUS_HARKONNEN_RULES.md#ecaz-occupy-and-revealed-moritani-traitor--16-november-2026). + ## Advanced standalone E3 Harkonnen Nexus — 16 November 2026 The existing provisional native-counter-first acknowledgement extends to -Nexus-only Advanced Ecaz or Moritani starts. Ecaz Occupy remains outside the -reaction; simultaneous Harkonnen and Moritani replacements currently draw in +Nexus-only Advanced Ecaz or Moritani starts. The newer section above adds Ecaz +Occupy; simultaneous Harkonnen and Moritani replacements currently draw in that order, provisionally, pending combined runtime evidence. [Scope](NEXUS_HARKONNEN_RULES.md#advanced-standalone-ecaz-or-moritani--16-november-2026). diff --git a/game/engine.ts b/game/engine.ts index 6a53ea1c..565d677f 100644 --- a/game/engine.ts +++ b/game/engine.ts @@ -11958,7 +11958,9 @@ function recordMoritaniAssassinateOpportunity(g: Game, b: Battle, winner: Player faction:winner.faction,event:g.lastBattleContext!.event,turn:g.turn,territory:b.territory, opposingLeader:opposingLeader?.id ?? null,opposingLeaderSurvived:!!opposingLeader && !opposingLeader.dead, normalBattle:g.lastBattleContext!.result === 'normal',lostBattle:true, - traitorCalled:Object.values(b.traitorCalls).some(Boolean)}; + // Betrayal cancels the battle outcome, not the preceding public reveal. + traitorCalled:Object.values(b.traitorCalls).some(Boolean) || + !!g.nexusHarkonnenBetrayalHistory?.some(r => r.outcome === 'use' && r.source.battle.event === b.event)}; if (!moritaniAssassinateTrigger(trigger)) return; const receipt = createMoritaniAssassinateOpportunity(trigger); if (g.leaderSkills) receipt.stage = 'skills'; @@ -12992,7 +12994,12 @@ function harkonnenNexusBetrayalContext(g: Game) { const plans = Object.fromEntries([b.attacker,b.defender].map(id => [id,{ leader:b.plans[id].leader,...(b.plans[id].kwisatz === undefined ? {} : {kwisatz:b.plans[id].kwisatz}), }])); + // A previously opened Basic Occupy reaction retains its original source + // shape; only newly opened reactions bind the coalition profile. + const legacyOccupySource = !!g.pendingNexusHarkonnenBetrayal && + !Object.hasOwn(g.pendingNexusHarkonnenBetrayal.source.battle, 'ecazOccupy'); const battle = {event:b.event!,attacker:b.attacker,defender:b.defender,plans, + ...(b.ecazOccupy && !legacyOccupySource ? {ecazOccupy:ecazBattleProfile(g)!} : {}), heroLeaderIds:g.expansions.includes('ix') ? physicalTreacheryCards(g).filter(card => card.kind === 'hero').map(card => card.id) : []}; return {status:g.status,phase:g.phase,turn:g.turn,advanced:g.advanced,ecazTreachery:g.ecazTreachery === true, ...(g.expansions.length ? {expansions:g.expansions} : {}), @@ -13010,7 +13017,9 @@ function harkonnenNexusBetrayalAuthority(g: Game): HarkonnenBetrayalAuthority { 'The Harkonnen reaction lost its original legal native call.'); const declaration = nexusRule(() => createTraitorDeclaration(traitorDeclarationContext(g),allowance.provider)); requireRule(JSON.stringify(declaration) === JSON.stringify(b.traitorDeclarations?.[allowance.provider]) && - allowance.nativeWindow === ([b.attacker,b.defender].includes(allowance.provider) ? 'direct' : 'harkonnenTraitor'), + allowance.nativeWindow === ([b.attacker,b.defender].includes(allowance.provider) || + !!b.ecazOccupy && [b.ecazOccupy.ecaz,b.ecazOccupy.ally].includes(allowance.provider) + ? 'direct' : 'harkonnenTraitor'), 'The Harkonnen call lost its original canonical declaration or native window.'); const required = allowance.nativeWindow === 'direct' ? [] : g.players.filter(p => responseCancelCards(g,p,{kind:'harkonnenTraitor',owner:allowance.provider,passed:[]}).length > 0).map(p => p.id); @@ -13093,9 +13102,6 @@ function harkonnenNexusBetrayalIntegrity(g: Game, mentatOpening = false): void { function offerHarkonnenNexusBetrayal(g: Game, provider: string, response?: ResponseWindow): boolean { if (!g.nexusHarkonnenBetrayalPreview || getPlayer(g,provider).faction !== 'harkonnen') return false; const b = g.battle!; - // Occupy can add co-side voters that the current two-sided source cannot bind. - // Retain the original Traitor call until that declaration is supported. - if (b.ecazOccupy && harkonnenE3NexusBetrayalProfile(g)) return false; const required = nexusRule(() => harkonnenBetrayalResponders(g.nexusCards!.cards!,g.players)); if (!required.length) return false; requireRule(!b.nexusHarkonnenAllowance && (!response || response.kind === 'harkonnenTraitor'), diff --git a/game/nexus-harkonnen-betrayal.ts b/game/nexus-harkonnen-betrayal.ts index 04ac93ae..c5ae72c2 100644 --- a/game/nexus-harkonnen-betrayal.ts +++ b/game/nexus-harkonnen-betrayal.ts @@ -1,6 +1,7 @@ import { createAuditorLeader, leaders, treacheryDeck, type Card } from './cards'; import { FACTIONS } from './catalog'; import { ecazTreacheryCards } from './ecaz-cards'; +import { quoteEcazOccupyBattle } from './ecaz-occupy-battle'; import { richeseCards } from './richese-cards'; import { nexusCardMode, validateNexusCards, validateNexusPlayers, @@ -151,7 +152,9 @@ function validatePhysical(cards: readonly Card[], independent: boolean, expansio } function validateBattle(battle: Battle, expansions: readonly string[]): void { const heroes = expansions.includes('ix') ? treacheryDeck(expansions).filter(card => card.kind === 'hero').map(card => card.id) : []; - requireBetrayal(exact(battle, ['event', 'attacker', 'defender', 'plans', 'heroLeaderIds']) && + requireBetrayal(plain(battle) && exact(battle, ['event', 'attacker', 'defender', 'plans', 'heroLeaderIds', + ...(Object.hasOwn(battle, 'ecazOccupy') ? ['ecazOccupy'] : [])]) && + (!Object.hasOwn(battle, 'ecazOccupy') || plain(battle.ecazOccupy)) && text(battle.event) && text(battle.attacker) && text(battle.defender) && battle.attacker !== battle.defender && exact(battle.plans, [battle.attacker, battle.defender]) && Array.isArray(battle.heroLeaderIds) && battle.heroLeaderIds.length === heroes.length && @@ -181,11 +184,28 @@ function validateAuthority( authority.declaration?.voter === authority.provider, 'Harkonnen Betrayal must follow its original allowed native Harkonnen declaration.'); try { + if (battle.ecazOccupy) { + const occupy = battle.ecazOccupy; + const ecaz = players.find(player => player.id === occupy.ecaz); + const ally = players.find(player => player.id === occupy.ally); + requireBetrayal(ecaz?.faction === 'ecaz' && ally && occupy.advanced === advanced, + 'Harkonnen Betrayal requires the original Occupy roster and rules band.'); + const profile = quoteEcazOccupyBattle({ advanced: occupy.advanced, + battleOrderActor: occupy.battleOrderActor, + ecaz: { id: ecaz.id, faction: 'ecaz', ally: ecaz.ally, forces: occupy.ecazForces }, + ally: { id: ally.id, faction: ally.faction, ally: ally.ally, forces: occupy.allyForces, + ...(occupy.allyNoFieldPresence ? { noFieldPresence: true as const } : {}) }, + lead: occupy.lead, canceled: occupy.canceled }); + requireBetrayal(equal(profile, occupy), 'Harkonnen Betrayal changed its original Occupy profile.'); + } validateTraitorDeclaration(declarationContext(battle, players), authority.declaration); } catch { throw new HarkonnenBetrayalError('Harkonnen Betrayal lost its canonical native declaration or roles.'); } - const direct = authority.declaration.beneficiary === authority.provider; + // Native Ecaz co-side voters call directly even if their ally owns the plan; + // only an external Harkonnen allied call uses the Karama counter window. + const direct = authority.declaration.beneficiary === authority.provider || + !!battle.ecazOccupy && [battle.ecazOccupy.ecaz, battle.ecazOccupy.ally].includes(authority.provider); requireBetrayal(direct ? authority.nativeWindow === 'direct' && authority.nativeRequired.length === 0 && authority.nativePassed.length === 0 : authority.nativeWindow === 'harkonnenTraitor', diff --git a/game/reference.ts b/game/reference.ts index c4e224a0..0f4b8421 100644 --- a/game/reference.ts +++ b/game/reference.ts @@ -4422,7 +4422,7 @@ export const RULE_TOPICS: RuleTopic[] = [ summary: 'Supported native Advanced Moritani reveals a different opposing-faction Traitor Card after a loss and replaces it during Mentat Pause.', steps: [ - 'After you lose a battle, this advanced advantage is available only if the opposing leader disc survived and no Traitor was called.', + 'After you lose a battle, this advanced advantage is available only if the opposing leader disc survived and no Traitor was revealed. A Harkonnen Traitor publicly revealed before Nexus Betrayal cancels its outcome still prevents this advantage; the combined interpretation is provisional.', 'You may reveal a Traitor Card for that opposing faction, but it must name a different leader from the one you just fought. If that named leader is not in the Tanks, kill it and collect spice for its value.', 'An already-dead named leader remains a legal reveal, awarding no death or spice. During Mentat Pause, set the revealed card aside face up as a marker and draw a new Traitor Card. You can use this advantage only once against each faction in the game.', 'A Mentat replacement is an ordinary physical Traitor Card, including the original Ix Hero identity when present. After original owned initialization, retire the victim permanently. The replacement itself may later be legally exchanged, returned and drawn again; keep its old receipt unchanged and count one live card, not one per historical reference.', @@ -6262,7 +6262,7 @@ export const RULE_TOPICS: RuleTopic[] = [ searchText: 'Harkonnen Nexus Betrayal revealed declared traitor ally caller beneficiary shuffle replacement Mentat neutral acknowledgement', steps: [ 'Fresh supported Basic and Advanced Nexus core starts with selected faction decks initialize this reaction for native expansion leaders and the Ix Cheap Hero Traitor. Advanced CHOAM’s Auditor has its real Traitor identity. An owed replacement waits through Ix phase-opening acknowledgements before the original Mentat draw. Fresh Advanced games with Harkonnen and one Ecaz or Moritani faction also support the reaction with Nexus alone; wider E3 combinations remain unfinished.', - 'Ecaz Occupy battles retain the ordinary Traitor call without the Harkonnen Nexus reaction until coalition declarations are supported. Harkonnen replacement precedes Moritani assassination replacement when both are due; that ordering is provisional.', + 'Ecaz Occupy retains the actual coalition lead and co-side declarations. Harkonnen calls directly as a combatant or co-side voter; a separate allied call retains its native counter. Harkonnen replacement precedes Moritani assassination replacement when both are due; that ordering is provisional and the simultaneous case still needs a full native journey.', 'Original standalone preview requires native Harkonnen, classic2–6 Basic/Advanced, base33 and Nexus alone. Fresh classic Nexus core initializes the same effect with base33 or selected36, optional14, original Tech3+ and Advanced Strongholds2+, alongside actual Guild/Ixian reactions. Public selection binds the census; real held-card effects and cleanup stay native. No played game is reflagged; other native/module envelopes remain separate.', 'Nexus has no initial deal. An actual alliance-qualified closing Nexus must supply the unallied holder. An effect scenario needs at least three seats; two seats can continue ordinary play without inventing a card. Two simultaneous receivers need four actual seats.', 'The photographed publisher face cancels a revealed Harkonnen traitor, shuffles that exact card back immediately, and gives Harkonnen one replacement during Mentat Pause. It is not a draw-now exchange, whole-battle ban or refund of an already resolved outcome. Native Cunning and absent-Harkonnen Secret Ally remain separate effects.', @@ -6283,7 +6283,7 @@ export const RULE_TOPICS: RuleTopic[] = [ { area: 'Player controls', status: 'Partial', detail: 'Public declared-Traitor inspector, own eligible event-only Use/Pass/Nexus inspector, sole/multiple public ownership and every-seat independent autopilot are connected. Actual phone Use, wrong-face Pass, partial refresh and raw administrator owner agree.', evidence: ['components/nexus-harkonnen-betrayal.tsx', 'components/game-table.tsx', 'game/table-turn.ts', 'db/admin-directory.ts'] }, { area: 'AI', status: 'Partial', detail: 'All four minimal policies consume canonical own-view choices and native pending priority with legal paced continuation; full strategy and calibration remain separate.', evidence: ['game/bot-nexus-harkonnen-betrayal.ts', 'game/bots.ts'] }, { area: 'Documentation', status: 'Partial', detail: 'Printed immediate/delayed operations, personal/allied roles, inferred local counter/privacy convention, fresh natural card rights and unchanged outside-profile/module/public/deployment questions are explicit.', evidence: ['docs/NEXUS_HARKONNEN_RULES.md', 'docs/NEXUS_CARD_RUNTIME.md', 'docs/RULE_DECISIONS.md'] }, - {area:'Verification',status:'Partial',detail:"Fresh classic and selected-deck evidence remains. Standalone Advanced Ecaz and Moritani have staged native battle, control and delayed-replacement smoke; Occupy and simultaneous replacement composition remain open. Other modes, universal timing and deferred assurance remain open.",evidence:['tests/classic-nexus-core.test.ts','tests/fixture-classic-nexus-core.ts','game/faction-module-profile.ts','tests/classic-independent-nexus-reactions.test.ts','tests/fixture-classic-independent-nexus-reactions.ts','tests/fixture-nexus-harkonnen-betrayal.ts', 'tests/nexus-harkonnen-betrayal.test.ts', 'tests/nexus-harkonnen-betrayal-runtime.test.ts', 'tests/nexus-harkonnen-betrayal-controls.test.tsx', 'tests/bot-nexus-harkonnen-betrayal.test.ts', 'tests/nexus-harkonnen-e3-runtime.test.ts', 'tests/nexus-harkonnen-e3-controls.test.tsx', 'tests/nexus-harkonnen-e3-quote.test.ts', 'tests/nexus-harkonnen-betrayal-recovery.test.ts', 'tests/prototype-room.test.ts', 'tests/admin-directory.test.ts']}, + {area:'Verification',status:'Partial',detail:"Fresh classic and selected-deck evidence remains. Standalone Advanced Ecaz and Moritani have staged native battle, control and delayed-replacement smoke; genuine Occupy battles cover both leads and Harkonnen on either side. Simultaneous replacement composition, other modes, universal timing and deferred assurance remain open.",evidence:['tests/classic-nexus-core.test.ts','tests/fixture-classic-nexus-core.ts','game/faction-module-profile.ts','tests/classic-independent-nexus-reactions.test.ts','tests/fixture-classic-independent-nexus-reactions.ts','tests/fixture-nexus-harkonnen-betrayal.ts', 'tests/nexus-harkonnen-betrayal.test.ts', 'tests/nexus-harkonnen-betrayal-runtime.test.ts', 'tests/nexus-harkonnen-betrayal-controls.test.tsx', 'tests/bot-nexus-harkonnen-betrayal.test.ts', 'tests/nexus-harkonnen-e3-runtime.test.ts', 'tests/nexus-harkonnen-e3-controls.test.tsx', 'tests/nexus-harkonnen-e3-quote.test.ts', 'tests/nexus-harkonnen-occupy-runtime.test.ts', 'tests/nexus-harkonnen-occupy-quote.test.ts', 'tests/nexus-harkonnen-moritani-reveal.test.ts', 'tests/nexus-harkonnen-betrayal-recovery.test.ts', 'tests/prototype-room.test.ts', 'tests/admin-directory.test.ts']}, ], }, { diff --git a/tests/coalition-traitor-declarations.test.ts b/tests/coalition-traitor-declarations.test.ts index e6774ed5..10491166 100644 --- a/tests/coalition-traitor-declarations.test.ts +++ b/tests/coalition-traitor-declarations.test.ts @@ -77,7 +77,9 @@ void test('a group declaration rejects retargeted battle, leader, identity and r void test('group declaration is unavailable in unsupported profiles or ambiguous group battles', () => { const game = source(); - for (const patch of [{advanced:true}, {expansions:['ix']}, {homeworlds:{}}, + const advanced = createTraitorDeclaration({...game, advanced:true}, 'h'); + assert.equal(advanced.beneficiary, 'a'); + for (const patch of [{expansions:['ix']}, {homeworlds:{}}, {nexusCards:{}}, {leaderSkills:{}}, {techTokens:{}}, {strongholdCards:{}}, {ecazTreachery:true}, {discoveryEnabled:true}]) { assert.throws(() => createTraitorDeclaration({...game, ...patch}, 'h')); diff --git a/tests/nexus-harkonnen-moritani-reveal.test.ts b/tests/nexus-harkonnen-moritani-reveal.test.ts new file mode 100644 index 00000000..03a26413 --- /dev/null +++ b/tests/nexus-harkonnen-moritani-reveal.test.ts @@ -0,0 +1,136 @@ +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 { TERRITORIES } from '../game/board'; +import { traitorDeck } from '../game/traitors'; +import { validateNexusTraitorSnapshot } from '../game/nexus-traitor-exchange'; +import { nextHarkonnenBetrayalNativeStep, settleHarkonnenBetrayalNativeCounters } from './fixture-nexus-harkonnen-betrayal'; + +const act = (game: Game, actor: string, action: Action) => applyAction(game, actor, action); +function player(game: Game, id: string) { + const seat = game.players.find(p => p.id === id); + assert.ok(seat); + return seat; +} +function step(game: Game): Game { + const next = nextHarkonnenBetrayalNativeStep(game); + try { return act(game, next.actor, next.action); } + catch (error) { throw Error(`Native Moritani step ${game.turn}/${game.phase}/${game.decision?.kind} ${JSON.stringify(next)}: ${String(error)}`); } +} +function advance(game: Game, until: (game: Game) => boolean): Game { + for (let i = 0; i < 1800; i++) { + if (until(game)) return game; + assert.notEqual(game.status, 'finished', 'Unexpected victory during the staged battle'); + game = step(game); + } + throw Error(`Moritani journey stalled at ${game.status}/${game.turn}/${game.phase}/${game.decision?.kind}`); +} +function checkTraitors(game: Game): void { + validateNexusTraitorSnapshot({ reserve: game.traitorReserve!, players: game.players.map(({id, faction, traitors, faceDancers}) => + ({ id, faction, traitors, ...(faceDancers ? { faceDancers } : {}) })) }, traitorDeck(game.players)); +} +/** Exchange an existing dealt card with its actual owner or reserve; never add a card. */ +function hold(game: Game, id: string, identity: string): void { + const owner = player(game, id); + if (owner.traitors.includes(identity)) return; + const old = owner.traitors[0]; assert.ok(old); + const other = game.players.find(p => p.id !== id && p.traitors.includes(identity)); + if (other) other.traitors[other.traitors.indexOf(identity)] = old; + else { + const index = game.traitorReserve!.indexOf(identity); assert.ok(index >= 0); + game.traitorReserve![index] = old; + } + owner.traitors[0] = identity; +} + +/** Fresh public Advanced setup; only unopened Nexus/Spice ordering, conserved + * dealt Traitor swaps and one reserve force on each side are staged. The real + * second-turn Nexus closes, Moritani receives its face, and normal controls + * choose the battle, seal plans, vote and resolve it. Harkonnen's strength-6 + * Feyd beats Moritani's strength-1 Vando with both forces undialed. */ +function beforeCall(): Game { + let game = createGame('MORITANIREVEAL', newPlayer('m', 'Moritani', 'moritani'), true, ['ecaz']); + for (const [id, faction] of [['h', 'harkonnen'], ['g', 'guild'], ['a', 'atreides']] as const) + joinGame(game, newPlayer(id, faction, faction)); + game = act(game, 'm', {type:'moduleOption', module:'nexusCards', enabled:true}); + for (const seat of game.players) game = act(game, seat.id, {type:'ready'}); + game = act(game, 'm', {type:'start', advancedPreview:true}); + assert.equal(game.nexusHarkonnenBetrayalPreview, true); + game = advance(game, g => g.status === 'playing'); + assert.equal(game.moritaniAssassinatePreview, true); + hold(game, 'm', 'harkonnen-1'); + hold(game, 'h', 'moritani-4'); + checkTraitors(game); + const nexus = game.nexusCards!.cards!, index = nexus.deck.indexOf('harkonnen'); + assert.ok(index >= 0); + nexus.deck.unshift(nexus.deck.splice(index, 1)[0]); + for (let pos = 0; pos < 2; pos++) { + const i = game.spiceDeck.findIndex((card, n) => n >= pos && 'territory' in card); assert.ok(i >= pos); + game.spiceDeck.splice(pos, 0, game.spiceDeck.splice(i, 1)[0]); + } + game = advance(game, g => g.turn === 2 && g.phase === 1 && !g.response && !g.decision); + const worm = game.spiceDeck.findIndex(card => 'worm' in card && !card.greatMaker && !card.suppressed); assert.ok(worm >= 0); + game.spiceDeck.unshift(game.spiceDeck.splice(worm, 1)[0]); + game = advance(game, g => g.nexus && !g.spiceWindow && !g.spiceResolution && !g.response && !g.decision); + game = act(game, 'h', {type:'alliance', target:'g'}); + game = act(game, 'g', {type:'alliance', target:'h'}); + game = advance(game, g => g.nexusCards?.phase?.stage === 'drawing'); + assert.ok(game.nexusCards!.phase!.eligible.includes('m')); + game = act(game, 'm', {type:'nexusCardChoice', turn:game.turn, card:null, choice:'draw', ownRedraws:0}); + assert.equal(game.nexusCards!.cards!.hands.m, 'harkonnen'); + game = advance(game, g => g.phase === 5 && !g.response && !g.decision && !g.pendingGuildBetrayal); + const territory = TERRITORIES.find(t => t.type === 'sand' && !t.sectors.includes(game.storm) && + game.players.every(p => !Object.keys(p.forces).some(key => key.startsWith(`${t.id}:`)))); + assert.ok(territory); + for (const id of ['h', 'm']) { + const seat = player(game, id); assert.ok(seat.reserves > 0); + seat.reserves--; seat.forces[`${territory.id}:${territory.sectors[0]}`] = 1; + } + game = advance(game, g => g.phase === 6 && !!g.active && !g.phaseOpening && !g.response && !g.decision); + const chooser = game.active!; assert.ok(['h', 'm'].includes(chooser)); + game = act(game, chooser, {type:'chooseBattle', territory:territory.id, target:chooser === 'h' ? 'm' : 'h'}); + game = advance(game, g => !!g.battle && !g.response && !g.decision && !g.battle.preparation && + (!g.battle.preLeader || g.battle.preLeader.closed)); + for (const id of [game.battle!.attacker, game.battle!.defender]) + game = act(game, id, {type:'battlePlan', dial:0, leader:id === 'h' ? 'harkonnen-0' : 'moritani-4'}); + assert.equal(game.battle!.revealed, true); + return advance(game, g => !g.response && !g.decision); +} + +void test('a publicly revealed Harkonnen traitor canceled by Nexus still prevents Moritani assassination', () => { + let game = beforeCall(); + const battleEvent = game.battle!.event; + game = act(game, 'h', {type:'traitorCall', call:true}); + game = settleHarkonnenBetrayalNativeCounters(game); + const reaction = viewGame(game, 'm').nexusHarkonnenBetrayalReaction; assert.ok(reaction?.canUse); + assert.equal(reaction.identity, 'moritani-4'); + assert.ok(player(game, 'h').revealedTraitors?.includes('moritani-4'), 'The original call reveals the physical Traitor'); + game = act(game, 'm', {type:'nexusHarkonnenBetrayalUse', event:reaction.event}); + assert.equal(game.battle!.traitorCalls.h, false); + assert.equal(game.pendingNexusHarkonnenReplacement?.status, 'due'); + for (let i = 0; i < 500 && game.turn === 2 && game.phase !== 8; i++) { + assert.notEqual(game.decision?.kind, 'moritaniAssassinate', 'A canceled call does not make its revealed Traitor unseen'); + game = step(game); + } + assert.equal(game.phase, 8); + assert.equal(game.lastBattleContext?.event, battleEvent); + assert.equal(game.lastBattleContext?.result, 'normal'); + assert.equal(game.lastBattleContext?.winner, 'h'); + assert.deepEqual(game.moritaniAssassinate!.opportunities, []); + assert.equal(game.nexusHarkonnenReplacementHistory!.length, 1); + checkTraitors(game); +}); + +void test('the same normal Moritani loss without a traitor reveal offers assassination', () => { + let game = beforeCall(); + game = act(game, 'h', {type:'traitorCall', call:false}); + game = advance(game, g => g.decision?.kind === 'moritaniAssassinate'); + assert.equal(game.lastBattleContext?.result, 'normal'); + assert.equal(game.lastBattleContext?.winner, 'h'); + const offer = viewGame(game, 'm').moritaniAssassinate?.pending; + assert.ok(offer); + assert.ok(offer.cards.some(card => card.card === 'harkonnen-1')); + assert.equal(game.nexusCards!.cards!.hands.m, 'harkonnen'); + assert.equal(game.pendingNexusHarkonnenReplacement, null); + checkTraitors(game); +}); diff --git a/tests/nexus-harkonnen-occupy-legacy.test.ts b/tests/nexus-harkonnen-occupy-legacy.test.ts new file mode 100644 index 00000000..820372bd --- /dev/null +++ b/tests/nexus-harkonnen-occupy-legacy.test.ts @@ -0,0 +1,47 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import { leaders, treacheryDeck } from '../game/cards'; +import { NEXUS_FACTIONS, type NexusPlayer } from '../game/nexus-cards'; +import { + closeHarkonnenBetrayalSource, createHarkonnenBetrayalSource, initialHarkonnenBetrayalCursor, + validateHarkonnenBetrayalHistory, validateHarkonnenBetrayalSource, + type HarkonnenBetrayalAuthority, type HarkonnenBetrayalContext, +} from '../game/nexus-harkonnen-betrayal'; +import { createTraitorDeclaration } from '../game/traitor-declarations'; +import { traitorDeck } from '../game/traitors'; + +/** A source using the exact old two-plan context, including its original + * physical snapshot and source constructor. This is helper compatibility, not + * evidence of a resumed room or an independently reproduced Basic battle. */ +void test('the prior two-plan Harkonnen source remains readable and closable', () => { + const players: NexusPlayer[] = [ + {id:'e', faction:'ecaz', ally:'g'}, + {id:'g', faction:'guild', ally:'e'}, + {id:'h', faction:'harkonnen', ally:null}, + {id:'a', faction:'atreides', ally:null}, + ]; + const universe = traitorDeck(players.map(p => ({leaders:leaders(p.faction)}))); + const held = 'ecaz-0'; + const ctx: HarkonnenBetrayalContext = { + status:'playing', phase:6, turn:2, advanced:false, sequence:0, expansions:['ecaz'], + players, universe, physicalCards:treacheryDeck(['ecaz']), + cards:{version:1, deck:NEXUS_FACTIONS.filter(id => id !== 'harkonnen'), discard:[], + hands:Object.fromEntries(players.map(p => [p.id, p.id === 'a' ? 'harkonnen' : null]))}, + traitors:{reserve:universe.filter(id => id !== held), + players:players.map(p => ({id:p.id, faction:p.faction, traitors:p.id === 'h' ? [held] : []}))}, + battle:{event:'old-basic-occupy-battle', attacker:'h', defender:'e', + plans:{h:{leader:'harkonnen-0'}, e:{leader:held}}, heroLeaderIds:[]}, + }; + const declaration = createTraitorDeclaration({...ctx.battle, + players:players.map(p => ({...p, traitors:p.id === 'h' ? [held] : []}))}, 'h'); + const authority: HarkonnenBetrayalAuthority = {provider:'h', declaration, + nativeWindow:'direct', nativeContext:'original-native-context', nativeRequired:[], nativePassed:[]}; + const source = createHarkonnenBetrayalSource(ctx, authority, 'original-battle-parent'); + assert.equal(Object.hasOwn(source.battle, 'ecazOccupy'), false); + const restored = JSON.parse(JSON.stringify(source)) as typeof source; + validateHarkonnenBetrayalSource(ctx, restored, authority, 'original-battle-parent'); + const closed = closeHarkonnenBetrayalSource(restored, 'use', 'a', initialHarkonnenBetrayalCursor()); + validateHarkonnenBetrayalHistory([closed.receipt], closed.cursor, universe); + assert.equal(closed.receipt.source.declaration.identity, held); + assert.equal(closed.receipt.outcome, 'use'); +}); diff --git a/tests/nexus-harkonnen-occupy-quote.test.ts b/tests/nexus-harkonnen-occupy-quote.test.ts new file mode 100644 index 00000000..a749016b --- /dev/null +++ b/tests/nexus-harkonnen-occupy-quote.test.ts @@ -0,0 +1,114 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import { leaders, treacheryDeck } from '../game/cards'; +import { quoteEcazOccupyBattle } from '../game/ecaz-occupy-battle'; +import { NEXUS_FACTIONS, type NexusPlayer } from '../game/nexus-cards'; +import { + closeHarkonnenBetrayalSource, + createHarkonnenBetrayalSource, + initialHarkonnenBetrayalCursor, + validateHarkonnenBetrayalHistory, + validateHarkonnenBetrayalSource, + type HarkonnenBetrayalAuthority, + type HarkonnenBetrayalContext, +} from '../game/nexus-harkonnen-betrayal'; +import { createTraitorDeclaration } from '../game/traitor-declarations'; +import { traitorDeck } from '../game/traitors'; + +/** The original public alliance, actual traitor custody and complete Occupy + * quote are retained in each source; no runtime battle is claimed here. */ +function fixture(side: 'ecaz-leads' | 'harkonnen-leads' | 'opposing' | 'external-ally') { + const together = side === 'ecaz-leads' || side === 'harkonnen-leads'; + const external = side === 'external-ally'; + const players: NexusPlayer[] = [ + { id: 'e', faction: 'ecaz', ally: together ? 'h' : 'g' }, + { id: 'h', faction: 'harkonnen', ally: together ? 'e' : external ? 'a' : null }, + { id: 'g', faction: 'guild', ally: together ? null : 'e' }, + { id: 'a', faction: 'atreides', ally: external ? 'h' : null }, + ...(external ? [{ id: 'f', faction: 'fremen' as const, ally: null }] : []), + ]; + const ally = together ? players[1] : players[2]; + const lead = side === 'harkonnen-leads' ? 'h' : 'e'; + const opposing = together ? 'g' : external ? 'a' : 'h'; + const identity = together ? 'guild-0' : 'ecaz-1'; + const holder = external ? 'f' : 'a'; + const ecazLoyalty = { player: 'e', card: 'ecaz-0' }; + const universe = traitorDeck(players.map(player => ({ leaders: leaders(player.faction) }))) + .filter(card => card !== ecazLoyalty.card); + const forces = { normal: 4, elite: 0, eliteStrength: 2 as const, freeSupport: false }; + const occupy = quoteEcazOccupyBattle({ advanced: true, battleOrderActor: opposing, + ecaz: { id: 'e', faction: 'ecaz', ally: ally.id, forces }, + ally: { id: ally.id, faction: ally.faction, ally: 'e', forces }, + lead, canceled: false }); + const ctx: HarkonnenBetrayalContext = { + status: 'playing', phase: 6, turn: 2, advanced: true, sequence: 0, + expansions: ['ecaz'], players, ecazLoyalty, universe, + physicalCards: treacheryDeck(['ecaz']), + cards: { version: 1, deck: NEXUS_FACTIONS.filter(card => card !== 'harkonnen'), + discard: [], hands: Object.fromEntries(players.map(player => [player.id, + player.id === holder ? 'harkonnen' : null])) }, + traitors: { reserve: universe.filter(card => card !== identity), + players: players.map(player => ({ id: player.id, faction: player.faction, + traitors: player.id === 'h' ? [identity] : [] })) }, + battle: { event: 'occupy-battle', attacker: lead, defender: opposing, + plans: { [lead]: { leader: lead === 'h' ? 'harkonnen-0' : 'ecaz-1' }, + [opposing]: { leader: opposing === 'g' ? 'guild-0' : opposing === 'a' ? 'atreides-0' : 'harkonnen-0' } }, + heroLeaderIds: [], ecazOccupy: occupy }, + }; + const declaration = createTraitorDeclaration({ ...ctx.battle, players: players.map(player => ({ ...player, + traitors: ctx.traitors.players.find(seat => seat.id === player.id)!.traitors })) }, 'h'); + const native: HarkonnenBetrayalAuthority = { provider: 'h', declaration, + nativeWindow: external ? 'harkonnenTraitor' : 'direct', nativeContext: 'original-native-source', + nativeRequired: external ? ['e'] : [], nativePassed: external ? ['e'] : [] }; + return { ctx, native, holder, identity }; +} + +for (const side of ['ecaz-leads', 'harkonnen-leads', 'opposing', 'external-ally'] as const) + void test(`Occupy ${side} preserves the canonical Harkonnen declaration and physical source`, () => { + const { ctx, native, holder, identity } = fixture(side); + const before = structuredClone(ctx); + const source = createHarkonnenBetrayalSource(ctx, native, 'battle-parent'); + assert.equal(source.declaration.identity, identity); + assert.equal(source.battle.ecazOccupy?.lead, ctx.battle.ecazOccupy?.lead); + assert.equal(source.eligible, holder); + validateHarkonnenBetrayalSource(ctx, source, native, 'battle-parent'); + const { receipt, cursor } = closeHarkonnenBetrayalSource(source, 'use', holder, + initialHarkonnenBetrayalCursor()); + validateHarkonnenBetrayalHistory([receipt], cursor, ctx.universe); + assert.deepEqual(ctx, before); + }); + +void test('Occupy co-side calls never invent an allied Karama counter', () => { + const { ctx, native } = fixture('ecaz-leads'); + assert.equal(native.declaration.beneficiary, 'e'); + assert.equal(native.declaration.voter, 'h'); + assert.throws(() => createHarkonnenBetrayalSource(ctx, + { ...native, nativeWindow: 'harkonnenTraitor' }, 'battle-parent')); + assert.throws(() => createHarkonnenBetrayalSource(ctx, + { ...native, nativeRequired: ['a'], nativePassed: ['a'] }, 'battle-parent')); +}); + +void test('Occupy external Harkonnen ally retains the completed native counter', () => { + const { ctx, native } = fixture('external-ally'); + assert.throws(() => createHarkonnenBetrayalSource(ctx, + { ...native, nativeWindow: 'direct', nativeRequired: [], nativePassed: [] }, 'battle-parent')); + assert.throws(() => createHarkonnenBetrayalSource(ctx, + { ...native, nativePassed: [] }, 'battle-parent')); +}); + +void test('Occupy source rejects changed derived profile, rules band or original alliance', () => { + const { ctx, native } = fixture('ecaz-leads'); + const source = createHarkonnenBetrayalSource(ctx, native, 'battle-parent'); + for (const altered of [ + { ...ctx.battle.ecazOccupy!, fixedEcazDial: ctx.battle.ecazOccupy!.fixedEcazDial + 1 }, + { ...ctx.battle.ecazOccupy!, forceOwner: 'e' }, + { ...ctx.battle.ecazOccupy!, advanced: false }, + ]) { + const changed = { ...ctx, battle: { ...ctx.battle, ecazOccupy: altered } }; + assert.throws(() => createHarkonnenBetrayalSource(changed, native, 'battle-parent')); + assert.throws(() => validateHarkonnenBetrayalSource(changed, source, native, 'battle-parent')); + } + const changedAlliance = { ...ctx, players: ctx.players.map(player => player.id === 'h' + ? { ...player, ally: null } : player) }; + assert.throws(() => createHarkonnenBetrayalSource(changedAlliance, native, 'battle-parent')); +}); diff --git a/tests/nexus-harkonnen-occupy-runtime.test.ts b/tests/nexus-harkonnen-occupy-runtime.test.ts new file mode 100644 index 00000000..2b4f46be --- /dev/null +++ b/tests/nexus-harkonnen-occupy-runtime.test.ts @@ -0,0 +1,146 @@ +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 { TERRITORIES } from '../game/board'; +import { traitorDeck } from '../game/traitors'; +import { withoutEcazLoyalty } from '../game/ecaz-loyalty'; +import { validateNexusTraitorSnapshot } from '../game/nexus-traitor-exchange'; +import { nextHarkonnenBetrayalNativeStep, settleHarkonnenBetrayalNativeCounters } from './fixture-nexus-harkonnen-betrayal'; + +const act = (game: Game, actor: string, action: Action) => applyAction(game, actor, action); +const seat = (game: Game, id: string) => { const player = game.players.find(p => p.id === id); assert.ok(player); return player; }; + +function step(game: Game): Game { + const next = nextHarkonnenBetrayalNativeStep(game); + try { return act(game, next.actor, next.action); } + catch (error) { throw Error(`Native Occupy/Nexus ${game.turn}/${game.phase}/${game.decision?.kind} ${JSON.stringify(next)}: ${String(error)}`); } +} +function advance(game: Game, until: (game: Game) => boolean): Game { + for (let i = 0; i < 1800; i++) { + if (until(game)) return game; + assert.notEqual(game.status, 'finished'); + game = step(game); + } + throw Error(`Native Occupy/Nexus stalled at ${game.status}/${game.turn}/${game.phase}/${game.decision?.kind}`); +} +function inventory(game: Game): string[] { + return [...game.deck, ...game.discard, ...(game.auction?.cards.slice(game.auction.index) ?? []), + ...game.players.flatMap(player => player.hand)].map(card => card.id).sort(); +} +function traitors(game: Game): void { + validateNexusTraitorSnapshot({ reserve: game.traitorReserve!, players: game.players.map(({ id, faction, traitors, faceDancers }) => + ({ id, faction, traitors, ...(faceDancers ? { faceDancers } : {}) })) }, + withoutEcazLoyalty(traitorDeck(game.players), game.ecazLoyalty)); +} +/** Swap one original held or reserve card; never create a Traitor identity. */ +function stageTraitor(game: Game, identity: string): void { + const owner = seat(game, 'h'); + if (owner.traitors.includes(identity)) return; + const previous = owner.traitors[0]; assert.ok(previous); + const holder = game.players.find(player => player.id !== 'h' && player.traitors.includes(identity)); + if (holder) holder.traitors[holder.traitors.indexOf(identity)] = previous; + else { + const index = game.traitorReserve!.indexOf(identity); assert.ok(index >= 0); + game.traitorReserve![index] = previous; + } + owner.traitors[0] = identity; +} + +/** Actual public Advanced E3 setup, natural second-turn Nexus, reciprocal + * alliance, Nexus draw, native Occupy lead, sealed plans and traitor call. + * Only unopened Nexus/Spice deck order, one conserved held Traitor exchange + * and one existing reserve force per battle participant are staged. */ +function fixture(side: 'ally' | 'opponent', lead: 'ecaz' | 'ally') { + let game = createGame('HARKOCCUPY', newPlayer('e', 'Ecaz', 'ecaz'), true, ['ecaz']); + for (const [id, faction] of [['h', 'harkonnen'], ['g', 'guild'], ['a', 'atreides']] as const) + joinGame(game, newPlayer(id, faction, faction)); + game = act(game, 'e', { type: 'moduleOption', module: 'nexusCards', enabled: true }); + for (const p of game.players) game = act(game, p.id, { type: 'ready' }); + game = act(game, 'e', { type: 'start', advancedPreview: true }); + assert.equal(game.nexusHarkonnenBetrayalPreview, true); + game = advance(game, state => state.status === 'playing'); + const cards = inventory(game); traitors(game); + const nexus = game.nexusCards!.cards!, face = nexus.deck.indexOf('harkonnen'); assert.ok(face >= 0); + nexus.deck.unshift(nexus.deck.splice(face, 1)[0]); + for (let pos = 0; pos < 2; pos++) { + const index = game.spiceDeck.findIndex((card, n) => n >= pos && 'territory' in card); assert.ok(index >= pos); + game.spiceDeck.splice(pos, 0, game.spiceDeck.splice(index, 1)[0]); + } + game = advance(game, state => state.turn === 2 && state.phase === 1 && !state.response && !state.decision); + const worm = game.spiceDeck.findIndex(card => 'worm' in card && !card.greatMaker && !card.suppressed); assert.ok(worm >= 0); + game.spiceDeck.unshift(game.spiceDeck.splice(worm, 1)[0]); + game = advance(game, state => state.nexus && !state.spiceWindow && !state.spiceResolution && !state.response && !state.decision); + const ally = side === 'ally' ? 'h' : 'g'; + const opponent = side === 'ally' ? 'a' : 'h'; + const holder = side === 'ally' ? 'g' : 'a'; + game = act(game, 'e', { type: 'alliance', target: ally }); + game = act(game, ally, { type: 'alliance', target: 'e' }); + game = advance(game, state => state.nexusCards?.phase?.stage === 'drawing'); + assert.ok(game.nexusCards!.phase!.eligible.includes(holder)); + game = act(game, holder, { type: 'nexusCardChoice', turn: game.turn, card: null, choice: 'draw', ownRedraws: 0 }); + assert.equal(game.nexusCards!.cards!.hands[holder], 'harkonnen'); + game = advance(game, state => state.phase === 5 && !state.response && !state.decision); + const territory = TERRITORIES.find(t => t.type === 'sand' && !t.sectors.includes(game.storm) && + game.players.every(p => !Object.keys(p.forces).some(key => key.startsWith(`${t.id}:`)))); assert.ok(territory); + for (const id of ['e', ally, opponent]) { + const p = seat(game, id); assert.ok(p.reserves > 0); p.reserves--; + p.forces[`${territory.id}:${territory.sectors[0]}`] = 1; + } + game = advance(game, state => state.phase === 6 && !!state.active && !state.phaseOpening && !state.response && !state.decision); + const choice = viewGame(game, game.active!).battleChoices.find(item => item.territory === territory.id); assert.ok(choice); + game = act(game, choice.chooser, { type: 'chooseBattle', territory: territory.id, + target: choice.attacker === choice.chooser ? choice.defender : choice.attacker }); + const decision = game.decision; + assert.ok(decision?.kind === 'ecazBattleLead'); + game = act(game, 'e', { type: 'decision', event: decision.event, lead: lead === 'ecaz' ? 'e' : ally }); + // Public Nexus setup may retain ordinary pre-leader or other native battle + // decisions after the Occupy lead and counter. Drive each original window; + // the standalone Occupy helper assumes those windows are already absent. + game = advance(game, state => !!state.battle && !state.response && !state.decision && + !state.battle.preparation && (!state.battle.preLeader || state.battle.preLeader.closed)); + assert.ok(game.battle?.ecazOccupy); + const actor = lead === 'ecaz' ? 'e' : ally; + const target = side === 'ally' ? opponent : actor; + const identity = seat(game, target).leaders.find(leader => !leader.dead && !leader.usedAt && + leader.id !== game.ecazLoyalty?.card)!.id; + stageTraitor(game, identity); traitors(game); + const profile = viewGame(game, actor).battle!.ecazOccupy!.profile!; + for (const id of [game.battle!.attacker, game.battle!.defender]) { + const leader = id === target ? identity : seat(game, id).leaders.find(l => !l.dead && !l.usedAt)!.id; + game = act(game, id, { type: 'battlePlan', dial: id === actor ? profile.fixedEcazDial : 0, leader }); + } + assert.equal(game.battle!.revealed, true); + game = advance(game, state => !state.response && !state.decision); + game = act(game, 'h', { type: 'traitorCall', call: true }); + game = settleHarkonnenBetrayalNativeCounters(game); + const reaction = viewGame(game, holder).nexusHarkonnenBetrayalReaction; + assert.ok(reaction, 'A genuine Occupy Harkonnen call must offer the held Nexus.'); + assert.equal(reaction.identity, identity); + assert.equal(reaction.target, target); + assert.equal(reaction.beneficiary, side === 'ally' ? actor : 'h'); + assert.equal(reaction.canUse, true); + assert.deepEqual(inventory(game), cards); traitors(game); + return { game, holder, identity, event: reaction.event, cards }; +} + +for (const side of ['ally', 'opponent'] as const) for (const lead of ['ecaz', 'ally'] as const) + for (const use of [false, true]) + void test(`Advanced Ecaz Occupy, Harkonnen ${side}, ${lead} lead: native Nexus ${use ? 'Use' : 'Pass'}`, () => { + const f = fixture(side, lead); let game = f.game; + if (use) game = act(game, f.holder, { type: 'nexusHarkonnenBetrayalUse', event: f.event }); + else for (const id of game.pendingNexusHarkonnenBetrayal!.required) + game = act(game, id, { type: 'nexusHarkonnenBetrayalPass', event: f.event }); + assert.equal(game.pendingNexusHarkonnenBetrayal, null); + assert.equal(game.battle!.traitorCalls.h, !use); + assert.equal(seat(game, 'h').traitors.includes(f.identity), !use); + assert.equal(game.pendingNexusHarkonnenReplacement?.status ?? null, use ? 'due' : null); + assert.equal(game.nexusCards!.cards!.hands[f.holder], use ? null : 'harkonnen'); + assert.deepEqual(inventory(game), f.cards); traitors(game); + const top = game.traitorReserve![0]; + game = advance(game, state => state.phase === 8 && !state.pendingNexusHarkonnenReplacement && !state.phaseOpening); + assert.equal(game.lastBattleContext!.result, use ? 'normal' : 'traitor'); + assert.equal(game.nexusHarkonnenReplacementHistory!.length, use ? 1 : 0); + if (use) assert.equal(game.nexusHarkonnenReplacementHistory![0].drawn, top); + assert.equal(seat(game, 'h').traitors.length, 4); + assert.deepEqual(inventory(game), f.cards); traitors(game); + });