Support Advanced No-Field reveal interruptions
Verify and publish checkpoint container / container (push) Successful in 11m29s

This commit is contained in:
Quintine committed 2026-11-16 18:00:57 +11:00
1 parent 5e7f7b45e4
commit ee8ec0a84e
11 files changed
+607 -4

No files matched your search

@@ -0,0 +1,145 @@
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 {territory} from '../game/board';
import {actTruthMovementNativeEarly as act, nextTruthMovementNativeEarlyStep} from './fixture-truth-movement-native-early';
import {truthMovementInventory as inventory} from './fixture-truth-movement';
import {beforeIxSpiceDraw, orderIxSpiceCards} from './fixture-ix-spice-cards';
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.response&&!game.decision&&!game.phaseOpening&&!game.truthtrance&&!game.pendingTreacheryDiscard;
function next(game:Game) {
if(game.decision?.kind==='richeseAllyOpportunity')
return {actor:game.decision.player,action:{type:'decision',decline:true} satisfies Action};
if(game.phase===5 && game.active && quiet(game)) {
const player=seat(game,game.active);
if(game.turn===1 && player.id==='richese' && !player.shipped) {
const token=player.noField!.tokens.find(row=>row.value===3);assert.ok(token&&player.noFieldEvent);
return {actor:player.id,action:{type:'ship',noField:token.id,event:player.noFieldEvent,
territory:'polar_sink',sector:0,allyPayment:0} satisfies Action};
}
return {actor:player.id,action:{type:'endMovement'} satisfies Action};
}
return nextTruthMovementNativeEarlyStep(game,{position:'first',method:'onceAround',direction:'clockwise',keepUnbid:false});
}
function reach(game:Game,until:(game:Game)=>boolean):Game {
for(let i=0;i<2500;i++) {
if(until(game)) return game;
assert.notEqual(game.status,'finished');
const step=next(game);assert.ok(step,`No native continuation at ${game.turn}/${game.phase}/${game.decision?.kind}`);
game=act(game,step.actor,step.action);
}
throw Error('Native Advanced response was not reached');
}
/** Genuine public Advanced four/five-seat start, actual paid first-turn marker,
* second-turn worm and reciprocal Emperor/Richese alliance. The unopened Spice
* order and two original Karamas' physical custody are staged. */
function base(withGuild=true) {
let game=createGame('ADVREVEALNATIVE',newPlayer('richese','Richese','richese'),true,['choam','ix']);
for(const id of ['tleilaxu','atreides','emperor',...(withGuild?['guild' as const]:[])] as const)joinGame(game,newPlayer(id,id,id));
for(const player of game.players)game=act(game,player.id,{type:'ready'});
game=act(game,game.host,{type:'start',advancedPreview:true});
game=reach(game,state=>state.status==='playing');
const cards=inventory(game);
for(const id of ['atreides','emperor'] as const) {
const recipient=seat(game,id);
if(recipient.hand.some(card=>card.effect==='karama')) continue;
const source=game.players.find(player=>!['atreides','emperor'].includes(player.id)&&player.hand.some(card=>card.effect==='karama'))?.hand??game.deck;
const index=source.findIndex(card=>card.effect==='karama');assert.ok(index>=0);
const [card]=source.splice(index,1);
if(recipient.hand.length>=4)source.push(recipient.hand.pop()!);
recipient.hand.push(card);
}
assert.deepEqual(inventory(game),cards);
game=reach(game,beforeIxSpiceDraw);orderIxSpiceCards(game,['land','land']);
game=reach(game,state=>state.turn===2&&beforeIxSpiceDraw(state));
assert.ok(seat(game,'richese').noField?.deployed,'The native first-turn shipment must have occurred');
orderIxSpiceCards(game,['worm','land','land']);
game=reach(game,state=>!!state.nexus&&!state.spiceWindow&&quiet(state));
game=act(game,'richese',{type:'alliance',target:'emperor'});
game=act(game,'emperor',{type:'alliance',target:'richese'});
assert.equal(seat(game,'richese').ally,'emperor');assert.equal(seat(game,'emperor').ally,'richese');
return {game,cards};
}
function reveal(before:Game) {
const owner=seat(before,'richese'), token=owner.noField?.deployed?.tokenId, event=owner.noFieldEvent;
assert.ok(token&&event);assert.equal(viewGame(before,'richese').richeseNoField?.canReveal,true);
const old=structuredClone(before),response=structuredClone(before.response);
const after=act(before,'richese',{type:'revealNoField',token,event});
assert.deepEqual(after.response,response);assert.deepEqual(after.decision,old.decision);
assert.equal(seat(after,'richese').reserves,seat(old,'richese').reserves-3);
assert.equal(seat(after,'richese').forces['polar_sink:0'],(seat(old,'richese').forces['polar_sink:0']??0)+3);
assert.deepEqual(inventory(after),inventory(old));
return after;
}
function passCurrent(game:Game,kind:string) {
for(let i=0;game.response?.kind===kind&&i<15;i++) {
const actor=game.players.find(player=>!game.response!.passed.includes(player.id));assert.ok(actor);
game=act(game,actor.id,{type:'passResponse'});
}
assert.notEqual(game.response?.kind,kind);return game;
}
void test('Advanced reveal preserves Atreides auction inspection and its original response',()=>{
let {game}=base();
game=reach(game,state=>state.turn===2&&state.phase===3&&state.response?.kind==='atreidesAuction'&&!!state.auction);
const cards=structuredClone(game.auction),old=structuredClone(game.response);
game=act(game,'richese',{type:'passResponse'});assert.equal(game.response?.kind,'atreidesAuction');
const before=structuredClone(game),after=reveal(game);
assert.notDeepEqual(old,after.response);assert.deepEqual(after.response,before.response);assert.deepEqual(after.auction,cards);
const continued=passCurrent(after,'atreidesAuction');
assert.ok(continued.auction);assert.deepEqual(continued.auction.cards,cards!.cards);
});
void test('Advanced reveal preserves the original Atreides Spice forecast and bot responses',()=>{
let {game}=base();
game=reach(game,state=>state.turn===2&&state.phase===5&&state.response?.kind==='atreidesSpice');
game=act(game,'richese',{type:'passResponse'});assert.equal(game.response?.kind,'atreidesSpice');
const before=structuredClone(game),after=reveal(game);
assert.deepEqual(after.spiceDeck,before.spiceDeck);
for(const difficulty of DIFFICULTIES) {
const view=viewGame(after,'emperor');view.players.find(player=>player.id==='emperor')!.bot=difficulty;
const choice=botActions(view).find(action=>action.type==='passResponse'||action.type==='card'&&action.mode==='cancel');
assert.ok(choice,difficulty);assert.doesNotThrow(()=>applyAction(after,'emperor',choice));
}
const continued=passCurrent(after,'atreidesSpice');
assert.deepEqual(continued.spiceDeck,before.spiceDeck);assert.equal(continued.spicePeekKnown,true);
});
void test('Advanced reveal preserves the original Emperor gift and transfers spice only once',()=>{
let {game}=base();
game=reach(game,state=>state.turn===2&&state.phase===5&&state.active==='emperor'&&quiet(state));
const emperor=seat(game,'emperor').spice,richese=seat(game,'richese').spice;
game=act(game,'emperor',{type:'emperorGift',amount:1});assert.equal(game.response?.kind,'emperorGift');
game=act(game,'richese',{type:'passResponse'});const after=reveal(game);
const continued=passCurrent(after,'emperorGift');
assert.equal(seat(continued,'emperor').spice,emperor-1);assert.equal(seat(continued,'richese').spice,richese+1);
});
void test('Advanced reveal after a real free revival preserves Tleilaxu income and ordered Revival',()=>{
let {game}=base();
game=reach(game,state=>state.turn===2&&state.phase===4&&quiet(state)&&state.revivalOrder?.remaining[0]==='richese');
// Staged casualties retain all physical counters; the actual return is native.
const owner=seat(game,'richese');assert.ok(owner.reserves>=3);owner.reserves-=3;owner.tanks+=3;
game=act(game,'richese',{type:'revive',amount:2,elite:0});
if(game.decision?.kind==='revivalStop')game=act(game,'tleilaxu',{type:'decision',decline:true});
assert.equal(game.response?.kind,'revivalIncome');assert.equal(game.response.owner,'tleilaxu');
const before=structuredClone(game),income=seat(game,'tleilaxu').spice,after=reveal(game);
assert.deepEqual(after.revivalOrder,before.revivalOrder);assert.equal(seat(after,'richese').tanks,seat(before,'richese').tanks);
const continued=passCurrent(after,'revivalIncome');
assert.equal(seat(continued,'tleilaxu').spice,income+1);
});
void test('Advanced reveal preserves the original Guild reserve rate and paid shipment',()=>{
let {game}=base();
game=reach(game,state=>state.turn===2&&state.phase===5&&state.active==='guild'&&quiet(state));
const sector=territory('arrakeen').sectors.find(value=>value!==game.storm);assert.notEqual(sector,undefined);
game=act(game,'guild',{type:'ship',territory:'arrakeen',sector,amount:2,allyPayment:0});
if(game.decision?.kind==='guildShipment')game=act(game,'guild',{type:'decision',allow:true});
assert.equal(game.response?.kind,'guildRate');const shipment=structuredClone(game.pendingShipment);
const after=reveal(game);assert.deepEqual(after.pendingShipment,shipment);
const continued=passCurrent(after,'guildRate');
assert.equal(continued.pendingShipment??null,null);assert.equal(seat(continued,'guild').shipped,true);
});