Preserve cache promises and support concealed Ambassador collection
Verify and publish checkpoint container / container (push) Successful in 11m9s
Verify and publish checkpoint container / container (push) Successful in 11m9s
This commit is contained in:
1 parent
3ede19c90a
commit
1a65e69932
14 files changed
+594
-9
No files matched your search
@@ -0,0 +1,156 @@
|
||||
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 { AmbassadorMovement } from '../components/ambassador-movement';
|
||||
import { applyAction, viewGame, type Action, type Game, type GameView } from '../game/engine';
|
||||
import * as board from '../game/board';
|
||||
import * as sandmaster from '../game/sandmaster-movement';
|
||||
import * as matching from '../game/advisor-ambassador-matching';
|
||||
import { placeAmbassador, validateAmbassadors } from '../game/ecaz-ambassadors';
|
||||
import { deployRicheseNoField } from '../game/richese-no-field';
|
||||
import { validateEcazLoyalty } from '../game/ecaz-loyalty';
|
||||
import { createSelectedDeckSkillsSetup, assertSelectedDeckSkillsInventory } from './fixture-selected-deck-skills';
|
||||
|
||||
const seat = (game: Game, id: string) => {
|
||||
const player = game.players.find(row => row.id === id); assert.ok(player); return player;
|
||||
};
|
||||
|
||||
/** The shared inventory fixture predates Advanced Ecaz Loyalty. Validate its
|
||||
* real custody, then include that unique card in the fixture's traitor count. */
|
||||
function assertInventory(game: Game) {
|
||||
validateEcazLoyalty(game);
|
||||
const inventory = structuredClone(game);
|
||||
if (inventory.ecazLoyalty?.card) {
|
||||
(inventory.traitorReserve ??= []).push(inventory.ecazLoyalty.card);
|
||||
delete inventory.ecazLoyalty;
|
||||
}
|
||||
assertSelectedDeckSkillsInventory(inventory);
|
||||
}
|
||||
|
||||
/** Public setup and original Sandmaster assignment. The original marker,
|
||||
* Ambassador, forces and destination Spice piles are staged at a controlled
|
||||
* movement boundary; the actual trigger and beneficiary choice are played. */
|
||||
function fixture(advanced: boolean) {
|
||||
const setup = createSelectedDeckSkillsSetup({advanced, factions:['richese','ecaz','atreides'],
|
||||
expansions:['choam','ecaz'],skill:'sandmaster'});
|
||||
let game = structuredClone(setup.afterSetup);
|
||||
for (const player of game.players) {
|
||||
player.reserves += Object.values(player.forces).reduce((sum,n) => sum+n,0);
|
||||
player.forces = {}; player.shipped = false; player.moved = 0;
|
||||
}
|
||||
const entrant = seat(game,'atreides'), richese = seat(game,'richese'), ecaz = seat(game,'ecaz');
|
||||
entrant.reserves--; entrant.forces = {'imperial_basin:10':1}; entrant.shipped = true;
|
||||
richese.ally = 'ecaz'; ecaz.ally = 'richese';
|
||||
assert.ok(richese.noField);
|
||||
const marker = richese.noField.tokens.find(token => token.value === 3); assert.ok(marker);
|
||||
richese.noField = deployRicheseNoField(richese.noField, {tokenId:marker.id,controller:richese.id,
|
||||
location:{territory:'red_chasm',sector:7}});
|
||||
richese.noFieldEvent = 'ui-marker-event';
|
||||
assert.ok(game.ecazAmbassadors);
|
||||
const ambassadors = structuredClone(game.ecazAmbassadors);
|
||||
const token = ambassadors.tokens.find(row => row.effect === 'fremen'); assert.ok(token);
|
||||
if (!ambassadors.cohort.includes(token.id)) {
|
||||
const replaced = ambassadors.tokens.find(row => row.id === ambassadors.cohort[0]); assert.ok(replaced);
|
||||
replaced.zone = 'pool'; token.zone = 'supply'; ambassadors.cohort[0] = token.id;
|
||||
}
|
||||
game.ecazAmbassadors = placeAmbassador(ambassadors,token.id,{turn:1,availableSpice:ecaz.spice,
|
||||
destination:{id:'arrakeen',stronghold:true,inStorm:false,allowed:true}}).state;
|
||||
validateAmbassadors(game.ecazAmbassadors);
|
||||
Object.assign(game,{turn:2,phase:5,storm:18,active:'atreides',ready:[],response:null,decision:null,
|
||||
phaseOpening:null,stormResolution:null,stormPending:null,movementRemaining:['atreides','richese','ecaz'],
|
||||
spice:{'south_mesa:4':4,'south_mesa:5':2}});
|
||||
delete game.stormMovementSource;
|
||||
assertInventory(game);
|
||||
game = applyAction(game,'atreides',{type:'move',forces:{'imperial_basin:10':1},territory:'arrakeen',sector:10});
|
||||
assert.equal(game.pendingAmbassador?.stage,'offer');
|
||||
game = applyAction(game,'ecaz',{type:'decision',event:game.pendingAmbassador!.event,
|
||||
trigger:true,beneficiary:'richese'});
|
||||
assert.equal(game.pendingAmbassador?.stage,'move');
|
||||
return {game,marker:marker.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)];
|
||||
}
|
||||
|
||||
/** Run the real component with persistent deterministic hooks so the real
|
||||
* select, checkbox and submit callbacks can be exercised without a DOM. */
|
||||
function controller(game: GameView, busy = false) {
|
||||
const states: unknown[] = [], sent: Action[] = [];
|
||||
let cursor = 0;
|
||||
const exports: {AmbassadorMovement?: typeof AmbassadorMovement} = {};
|
||||
const code = ts.transpileModule(readFileSync(new URL('../components/ambassador-movement.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) {
|
||||
if (name === 'react/jsx-runtime') return jsxRuntime;
|
||||
if (name === 'react') return {useId:() => 'ambassador-fixture',useState(initial:unknown) {
|
||||
const index = cursor++; if (!(index in states)) states[index] = initial;
|
||||
return [states[index],(next:unknown) => {
|
||||
states[index] = typeof next === 'function' ? (next as (value:unknown) => unknown)(states[index]) : next;
|
||||
}];
|
||||
}};
|
||||
if (name === '@/game/board') return board;
|
||||
if (name === '@/game/sandmaster-movement') return sandmaster;
|
||||
if (name === '@/game/advisor-ambassador-matching') return matching;
|
||||
if (name === './ui/button') return {Button:'button'};
|
||||
if (name === './ui/input') return {Input:'input'};
|
||||
throw Error(`Unexpected component import ${name}`);
|
||||
}});
|
||||
assert.ok(exports.AmbassadorMovement);
|
||||
const render = () => { cursor=0; return elements(exports.AmbassadorMovement!({game,busy,act:action=>sent.push(action)})); };
|
||||
const select = (suffix:string,value:string) => {
|
||||
const node = render().find(element => element.props.id === `ambassador-fixture-${suffix}`); assert.ok(node);
|
||||
assert.ok(elements(node).some(option => option.type === 'option' && option.props.value === value));
|
||||
(node.props.onChange as (event:{target:{value:string}})=>void)({target:{value}});
|
||||
};
|
||||
return {render,sent,select};
|
||||
}
|
||||
|
||||
for (const advanced of [false,true]) void test(
|
||||
`${advanced ? 'Advanced' : 'Basic'} marker-only Ambassador owner selects an actual Sandmaster pile`, () => {
|
||||
const {game,marker} = fixture(advanced), view = viewGame(game,'richese');
|
||||
const html = renderToStaticMarkup(createElement(AmbassadorMovement,{game:view,busy:false,act() {}}));
|
||||
assert.match(html,/Ambassador force relocation/);
|
||||
assert.match(html,/Include concealed No-Field/);
|
||||
assert.match(html,/Choose physical forces or the concealed No-Field/);
|
||||
assert.equal(renderToStaticMarkup(createElement(AmbassadorMovement,
|
||||
{game:viewGame(game,'atreides'),busy:false,act() {}})), '');
|
||||
const ui = controller(view);
|
||||
ui.select('destination','south_mesa'); ui.select('sector','south_mesa:4');
|
||||
const checkbox = ui.render().find(element => element.type === 'input' && element.props.type === 'checkbox' &&
|
||||
element.props.checked === false); assert.ok(checkbox);
|
||||
(checkbox.props.onChange as (event:{target:{checked:boolean}})=>void)({target:{checked:true}});
|
||||
ui.select('sandmaster-pile','south_mesa:5');
|
||||
const button = ui.render().find(element => element.type === 'button' &&
|
||||
element.props.children === 'Relocate selected forces'); assert.ok(button);
|
||||
assert.equal(button.props.disabled,false); (button.props.onClick as ()=>void)();
|
||||
assert.deepEqual(JSON.parse(JSON.stringify(ui.sent)),[{type:'decision',event:game.pendingAmbassador!.event,
|
||||
forces:{},eliteForces:{},territory:'south_mesa',sector:4,
|
||||
noField:{tokenId:marker,event:'ui-marker-event'},sandmasterCollect:true,sandmasterPile:'south_mesa:5'}]);
|
||||
const before = seat(game,'richese').spice, done = applyAction(game,'richese',ui.sent[0]);
|
||||
assert.equal(seat(done,'richese').spice,before+1);
|
||||
assert.equal(done.spice['south_mesa:5'],1);
|
||||
assert.deepEqual(seat(done,'richese').noField?.deployed?.location,{territory:'south_mesa',sector:4});
|
||||
assert.throws(() => applyAction(done,'richese',ui.sent[0]),'The spent event cannot repeat');
|
||||
assertInventory(done);
|
||||
|
||||
const blocked = controller(view,true);
|
||||
blocked.select('destination','south_mesa'); blocked.select('sector','south_mesa:4');
|
||||
const busyCheckbox = blocked.render().find(element => element.type === 'input' && element.props.type === 'checkbox' &&
|
||||
element.props.checked === false); assert.ok(busyCheckbox);
|
||||
(busyCheckbox.props.onChange as (event:{target:{checked:boolean}})=>void)({target:{checked:true}});
|
||||
const busyButton = blocked.render().find(element => element.type === 'button' &&
|
||||
element.props.children === 'Relocate selected forces'); assert.ok(busyButton);
|
||||
assert.equal(busyButton.props.disabled,true); (busyButton.props.onClick as ()=>void)();
|
||||
assert.deepEqual(blocked.sent,[]);
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,112 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { applyAction, viewGame, type Game } from '../game/engine';
|
||||
import { botActions } from '../game/bots';
|
||||
import { DIFFICULTIES } from '../game/bot-profiles';
|
||||
import { placeAmbassador, validateAmbassadors } from '../game/ecaz-ambassadors';
|
||||
import { deployRicheseNoField } from '../game/richese-no-field';
|
||||
import { validateEcazLoyalty } from '../game/ecaz-loyalty';
|
||||
import { createSelectedDeckSkillsSetup, assertSelectedDeckSkillsInventory } from './fixture-selected-deck-skills';
|
||||
|
||||
const player = (game: Game, id: string) => {
|
||||
const result = game.players.find(seat => seat.id === id); assert.ok(result); return result;
|
||||
};
|
||||
|
||||
/** The shared fixture predates Advanced Ecaz Loyalty: count its unique public
|
||||
* card alongside circulating Traitors, after validating its real custody. */
|
||||
function assertInventory(game: Game) {
|
||||
validateEcazLoyalty(game);
|
||||
const inventory = structuredClone(game);
|
||||
if (inventory.ecazLoyalty?.card) {
|
||||
(inventory.traitorReserve ??= []).push(inventory.ecazLoyalty.card);
|
||||
delete inventory.ecazLoyalty;
|
||||
}
|
||||
assertSelectedDeckSkillsInventory(inventory);
|
||||
}
|
||||
|
||||
/** Genuine public setup and Sandmaster assignment. Controlled supplements
|
||||
* relocate original forces to reserves/board, place the original Ambassador,
|
||||
* deploy the actual marker, set the alliance/phase boundary and destination
|
||||
* piles. No card, skill, leader, Ambassador or No-Field identity is minted. */
|
||||
function source(advanced: boolean, value: 0 | 3 | 5, withForces: boolean) {
|
||||
const setup = createSelectedDeckSkillsSetup({advanced, factions:['richese','ecaz','atreides'],
|
||||
expansions:['choam','ecaz'],skill:'sandmaster'});
|
||||
let game = structuredClone(setup.afterSetup);
|
||||
assert.equal(game.players[0].faction,'richese');
|
||||
assert.equal(game.leaderSkills!.assignments.find(row => row.owner === 'richese')?.skill,'sandmaster');
|
||||
const beforeSkills = structuredClone(game.leaderSkills);
|
||||
for (const seat of game.players) {
|
||||
const returned = Object.values(seat.forces).reduce((sum,n) => sum+n,0);
|
||||
seat.reserves += returned; seat.forces = {}; seat.shipped = false; seat.moved = 0;
|
||||
}
|
||||
const entrant = player(game,'atreides'), richese = player(game,'richese'), ecaz = player(game,'ecaz');
|
||||
entrant.reserves--; entrant.forces = {'imperial_basin:10':1}; entrant.shipped = true;
|
||||
if (withForces) { richese.reserves -= 2; richese.forces = {'red_chasm:7':2}; }
|
||||
richese.ally = 'ecaz'; ecaz.ally = 'richese';
|
||||
assert.ok(richese.noField);
|
||||
const marker = richese.noField.tokens.find(token => token.value === value); assert.ok(marker);
|
||||
richese.noField = deployRicheseNoField(richese.noField, {tokenId:marker.id,controller:richese.id,
|
||||
location:{territory:'red_chasm',sector:7}});
|
||||
richese.noFieldEvent = 'staged-marker-event';
|
||||
assert.ok(game.ecazAmbassadors);
|
||||
const ambassadors = structuredClone(game.ecazAmbassadors);
|
||||
const token = ambassadors.tokens.find(row => row.effect === 'fremen'); assert.ok(token);
|
||||
if (!ambassadors.cohort.includes(token.id)) {
|
||||
const replaced = ambassadors.tokens.find(row => row.id === ambassadors.cohort[0]); assert.ok(replaced);
|
||||
replaced.zone = 'pool'; token.zone = 'supply'; ambassadors.cohort[0] = token.id;
|
||||
}
|
||||
game.ecazAmbassadors = placeAmbassador(ambassadors,token.id,{turn:1,availableSpice:ecaz.spice,
|
||||
destination:{id:'arrakeen',stronghold:true,inStorm:false,allowed:true}}).state;
|
||||
validateAmbassadors(game.ecazAmbassadors);
|
||||
Object.assign(game,{turn:2,phase:5,storm:18,active:'atreides',ready:[],response:null,decision:null,
|
||||
phaseOpening:null,stormResolution:null,stormPending:null,movementRemaining:['atreides','richese','ecaz'],
|
||||
spice:{'south_mesa:4':4,'south_mesa:5':2}});
|
||||
delete game.stormMovementSource;
|
||||
assert.deepEqual(game.leaderSkills,beforeSkills);
|
||||
assertInventory(game);
|
||||
game = applyAction(game,'atreides',{type:'move',forces:{'imperial_basin:10':1},territory:'arrakeen',sector:10});
|
||||
assert.equal(game.pendingAmbassador?.stage,'offer');
|
||||
game = applyAction(game,'ecaz',{type:'decision',event:game.pendingAmbassador!.event,
|
||||
trigger:true,beneficiary:'richese'});
|
||||
assert.equal(game.pendingAmbassador?.stage,'move');
|
||||
return {game,marker:marker.id};
|
||||
}
|
||||
|
||||
for (const advanced of [false,true]) for (const value of [0,3,5] as const)
|
||||
for (const withForces of [false,true]) void test(
|
||||
`${advanced ? 'Advanced' : 'Basic'} marker ${value}${withForces ? ' with forces' : ' alone'} collects on actual Ambassador relocation`, () => {
|
||||
const {game,marker} = source(advanced,value,withForces);
|
||||
const before = structuredClone(game), richese = player(game,'richese');
|
||||
const publicMarker = viewGame(game,'atreides').players.find(seat => seat.id === 'richese')!.noField;
|
||||
assert.ok(publicMarker);
|
||||
assert.ok(!JSON.stringify(publicMarker).includes(marker), 'A rival does not receive the private token identity');
|
||||
const own = viewGame(game,'richese');
|
||||
const offered = own.ambassadorEntry?.movement?.sources.find(row => row.territory === 'red_chasm');
|
||||
assert.equal(offered?.marker?.tokenId,marker);
|
||||
const done = applyAction(game,'richese',{type:'decision',event:game.pendingAmbassador!.event,
|
||||
forces:withForces ? {'red_chasm:7':2} : {},noField:{tokenId:marker,event:richese.noFieldEvent!},
|
||||
territory:'south_mesa',sector:4,sandmasterCollect:true,sandmasterPile:'south_mesa:5'});
|
||||
const moved = player(done,'richese');
|
||||
assert.equal(moved.spice,richese.spice+1);
|
||||
assert.equal(done.spice['south_mesa:4'],4); assert.equal(done.spice['south_mesa:5'],1);
|
||||
assert.deepEqual(moved.noField?.deployed?.location,{territory:'south_mesa',sector:4});
|
||||
assert.equal(moved.noField?.deployed?.tokenId,marker);
|
||||
assert.notEqual(moved.noFieldEvent,richese.noFieldEvent);
|
||||
assert.equal(moved.reserves,richese.reserves);
|
||||
assert.equal(moved.forces['south_mesa:4'] ?? 0,withForces ? 2 : 0);
|
||||
assert.equal(moved.moved,richese.moved); assert.equal(moved.shipped,richese.shipped);
|
||||
assert.equal(done.log.filter(row => row.automatic?.name === 'Sandmaster collection').length,
|
||||
before.log.filter(row => row.automatic?.name === 'Sandmaster collection').length + 1);
|
||||
assertInventory(done);
|
||||
});
|
||||
|
||||
void test('four bot profiles can legally relocate the sole marker in the real Ambassador window', () => {
|
||||
const {game} = source(false,0,false);
|
||||
for (const difficulty of DIFFICULTIES) {
|
||||
const view = viewGame(game,'richese');
|
||||
view.players.find(seat => seat.id === 'richese')!.bot = difficulty;
|
||||
const choice = botActions(view).find(action => action.type === 'decision' && action.noField);
|
||||
assert.ok(choice,difficulty);
|
||||
assert.doesNotThrow(() => applyAction(structuredClone(game),'richese',choice),difficulty);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,61 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { createGame, newPlayer, type Action, type Game } from '../game/engine';
|
||||
import { createLeaderSkills } from '../game/leader-skills';
|
||||
import { createRicheseNoField, deployRicheseNoField } from '../game/richese-no-field';
|
||||
import { quoteFremenAmbassadorMove } from '../game/fremen-ambassador';
|
||||
|
||||
/** Controlled board position; all marker denominations use the same public
|
||||
* movement and Sandmaster calculation. No card or physical unit is invented. */
|
||||
function source(value: 0 | 3 | 5, advanced: boolean, withForces: boolean) {
|
||||
const game = createGame('SAMARKER', newPlayer('r', 'Richese', 'richese'), advanced, ['choam', 'ecaz']);
|
||||
game.players.push(newPlayer('e', 'Ecaz', 'ecaz'), newPlayer('a', 'Atreides', 'atreides'));
|
||||
Object.assign(game, {status:'playing',turn:2,phase:5,storm:18,order:['e','a','r'],active:'a'});
|
||||
const richese = game.players[0];
|
||||
richese.spice = 5;
|
||||
richese.forces = withForces ? {'red_chasm:7':2} : {};
|
||||
richese.reserves = withForces ? 18 : 20;
|
||||
richese.noField = deployRicheseNoField(createRicheseNoField(['nf0','nf3','nf5']), {
|
||||
tokenId:`nf${value}`,controller:'r',location:{territory:'red_chasm',sector:7},
|
||||
});
|
||||
richese.noFieldEvent = 'marker-event';
|
||||
const skills = createLeaderSkills(() => 0.2);
|
||||
skills.deck = skills.deck.filter(skill => skill !== 'sandmaster');
|
||||
skills.assignments = [{skill:'sandmaster',owner:'r',leader:richese.leaders[0].id}];
|
||||
game.leaderSkills = skills;
|
||||
game.spice = {'south_mesa:4':4,'south_mesa:5':2};
|
||||
const action: Action = {type:'decision',event:'ambassador-event',
|
||||
forces:withForces ? {'red_chasm:7':2} : {},noField:{tokenId:`nf${value}`,event:'marker-event'},
|
||||
territory:'south_mesa',sector:4,sandmasterCollect:true,sandmasterPile:'south_mesa:5'};
|
||||
return {game,action};
|
||||
}
|
||||
|
||||
for (const advanced of [false,true]) for (const value of [0,3,5] as const)
|
||||
for (const withForces of [false,true]) void test(
|
||||
`${advanced ? 'Advanced' : 'Basic'} concealed ${value}${withForces ? ' with forces' : ' alone'} quotes one Sandmaster collection`, () => {
|
||||
const {game,action} = source(value,advanced,withForces);
|
||||
const before = structuredClone(game), priorAction = structuredClone(action);
|
||||
const result = quoteFremenAmbassadorMove(game,'r',action);
|
||||
assert.equal(result.total,withForces ? 3 : 1);
|
||||
assert.deepEqual(result.noField,{tokenId:`nf${value}`,event:'marker-event',from:'red_chasm:7'});
|
||||
assert.deepEqual(result.ambassadorSandmaster,{leader:game.players[0].leaders[0].id,key:'south_mesa:5',before:2});
|
||||
assert.deepEqual(game,before);
|
||||
assert.deepEqual(action,priorAction);
|
||||
});
|
||||
|
||||
void test('marker quote requires a live token, an eligible trainer and an actual destination pile', () => {
|
||||
const {game,action} = source(0,false,false);
|
||||
const before: Game = structuredClone(game);
|
||||
assert.throws(() => quoteFremenAmbassadorMove(game,'r',{
|
||||
...action,noField:{tokenId:'nf0',event:'stale'},
|
||||
}));
|
||||
assert.throws(() => quoteFremenAmbassadorMove(game,'r',{
|
||||
...action,sandmasterPile:'false_wall_west:13',
|
||||
}));
|
||||
const denied = structuredClone(game);
|
||||
denied.players[0].leaders[0].dead = true;
|
||||
assert.throws(() => quoteFremenAmbassadorMove(denied,'r',action));
|
||||
assert.deepEqual(game,before);
|
||||
assert.equal(quoteFremenAmbassadorMove(game,'r',{...action,sandmasterCollect:false,sandmasterPile:undefined})
|
||||
.ambassadorSandmaster,undefined);
|
||||
});
|
||||
@@ -0,0 +1,136 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { viewGame, type Game } from '../game/engine';
|
||||
import { SEMUTA_DRUG_ID } from '../game/semuta-drug';
|
||||
import {
|
||||
actTruthtranceRichesePromises as act,
|
||||
advanceTruthtranceRichesePromises as advance,
|
||||
askTruthtranceRichesePromises as ask,
|
||||
createTruthtranceRichesePromisesFixture as fixture,
|
||||
passTruthRicheseFreshDiscard,
|
||||
truthtranceRichesePromisesClean as clean,
|
||||
truthtranceRichesePromisesInventory as inventory,
|
||||
truthtranceRichesePromisesPlayer as player,
|
||||
} from './fixture-truthtrance-richese-promises';
|
||||
|
||||
/** Public Basic Richese/Atreides/Emperor start. The original unopened Karama,
|
||||
* second Truthtrance and cached Semuta are moved to named hands, conserving
|
||||
* the full physical inventory. No wallet, promise or auction is installed. */
|
||||
function source(earlyAnswer: 'yes' | 'no', joint: boolean, position: 'first' | 'last') {
|
||||
const f = fixture({advanced:false});
|
||||
let game = structuredClone(f.earlySource);
|
||||
const take = (effect: string) => {
|
||||
const index = game.deck.findIndex(card => card.effect === effect && card.id !== f.truth);
|
||||
assert.ok(index >= 0, `The original ${effect} remains in the deck`);
|
||||
return game.deck.splice(index,1)[0];
|
||||
};
|
||||
const selfKarama = take('karama'), otherKarama = take('karama');
|
||||
player(game,f.emperor).hand.push(selfKarama);
|
||||
player(game,f.asker).hand.push(otherKarama);
|
||||
const secondTruth = joint ? take('truthtrance') : null;
|
||||
if (secondTruth) player(game,f.asker).hand.push(secondTruth);
|
||||
const semutaIndex = game.richeseCache!.findIndex(card => card.id === SEMUTA_DRUG_ID);
|
||||
assert.ok(semutaIndex >= 0);
|
||||
const [semuta] = game.richeseCache!.splice(semutaIndex,1);
|
||||
player(game,f.richese).hand.push(semuta);
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
|
||||
game = ask(game,f,{kind:'earlyRicheseBid',target:f.emperor,turn:game.turn,minimum:4});
|
||||
assert.ok(viewGame(game,f.emperor).truthEarlyRicheseBidAnswers?.includes(earlyAnswer));
|
||||
game = passTruthRicheseFreshDiscard(act(game,f.emperor,{type:'truthAnswer',answer:earlyAnswer}));
|
||||
const early = game.earlyRicheseBidPromises?.find(row => row.player === f.emperor); assert.ok(early);
|
||||
if (secondTruth) {
|
||||
game = act(game,f.asker,{type:'card',card:secondTruth.id});
|
||||
game = advance(game,state => state.truthtrance?.stage === 'ask');
|
||||
game = act(game,f.asker,{type:'truthAsk',question:{
|
||||
kind:'phaseAnyBid',target:f.emperor,turn:game.turn,minimum:6,
|
||||
}});
|
||||
assert.ok(viewGame(game,f.emperor).truthPhaseAnyBidAnswers?.includes('yes'));
|
||||
game = passTruthRicheseFreshDiscard(act(game,f.emperor,{type:'truthAnswer',answer:'yes'}));
|
||||
}
|
||||
const phase = game.phaseAnyBidPromises?.find(row => row.player === f.emperor);
|
||||
game = advance(game,state => state.decision?.kind === 'richeseDeclaration');
|
||||
const ordinaryBefore = game.richeseBidding!.normalCount!;
|
||||
game = act(game,f.richese,{type:'decision',event:game.richeseBidding!.event,position});
|
||||
assert.equal(game.response?.kind,'richeseAuction');
|
||||
assert.ok(!game.richeseBidding?.cacheCanceled);
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
return {f,game,early,phase,selfKarama,otherKarama,ordinaryBefore};
|
||||
}
|
||||
|
||||
function settleDiscard(state: Game, owner: string, claim: boolean): Game {
|
||||
let game = state;
|
||||
const pending = game.pendingTreacheryDiscard;
|
||||
assert.ok(pending?.reaction?.stage === 'offer', 'The actual cancellation opens Semuta');
|
||||
const event = pending.batch.event;
|
||||
if (!claim) return passTruthRicheseFreshDiscard(game);
|
||||
assert.ok(viewGame(game,owner).semutaReaction?.canCommit);
|
||||
game = act(game,owner,{type:'semutaCommit',event});
|
||||
if (game.pendingTreacheryDiscard?.reaction?.stage === 'select') {
|
||||
const card = pending.batch.entries[0].card.id;
|
||||
game = act(game,owner,{type:'semutaSelect',event,card});
|
||||
}
|
||||
assert.notEqual(game.pendingTreacheryDiscard?.batch.event,event);
|
||||
return game;
|
||||
}
|
||||
|
||||
for (const position of ['first','last'] as const)
|
||||
for (const joint of [false,true]) void test(
|
||||
`Basic ${position} self-cancellation cannot evade an early cache Yes${joint ? ' with phase Yes' : ''}`, () => {
|
||||
const f = source('yes',joint,position), before = structuredClone(f.game);
|
||||
assert.ok(!viewGame(f.game,f.f.emperor).responseControls?.cancelCards.includes(f.selfKarama.id),
|
||||
'The private cancellation controls explain the unsupported voluntary action');
|
||||
assert.match(viewGame(f.game,f.f.emperor).responseControls?.blocked ?? '', /Truthtrance Yes/);
|
||||
assert.throws(() => act(f.game,f.f.emperor,{type:'card',card:f.selfKarama.id,mode:'cancel'}));
|
||||
assert.deepEqual(f.game,before, 'Rejected action does not spend Karama or alter the cache response');
|
||||
assert.ok(player(f.game,f.f.emperor).hand.some(card => card.id === f.selfKarama.id));
|
||||
assert.ok(f.game.earlyRicheseBidPromises?.some(row => row.id === f.early.id && !row.released && !row.boundEvent));
|
||||
if (f.phase) assert.ok(f.game.phaseAnyBidPromises?.some(row => row.event === f.phase!.event && !row.released));
|
||||
assert.deepEqual(inventory(f.game),f.f.originalCards);
|
||||
},
|
||||
);
|
||||
|
||||
for (const claim of [false,true]) void test(
|
||||
`Another player's cache cancellation releases the Yes; Semuta ${claim ? 'claims' : 'passes'}`, () => {
|
||||
const f = source('yes',true,'first');
|
||||
let game = act(f.game,f.f.asker,{type:'card',card:f.otherKarama.id,mode:'cancel'});
|
||||
game = settleDiscard(game,f.f.richese,claim);
|
||||
assert.equal(game.richeseBidding?.cacheCanceled,true);
|
||||
assert.equal(game.richeseBidding?.normalCount,f.ordinaryBefore+1);
|
||||
assert.ok(game.phaseAnyBidPromises?.some(row => row.event === f.phase!.event && !row.fulfilled && !row.released));
|
||||
assert.equal(player(game,f.f.richese).hand.some(card => card.id === f.otherKarama.id),claim);
|
||||
assert.equal(player(game,f.f.richese).hand.some(card => card.id === SEMUTA_DRUG_ID),!claim);
|
||||
game = advance(game,state => clean(state) && !!state.auction && state.auction.active === f.f.emperor);
|
||||
assert.ok(game.earlyRicheseBidPromises?.some(row => row.id === f.early.id && row.released && !row.boundEvent));
|
||||
const guide = viewGame(game,f.f.emperor).phaseAnyBidGuide?.action;
|
||||
assert.ok(guide); assert.equal(guide.type,'bid'); assert.equal(guide.amount,6);
|
||||
game = act(game,f.f.emperor,guide);
|
||||
assert.ok(game.phaseAnyBidPromises?.some(row => row.event === f.phase!.event && row.fulfilled));
|
||||
assert.deepEqual(inventory(game),f.f.originalCards);
|
||||
},
|
||||
);
|
||||
|
||||
void test('a player may cancel the cache after answering No to the early bid question', () => {
|
||||
const f = source('no',false,'first');
|
||||
let game = act(f.game,f.f.emperor,{type:'card',card:f.selfKarama.id,mode:'cancel'});
|
||||
game = settleDiscard(game,f.f.richese,false);
|
||||
assert.equal(game.richeseBidding?.cacheCanceled,true);
|
||||
assert.ok(game.earlyRicheseBidPromises?.some(row => row.id === f.early.id && row.fulfilled && !row.released));
|
||||
assert.deepEqual(inventory(game),f.f.originalCards);
|
||||
});
|
||||
|
||||
void test('self-cancellation is allowed after an external shortfall already made the Yes impossible', () => {
|
||||
const f = source('yes',false,'first');
|
||||
// Disclosed external-state supplement: this completed loss is staged while
|
||||
// the cache response is open, so the old Yes has not been reconciled yet.
|
||||
// No physical cards, bids, responses or promise receipts are fabricated.
|
||||
const game = structuredClone(f.game);
|
||||
player(game,f.f.emperor).spice = 0;
|
||||
assert.ok(game.earlyRicheseBidPromises?.some(row => row.id === f.early.id && !row.released));
|
||||
assert.ok(viewGame(game,f.f.emperor).responseControls?.cancelCards.includes(f.selfKarama.id));
|
||||
let resolved = act(game,f.f.emperor,{type:'card',card:f.selfKarama.id,mode:'cancel'});
|
||||
resolved = settleDiscard(resolved,f.f.richese,false);
|
||||
assert.equal(resolved.richeseBidding?.cacheCanceled,true);
|
||||
assert.ok(resolved.earlyRicheseBidPromises?.some(row => row.id === f.early.id && row.released));
|
||||
assert.deepEqual(inventory(resolved),f.f.originalCards);
|
||||
});
|
||||
Reference in new issue
Block a user