Allow Richese special purchase at Ix openings
Verify and publish checkpoint container / container (push) Successful in 10m34s

This commit is contained in:
Quintine committed 2026-11-16 15:40:07 +11:00
1 parent d169740adf
commit 53780c11d8
10 files changed
+395 -5

No files matched your search

+4 -1
View File
@@ -92,11 +92,14 @@ void test('original Richese Nexus profiles compose, but unsupported full overlay
independent.g.ecazTreachery = true;
assert.equal(quoteEmperorNexusSpecialPurchase(independent.g, 'r').blocked, null,
'The selected E1/E2 independent-card profile already supports native purchases.');
const selected = original();
selected.g.expansions = ['choam', 'ix', 'ecaz'];
assert.equal(quoteEmperorNexusSpecialPurchase(selected.g, 'r').blocked, null,
'Selected decks with the supported native roster retain the existing Nexus quote.');
for (const change of [
(g: Game) => { g.advancedPreview = true; },
(g: Game) => { g.sandtrout = true; },
(g: Game) => { g.nexusCards = undefined; },
(g: Game) => { g.expansions = ['choam', 'ix', 'ecaz']; },
]) {
const { g, activation, acquire } = original();
change(g);
@@ -0,0 +1,95 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { readFileSync } from 'node:fs';
import { runInNewContext } from 'node:vm';
import { isValidElement, type ReactElement, type ReactNode } from 'react';
import * as jsxRuntime from 'react/jsx-runtime';
import ts from 'typescript';
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 { nextStrongholdFactionsNativeStep } from './fixture-stronghold-factions';
import type { RicheseSpecialKarama } from '../components/richese-special-karama';
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)];
}
/** Genuine Advanced native setup to the original Ix opening. A single held
* card is exchanged with an existing physical Karama solely to exercise its
* control; card inventory and all phase-opening state remain intact. */
function opening(): Game {
let game = createGame('RICHOPENCONTROL',newPlayer('r','Richese','richese'),true,['ix','choam']);
joinGame(game,newPlayer('i','Ixians','ixians'));
joinGame(game,newPlayer('e','Emperor','emperor'));
for (const player of game.players) game = applyAction(game,player.id,{type:'ready'});
game = applyAction(game,'r',{type:'start',advancedPreview:true});
for (let count = 0; game.status === 'setup' && count < 200; count++) {
const step = nextStrongholdFactionsNativeStep(game); assert.ok(step);
game = applyAction(game,step.actor,step.action);
}
assert.equal(game.status,'playing'); assert.ok(game.phaseOpening);
const owner = game.players.find(player => player.id === 'r')!;
if (!owner.hand.some(card => card.effect === 'karama')) {
const source = [game.deck,...game.players.filter(player => player.id !== owner.id).map(player => player.hand)]
.find(cards => cards.some(card => card.effect === 'karama'));
assert.ok(source); const index = source.findIndex(card => card.effect === 'karama');
assert.ok(owner.hand.length); [owner.hand[0],source[index]] = [source[index],owner.hand[0]];
}
return game;
}
/** Render the actual stateful component with hooks isolated in a small test
* harness, then invoke its original button callback. */
function control(game: ReturnType<typeof viewGame>, busy = false) {
const states:unknown[] = [], sent:Action[] = [];
let cursor = 0;
const exported:{RicheseSpecialKarama?:typeof RicheseSpecialKarama} = {};
runInNewContext(ts.transpileModule(readFileSync(new URL('../components/richese-special-karama.tsx',import.meta.url),'utf8'), {
compilerOptions:{module:ts.ModuleKind.CommonJS,target:ts.ScriptTarget.ES2022,jsx:ts.JsxEmit.ReactJSX},
}).outputText,{exports:exported,require(name:string) {
if (name === 'react/jsx-runtime') return jsxRuntime;
if (name === 'react') return {useId:() => 'test',useState(initial:unknown) {
const index = cursor++; if (!(index in states)) states[index] = initial;
return [states[index],(next:unknown) => {states[index] = next;}];
}};
if (name === './ui/button') return {Button:'button'};
if (name === './card-inspector') return {CardInspector:'span',CardRules:'span'};
throw Error(`Unexpected import ${name}`);
}});
assert.ok(exported.RicheseSpecialKarama);
const render = () => {cursor = 0; return elements(exported.RicheseSpecialKarama!({game,busy,act(action) {sent.push(action);}}));};
return {render,sent};
}
void test('Richese sees and can submit the private special purchase during the original Ix opening', () => {
const game = opening(), view = viewGame(game,'r'), original = structuredClone(game.phaseOpening);
const quote = view.richeseSpecialKarama; assert.ok(quote && !quote.blocked);
assert.ok(quote.karamas.length && quote.cards.length);
const ui = control(view), button = ui.render().find(row => row.type === 'button');
assert.ok(button); assert.equal(button.props.disabled,false);
(button.props.onClick as () => void)();
assert.deepEqual(JSON.parse(JSON.stringify(ui.sent)), [{type:'card',mode:'special',
card:quote.karamas[0].id, acquire:quote.cards[0].id}]);
const after = applyAction(game,'r',ui.sent[0]);
assert.equal(after.players.find(player => player.id === 'r')!.specialKaramaUsed,true);
assert.ok(after.response || after.phaseOpening);
assert.deepEqual(after.response ? after.pendingRichesePurchaseIncome?.resume.phaseOpening : after.phaseOpening,original);
assert.equal(viewGame(game,'i').richeseSpecialKarama,null);
const locked = control(view,true).render().find(row => row.type === 'button');
assert.ok(locked); assert.equal(locked.props.disabled,true);
});
void test('each AI difficulty can continue the original opening without a strategic purchase', () => {
const game = opening();
for (const difficulty of DIFFICULTIES) {
const view = viewGame(game,'r');
view.players.find(player => player.id === 'r')!.bot = difficulty;
const action = botActions(view)[0]; assert.deepEqual(action,{type:'ready'},difficulty);
const after = applyAction(game,'r',action);
assert.ok(after.phaseOpening?.passed.includes('r'));
}
});
@@ -0,0 +1,59 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { createGame, joinGame, newPlayer, type Game, type ResponseWindow } from '../game/engine';
import { quoteRicheseCancellation, RicheseCancellationError } from '../game/richese-cancellation';
/** Staged cancellation envelopes exercise the pure receipt validator only;
* native purchase and cancel execution have their own gameplay cases. */
function source(withOpening: boolean): {game: Game; response: ResponseWindow} {
const game = createGame('RICHOPENRECEIPT',newPlayer('r','Richese','richese'),true,
withOpening ? ['choam','ix'] : ['choam']);
joinGame(game,newPlayer('e','Emperor','emperor'));
joinGame(game,newPlayer('a','Atreides','atreides'));
game.status = 'playing'; game.turn = 2; game.phase = 3;
const response: ResponseWindow = {kind:'richesePurchaseIncome',owner:'e',amount:3,passed:['a']};
game.response = response;
game.pendingRichesePurchaseIncome = {owner:'e',turn:game.turn,phase:game.phase,
resume:{response:null,decision:null,pendingKarama:null,
...(withOpening ? {phaseOpening:{initialize:true,passed:['a']}} : {})}};
return {game,response};
}
void test('a parked clean Ix opening is returned unchanged by the purchase-income cancellation quote', () => {
const {game,response} = source(true), before = structuredClone(game);
const quote = quoteRicheseCancellation(game,response);
assert.equal(quote?.kind,'richesePurchaseIncome');
assert.deepEqual(quote?.resume,game.pendingRichesePurchaseIncome!.resume);
assert.deepEqual(quote?.resume.phaseOpening,{initialize:true,passed:['a']});
assert.deepEqual(game,before);
const saved = JSON.parse(JSON.stringify(game)) as Game;
assert.deepEqual(quoteRicheseCancellation(saved,saved.response!),quote);
});
void test('legacy income receipts without a parked opening retain the original quoted shape', () => {
const {game,response} = source(false), before = structuredClone(game);
const quote = quoteRicheseCancellation(game,response);
assert.equal(quote?.kind,'richesePurchaseIncome');
assert.deepEqual(quote?.resume,{response:null,decision:null,pendingKarama:null});
assert.equal(Object.hasOwn(quote!.resume,'phaseOpening'),false);
assert.deepEqual(game,before);
});
void test('invalid parked openings and mixed parent controls reject without changing the receipt', () => {
const mutations: Array<(game: Game) => void> = [
game => {game.expansions = ['choam'];},
game => {game.pendingRichesePurchaseIncome!.resume.phaseOpening = null;},
game => {game.pendingRichesePurchaseIncome!.resume.phaseOpening = {initialize:true,passed:['a','a']};},
game => {game.pendingRichesePurchaseIncome!.resume.phaseOpening = {initialize:true,passed:['not-seated']};},
game => {game.pendingRichesePurchaseIncome!.resume.phaseOpening = {initialize:'yes',passed:[]} as never;},
game => {game.pendingRichesePurchaseIncome!.resume.response = {kind:'choamCharity',owner:'r',passed:[]};},
game => {game.pendingRichesePurchaseIncome!.resume.decision = {kind:'auctionPayment',player:'a'};},
game => {game.pendingRichesePurchaseIncome!.resume.pendingKarama = {owner:'a',use:{kind:'shipment',recipient:'a'}};},
];
for (const mutate of mutations) {
const {game,response} = source(true); mutate(game);
const before = structuredClone(game);
assert.throws(() => quoteRicheseCancellation(game,response),RicheseCancellationError);
assert.deepEqual(game,before);
}
});
@@ -0,0 +1,104 @@
import assert from 'node:assert/strict';
import test from 'node:test';
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 } from './fixture-truth-movement';
const player = (game:Game, id:string) => {
const result = game.players.find(seat => seat.id === id); assert.ok(result); return result;
};
function advance(game:Game, until:(game:Game)=>boolean):Game {
for (let n = 0; n < 500; n++) {
if (until(game)) return game;
const next = nextTruthMovementNativeEarlyStep(game); assert.ok(next);
game = act(game,next.actor,next.action);
}
throw Error('The original native game did not reach its opening.');
}
/** Native Advanced Richese/Ix setup. Select only original unopened starting
* cards; after setup, swap conserved held cards if needed so Richese and a
* non-Emperor responder hold the two actual Karama cards. */
function source(emperor:boolean) {
let game = createGame('RICHOPEN',newPlayer('r','Richese','richese'),true,['choam','ix']);
joinGame(game,newPlayer('i','Ixians','ixians'));
joinGame(game,newPlayer('a','Atreides','atreides'));
if (emperor) joinGame(game,newPlayer('e','Emperor','emperor'));
for (const seat of game.players) game = act(game,seat.id,{type:'ready'});
game = act(game,'r',{type:'start',advancedPreview:true});
const shield = game.deck.find(card => card.kind === 'shield'); assert.ok(shield);
const karamas = game.deck.filter(card => card.effect === 'karama'); assert.ok(karamas.length >= 2);
const ordinary = game.deck.find(card => card.kind === 'projectile'); assert.ok(ordinary);
const initial = [shield,karamas[0],karamas[1],ordinary].slice(0,game.players.length);
for (const [position,card] of initial.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 = advance(game,state => state.status === 'playing' && !!state.phaseOpening &&
state.amalWindowOpen === true && !state.response && !state.decision);
const held = (id:string) => player(game,id).hand;
const assignKarama = (id:string, protectedSeat?:string) => {
if (held(id).some(card => card.effect === 'karama')) return;
const donor = game.players.find(seat => seat.id !== id && seat.id !== protectedSeat &&
seat.hand.some(card => card.effect === 'karama')); assert.ok(donor);
const from = donor.hand.findIndex(card => card.effect === 'karama');
assert.ok(held(id).length > 0);
[held(id)[0],donor.hand[from]] = [donor.hand[from],held(id)[0]];
};
assignKarama('r'); assignKarama('a','r');
assert.ok(player(game,'r').spice >= 3);
const card = held('r').find(row => row.effect === 'karama'); assert.ok(card);
const acquire = game.richeseCache?.[0]; assert.ok(acquire);
const canceledBy = held('a').find(row => row.effect === 'karama'); assert.ok(canceledBy);
return {game,card:card.id,acquire:acquire.id,canceledBy:canceledBy.id};
}
const cached = new Map<boolean,ReturnType<typeof source>>();
const fixture = (emperor:boolean) => {
let item = cached.get(emperor); if (!item) {item = source(emperor); cached.set(emperor,item);}
return {...item,game:structuredClone(item.game)};
};
const purchase = (card:string,acquire:string):Action =>
({type:'card',mode:'special',card,acquire});
for (const emperor of [false,true]) void test(`Advanced Richese special purchase retains the Ix opening with Emperor ${emperor ? 'present' : 'absent'}`, () => {
const f = fixture(emperor);
const before = act(f.game,'i',{type:'ready'});
const opening = structuredClone(before.phaseOpening), inventory = truthMovementInventory(before);
const spice = player(before,'r').spice, emperorSpice = emperor ? player(before,'e').spice : 0;
assert.ok(opening);
assert.ok(opening.passed.includes('i'));
assert.equal(viewGame(before,'r').richeseSpecialKarama?.blocked,null);
let after = act(before,'r',purchase(f.card,f.acquire));
assert.equal(player(after,'r').spice,spice - 3);
assert.equal(player(after,'r').specialKaramaUsed,true);
assert.ok(player(after,'r').hand.some(card => card.id === f.acquire));
assert.ok(!after.richeseCache?.some(card => card.id === f.acquire));
assert.deepEqual(truthMovementInventory(after),inventory);
if (emperor) {
assert.equal(after.response?.kind,'richesePurchaseIncome');
after = advance(after,state => !!state.phaseOpening && !state.response && !state.decision);
assert.equal(player(after,'e').spice,emperorSpice + 3);
}
assert.deepEqual(after.phaseOpening,opening);
assert.equal(after.amalWindowOpen,true);
assert.equal(viewGame(after,'i').players.find(seat => seat.id === 'r')!.hand,undefined);
for (const seat of after.players.filter(seat => !opening.passed.includes(seat.id)))
after = act(after,seat.id,{type:'ready'});
assert.equal(after.phaseOpening,null);
assert.ok(player(after,'r').hand.some(card => card.id === f.acquire));
});
void test('preventing Emperor income preserves the purchased card and the exact Ix opening', () => {
const f = fixture(true);
const before = act(f.game,'i',{type:'ready'}), opening = structuredClone(before.phaseOpening);
const richeseSpice = player(before,'r').spice, emperorSpice = player(before,'e').spice;
let game = act(before,'r',purchase(f.card,f.acquire));
assert.equal(game.response?.kind,'richesePurchaseIncome');
game = act(game,'a',{type:'card',mode:'cancel',card:f.canceledBy});
game = advance(game,state => !!state.phaseOpening && !state.response && !state.decision);
assert.deepEqual(game.phaseOpening,opening);
assert.equal(player(game,'r').spice,richeseSpice - 3);
assert.equal(player(game,'e').spice,emperorSpice);
assert.equal(player(game,'r').specialKaramaUsed,true);
assert.ok(player(game,'r').hand.some(card => card.id === f.acquire));
});
@@ -0,0 +1,78 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { createGame, initializeSemutaGameForAudit, joinGame, newPlayer, viewGame, type Game } from '../game/engine';
import { SEMUTA_DRUG_ID } from '../game/semuta-drug';
import { nextStrongholdFactionsNativeStep } from './fixture-stronghold-factions';
import { actTruthMovementNativeEarly as act, nextTruthMovementNativeEarlyStep } from './fixture-truth-movement-native-early';
import { truthMovementInventory } from './fixture-truth-movement';
import { moveSemutaEmperorCard, semutaEmperorCardId } from './fixture-semuta-emperor-share';
import { reactSemutaSpecial } from './fixture-semuta-special-karama';
const player = (game:Game, id:string) => {
const result = game.players.find(seat => seat.id === id); assert.ok(result); return result;
};
function advance(game:Game, until:(state:Game) => boolean):Game {
for (let count = 0; count < 500; count++) {
if (until(game)) return game;
const step = nextTruthMovementNativeEarlyStep(game); assert.ok(step);
game = act(game,step.actor,step.action);
}
throw Error('The original game did not return to its Ix opening.');
}
/** Genuine Advanced native Semuta setup and Ix opening. Staging moves the
* original Semuta and, if needed, an existing printed Karama between physical
* zones to exercise its special discard and reaction. No opening, spice or
* force state is installed by the fixture. */
function source() {
let game = createGame('RICHSEMUTAOPEN',newPlayer('r','Richese','richese'),true,['choam','ix']);
joinGame(game,newPlayer('i','Ixians','ixians'));
joinGame(game,newPlayer('a','Atreides','atreides'));
joinGame(game,newPlayer('e','Emperor','emperor'));
for (const seat of game.players) game = act(game,seat.id,{type:'ready'});
game = initializeSemutaGameForAudit(game);
for (let count = 0; game.status === 'setup' && count < 200; count++) {
const step = nextStrongholdFactionsNativeStep(game); assert.ok(step);
game = act(game,step.actor,step.action);
}
assert.equal(game.status,'playing'); assert.equal(game.phase,0);
assert.ok(game.phaseOpening && game.amalWindowOpen);
moveSemutaEmperorCard(game,SEMUTA_DRUG_ID,'a');
let karama = player(game,'r').hand.find(card => card.effect === 'karama');
if (!karama) {
const id = semutaEmperorCardId(game,card => card.effect === 'karama');
moveSemutaEmperorCard(game,id,'r');
karama = player(game,'r').hand.find(card => card.id === id);
}
assert.ok(karama);
const acquired = game.richeseCache?.find(card => card.id !== SEMUTA_DRUG_ID); assert.ok(acquired);
return {game,karama:karama.id,acquired:acquired.id};
}
let cached:ReturnType<typeof source> | undefined;
const fixture = () => {cached ??= source(); return {...cached,game:structuredClone(cached.game)};};
for (const claim of [false,true]) void test(`Semuta ${claim ? 'claims' : 'passes'} the Richese cost and restores the same Ix opening after Emperor income`, () => {
const {game,karama,acquired} = fixture();
const before = act(game,'i',{type:'ready'});
const opening = structuredClone(before.phaseOpening), inventory = truthMovementInventory(before);
const richeseSpice = player(before,'r').spice, emperorSpice = player(before,'e').spice;
assert.ok(opening?.passed.includes('i'));
assert.equal(viewGame(before,'r').richeseSpecialKarama?.blocked,null);
let next = act(before,'r',{type:'card',mode:'special',card:karama,acquire:acquired});
assert.equal(next.pendingTreacheryDiscard?.batch.cause,'specialKarama:richese');
assert.deepEqual(next.pendingTreacheryDiscard?.continuation?.kind,'specialKaramaDiscard');
assert.equal(next.phaseOpening,null);
assert.equal(player(next,'r').spice,richeseSpice);
assert.equal(player(next,'r').specialKaramaUsed,undefined);
assert.ok(next.richeseCache?.some(card => card.id === acquired));
next = reactSemutaSpecial(next,'a',claim);
assert.equal(player(next,'r').spice,richeseSpice - 3);
assert.equal(player(next,'r').specialKaramaUsed,true);
assert.ok(player(next,'r').hand.some(card => card.id === acquired));
assert.equal(player(next,'a').hand.some(card => card.id === karama),claim);
if (next.response) next = advance(next,state => !!state.phaseOpening && !state.response && !state.decision);
assert.deepEqual(next.phaseOpening,opening);
assert.equal(next.amalWindowOpen,true);
assert.equal(player(next,'e').spice,emperorSpice + 3);
assert.deepEqual(truthMovementInventory(next),inventory);
});