Files
Dune/tests/richese-reveal-advanced-bg-destination.test.ts
T
Quintine 1f3bc349ba
Verify and publish checkpoint container / container (push) Successful in 11m32s
Connect Advanced Black Market gifts and BG arrivals
2026-11-16 18:33:50 +11:00

100 lines
5.8 KiB
TypeScript

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);
});