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

+10
View File
@@ -17,6 +17,16 @@ open mode gates.
## Current checkpoint and work
**Advanced No-Field reveal interruptions — 16 November. Prototyped / Partial.**
Supported Advanced economic, Revival and independent response windows now
admit Richese's voluntary before-Battle reveal. Current reserves and original
continuations remain authoritative, including the Atreides forecast alongside
Guild timing. CHOAM's La La La now preserves completed seats in ordered
Revival. Genuine public-start journeys and owner-only control cover the changed
paths; 17 related unit files pass 172 cases. Other nested parents, modules,
complete games and deployed acceptance remain open.
[Scope](RICHESE_NO_FIELD_RULES.md#advanced-before-battle-interruptions--16-november-2026).
**Advanced Emperor gift at a Guild rate response — 16 November. Prototyped /
Partial.** A neutral Emperor opportunity precedes a supported classic Advanced
rate response's automatic or bot completion. A gift or Continue retains the
+28
View File
@@ -2,6 +2,34 @@
Audit date: 2026-09-06. This document distinguishes the printed token lifecycle from engine integration and unresolved combinations. It does not certify Richese, Homeworlds, or any other gated game mode.
## Advanced before-Battle interruptions — 16 November 2026
**Prototyped / Partial.** The existing supported independent interruption
parents now admit the voluntary reveal in Advanced games too, using the same
native response, cost and force handling. This includes ordered CHOAM free
Revival, economic decisions, and the existing individually checked responses.
The reveal draws from current reserves and leaves the original request or
response pending. Ordinary foreign-movement interruptions still use their
Basic-only parent helper; nested children, optional modules and existing
Truthtrance commitment boundaries remain guarded. The native Advanced
Atreides Spice forecast may coexist with the original Guild timing choice;
both are retained during the reveal.
The user-authorized revised rules physical p. 5 / printed p. 3 permit
Richese's reveal at any time before Battle. Interruption and priority during
online decisions remain a provisional software interpretation rather than a
separately published timing ruling. Public-start [ordered Revival cases](../tests/richese-reveal-advanced-choam-free-revival.test.ts),
[economic cases](../tests/richese-reveal-advanced-economic.test.ts) and
[native response cases](../tests/richese-reveal-advanced-native-responses.test.ts)
use genuine setup and token shipments with explicitly staged Spice order,
selected physical cards, purses or casualties. The [Advanced control case](../tests/richese-reveal-advanced-controls.test.tsx)
renders and submits the owner-only reveal. Complete games, wider
combinations and deployed acceptance remain open.
CHOAM's Worthless response now keeps the existing Advanced ordered Revival
completed-seat list instead of clearing it when the response opens.
This also fixes native La La La without a No-Field reveal.
## Basic reveal at Emperor auction gifts — 16 November 2026
**Prototyped / Partial.** In supported Basic ordinary and Richese cache
+7
View File
@@ -1,5 +1,12 @@
# Rule decision index
## Advanced No-Field reveal interruptions — 16 November 2026
The existing provisional before-Battle reveal ordering extends to the
supported Advanced economic, Revival and independent response parents;
physical reserves and original continuations remain authoritative.
[Scope](RICHESE_NO_FIELD_RULES.md#advanced-before-battle-interruptions--16-november-2026).
## Advanced Emperor gift at a Guild rate response — 16 November 2026
The Emperor's existing allied gift can interrupt a supported Guild-rate
+1 -1
View File
@@ -42890,7 +42890,7 @@ function playChoamWorthless(g: Game, p: Player, action: Action, movementPreparat
};
if (nexus) recordNexusChoam(g,p,card,effect);
if (reactive || mentat || moving || storming) g.decision = null;
g.ready = [];
if (!(g.phase === 4 && g.revivalOrder)) g.ready = [];
g.response = {
kind: 'choamWorthless',
owner: p.id,
+1
View File
@@ -1136,6 +1136,7 @@ export const RULE_TOPICS: RuleTopic[] = [
'In Basic play, your own single concealed No-Field may provisionally ship into an ally’s territory if it can legally enter; move it and any paid accompanying forces out before your turn ends. Paid companions require the High Richese Homeworld power. If the marker remains, reveal it and send its newly materialized forces to Tanks under the provisional no-departure policy. A zero marker reveals but contributes no casualties. Existing physical forces and the ally are not part of that new-visitor loss. Paired markers keep their separate guards.',
'A normal No-Field shipment pays the one-force price. The concealed token moves like a force. Before Battle, Richese may reveal it voluntarily; a token involved in battle is revealed with the Battle Plan. Revelation brings the indicated forces from reserves, limited by what remains there.',
'A waiting Sandtrout does not prevent the supported Basic voluntary-reveal interruption windows.',
'In supported Advanced games, the same before-Battle reveal is available during the connected auction, Revival, inspection and other independent response windows. Your actual reserves determine how many forces appear; the original decision or response continues.',
'In supported Basic interruptions, a current-turn history of factual Truthtrance answers does not by itself block your reveal. Live promises and questions about future actions retain their existing safeguards.',
'In supported Basic games the voluntary reveal can also occur while CHOAM decides whether to prevent an already-declared free Revival. Reveal uses current reserves; the original Revival and CHOAM decision then continue once.',
'In supported Basic auctions, reveal can also occur during the Emperor’s allied gift opportunity or its response. The original lot, pledged funds and gift continue unchanged.',
+7 -2
View File
@@ -13,7 +13,7 @@ const factions = new Set([
* This does not authorize a seat, marker or event, and does not mutate the
* game. The normal No-Field action and view own those checks. */
export function richeseRevealInterruptSupported(g: Game): boolean {
if (g.status !== 'playing' || g.advanced || !Number.isSafeInteger(g.phase) ||
if (g.status !== 'playing' || !Number.isSafeInteger(g.phase) ||
g.phase < 0 || g.phase >= 6 || !Number.isSafeInteger(g.turn) || g.turn < 1 ||
!Array.isArray(g.expansions) || !g.expansions.includes('choam') ||
g.expansions.some(deck => deck !== 'choam' && deck !== 'ix' && deck !== 'ecaz') ||
@@ -123,7 +123,12 @@ export function richeseRevealInterruptSupported(g: Game): boolean {
// source are admitted. Other shipment and revival transactions still
// need their own continuation proofs.
const response = g.response;
if (g.decision || g.phaseOpening || g.choamMarket ||
// Advanced begins Atreides' forecast and the Guild timing choice together;
// revealing an existing marker changes neither of those original parents.
const forecastGuildTiming = g.advanced && response.kind === 'atreidesSpice' &&
g.phase === 5 && g.decision?.kind === 'guildTiming' &&
g.players.some(player => player.id === g.decision!.player && player.faction === 'guild');
if ((g.decision && !forecastGuildTiming) || g.phaseOpening || g.choamMarket ||
!Array.isArray(response.passed) || new Set(response.passed).size !== response.passed.length ||
response.passed.some(id => !g.players.some(player => player.id === id))) return false;
const owner = g.players.find(player => player.id === response.owner);
@@ -0,0 +1,172 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { botActions } from '../game/bots';
import { DIFFICULTIES } from '../game/bot-profiles';
import { createGame, joinGame, newPlayer, viewGame, type Action, type Game } from '../game/engine';
import { actTruthMovementNativeEarly as act, nextTruthMovementNativeEarlyStep } from './fixture-truth-movement-native-early';
import { truthMovementInventory as inventory } from './fixture-truth-movement';
const richese = 'richese', choam = 'choam', atreides = 'atreides';
function seat(g: Game, id: string) {
const p = g.players.find(row => row.id === id); assert.ok(p); return p;
}
const clean = (g: Game) => !g.response && !g.decision && !g.phaseOpening &&
!g.truthtrance && !g.pendingRevival && !g.pendingTreacheryDiscard;
function step(g: Game) {
if (g.turn === 1 && g.phase === 5 && g.active === richese && clean(g)) {
const p = seat(g, richese);
if (!p.shipped) {
const token = p.noField!.tokens.find(row => row.value === 3); assert.ok(token);
return {actor:richese, action:{type:'ship', noField:token.id, event:p.noFieldEvent,
territory:'polar_sink', sector:0, allyPayment:0} satisfies Action};
}
return {actor:richese, action:{type:'endMovement'} satisfies Action};
}
if (g.phase === 5 && g.active && clean(g))
return {actor:g.active, action:{type:'endMovement'} satisfies Action};
return nextTruthMovementNativeEarlyStep(g, {position:'first', method:'onceAround', direction:'clockwise'});
}
function reach(g: Game, until: (state: Game) => boolean): Game {
for (let i = 0; i < 2000; i++) {
if (until(g)) return g;
assert.notEqual(g.status, 'finished');
const next = step(g); assert.ok(next, `Supply a native action at ${g.turn}/${g.phase}/${g.decision?.kind}`);
g = act(g, next.actor, next.action);
}
throw Error('Native game did not reach its Revival control');
}
/** Genuine public Advanced preview, real paid marker shipment and ordered next-turn Revival.
* Only the original unopened Spice order, Worthless card location and selected
* recipient's physical casualty count are staged; each inventory is conserved. */
function source(recipient: string, oneReserve = false) {
let g = createGame('RICHESECHOAMREVIVAL', newPlayer(richese, 'Richese', 'richese'), true, ['choam']);
joinGame(g, newPlayer(choam, 'CHOAM', 'choam'));
joinGame(g, newPlayer(atreides, 'Atreides', 'atreides'));
for (const p of g.players) g = act(g, p.id, {type:'ready'});
g = act(g, g.host, {type:'start', advancedPreview:true});
g = reach(g, state => state.status === 'playing');
for (const position of [0, 1, 2, 3]) {
const from = g.spiceDeck.findIndex((card, index) => index >= position && 'territory' in card && !card.discovery);
assert.ok(from >= position);
[g.spiceDeck[position], g.spiceDeck[from]] = [g.spiceDeck[from], g.spiceDeck[position]];
}
g = reach(g, state => state.turn === 2 && state.phase === 4 && clean(state) && state.revivalOrder?.remaining[0] === recipient);
const owner = seat(g, richese), marker = owner.noField?.deployed, event = owner.noFieldEvent;
assert.ok(marker); assert.ok(event);
const p = seat(g, recipient); assert.ok(p.reserves >= 3);
p.reserves -= 3; p.tanks += 3;
if (oneReserve) {
assert.equal(recipient, richese); assert.ok(p.reserves > 1);
const staged = p.reserves - 1;
p.reserves -= staged;
p.forces['polar_sink:0'] = (p.forces['polar_sink:0'] ?? 0) + staged;
}
const physical = inventory(g);
const c = seat(g, choam);
if (!c.hand.some(card => card.name === 'La La La')) {
let card = g.deck.findIndex(row => row.name === 'La La La');
if (card >= 0) c.hand.push(g.deck.splice(card, 1)[0]);
else {
const holder = g.players.find(row => row.hand.some(held => held.name === 'La La La'));
if (holder) {
card = holder.hand.findIndex(held => held.name === 'La La La');
c.hand.push(holder.hand.splice(card, 1)[0]);
} else {
card = g.discard.findIndex(held => held.name === 'La La La'); assert.ok(card >= 0);
c.hand.push(g.discard.splice(card, 1)[0]);
}
}
}
assert.deepEqual(inventory(g), physical);
g = act(g, recipient, {type:'revive', amount:2, elite:0});
assert.ok(g.decision?.kind === 'choamFreeRevival');
assert.equal(g.decision.player, choam);
assert.equal(g.decision.recipient, recipient);
assert.equal(g.pendingRevival?.player, recipient);
return {g, token:marker.tokenId, event, physical};
}
for (const recipient of [richese, atreides]) for (const deny of [false, true]) void test(
`Advanced Richese reveal preserves ${recipient}'s ordered free Revival while CHOAM ${deny ? 'plays La La La' : 'allows'}`, () => {
const {g, token, event, physical} = source(recipient), before = structuredClone(g);
const reserves = seat(g, richese).reserves, field = seat(g, richese).forces['polar_sink:0'] ?? 0;
const tanks = seat(g, recipient).tanks, revived = seat(g, recipient).revived;
assert.equal(viewGame(g, richese).richeseNoField?.canReveal, true);
let next = act(g, richese, {type:'revealNoField', token, event});
assert.deepEqual(g, before);
assert.deepEqual(next.decision, before.decision);
assert.deepEqual(next.pendingRevival, before.pendingRevival);
assert.deepEqual(next.revivalOrder, before.revivalOrder);
assert.equal(seat(next, richese).noField?.deployed, null);
assert.equal(seat(next, richese).reserves, reserves - 3);
assert.equal(seat(next, richese).forces['polar_sink:0'], field + 3);
assert.equal(seat(next, recipient).tanks, tanks);
if (deny) {
const card = seat(next, choam).hand.find(row => row.name === 'La La La'); assert.ok(card);
next = act(next, choam, {type:'card', mode:'choam', card:card.id});
} else next = act(next, choam, {type:'decision', decline:true});
for (let i = 0; (next.response || next.pendingTreacheryDiscard) && i < 40; i++) {
if (next.pendingTreacheryDiscard?.reaction) {
const reaction = next.pendingTreacheryDiscard.reaction;
assert.ok(reaction.stage === 'offer');
const p = next.players.find(row => !reaction.passed.includes(row.id)); assert.ok(p);
next = act(next, p.id, {type:'semutaPass', event:next.pendingTreacheryDiscard.batch.event});
} else if (next.response) {
const p = next.players.find(row => !next.response!.passed.includes(row.id)); assert.ok(p);
next = act(next, p.id, {type:'passResponse'});
} else break;
}
assert.equal(next.pendingRevival, null);
assert.equal(next.revivalOrder?.remaining[0], recipient);
assert.equal(seat(next, recipient).tanks, tanks - (deny ? 0 : 2));
assert.equal(seat(next, recipient).revived, revived + (deny ? 0 : 2));
assert.equal(seat(next, richese).forces['polar_sink:0'], field + 3);
assert.deepEqual(inventory(next), physical);
},
);
void test('Advanced three-marker uses the one current reserve before the pending free return adds two', () => {
const {g, token, event, physical} = source(richese, true), before = seat(g, richese);
const field = before.forces['polar_sink:0'] ?? 0, tanks = before.tanks, revived = before.revived;
const forceCount = (game: Game) => {
const player = seat(game, richese);
return player.reserves + player.tanks + Object.values(player.forces).reduce((sum, n) => sum + n, 0);
};
assert.equal(before.reserves, 1);
assert.equal(forceCount(g), 20);
const pending = structuredClone(g.pendingRevival);
let next = act(g, richese, {type:'revealNoField', token, event});
assert.equal(seat(next, richese).reserves, 0);
assert.equal(seat(next, richese).forces['polar_sink:0'], field + 1);
assert.equal(seat(next, richese).tanks, tanks);
assert.deepEqual(next.pendingRevival, pending);
assert.equal(forceCount(next), 20);
next = act(next, choam, {type:'decision', decline:true});
assert.equal(next.pendingRevival, null);
assert.equal(seat(next, richese).reserves, 2);
assert.equal(seat(next, richese).tanks, tanks - 2);
assert.equal(seat(next, richese).revived, revived + 2);
assert.equal(seat(next, richese).forces['polar_sink:0'], field + 1);
assert.equal(forceCount(next), 20);
assert.deepEqual(inventory(next), physical);
});
void test('Advanced CHOAM La La La preserves completed Revival turns without a No-Field reveal', () => {
const {g} = source(atreides), before = structuredClone(g.revivalOrder);
assert.ok(g.ready.length > 0, 'The ordered phase already has completed factions');
const card = seat(g, choam).hand.find(row => row.name === 'La La La'); assert.ok(card);
const next = act(g, choam, {type:'card', mode:'choam', card:card.id});
assert.deepEqual(next.revivalOrder, before);
assert.deepEqual(next.ready, g.ready);
});
void test('all bot profiles can respond to the original Advanced CHOAM decision after a voluntary reveal', () => {
const {g, token, event} = source(atreides);
const revealed = act(g, richese, {type:'revealNoField', token, event});
for (const difficulty of DIFFICULTIES) {
const view = viewGame(revealed, choam); view.players.find(p => p.id === choam)!.bot = difficulty;
const action = botActions(view)[0]; assert.ok(action, difficulty);
assert.doesNotThrow(() => act(revealed, choam, action), difficulty);
}
});
@@ -0,0 +1,110 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import {readFileSync} from 'node:fs';
import {runInNewContext} from 'node:vm';
import {createElement, isValidElement, type ReactElement, type ReactNode} from 'react';
import {renderToStaticMarkup} from 'react-dom/server';
import * as jsxRuntime from 'react/jsx-runtime';
import ts from 'typescript';
import {RicheseNoFieldControls} from '../components/richese-no-field';
import {applyAction, createGame, joinGame, newPlayer, viewGame, type Action, type Game, type GameView} from '../game/engine';
import * as catalog from '../game/catalog';
import * as board from '../game/board';
import * as advisors from '../game/advisors';
import * as shipmentPrice from '../game/shipment-price';
import * as noField from '../game/richese-no-field';
import * as homeworldCards from '../game/homeworld-cards';
import * as smuggler from '../game/smuggler-no-field';
import * as homeworldShipment from '../game/richese-homeworld-shipment';
import {actTruthMovementNativeEarly as act, nextTruthMovementNativeEarlyStep} from './fixture-truth-movement-native-early';
const seat=(game:Game,id:string)=>{const player=game.players.find(row=>row.id===id);assert.ok(player);return player;};
const clean=(game:Game)=>!game.response&&!game.decision&&!game.phaseOpening&&!game.truthtrance&&!game.pendingTreacheryDiscard;
function reach(game:Game,until:(state:Game)=>boolean):Game {
for(let n=0;n<2400;n++) {
if(until(game))return game;
assert.notEqual(game.status,'finished');
const step=nextTruthMovementNativeEarlyStep(game,{position:'first',method:'onceAround',direction:'clockwise',keepUnbid:false});
assert.ok(step,`Missing native action at ${game.turn}/${game.phase}/${game.decision?.kind}`);
game=act(game,step.actor,step.action);
}
throw Error('Advanced No-Field control source did not reach its economic decision');
}
/** Real public Advanced setup and paid original No-Field shipment; only
* unopened starting/Spice order and conserved initial board counters staged. */
function fixture() {
let game=createGame('ADVREVEALCONTROL',newPlayer('richese','Richese','richese'),true,['choam','ix']);
joinGame(game,newPlayer('atreides','Atreides','atreides'));
joinGame(game,newPlayer('choam','CHOAM','choam'));
for(const player of game.players)game=act(game,player.id,{type:'ready'});
game=act(game,'richese',{type:'start',advancedPreview:true});
const cards=game.deck.filter(card=>['projectile','poison','shield','snooper'].includes(card.kind)).slice(0,3);
assert.equal(cards.length,3);
for(const [position,card] of cards.entries()) {
const from=game.deck.findIndex(candidate=>candidate.id===card.id);assert.ok(from>=position);
[game.deck[position],game.deck[from]]=[game.deck[from],game.deck[position]];
}
game=reach(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={};
}
for(const position of [0,1,2,3]) {
const from=game.spiceDeck.findIndex((card,index)=>index>=position&&'territory' in card&&!card.discovery);
assert.ok(from>=position);[game.spiceDeck[position],game.spiceDeck[from]]=[game.spiceDeck[from],game.spiceDeck[position]];
}
game=reach(game,state=>state.turn===1&&state.phase===5&&state.active==='richese'&&clean(state));
const token=seat(game,'richese').noField!.tokens.find(row=>row.value===3);assert.ok(token);
const event=seat(game,'richese').noFieldEvent;assert.ok(event);
game=act(game,'richese',{type:'ship',noField:token.id,event,territory:'polar_sink',sector:0,allyPayment:0});
game=reach(game,clean);game=act(game,'richese',{type:'endMovement'});
game=reach(game,state=>state.turn===2&&state.decision?.kind==='richeseDeclaration'&&!state.response&&!state.phaseOpening);
assert.equal(seat(game,'richese').noField?.deployed?.tokenId,token.id);
return {game,token:token.id};
}
type Element=ReactElement<{children?:ReactNode;[key:string]:unknown}>;
function elements(node:ReactNode):Element[] {
if(Array.isArray(node))return node.flatMap(elements);
if(!isValidElement<{children?:ReactNode;[key:string]:unknown}>(node))return [];
return [node,...elements(node.props.children)];
}
const props=(game:GameView,busy:boolean,act:(action:Action)=>void)=>
({game,busy,act,destination:'arrakeen',sector:10,allyPayment:''});
/** Invoke the real component using deterministic hooks so its click callback
* is exercised against the actual Advanced engine projection. */
function controls(game:GameView,busy:boolean,sent:Action[]) {
const exports:{RicheseNoFieldControls?:typeof RicheseNoFieldControls}={};
const code=ts.transpileModule(readFileSync(new URL('../components/richese-no-field.tsx',import.meta.url),'utf8'),{
compilerOptions:{module:ts.ModuleKind.CommonJS,target:ts.ScriptTarget.ES2022,jsx:ts.JsxEmit.ReactJSX},
}).outputText;
runInNewContext(code,{exports,require(name:string){
const modules:Record<string,unknown>={
'react/jsx-runtime':jsxRuntime,react:{useId:()=> 'fixture',useState:(initial:unknown)=>[initial,()=>{}]},
'@/game/catalog':catalog,'@/game/board':board,'@/game/advisors':advisors,'@/game/shipment-price':shipmentPrice,
'@/game/richese-no-field':noField,'@/game/homeworld-cards':homeworldCards,'@/game/smuggler-no-field':smuggler,
'@/game/richese-homeworld-shipment':homeworldShipment,'./richese-homeworld-forces':{},'./shipment-quote':{},
'./ui/button':{Button:'button'},
};
if(!(name in modules))throw Error(`Unexpected component import ${name}`);
return modules[name];
}});
assert.ok(exports.RicheseNoFieldControls);
return elements(exports.RicheseNoFieldControls(props(game,busy,action=>sent.push(action))));
}
void test('real Advanced economic decision shows an owner-only reveal and its click performs the original action',()=>{
const f=fixture(),view=viewGame(f.game,'richese'),observer=viewGame(f.game,'atreides'),sent:Action[]=[];
assert.equal(f.game.decision?.kind,'richeseDeclaration');assert.equal(view.richeseNoField?.canReveal,true);
assert.equal(observer.richeseNoField?.private,null);
assert.match(renderToStaticMarkup(createElement(RicheseNoFieldControls,props(view,false,()=>{}))),/Reveal your No-Field/);
assert.equal(renderToStaticMarkup(createElement(RicheseNoFieldControls,props(observer,false,()=>{}))),'');
const button=controls(view,false,sent).find(element=>element.type==='button'&&element.props.children==='Reveal your No-Field');
assert.ok(button);assert.equal(button.props.disabled,false);(button.props.onClick as ()=>void)();
assert.deepEqual(JSON.parse(JSON.stringify(sent)),[{type:'revealNoField',event:view.richeseNoField!.event,token:f.token}]);
const parent=structuredClone(f.game.decision),after=applyAction(f.game,'richese',sent[0]);
assert.deepEqual(after.decision,parent);assert.equal(seat(after,'richese').forces['polar_sink:0'],3);
const busySent:Action[]=[];
const busyButton=controls(view,true,busySent).find(element=>element.type==='button'&&element.props.children==='Reveal your No-Field');
assert.ok(busyButton);assert.equal(busyButton.props.disabled,true);(busyButton.props.onClick as ()=>void)();
assert.deepEqual(busySent,[]);
});
@@ -0,0 +1,120 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import {applyAction, createGame, joinGame, newPlayer, viewGame, type Game} from '../game/engine';
import {botActions} from '../game/bots';
import {DIFFICULTIES} from '../game/bot-profiles';
import {actTruthMovementNativeEarly as act, nextTruthMovementNativeEarlyStep} from './fixture-truth-movement-native-early';
const owner='richese', observer='atreides', choam='choam';
const seat=(game:Game,id:string)=>{const player=game.players.find(row=>row.id===id);assert.ok(player);return player;};
const clean=(game:Game)=>!game.response&&!game.decision&&!game.phaseOpening&&!game.truthtrance&&!game.pendingTreacheryDiscard;
function next(game:Game) {
return nextTruthMovementNativeEarlyStep(game,{position:'first',method:'onceAround',direction:'clockwise',keepUnbid:false});
}
function reach(game:Game,until:(state:Game)=>boolean):Game {
for(let count=0;count<2400;count++) {
if(until(game))return game;
assert.notEqual(game.status,'finished','Original Advanced game must reach its next requested window');
const step=next(game);assert.ok(step,`Missing native action at ${game.turn}/${game.phase}/${game.decision?.kind}`);
game=act(game,step.actor,step.action);
}
throw Error('Advanced native reveal programme did not reach its window');
}
/** Real public Advanced setup and paid No-Field shipment before turn two.
* Only unopened starting/Spice order and conserved board positions are staged;
* the auction-specific branch additionally stages its purse and Karama card. */
function source() {
let game=createGame('ADVREVEALECON',newPlayer(owner,'Richese','richese'),true,['choam','ix']);
joinGame(game,newPlayer(observer,'Atreides','atreides'));
joinGame(game,newPlayer(choam,'CHOAM','choam'));
for(const player of game.players)game=act(game,player.id,{type:'ready'});
game=act(game,owner,{type:'start',advancedPreview:true});
const ordinary=game.deck.filter(card=>['projectile','poison','shield','snooper'].includes(card.kind)).slice(0,3);
assert.equal(ordinary.length,3);
for(const [position,card] of ordinary.entries()) {
const from=game.deck.findIndex(candidate=>candidate.id===card.id);assert.ok(from>=position);
[game.deck[position],game.deck[from]]=[game.deck[from],game.deck[position]];
}
game=reach(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={};
}
for(const position of [0,1,2,3]) {
const from=game.spiceDeck.findIndex((card,index)=>index>=position&&'territory' in card&&!card.discovery);
assert.ok(from>=position);
[game.spiceDeck[position],game.spiceDeck[from]]=[game.spiceDeck[from],game.spiceDeck[position]];
}
game=reach(game,state=>state.turn===1&&state.phase===5&&state.active===owner&&clean(state));
const token=seat(game,owner).noField!.tokens.find(row=>row.value===3);assert.ok(token);
const event=seat(game,owner).noFieldEvent;assert.ok(event);
game=act(game,owner,{type:'ship',noField:token.id,event,territory:'polar_sink',sector:0,allyPayment:0});
game=reach(game,clean);
assert.equal(seat(game,owner).noField?.deployed?.tokenId,token.id);
game=act(game,owner,{type:'endMovement'});
game=reach(game,state=>state.turn===2&&state.phase===0&&!!state.phaseOpening&&!state.response&&!state.decision);
const revealEvent=seat(game,owner).noFieldEvent;assert.ok(revealEvent);
return {game,token:token.id,event:revealEvent};
}
let cached:ReturnType<typeof source>|undefined;
const fixture=()=>{const f=cached??=source();return {...f,game:structuredClone(f.game)};};
function reveal(game:Game,token:string,event:string) {
assert.equal(viewGame(game,owner).richeseNoField?.canReveal,true);
const before=structuredClone(game), next=applyAction(game,owner,{type:'revealNoField',token,event});
assert.equal(seat(next,owner).reserves,seat(before,owner).reserves-3);
assert.equal(seat(next,owner).forces['polar_sink:0'],(seat(before,owner).forces['polar_sink:0']??0)+3);
assert.equal(seat(next,owner).noField?.deployed,null);
assert.notEqual(seat(next,owner).noFieldEvent,event);
assert.throws(()=>applyAction(next,owner,{type:'revealNoField',token,event}));
return next;
}
void test('Advanced Ix opening preserves existing passes through a real voluntary No-Field reveal',()=>{
const f=fixture();let game=act(f.game,owner,{type:'ready'});
const opening=structuredClone(game.phaseOpening);assert.ok(opening?.passed.includes(owner));
game=reveal(game,f.token,f.event);
assert.deepEqual(game.phaseOpening,opening);assert.equal(game.turn,f.game.turn);assert.equal(game.phase,f.game.phase);
game=reach(game,state=>!state.phaseOpening);
assert.equal(seat(game,owner).forces['polar_sink:0'],3);
});
for(const kind of ['choamMarket','richeseDeclaration','richeseCache','richeseUnbid'] as const) void test(
`Advanced ${kind} preserves its original economic decision through a No-Field reveal`,()=>{
const f=fixture();
const before=reach(f.game,state=>state.turn===2&&state.decision?.kind===kind&&!state.response&&!state.phaseOpening);
const parent=structuredClone(before.decision),market=structuredClone(before.choamMarket??null),
bidding=structuredClone(before.richeseBidding??null),auction=structuredClone(before.auction??null);
let game=reveal(before,f.token,f.event);
assert.deepEqual(game.decision,parent);assert.deepEqual(game.choamMarket??null,market);
assert.deepEqual(game.richeseBidding??null,bidding);assert.deepEqual(game.auction??null,auction);
const step=next(game);assert.ok(step);assert.equal(step.actor,parent!.player);
if(kind==='richeseDeclaration')for(const difficulty of DIFFICULTIES) {
const view=viewGame(game,step.actor);view.players.find(player=>player.id===step.actor)!.bot=difficulty;
const choice=botActions(view).find(action=>action.type==='decision');assert.ok(choice,difficulty);
assert.doesNotThrow(()=>applyAction(game,step.actor,choice),difficulty);
}
game=act(game,step.actor,step.action);
assert.notDeepEqual(game.decision,parent);assert.equal(seat(game,owner).forces['polar_sink:0'],3);
});
void test('Advanced normal auction payment retains its paid lot and buyer decision through reveal',()=>{
const f=fixture();let game=reach(f.game,state=>state.turn===2&&state.phase===3&&!!state.auction&&clean(state));
// Ensure space for the real purchased card and a real Karama payment option.
for(const player of game.players)game.deck.push(...player.hand.splice(0));
const counter=game.deck.findIndex(card=>card.effect==='karama');assert.ok(counter>=0);
seat(game,observer).hand.push(...game.deck.splice(counter,1));seat(game,observer).spice=6;
while(game.auction!.active!==observer)game=act(game,game.auction!.active,{type:'passBid'});
const card=game.auction!.cards[game.auction!.index].id;
game=act(game,observer,{type:'bid',amount:3});
for(let n=0;game.auction&&!game.response&&!game.decision&&n<15;n++)game=act(game,game.auction.active,{type:'passBid'});
assert.equal(game.decision?.kind,'auctionPayment');
const parent=structuredClone(game.decision),auction=structuredClone(game.auction),aid=structuredClone(game.aid);
game=reveal(game,f.token,f.event);
assert.deepEqual(game.decision,parent);assert.deepEqual(game.auction,auction);assert.deepEqual(game.aid,aid);
game=act(game,observer,{type:'decision',karama:false});
while(game.response) {
const actor=game.players.find(player=>!game.response!.passed.includes(player.id));assert.ok(actor);
game=act(game,actor.id,{type:'passResponse'});
}
assert.ok(seat(game,observer).hand.some(row=>row.id===card));
});
@@ -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);
});
@@ -148,7 +148,7 @@ void test('a legacy table without public Truthtrance history keeps its earlier i
void test('profile and nested-interaction boundaries do not admit another parent or module', () => {
const patches: Array<Partial<Game>> = [
{advanced:true}, {status:'setup'}, {phase:6}, {phase:-1}, {turn:0},
{status:'setup'}, {phase:6}, {phase:-1}, {turn:0},
{expansions:['choam','unknown']}, {expansions:['ix']},
{response:{kind:'richeseAuction', owner:'r', passed:[]}},
{pendingNullentropy:{} as NonNullable<Game['pendingNullentropy']>},
@@ -176,6 +176,11 @@ void test('profile and nested-interaction boundaries do not admit another parent
e3.expansions = ['choam','ecaz']; assert.equal(supported(e3), true);
});
void test('an otherwise supported auction-payment parent admits Advanced reveal', () => {
const game = parent('auctionPayment'); game.advanced = true;
assert.equal(supported(game), true);
});
void test('live current-turn commitments block the interruption; settled and previous-turn records do not', () => {
const game = parent('auctionPayment');
game.shipmentPromises = [{turn:game.turn, player:'e', asker:'r', answer:true, territory:'carthag', minimum:3}];