Connect Advanced Black Market gifts and BG arrivals
Verify and publish checkpoint container / container (push) Successful in 11m32s
Verify and publish checkpoint container / container (push) Successful in 11m32s
This commit is contained in:
1 parent
28700389dc
commit
1f3bc349ba
9 files changed
+274
-25
No files matched your search
@@ -0,0 +1,134 @@
|
||||
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=(game:Game,id:string,action:Action)=>applyAction(game,id,action);
|
||||
const seat=(game:Game,id:string)=>{const player=game.players.find(row=>row.id===id);assert.ok(player);return player;};
|
||||
const quiet=(game:Game)=>!game.phaseOpening&&!game.response&&!game.decision&&!game.truthtrance&&!game.pendingTreacheryDiscard;
|
||||
function inventory(game:Game) {
|
||||
const cards=[...game.deck,...game.discard,...(game.richeseCache??[]),...(game.richeseRemoved??[]),
|
||||
...(game.auction?.cards.slice(game.auction.index+Number(game.currentAuctionSale?.origin==='normal'))??[]),
|
||||
...(game.ixAuction?.cards??[]),...game.players.flatMap(player=>player.hand)].map(card=>card.id).sort();
|
||||
assert.equal(new Set(cards).size,cards.length);return cards;
|
||||
}
|
||||
function finishResponses(game:Game):Game {
|
||||
for(let n=0;game.response&&n<20;n++) {
|
||||
const actor=game.players.find(player=>!game.response!.passed.includes(player.id));assert.ok(actor);
|
||||
game=act(game,actor.id,{type:'passResponse'});
|
||||
}
|
||||
return game;
|
||||
}
|
||||
function finishDiscardOffers(game:Game):Game {
|
||||
for(let n=0;game.pendingTreacheryDiscard?.reaction?.stage==='offer'&&n<20;n++) {
|
||||
const pending=game.pendingTreacheryDiscard,reaction=pending.reaction;
|
||||
assert.ok(reaction&&reaction.stage==='offer');
|
||||
const actor=game.players.find(player=>!reaction.passed.includes(player.id));assert.ok(actor);
|
||||
game=act(game,actor.id,{type:'semutaPass',event:pending.batch.event});
|
||||
}
|
||||
return game;
|
||||
}
|
||||
|
||||
/** Original Advanced setup, natural second-turn worm and actual mutual alliance.
|
||||
* The unopened Spice order, conserved board positions, hands and purses are staged. */
|
||||
function fixture(method:'normal'|'onceAround'|'silent', self=false) {
|
||||
let game=createGame('ADVBLACKGIFT',newPlayer('e','Emperor','emperor'),true,['choam','ix']);
|
||||
for(const [id,faction] of [['g','guild'],['c','choam'],['r','richese'],['a','atreides']] as const)
|
||||
joinGame(game,newPlayer(id,faction,faction));
|
||||
for(const player of game.players)game=act(game,player.id,{type:'ready'});
|
||||
game=act(game,'e',{type:'start',advancedPreview:true});
|
||||
game=advanceSemutaNexusTrade(game,state=>state.status==='playing');
|
||||
for(const player of game.players){player.reserves+=Object.values(player.forces).reduce((sum,n)=>sum+n,0);player.forces={};}
|
||||
game=advanceSemutaNexusTrade(game,beforeIxSpiceDraw);orderIxSpiceCards(game,['land','land']);
|
||||
game=advanceSemutaNexusTrade(game,state=>state.turn===2&&beforeIxSpiceDraw(state));
|
||||
orderIxSpiceCards(game,['worm','land','land']);
|
||||
game=advanceSemutaNexusTrade(game,state=>!!state.nexus&&!state.spiceWindow&&quiet(state));
|
||||
const buyer=self?'r':'g';
|
||||
game=act(game,'e',{type:'alliance',target:buyer});game=act(game,buyer,{type:'alliance',target:'e'});
|
||||
game=advanceSemutaNexusTrade(game,state=>state.phase===3&&state.phaseOpening?.initialize===true);
|
||||
for(const player of game.players)game.deck.push(...player.hand.splice(0));
|
||||
const karama=takeKullCard(game,'karama');seat(game,'a').hand.push(karama);
|
||||
const card=game.deck.shift();assert.ok(card);seat(game,'r').hand.push(card);
|
||||
seat(game,buyer).spice=7;seat(game,'e').spice=8;
|
||||
game=advanceSemutaNexusTrade(game,state=>state.decision?.kind==='richeseBlackMarket');
|
||||
const physical=inventory(game), originalHand=seat(game,'r').hand.map(row=>row.id);
|
||||
game=act(game,'r',{type:'decision',event:game.richeseBidding!.event,card:card.id,method,
|
||||
...(method==='onceAround'?{direction:'clockwise'}:{})});
|
||||
game=finishResponses(game);
|
||||
assert.equal(game.richeseAuction?.source,'blackMarket');
|
||||
game=act(game,'e',{type:'pledgeAid',amount:1});
|
||||
let bid=false, opening=false;
|
||||
for(let n=0;!game.pendingEmperorAuctionGift&&n<300;n++) {
|
||||
const lot=game.richeseAuction;
|
||||
if(lot&&!lot.outcome&&!game.response&&!game.decision&&lot.method!=='silent'&&lot.active) {
|
||||
const actor=lot.active, winning=actor===buyer&&!bid;
|
||||
const prebid=self&&method==='onceAround'&&actor!==buyer&&!opening;
|
||||
game=act(game,actor,{type:'richeseBid',event:lot.event,amount:winning?3:prebid?1:null,
|
||||
...(winning?{allyPayment:1}:{})});
|
||||
if(winning)bid=true;
|
||||
if(prebid)opening=true;
|
||||
} else if(lot&&!lot.outcome&&!game.response&&!game.decision&&lot.method==='silent') {
|
||||
const actor=lot.eligible.find(id=>!Object.hasOwn(lot.sealed,id));assert.ok(actor);
|
||||
const winning=actor===buyer&&!bid;
|
||||
game=act(game,actor,{type:'richeseBid',event:lot.event,amount:winning?3:0,...(winning?{allyPayment:1}:{})});
|
||||
if(winning)bid=true;
|
||||
} else {
|
||||
const next=nextSemutaNexusTradeNativeStep(game);game=act(game,next.actor,next.action);
|
||||
}
|
||||
}
|
||||
assert.equal(bid,true);assert.ok(game.pendingEmperorAuctionGift,'Emperor receives the original Black Market purchase opportunity');
|
||||
assert.equal(game.richeseAuction?.outcome?.kind,'sold');assert.equal(game.currentAuctionSale??null,null);
|
||||
assert.equal(viewGame(game,'e').emperorAuctionGift?.recipient,buyer);
|
||||
return {game,buyer,card:card.id,karama:karama.id,physical,originalHand};
|
||||
}
|
||||
|
||||
for(const method of ['normal','onceAround','silent'] as const) for(const mode of ['continue','allow','cancel'] as const) void test(
|
||||
`Advanced ${method} Black Market sale retains seller custody and split after Emperor ${mode}`,()=>{
|
||||
const f=fixture(method),before=structuredClone(f.game),lot=structuredClone(f.game.richeseAuction);
|
||||
const funding=structuredClone(f.game.richeseFunding),aid=structuredClone(f.game.aid);
|
||||
const offer=viewGame(f.game,'e').emperorAuctionGift;assert.ok(offer);
|
||||
for(const difficulty of DIFFICULTIES) {
|
||||
const view=viewGame(f.game,'e');view.players.find(player=>player.id==='e')!.bot=difficulty;
|
||||
const action=botActions(view).find(row=>row.type==='emperorAuctionGiftContinue');assert.ok(action,difficulty);
|
||||
assert.doesNotThrow(()=>act(f.game,'e',action),difficulty);
|
||||
}
|
||||
let game=f.game;
|
||||
if(mode!=='continue') {
|
||||
game=act(game,'e',{type:'emperorGift',amount:2});assert.equal(game.response?.kind,'emperorGift');
|
||||
if(mode==='cancel')game=finishDiscardOffers(act(game,'a',{type:'card',mode:'cancel',card:f.karama}));
|
||||
else game=finishResponses(game);
|
||||
}
|
||||
assert.deepEqual(game.richeseAuction,lot);assert.deepEqual(game.richeseFunding,funding);assert.deepEqual(game.aid,aid);
|
||||
assert.equal(game.pendingEmperorAuctionGift?.event,offer.event);
|
||||
assert.ok(seat(game,'r').hand.some(row=>row.id===f.card),'Seller retains the physical card before settlement');
|
||||
assert.equal(seat(game,'e').spice,seat(before,'e').spice-(mode==='allow'?2:0));
|
||||
assert.equal(seat(game,f.buyer).spice,seat(before,f.buyer).spice+(mode==='allow'?2:0));
|
||||
game=act(game,'e',{type:'emperorAuctionGiftContinue',event:offer.event});
|
||||
game=finishResponses(game);
|
||||
assert.ok(seat(game,f.buyer).hand.some(row=>row.id===f.card));
|
||||
assert.ok(!seat(game,'r').hand.some(row=>row.id===f.card));
|
||||
assert.equal(seat(game,f.buyer).spice,seat(before,f.buyer).spice+(mode==='allow'?2:0)-2);
|
||||
assert.equal(seat(game,'e').spice,seat(before,'e').spice-(mode==='allow'?2:0));
|
||||
assert.equal(game.aid.e?.amount??0,0);
|
||||
assert.equal(seat(game,'r').spice,seat(before,'r').spice+2,'Emperor-funded one goes to the bank, buyer-funded two to Richese');
|
||||
assert.deepEqual(inventory(game),f.physical);
|
||||
});
|
||||
|
||||
for(const method of ['normal','onceAround','silent'] as const) void test(
|
||||
`Advanced ${method} Black Market seller retains its own card after an Emperor gift`,()=>{
|
||||
const f=fixture(method,true),before=structuredClone(f.game);
|
||||
const offer=viewGame(f.game,'e').emperorAuctionGift;assert.ok(offer);
|
||||
let game=act(f.game,'e',{type:'emperorGift',amount:2});game=finishResponses(game);
|
||||
assert.deepEqual(seat(game,'r').hand.map(row=>row.id),f.originalHand);
|
||||
game=act(game,'e',{type:'emperorAuctionGiftContinue',event:offer.event});
|
||||
game=finishResponses(game);
|
||||
assert.deepEqual(seat(game,'r').hand.map(row=>row.id),f.originalHand,'Paid self-retention does not reacquire or reorder the card');
|
||||
assert.equal(seat(game,'r').spice,seat(before,'r').spice,'Gift two less buyer-funded two');
|
||||
assert.equal(seat(game,'e').spice,seat(before,'e').spice,'Gift two less Emperor-funded bank one plus buyer-funded income two');
|
||||
assert.equal(game.aid.e?.amount??0,0);
|
||||
assert.deepEqual(inventory(game),f.physical);
|
||||
});
|
||||
@@ -0,0 +1,99 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { createGame, joinGame, newPlayer, viewGame, type Action, type Game } from '../game/engine';
|
||||
import { TERRITORIES, gameDistance, location, splitLocation } from '../game/board';
|
||||
import { presenceAt } from '../game/force-presence';
|
||||
import { actTruthMovementNativeEarly as act, nextTruthMovementNativeEarlyStep } from './fixture-truth-movement-native-early';
|
||||
|
||||
const seat = (g: Game, id: string) => { const p = g.players.find(p => p.id === id); assert.ok(p); return p; };
|
||||
const clean = (g: Game) => !g.response && !g.decision && !g.phaseOpening && !g.truthtrance && !g.pendingTreacheryDiscard;
|
||||
|
||||
/** Start and play an actual Advanced preview through Richese's paid marker
|
||||
* shipment. Only unopened Spice order and the conserved position/stance for
|
||||
* this isolated CHOAM reaction are staged. */
|
||||
function fixture(value: 0 | 3, source: 'advisor' | 'fighter', fighters = false) {
|
||||
let g = createGame(`ADV-BG-REVEAL-${value}-${source}`, newPlayer('richese', 'Richese', 'richese'), true, ['choam']);
|
||||
joinGame(g, newPlayer('choam', 'CHOAM', 'choam'));
|
||||
joinGame(g, newPlayer('bg', 'Bene Gesserit', 'beneGesserit'));
|
||||
for (const p of g.players) g = act(g, p.id, {type:'ready'});
|
||||
g = act(g, g.host, {type:'start', advancedPreview:true});
|
||||
const next = (state: Game) => {
|
||||
if (state.phase === 5 && state.active === 'richese' && clean(state) && !seat(state,'richese').shipped &&
|
||||
!seat(state,'richese').noField?.deployed) {
|
||||
const owner = seat(state,'richese'), marker = owner.noField!.tokens.find(t => t.value === value);
|
||||
assert.ok(marker && owner.noFieldEvent);
|
||||
return {actor:'richese',action:{type:'ship',noField:marker.id,event:owner.noFieldEvent,
|
||||
territory:'polar_sink',sector:0,allyPayment:0} satisfies Action};
|
||||
}
|
||||
const step = nextTruthMovementNativeEarlyStep(state);
|
||||
assert.ok(step, `Missing native continuation ${state.status}/${state.turn}/${state.phase}/${state.decision?.kind}`);
|
||||
if (step.action.type === 'stormDial' && state.turn === 1)
|
||||
return {...step, action:{...step.action, amount:0}};
|
||||
return step;
|
||||
};
|
||||
const reach = (until: (s: Game) => boolean) => {
|
||||
for (let n = 0; n < 2400 && !until(g); n++) {
|
||||
assert.notEqual(g.status, 'finished');
|
||||
const step = next(g); g = act(g, step.actor, step.action);
|
||||
}
|
||||
assert.ok(until(g), 'The real game reached the requested boundary');
|
||||
};
|
||||
reach(state => state.status === 'playing');
|
||||
for (let pos = 0; pos < 4; pos++) {
|
||||
const at = g.spiceDeck.findIndex((card, index) => index >= pos && 'territory' in card && !card.discovery);
|
||||
assert.ok(at >= pos); [g.spiceDeck[pos], g.spiceDeck[at]] = [g.spiceDeck[at], g.spiceDeck[pos]];
|
||||
}
|
||||
reach(state => state.turn === 2 && state.phase === 5 && state.active === 'bg' && clean(state) &&
|
||||
!!seat(state,'richese').noField?.deployed);
|
||||
const richese = seat(g,'richese'), marker = richese.noField!.deployed!.tokenId, event = richese.noFieldEvent;
|
||||
assert.ok(event);
|
||||
const bg = seat(g,'bg'), choam = seat(g,'choam');
|
||||
// Return only these factions' current board counters to their reserves, then
|
||||
// place one counter each at the source and one CHOAM counter at destination.
|
||||
for (const player of [bg,choam]) {
|
||||
player.reserves += Object.values(player.forces).reduce((sum, n) => sum + n, 0);
|
||||
player.forces = {};
|
||||
}
|
||||
const origin = TERRITORIES.filter(t => t.type === 'sand').flatMap(t => t.sectors.map(s => location(t.id,s)))
|
||||
.find(key => splitLocation(key).sector !== g.storm &&
|
||||
gameDistance(g,key,'polar_sink:0',k => splitLocation(k).sector === g.storm) === 1);
|
||||
assert.ok(origin);
|
||||
bg.reserves--; bg.forces[origin] = 1;
|
||||
choam.reserves -= 2; choam.forces[origin] = 1; choam.forces['polar_sink:0'] = 1;
|
||||
bg.advisors = source === 'advisor' ? {[splitLocation(origin).territory]:{}} : {};
|
||||
const beforeMove = structuredClone(g);
|
||||
g = act(g,'bg',{type:'move',forces:{[origin]:1},territory:'polar_sink',sector:0,
|
||||
...(fighters ? {fighters:true} : {})});
|
||||
assert.equal(g.decision?.kind,'choamMovement');
|
||||
assert.deepEqual(seat(g,'bg').forces,seat(beforeMove,'bg').forces);
|
||||
return {game:g,beforeMove,origin,marker,event,value,source,fighters};
|
||||
}
|
||||
|
||||
function finish(g: Game) {
|
||||
for (let n = 0; n < 40 && !clean(g); n++) {
|
||||
const step = nextTruthMovementNativeEarlyStep(g);
|
||||
assert.ok(step); g = act(g,step.actor,step.action);
|
||||
}
|
||||
assert.ok(clean(g));
|
||||
return g;
|
||||
}
|
||||
|
||||
for (const value of [0,3] as const) for (const source of ['advisor','fighter'] as const)
|
||||
for (const fighters of source === 'advisor' ? [false,true] : [false])
|
||||
void test(`Advanced BG ${source}${fighters ? ' requesting fighters' : ''} keeps its arrival after No-Field ${value} reveal`, () => {
|
||||
const f = fixture(value,source,fighters), original = structuredClone(f.game);
|
||||
assert.equal(presenceAt(seat(original,'richese'),'polar_sink'),1);
|
||||
assert.equal(presenceAt(seat(original,'choam'),'polar_sink'),1);
|
||||
assert.equal(viewGame(original,'richese').richeseNoField?.canReveal,true);
|
||||
const pending = structuredClone(original.pendingChoamMove), decision = structuredClone(original.decision);
|
||||
const after = act(original,'richese',{type:'revealNoField',token:f.marker,event:f.event});
|
||||
assert.deepEqual(after.pendingChoamMove,pending);
|
||||
assert.deepEqual(after.decision,decision);
|
||||
assert.equal(presenceAt(seat(after,'richese'),'polar_sink'),value);
|
||||
const result = finish(after), control = finish(structuredClone(f.game));
|
||||
assert.deepEqual(seat(result,'bg'),seat(control,'bg'));
|
||||
assert.equal(seat(result,'bg').forces[f.origin] ?? 0,0);
|
||||
assert.equal(seat(result,'bg').forces['polar_sink:0'],1);
|
||||
assert.equal(seat(result,'bg').moved,seat(f.beforeMove,'bg').moved+1);
|
||||
assert.equal(!!seat(result,'bg').advisors?.polar_sink,source === 'advisor' && !fighters);
|
||||
});
|
||||
Reference in new issue
Block a user