diff --git a/docs/CURRENT_STATUS.md b/docs/CURRENT_STATUS.md index a9532611..d7460e0a 100644 --- a/docs/CURRENT_STATUS.md +++ b/docs/CURRENT_STATUS.md @@ -17,6 +17,16 @@ open mode gates. ## Current checkpoint and work +**Basic Emperor gifts at Nexus Richese cache sales — 16 November. Prototyped / +Partial.** Supported public Nexus games retain the original cache lot and +committed split through gift, cancellation and Continue. The separate audit +preview also preserves a Richese Betrayal bank diversion or self-purchase +veto. An old preview initialization conflict and seller-lot clock validation +were repaired. Seven related files pass 54 cases; type checking and lint pass. +Other optional modules, broader timing, complete games and deployed acceptance +remain open. +[Scope](EMPEROR_ALLIANCE_TIMING.md#basic-nexus-richese-cache-gifts--16-november-2026). + **Advanced selected-deck Harkonnen Nexus Betrayal — 30 October. Prototyped / Partial.** Supported Advanced selected-deck core games now open the original traitor reaction and Mentat replacement for native Ixian, Tleilaxu, CHOAM and diff --git a/docs/EMPEROR_ALLIANCE_TIMING.md b/docs/EMPEROR_ALLIANCE_TIMING.md index 5c23fb9b..00b98312 100644 --- a/docs/EMPEROR_ALLIANCE_TIMING.md +++ b/docs/EMPEROR_ALLIANCE_TIMING.md @@ -1,5 +1,22 @@ # Emperor alliance gift timing +## Basic Nexus Richese cache gifts — 16 November 2026 + +Supported Basic Nexus games now offer the Emperor's gift before an allied +Richese cache purchase settles, preserving the lot and its committed funding. +If the separate Richese Betrayal preview diverted a sale to the bank, Continue +retains that destination; a vetoed self-purchase opens no payment gift. The +public [Once Around and Silent journeys](../tests/emperor-richese-cache-gift-nexus-basic.test.ts) +include an earned Nexus, Kull and Semuta. The [Betrayal journeys](../tests/emperor-richese-cache-gift-betrayal-basic.test.ts) +use the separate audit initializer and stage alliances and physical custody. +The online ordering is provisional; other optional modules, wider timing, +complete games and deployed acceptance remain open. + +The older Richese Betrayal audit initializer no longer initializes unrelated +native Nexus reaction stamps that its own profile rejects. Seller purchase +validation now accepts the original sequential lot's version-one clock; +already-opened lots without a clock retain their previous validation. + ## Basic Nexus and Richese cache auction gifts — 30 October 2026 Supported Basic ordinary Nexus auctions offer the Emperor's gift before the @@ -17,9 +34,10 @@ are provisional online interpretations. Evidence includes public-start [cache sales](../tests/emperor-richese-cache-gift-basic-public.test.ts), [Kull and counter-Karama](../tests/emperor-richese-cache-gift-kull-basic.test.ts), and [cache controls](../tests/emperor-auction-gift-cache-controls.test.tsx). -Fixtures stage selected balances, cards and unopened Spice order. Cache sales -combined with Nexus or other optional modules, other special auctions, wider -timing interactions, complete games and deployed acceptance remain open. +Fixtures stage selected balances, cards and unopened Spice order. At that +checkpoint cache sales combined with Nexus or other optional modules, other +special auctions, wider timing interactions, complete games and deployed +acceptance remained open; the newer section above covers supported Nexus sales. ## Basic allied auction payment — 30 October 2026 diff --git a/docs/RULE_DECISIONS.md b/docs/RULE_DECISIONS.md index 951d3154..12c2900e 100644 --- a/docs/RULE_DECISIONS.md +++ b/docs/RULE_DECISIONS.md @@ -1,5 +1,13 @@ # Rule decision index +## Basic Nexus Richese cache gifts — 16 November 2026 + +The existing provisional prepayment gift applies to supported Nexus cache +sales. A completed Richese Betrayal preserves its original seller or bank +destination through the gift. This ordering is a software interpretation, +not a new publisher timing ruling. +[Scope](EMPEROR_ALLIANCE_TIMING.md#basic-nexus-richese-cache-gifts--16-november-2026). + ## Advanced selected-deck Harkonnen Nexus reaction — 30 October 2026 The existing native-counter-first and neutral acknowledgement convention diff --git a/game/engine.ts b/game/engine.ts index a3e47361..92910603 100644 --- a/game/engine.ts +++ b/game/engine.ts @@ -2129,6 +2129,8 @@ export type Game = { giftAmount?: number; source?: 'richese'; quote?: Extract; + /** A previously allowed Richese Nexus diversion sends this sale to the bank. */ + bank?: true; } | null; richeseGiftBlocked?: { turn: number; phase: number; cards: string[] }; richeseAllyOffer?: RicheseAllyOffer | null; @@ -13550,7 +13552,7 @@ export function initializeRicheseBetrayalGameForAudit(state: Game): Game { richeseBetrayalModeSupported(state) && state.nexusCards?.cards === null && state.nexusCards.phase === null, 'Richese Betrayal needs a fresh CHOAM/Richese lobby, the CHOAM deck and only Nexus Cards.'); - const g = initializeSetupGameForAudit(state, false, true, false, false, false, false, true); + const g = initializeSetupGameForAudit(state, false, true, false, false, false, false, true, false, false, false, false); g.richeseBetrayalPreview = true; g.richeseBetrayal = {sequence:0,current:null,completed:[]}; g.pendingRicheseBetrayal = null; @@ -13991,7 +13993,7 @@ export function initializeEcazTreacheryGameForAudit(state: Game): Game { if (moritaniAssassinateModeSupported(initialized)) initializeMoritaniAssassinateState(initialized); return initialized; } -function initializeSetupGameForAudit(state: Game, homeworlds: boolean, nexus = false, ix = false, discovery = false, leaderSkills = false, choam = false, factions = false, ecazTreachery = false, strongholdFactions = false, semuta = false): Game { +function initializeSetupGameForAudit(state: Game, homeworlds: boolean, nexus = false, ix = false, discovery = false, leaderSkills = false, choam = false, factions = false, ecazTreachery = false, strongholdFactions = false, semuta = false, nativeNexusReactions = true): Game { nexusCardsIntegrity(state); homeworldRule(() => homeworldGameIntegrity(state)); homeworldBattleLossIntegrity(state); @@ -14066,7 +14068,7 @@ function initializeSetupGameForAudit(state: Game, homeworlds: boolean, nexus = f g.spiceBankerIncomePreview = true; g.spiceBankerIncome = bankerIncomeRule(() => createBankerIncomeState(bankerIncomeContext(g))); } - if (nexusCoreProfile(g)) { + if (nativeNexusReactions && nexusCoreProfile(g)) { requireRule(g.nexusIxianReplacementPreview === undefined && g.nexusIxianReplacementHistory === undefined && g.nexusIxianReplacementCursor === undefined && !g.pendingNexusIxianReplacement && !g.pendingNexusIxianSpecialPurchase && @@ -15821,7 +15823,17 @@ function richeseBetrayalIntegrity(g: Game): void { completed.round === g.richeseBidding?.event && !(completed.stage === 'used' && completed.invoice.kind === 'purchase'), 'The completed Richese reaction lost its original source.'); - if (waiting) { + const gift = g.pendingEmperorAuctionGift; + if (gift?.source === 'richese') { + requireRule(!sale && !waiting && (completed.invoice.kind === 'sale' || completed.stage === 'passed') && + gift.recipient === completed.invoice.buyer && gift.quote && + g.richeseAuction?.owner === completed.invoice.target && + gift.quote.amount === completed.invoice.price && gift.quote.ownPayment === completed.invoice.ownPayment && + gift.quote.allyPayment === completed.invoice.allyPayment && + JSON.stringify(gift.quote.card) === JSON.stringify(completed.invoice.card) && + (gift.bank === true) === (completed.stage === 'used'), + 'The completed Richese reaction lost its original gift and payment continuation.'); + } else if (waiting) { requireRule(!sale && waiting.round === completed.round && waiting.lot.event === completed.lot && waiting.winner === completed.invoice.buyer && waiting.lot.owner === completed.invoice.target && waiting.lot.source === completed.invoice.source && waiting.quote.amount === completed.invoice.price && @@ -15962,6 +15974,7 @@ function decideRicheseBetrayal(g: Game, p: Player, action: Action): void { finishRicheseLot(g); } else { if (use) log(g,`${p.name} spent Richese Nexus Betrayal: the ${receipt.invoice.price}-spice Richese sale payment goes to the Spice Bank instead.`); + if (beginEmperorRicheseAuctionGift(g,frame.quote,use)) return; settleRicheseSoldLot(g,frame.quote,use); } } @@ -18963,20 +18976,22 @@ function emperorAuctionGiftParked(g: Game) { function emperorAuctionGiftSignature(g: Game): string { if (g.pendingEmperorAuctionGift?.source === 'richese') return JSON.stringify(['richese',g.turn,g.phase,g.active,g.richeseAuction,g.richeseBidding, - g.richeseFunding,g.aid,g.pendingEmperorAuctionGift.quote]); + g.richeseFunding,g.aid,g.pendingEmperorAuctionGift.quote, + ...(g.pendingEmperorAuctionGift.bank ? [true] : [])]); return JSON.stringify([g.turn, g.phase, g.active, g.decision ?? emperorAuctionGiftParked(g)?.decision, g.order, g.auction, g.aid]); } -function beginEmperorRicheseAuctionGift(g: Game, quote: Extract): boolean { +function beginEmperorRicheseAuctionGift(g: Game, quote: Extract, bank = false): boolean { if (g.advanced || g.status !== 'playing' || g.phase !== 3 || g.richeseAuction?.source !== 'cache' || - g.techTokens || g.strongholdCards || g.leaderSkills || g.homeworlds || g.nexusCards || + g.techTokens || g.strongholdCards || g.leaderSkills || g.homeworlds || g.discoveryEnabled || g.sandtrout || g.coalitionState || g.ecazTreachery || g.pendingEmperorAuctionGift || g.response || g.decision || g.phaseOpening || g.truthtrance || g.pendingKarama || g.pendingTreacheryDiscard || g.pendingRicheseGift || g.pendingNullentropy || + g.pendingRicheseBetrayal || g.pendingNexusEmperorSellerPurchase || g.currentAuctionSale || g.auction || g.ixAuction) return false; const emperor = byFaction(g,'emperor'), buyer = g.players.find(player => player.id === quote.winner); if (!emperor || !buyer || emperor.id === buyer.id || emperor.ally !== buyer.id || buyer.ally !== emperor.id) return false; g.pendingEmperorAuctionGift = {event:crypto.randomUUID(), owner:emperor.id, recipient:buyer.id, - turn:g.turn, source:'richese', quote:structuredClone(quote), signature:''}; + turn:g.turn, source:'richese', quote:structuredClone(quote), ...(bank ? {bank:true as const} : {}), signature:''}; g.pendingEmperorAuctionGift.signature = emperorAuctionGiftSignature(g); return true; } @@ -19016,9 +19031,13 @@ function emperorAuctionGiftIntegrity(g: Game) { typeof pending.event === 'string' && !!pending.event && owner?.faction === 'emperor' && recipient && owner.ally === recipient.id && recipient.ally === owner.id && (pending.source === 'richese' - ? !decision && !g.auction && g.richeseAuction?.source === 'cache' && !!pending.quote && - pending.quote.winner === recipient.id && JSON.stringify(pending.quote) === JSON.stringify(richeseSettlementQuote(g)) - : pending.source === undefined && pending.quote === undefined && + ? (pending.bank === undefined || pending.bank === true) && !decision && !g.auction && g.richeseAuction?.source === 'cache' && !!pending.quote && + pending.quote.winner === recipient.id && JSON.stringify(pending.quote) === JSON.stringify(richeseSettlementQuote(g)) && + (!pending.bank || !!g.richeseBetrayalPreview && !!g.richeseBetrayal?.completed.some(receipt => + receipt.stage === 'used' && receipt.invoice.kind === 'sale' && receipt.lot === g.richeseAuction!.event && + receipt.round === g.richeseBidding?.event && receipt.invoice.buyer === recipient.id && + receipt.invoice.target === g.richeseAuction!.owner && receipt.invoice.price === pending.quote!.amount)) + : pending.source === undefined && pending.quote === undefined && pending.bank === undefined && decision?.kind === 'auctionPayment' && decision.player === recipient.id && g.auction?.bidder === recipient.id) && pending.signature === emperorAuctionGiftSignature(g), 'The Emperor auction gift lost its original payment opportunity.'); @@ -44693,7 +44712,7 @@ function applyActionInner( g.pendingEmperorAuctionGift = null; if (pending.source === 'richese') { requireRule(pending.quote, 'The Richese auction gift lost its committed sale.'); - settleRicheseSoldLot(g,pending.quote,false); + settleRicheseSoldLot(g,pending.quote,pending.bank === true); return g; } if (!g.advanced && g.nexusCards && !beginNexusEmperorPayment(g)) diff --git a/game/faction-reference.ts b/game/faction-reference.ts index 0704a761..e7f4126d 100644 --- a/game/faction-reference.ts +++ b/game/faction-reference.ts @@ -86,7 +86,7 @@ export const FACTION_RULES: Record< 'Start with all twenty forces in reserve and ten spice. One force revival is free each turn.', 'Receive payments for other players’ auction purchases. Your own purchases pay the bank; a Karama purchase pays no spice. A cancellation sends one auction payment to the bank.', 'Give spice directly to your ally. After the response window it is immediately spendable, unlike a deferred bribe between non-allies.', - 'In supported Basic ordinary auctions, including Nexus games, and Richese cache sales, you may give your mutual ally spice after they win and before their original payment. Continue preserves the bid and pledged split; a canceled gift transfers nothing.', + 'In supported Basic ordinary auctions and Richese cache sales, including Nexus games, you may give your mutual ally spice after they win and before their original payment. Continue preserves the bid and pledged split; a canceled gift transfers nothing.', 'In supported Moritani games, including Basic games with other selected faction decks, you may also give spice while your ally is choosing whether to pay Extortion. The original choice resumes after the gift’s Karama response.', 'In supported Basic Ix-deck games with classic factions, Ixians or Tleilaxu, you may give an ally spice during the Amal phase opening, even after you have passed. The original opening resumes after the gift response.', 'During Revival, pay two spice per extra allied force, up to three extra forces per turn. These are separate from the ally’s normal three-force allowance and may be purchased before or after ordinary revivals.', diff --git a/game/nexus-emperor-purchase.ts b/game/nexus-emperor-purchase.ts index 0694a7a6..e464d03f 100644 --- a/game/nexus-emperor-purchase.ts +++ b/game/nexus-emperor-purchase.ts @@ -429,7 +429,9 @@ export function quoteEmperorNexusSellerPurchase( !text(input.round) || typeof input.bank !== 'boolean' || !plain(input.lot) || !plain(input.quote) || Object.keys(input.lot).sort().join(',') !== - 'acted,active,bid,bidder,cardId,eligible,event,method,order,outcome,owner,passed,sealed,source,tieOrder' || + ['acted','active','bid','bidder','cardId','eligible','event','method','order','outcome','owner','passed','sealed','source','tieOrder', + ...(Object.hasOwn(input.lot, 'clockVersion') ? ['clockVersion'] : [])].sort().join(',') || + (Object.hasOwn(input.lot, 'clockVersion') && input.lot.clockVersion !== 1) || Object.keys(input.quote).sort().join(',') !== 'allyPayment,amount,card,kind,ownPayment,winner' || input.quote.kind !== 'sold' || g.status !== 'playing' || g.phase !== 3 || !whole(g.turn) || g.turn < 1 || diff --git a/tests/emperor-richese-cache-gift-betrayal-basic.test.ts b/tests/emperor-richese-cache-gift-betrayal-basic.test.ts new file mode 100644 index 00000000..32d93d27 --- /dev/null +++ b/tests/emperor-richese-cache-gift-betrayal-basic.test.ts @@ -0,0 +1,59 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import {applyAction, viewGame, type Game} from '../game/engine'; +import {createRicheseBetrayalFixture} from './fixture-richese-betrayal'; + +const player=(game:Game,id:string)=>{const p=game.players.find(row=>row.id===id);assert.ok(p);return p;}; +function allow(game:Game) { + for(let n=0;game.response&&n<20;n++) { + const actor=game.players.find(p=>!game.response!.passed.includes(p.id));assert.ok(actor); + game=applyAction(game,actor.id,{type:'passResponse'}); + } + return game; +} +for(const diverted of [false,true]) void test(`Basic Emperor gift resumes a ${diverted?'diverted':'ordinary'} Nexus cache sale`,()=>{ + const f=createRicheseBetrayalFixture('sale',{source:'cache',advanced:false,allyPayment:2,emperorAlly:true}); + const before=structuredClone(f.game),emperor=f.ally!; + assert.equal(player(before,emperor).faction,'emperor'); + let game=before; + if(diverted)game=applyAction(game,f.holder,{type:'richeseBetrayalUse',event:f.event}); + else for(const id of before.pendingRicheseBetrayal!.receipt.required) + game=applyAction(game,id,{type:'richeseBetrayalPass',event:f.event}); + const gift=viewGame(game,emperor).emperorAuctionGift;assert.ok(gift); + assert.equal(gift.recipient,f.buyer); + assert.equal(game.pendingEmperorAuctionGift!.bank===true,diverted); + const wallet=player(game,emperor).spice,buyer=player(game,f.buyer).spice,seller=player(game,f.target).spice; + game=applyAction(game,emperor,{type:'emperorGift',amount:1});game=allow(game); + game=applyAction(game,emperor,{type:'emperorAuctionGiftContinue',event:gift.event}); + game=allow(game); + assert.equal(player(game,emperor).spice,wallet-1); + assert.equal(player(game,f.buyer).spice,buyer+1-4); + assert.equal(player(game,f.target).spice,seller+(diverted?0:6)); + assert.equal(player(game,f.buyer).hand.filter(card=>card.id===f.card).length,1); + assert.equal(game.richeseBetrayal!.completed[0].stage,diverted?'used':'passed'); +}); + +void test('Basic Emperor gift follows a passed Nexus veto for an allied Richese self-purchase',()=>{ + const f=createRicheseBetrayalFixture('purchase',{source:'cache',advanced:false,emperorAlly:true}); + let game=f.game; + for(const id of f.game.pendingRicheseBetrayal!.receipt.required) + game=applyAction(game,id,{type:'richeseBetrayalPass',event:f.event}); + const gift=viewGame(game,f.ally!).emperorAuctionGift;assert.ok(gift); + assert.equal(gift.recipient,f.target); + const buyer=player(game,f.target).spice; + game=applyAction(game,f.ally!,{type:'emperorGift',amount:1});game=allow(game); + game=applyAction(game,f.ally!,{type:'emperorAuctionGiftContinue',event:gift.event});game=allow(game); + assert.equal(player(game,f.target).spice,buyer+1-6); + assert.equal(player(game,f.target).hand.filter(card=>card.id===f.card).length,1); + assert.equal(game.richeseBetrayal!.completed[0].stage,'passed'); +}); + +void test('A Nexus veto of an allied Richese self-purchase does not open a payment gift',()=>{ + const f=createRicheseBetrayalFixture('purchase',{source:'cache',advanced:false,emperorAlly:true}); + const before=player(f.game,f.ally!).spice; + const game=applyAction(f.game,f.holder,{type:'richeseBetrayalUse',event:f.event}); + assert.equal(game.pendingEmperorAuctionGift??null,null); + assert.equal(player(game,f.ally!).spice,before); + assert.equal(game.discard.filter(card=>card.id===f.card).length,1); + assert.equal(player(game,f.target).hand.some(card=>card.id===f.card),false); +}); diff --git a/tests/emperor-richese-cache-gift-nexus-basic.test.ts b/tests/emperor-richese-cache-gift-nexus-basic.test.ts new file mode 100644 index 00000000..c2a9c649 --- /dev/null +++ b/tests/emperor-richese-cache-gift-nexus-basic.test.ts @@ -0,0 +1,126 @@ +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 {takeKullCard} from './fixture-choam-kull'; +import {advanceSemutaNexusTrade, nextSemutaNexusTradeNativeStep} from './fixture-semuta-nexus-trade'; +import {beforeIxSpiceDraw, orderIxSpiceCards} from './fixture-ix-spice-cards'; + +const act=(g:Game,id:string,action:Action)=>applyAction(g,id,action); +const player=(g:Game,id:string)=>{const p=g.players.find(row=>row.id===id);assert.ok(p);return p;}; +const quiet=(g:Game)=>!g.phaseOpening&&!g.response&&!g.decision&&!g.truthtrance&&!g.pendingTreacheryDiscard; +function inventory(g:Game) { + const cards=[...g.deck,...g.discard,...(g.richeseCache??[]),...(g.richeseRemoved??[]), + ...(g.auction?.cards.slice(g.auction.index+Number(g.currentAuctionSale?.origin==='normal'))??[]), + ...(g.ixAuction?.cards??[]),...g.players.flatMap(row=>row.hand)].map(card=>card.id).sort(); + assert.equal(new Set(cards).size,cards.length);return cards; +} +function passResponse(g:Game) { + for(let n=0;g.response&&n!g.response!.passed.includes(p.id));assert.ok(seat); + g=act(g,seat.id,{type:'passResponse'}); + } + return g; +} +function passSemuta(g:Game) { + for(let n=0;g.pendingTreacheryDiscard?.reaction?.stage==='offer'&&n!reaction.passed.includes(p.id));assert.ok(seat); + g=act(g,seat.id,{type:'semutaPass',event:pending.batch.event}); + } + return g; +} + +/** Genuine public Basic setup, qualifying worm, alliance and paid cache bid. + * Staged only unopened Spice, reserve positions, purses and conserved physical + * hand/deck ownership before Ix's auction pool is drawn. */ +function fixture(method:'onceAround'|'silent') { + let g=createGame('BASICRICHGIFT',newPlayer('e','Emperor','emperor'),false,['choam','ix']); + for(const [id,faction] of [['g','guild'],['c','choam'],['r','richese'],['a','atreides']] as const) + joinGame(g,newPlayer(id,faction,faction)); + g=act(g,'e',{type:'moduleOption',module:'nexusCards',enabled:true}); + for(const p of g.players) g=act(g,p.id,{type:'ready'}); + g=act(g,'e',{type:'start'}); + assert.equal(g.kullPreview,true);assert.equal(g.semutaPreview,true); + g=advanceSemutaNexusTrade(g,s=>s.status==='playing'); + for(const p of g.players){p.reserves+=Object.values(p.forces).reduce((sum,n)=>sum+n,0);p.forces={};} + g=advanceSemutaNexusTrade(g,beforeIxSpiceDraw);orderIxSpiceCards(g,['land','land']); + g=advanceSemutaNexusTrade(g,s=>s.turn===2&&beforeIxSpiceDraw(s));orderIxSpiceCards(g,['worm','land','land']); + g=advanceSemutaNexusTrade(g,s=>!!s.nexus&&!s.spiceWindow&&quiet(s)); + g=act(g,'e',{type:'alliance',target:'g'});g=act(g,'g',{type:'alliance',target:'e'}); + g=advanceSemutaNexusTrade(g,s=>s.phase===3&&s.phaseOpening?.initialize===true); + for(const p of g.players)g.deck.push(...p.hand.splice(0)); + const semuta=takeKullCard(g,'richese-semuta-drug');player(g,'r').hand.push(semuta); + const kull=takeKullCard(g,'ix-kull-wahad');player(g,'c').hand.push(kull); + const karama=takeKullCard(g,'karama');player(g,'a').hand.push(karama); + player(g,'g').spice=7;player(g,'e').spice=8; + g=advanceSemutaNexusTrade(g,s=>s.decision?.kind==='richeseCache'); + const selected=g.richeseCache!.find(card=>card.id!==semuta.id);assert.ok(selected); + const original=inventory(g),card=selected.id; + g=act(g,'r',{type:'decision',event:g.richeseBidding!.event,card,method, + ...(method==='onceAround'?{direction:'clockwise'}:{})}); + g=act(g,'e',{type:'pledgeAid',amount:1}); + let bid=false; + for(let n=0;!g.pendingEmperorAuctionGift&&n<300;n++) { + const lot=g.richeseAuction; + if(lot&&!lot.outcome&&!g.response&&!g.decision&&lot.method==='onceAround'&&lot.active) { + const seat=lot.active, buy=seat==='g'&&!bid; + g=act(g,seat,{type:'richeseBid',event:lot.event,amount:buy?3:null,...(buy?{allyPayment:1}:{})}); + if(buy)bid=true; + } else if(lot&&!lot.outcome&&!g.response&&!g.decision&&lot.method==='silent') { + const seat=lot.eligible.find(id=>!Object.hasOwn(lot.sealed,id));assert.ok(seat); + const buy=seat==='g'&&!bid; + g=act(g,seat,{type:'richeseBid',event:lot.event,amount:buy?3:0,...(buy?{allyPayment:1}:{})}); + if(buy)bid=true; + } else { + const next=nextSemutaNexusTradeNativeStep(g);g=act(g,next.actor,next.action); + } + } + assert.equal(bid,true);assert.ok(g.pendingEmperorAuctionGift,'Emperor receives a prepayment opportunity'); + assert.equal(g.richeseAuction?.outcome?.kind,'sold');assert.equal(g.currentAuctionSale??null,null); + assert.equal(viewGame(g,'e').emperorAuctionGift?.recipient,'g'); + return {g,card,kull:kull.id,karama:karama.id,original}; +} +function finishSale(g:Game, card:string) { + const pending=g.pendingEmperorAuctionGift;assert.ok(pending); + g=act(g,'e',{type:'emperorAuctionGiftContinue',event:pending.event}); + g=passResponse(g); + assert.ok(player(g,'g').hand.some(row=>row.id===card)); + return g; +} + + +for(const method of ['onceAround','silent'] as const) void test(`Basic Nexus ${method} cache gift retains original sale`,()=>{ + const f=fixture(method),original=structuredClone(f.g.richeseAuction); + assert.ok(f.g.nexusCards?.cards); + const emperor=player(f.g,'e').spice,buyer=player(f.g,'g').spice,seller=player(f.g,'r').spice; + for(const level of DIFFICULTIES) { + const view=viewGame(f.g,'e');view.players.find(row=>row.id==='e')!.bot=level; + const choice=botActions(view).find(action=>action.type==='emperorAuctionGiftContinue');assert.ok(choice); + assert.doesNotThrow(()=>act(f.g,'e',choice)); + } + let game=act(f.g,'e',{type:'emperorGift',amount:2}); + game=passResponse(game); + assert.deepEqual(game.richeseAuction,original); + game=finishSale(game,f.card); + assert.equal(player(game,'e').spice,emperor-2); + assert.equal(player(game,'g').spice,buyer); + assert.equal(player(game,'r').spice,seller+3); + assert.deepEqual(inventory(game),f.original); +}); + +void test('Basic Nexus cache gift cancellation resumes through Kull and Semuta',()=>{ + const f=fixture('onceAround'),emperor=player(f.g,'e').spice,buyer=player(f.g,'g').spice; + let game=act(f.g,'e',{type:'emperorGift',amount:2}); + game=act(game,'a',{type:'card',mode:'cancel',card:f.karama}); + assert.equal(game.pendingKull?.stage,'offer'); + game=act(game,'c',{type:'kullDecision',event:game.pendingKull!.event,decline:true}); + assert.equal(game.pendingTreacheryDiscard?.reaction?.stage,'offer'); + game=passSemuta(game); + assert.equal(player(game,'e').spice,emperor);assert.equal(player(game,'g').spice,buyer); + game=finishSale(game,f.card); + assert.equal(player(game,'e').spice,emperor);assert.equal(player(game,'g').spice,buyer-2); + assert.deepEqual(inventory(game),f.original); +}); diff --git a/tests/fixture-nexus-emperor-seller.ts b/tests/fixture-nexus-emperor-seller.ts index 1f178ce8..fc7c5519 100644 --- a/tests/fixture-nexus-emperor-seller.ts +++ b/tests/fixture-nexus-emperor-seller.ts @@ -46,6 +46,9 @@ export function nextNexusEmperorSellerStep(game: Game): NexusEmperorSellerStep { if (!game.phaseOpening && !game.response && game.decision?.kind === 'nexusEmperorSellerPurchase') return { actor: game.decision.player, action: { type: 'nexusEmperorSellerPurchase', event: game.decision.event, use: false } }; + if (!game.phaseOpening && !game.response && game.decision?.kind === 'nexusIxianReplacement') + return { actor: game.decision.player, + action: { type: 'nexusIxianReplacementPass', event: game.decision.event } }; const next = nextPairedChoamStep(game); assert.ok(next, 'The original seller chronology requires a real human battle plan'); return next; diff --git a/tests/fixture-richese-betrayal.ts b/tests/fixture-richese-betrayal.ts index a9a6ba25..72fa7a92 100644 --- a/tests/fixture-richese-betrayal.ts +++ b/tests/fixture-richese-betrayal.ts @@ -16,6 +16,7 @@ export type RicheseBetrayalFixtureOptions = { allyPayment?: number; allyIsSeller?: boolean; allySpice?: number; + emperorAlly?: boolean; beforeFinalBid?: (g: Game) => void; bonusCounter?: boolean; }; @@ -58,9 +59,12 @@ export function createRicheseBetrayalFixture( assert.ok(kind !== 'purchase' || source === 'cache'); const advanced = options.advanced ?? source === 'blackMarket'; assert.ok(source !== 'blackMarket' || advanced); + if (options.emperorAlly) assert.ok(source === 'cache' && !options.allyIsSeller && + (kind === 'purchase' || options.allyPayment)); let g = createGame('RICHESEBETRAYAL',newPlayer(target,'Richese','richese'),advanced,['choam']); for (let i = 1; i < ids.length; i++) - joinGame(g,newPlayer(ids[i],RICHESE_BETRAYAL_FIXTURE_FACTIONS[i],RICHESE_BETRAYAL_FIXTURE_FACTIONS[i])); + joinGame(g,newPlayer(ids[i],RICHESE_BETRAYAL_FIXTURE_FACTIONS[i], + options.emperorAlly && i === 3 ? 'emperor' : RICHESE_BETRAYAL_FIXTURE_FACTIONS[i])); g.nexusCards = {cards:null,phase:null}; for (const p of g.players) g = applyAction(g,p.id,{type:'ready'}); g = initializeRicheseBetrayalGameForAudit(g); @@ -83,6 +87,10 @@ export function createRicheseBetrayalFixture( ally = options.allyIsSeller ? target : other; g.players.find(p => p.id === harkonnen)!.ally = ally; g.players.find(p => p.id === ally)!.ally = harkonnen; + } else if (options.emperorAlly && kind === 'purchase') { + ally = other; + g.players.find(p => p.id === target)!.ally = other; + g.players.find(p => p.id === other)!.ally = target; } else holdNexus(g,other,'guild'); const card = source === 'cache' ? g.richeseCache![0].id : (() => { const index = g.deck.findIndex(c => c.kind === 'shield'); @@ -111,7 +119,7 @@ export function createRicheseBetrayalFixture( g.players.find(p => p.id === other)!.hand.push(counter); counterCard = counter.id; } - if (ally) { + if (ally && contribution) { if (options.allySpice !== undefined) g.players.find(p => p.id === ally)!.spice = options.allySpice; g = applyAction(g,ally,{type:'pledgeAid',amount:contribution}); } diff --git a/tests/nexus-emperor-seller-runtime.test.ts b/tests/nexus-emperor-seller-runtime.test.ts index 14051ef0..c3028024 100644 --- a/tests/nexus-emperor-seller-runtime.test.ts +++ b/tests/nexus-emperor-seller-runtime.test.ts @@ -21,7 +21,8 @@ function finishOriginalLot(f: NexusEmperorSellerFixture, game: Game): { game: Ga const bonus = game.response?.kind === 'harkonnenBonus'; if (bonus && !inBonus) bonuses++; inBonus = bonus; - assert.ok(!game.decision, 'The original paid/free acquisition cannot reopen buyer confirmation'); + assert.ok(!game.decision || game.decision.kind === 'nexusIxianReplacement', + 'The original paid/free acquisition cannot reopen buyer confirmation'); game = stepNexusEmperorSeller(game, nextNexusEmperorSellerStep(game)); } throw Error(`Original ${f.source} acquisition did not reach its source successor`); @@ -44,6 +45,8 @@ for (const scenario of scenarios) for (const use of [false, true]) void test( assert.deepEqual(f.game, original); assert.equal(nexusEmperorSellerPlayer(game, f.winner).spice, f.wallets[f.winner] - (use ? 0 : f.price)); assert.equal(nexusEmperorSellerPlayer(game, f.winner).hand.filter(card => card.id === f.card.id).length, 1); + if (game.decision?.kind === 'nexusIxianReplacement') + game = stepNexusEmperorSeller(game, nextNexusEmperorSellerStep(game)); assert.equal(game.response?.kind, 'harkonnenBonus', 'The existing native bonus cancellation boundary must remain'); assert.equal(game.currentAuctionSale!.origin, f.source); assert.equal(game.currentAuctionSale!.free, use);