Support Advanced expansion auction gifts
Verify and publish checkpoint container / container (push) Successful in 11m23s
Verify and publish checkpoint container / container (push) Successful in 11m23s
This commit is contained in:
1 parent
51c48e371b
commit
28700389dc
14 files changed
+840
-15
No files matched your search
@@ -0,0 +1,114 @@
|
||||
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 {SEMUTA_DRUG_ID} from '../game/semuta-drug';
|
||||
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 seat=(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 ids=[...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(ids).size,ids.length);return ids;
|
||||
}
|
||||
function take(g:Game,predicate:(card:Game['deck'][number])=>boolean) {
|
||||
const zones=[g.deck,g.discard,g.richeseCache!,...g.players.map(row=>row.hand)];
|
||||
const zone=zones.find(row=>row.some(predicate));assert.ok(zone);
|
||||
return zone.splice(zone.findIndex(predicate),1)[0];
|
||||
}
|
||||
function passResponse(g:Game) {
|
||||
for(let n=0;g.response&&n<20;n++) {
|
||||
const actor=g.players.find(row=>!g.response!.passed.includes(row.id));assert.ok(actor);
|
||||
g=act(g,actor.id,{type:'passResponse'});
|
||||
}
|
||||
return g;
|
||||
}
|
||||
/** Genuine public Advanced CHOAM-only setup, a real second-turn worm and
|
||||
* mutual Emperor/Guild alliance. Only unopened Spice order, conserved board
|
||||
* counters, physical card locations and auction wallets are staged. */
|
||||
function fixture(source:'onceAround'|'silent'|'ordinary') {
|
||||
let g=createGame('ADVSEMUTAAUCTION',newPlayer('e','Emperor','emperor'),true,['choam']);
|
||||
for(const id of ['g','r','a'] as const) {
|
||||
const faction={g:'guild',r:'richese',a:'atreides'} as const;
|
||||
joinGame(g,newPlayer(id,id,faction[id]));
|
||||
}
|
||||
for(const p of g.players)g=act(g,p.id,{type:'ready'});
|
||||
g=act(g,'e',{type:'start',advancedPreview:true});
|
||||
assert.equal(g.semutaAdvancedOrdinaryPreview,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===2&&quiet(s));
|
||||
for(const p of g.players)g.deck.push(...p.hand.splice(0));
|
||||
const semuta=take(g,card=>card.id===SEMUTA_DRUG_ID);seat(g,'r').hand.push(semuta);
|
||||
const karama=take(g,card=>card.effect==='karama');seat(g,'a').hand.push(karama);
|
||||
seat(g,'g').spice=7;seat(g,'e').spice=8;
|
||||
const cards=inventory(g);
|
||||
let card:string;
|
||||
if(source==='ordinary') {
|
||||
g=advanceSemutaNexusTrade(g,s=>s.phase===3&&!!s.auction&&!s.richeseAuction&&quiet(s));
|
||||
while(g.auction!.active!=='g')g=act(g,g.auction!.active,{type:'passBid'});
|
||||
card=g.auction!.cards[g.auction!.index].id;
|
||||
g=act(g,'e',{type:'pledgeAid',amount:1});
|
||||
g=act(g,'g',{type:'bid',amount:3,allyPayment:1});
|
||||
for(let n=0;g.auction&&!g.response&&!g.decision&&n<15;n++)g=act(g,g.auction.active,{type:'passBid'});
|
||||
} else {
|
||||
g=advanceSemutaNexusTrade(g,s=>s.decision?.kind==='richeseCache');
|
||||
const selected=g.richeseCache![0];assert.ok(selected);card=selected.id;
|
||||
g=act(g,'r',{type:'decision',event:g.richeseBidding!.event,card,method:source,
|
||||
...(source==='onceAround'?{direction:'clockwise' as const}:{})});
|
||||
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 buyer=lot.active==='g'&&!bid;
|
||||
g=act(g,lot.active,{type:'richeseBid',event:lot.event,amount:buyer?3:null,...(buyer?{allyPayment:1}:{})});
|
||||
if(buyer)bid=true;
|
||||
} else if(lot&&!lot.outcome&&!g.response&&!g.decision&&lot.method==='silent') {
|
||||
const actor=lot.eligible.find(id=>!Object.hasOwn(lot.sealed,id));assert.ok(actor);
|
||||
const buyer=actor==='g'&&!bid;
|
||||
g=act(g,actor,{type:'richeseBid',event:lot.event,amount:buyer?3:0,...(buyer?{allyPayment:1}:{})});
|
||||
if(buyer)bid=true;
|
||||
} else {const next=nextSemutaNexusTradeNativeStep(g);g=act(g,next.actor,next.action);}
|
||||
}
|
||||
assert.equal(bid,true);
|
||||
}
|
||||
assert.ok(g.pendingEmperorAuctionGift,'The allied winner receives the original prepayment opportunity');
|
||||
return {g,card,karama:karama.id,semuta:semuta.id,cards};
|
||||
}
|
||||
|
||||
for(const source of ['ordinary','onceAround','silent'] as const) for(const claim of [false,true]) void test(
|
||||
`Advanced ${source} Emperor gift cancellation offers its Karama to Semuta; ${claim?'claim':'pass'} resumes sale`,()=>{
|
||||
const f=fixture(source), original=structuredClone(f.g), opportunity=f.g.pendingEmperorAuctionGift!;
|
||||
let g=act(f.g,'e',{type:'emperorGift',amount:2});
|
||||
assert.equal(g.response?.kind,'emperorGift');
|
||||
g=act(g,'a',{type:'card',mode:'cancel',card:f.karama});
|
||||
assert.equal(g.pendingTreacheryDiscard?.continuation.kind,'karamaEmperorShareDiscard');
|
||||
assert.equal(g.pendingTreacheryDiscard?.reaction?.stage,'offer');
|
||||
const event=g.pendingTreacheryDiscard!.batch.event;
|
||||
if(claim)g=act(g,'r',{type:'semutaCommit',event});
|
||||
else while(g.pendingTreacheryDiscard?.reaction?.stage==='offer') {
|
||||
const reaction=g.pendingTreacheryDiscard.reaction;
|
||||
const actor=g.players.find(row=>!reaction.passed.includes(row.id));assert.ok(actor);
|
||||
g=act(g,actor.id,{type:'semutaPass',event});
|
||||
}
|
||||
assert.equal(seat(g,'r').hand.some(card=>card.id===f.karama),claim);
|
||||
assert.equal(g.discard.some(card=>card.id===f.semuta),claim);
|
||||
assert.equal(seat(g,'e').spice,seat(original,'e').spice);
|
||||
assert.equal(seat(g,'g').spice,seat(original,'g').spice);
|
||||
assert.deepEqual(g.auction,original.auction);assert.deepEqual(g.richeseAuction,original.richeseAuction);
|
||||
assert.deepEqual(g.richeseFunding,original.richeseFunding);assert.deepEqual(g.aid,original.aid);
|
||||
assert.equal(viewGame(g,'e').emperorAuctionGift?.event,opportunity.event);
|
||||
g=act(g,'e',{type:'emperorAuctionGiftContinue',event:opportunity.event});
|
||||
if(g.decision?.kind==='auctionPayment')g=act(g,'g',{type:'decision',karama:false});
|
||||
g=passResponse(g);
|
||||
assert.ok(seat(g,'g').hand.some(card=>card.id===f.card));
|
||||
assert.equal(g.aid.e?.amount??0,0);assert.deepEqual(inventory(g),f.cards);
|
||||
});
|
||||
Reference in new issue
Block a user