Support Emperor gifts in Nexus Richese cache sales
Verify and publish checkpoint container / container (push) Successful in 11m37s
Verify and publish checkpoint container / container (push) Successful in 11m37s
This commit is contained in:
1 parent
eaaab566e2
commit
021a8c3e7f
11 files changed
+276
-20
No files matched your search
@@ -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);
|
||||
});
|
||||
@@ -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.players.length+2;n++) {
|
||||
const seat=g.players.find(p=>!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<g.players.length;n++) {
|
||||
const pending=g.pendingTreacheryDiscard, reaction=pending.reaction;
|
||||
assert.ok(reaction&&reaction.stage==='offer');
|
||||
const seat=g.players.find(p=>!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);
|
||||
});
|
||||
@@ -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;
|
||||
|
||||
@@ -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});
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user