Files
Dune/tests/kull-richese-alliance-worm-ride.test.ts
T
Quintine d6ddb7cb5c
Verify and publish checkpoint container / container (push) Successful in 10m15s
Support alliance answers with Richese Semuta
2026-10-29 01:17:58 +11:00

83 lines
5.0 KiB
TypeScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { territory } from '../game/board';
import { createGame, joinGame, newPlayer, viewGame, type Game } from '../game/engine';
import { SEMUTA_DRUG_ID } from '../game/semuta-drug';
import { act, advance, clean, inventory, player } from './fixture-kull-richese-semuta';
import { beforeIxSpiceDraw, orderIxSpiceCards } from './fixture-ix-spice-cards';
/** Public Basic setup, original cache purchase and a real Worm/Nexus. Only
* unopened card positions and one physical Fremen reserve are selected: the
* latter is placed at the previous blow so the real Worm creates a ride. */
function source() {
let game = createGame('ALLIANCERIDE', newPlayer('choam','CHOAM','choam'), false, ['choam','ix']);
for (const faction of ['richese','fremen','emperor','guild'] as const)
joinGame(game, newPlayer(faction,faction,faction));
game = act(game,'choam',{type:'moduleOption',module:'kullPreview',enabled:true});
for (const seat of game.players) game = act(game,seat.id,{type:'ready'});
game = act(game,'choam',{type:'start'});
assert.equal(game.status,'setup'); assert.ok(game.kullPreview && game.semutaPreview);
const originalCards = inventory(game), selected: Game['deck'] = [];
for (const kind of ['kull','filler','filler','filler','truth'] as const) {
const index = game.deck.findIndex(card => kind === 'kull' ? card.id === 'ix-kull-wahad' :
kind === 'truth' ? card.effect === 'truthtrance' : card.kind === 'worthless' && card.id !== 'ix-kull-wahad');
assert.ok(index >= 0); selected.push(game.deck.splice(index,1)[0]);
}
game.deck.unshift(...selected);
game = advance(game,state => state.status === 'playing');
const truth = selected.at(-1)!.id;
assert.ok(player(game,'guild').hand.some(card => card.id === truth));
const land = game.spiceDeck.findIndex(card => 'territory' in card && !card.discovery &&
territory(card.territory).type === 'sand');
assert.ok(land >= 0); game.spiceDeck.unshift(game.spiceDeck.splice(land,1)[0]);
game = advance(game,state => player(state,'richese').hand.some(card => card.id === SEMUTA_DRUG_ID));
game = advance(game,state => state.turn === 2 && beforeIxSpiceDraw(state));
const previous = game.spiceDiscard[0].findLast(card => 'territory' in card);
assert.ok(previous && 'territory' in previous);
const sector = territory(previous.territory).sectors.find(value => value !== game.storm);
assert.notEqual(sector,undefined);
const fremen = player(game,'fremen'); assert.ok(fremen.reserves >= 1);
fremen.reserves--;
const key = `${previous.territory}:${sector}`;
fremen.forces[key] = (fremen.forces[key] ?? 0) + 1;
orderIxSpiceCards(game,['worm','land']);
game = advance(game,state => state.nexus && clean(state) && !state.spiceWindow && !state.spiceResolution);
assert.deepEqual(game.wormRides,[previous.territory]);
assert.deepEqual(inventory(game),originalCards);
return {game,truth,originalCards,ride:previous.territory};
}
for (const claim of [false,true]) void test(`Semuta ${claim ? 'claims' : 'passes'} alliance Truth while the Fremen ride waits`, () => {
const f = source(); let game = act(f.game,'guild',{type:'card',card:f.truth});
while (game.truthtrance?.stage === 'priority') {
const next = game.players.find(seat => !game.truthtrance!.passed.includes(seat.id)); assert.ok(next);
game = act(game,next.id,{type:'truthPass'});
}
game = act(game,'guild',{type:'truthAsk',question:{kind:'alliance',target:'emperor',turn:game.turn,partner:'choam'}});
assert.ok(viewGame(game,'emperor').truthAllianceAnswers?.includes('no'));
game = act(game,'emperor',{type:'truthAnswer',answer:'no'});
const pending = game.pendingTreacheryDiscard; assert.ok(pending);
assert.equal(pending.reaction?.stage,'offer');
assert.deepEqual(game.wormRides,[f.ride]);
const event = pending.batch.event;
if (claim) {
game = act(game,'richese',{type:'semutaCommit',event});
if (game.pendingTreacheryDiscard?.reaction?.stage === 'select')
game = act(game,'richese',{type:'semutaSelect',event,card:f.truth});
} else for (let count=0;game.pendingTreacheryDiscard?.batch.event === event && count < game.players.length;count++) {
const reaction = game.pendingTreacheryDiscard!.reaction; assert.ok(reaction?.stage === 'offer');
const next = game.players.find(seat => !reaction.passed.includes(seat.id)); assert.ok(next);
game = act(game,next.id,{type:'semutaPass',event});
}
assert.notEqual(game.pendingTreacheryDiscard?.batch.event,event);
assert.deepEqual(game.wormRides,[f.ride]);
assert.ok(game.alliancePromises?.some(row => row.player === 'emperor' && !row.released));
for (const seat of game.players) if (!game.ready.includes(seat.id)) game = act(game,seat.id,{type:'ready'});
assert.equal(game.decision?.kind,'wormRide');
assert.equal(game.decision?.player,'fremen');
game = act(game,'fremen',{type:'decision',accept:false});
assert.equal(game.nexus,false);
assert.ok(game.alliancePromises?.some(row => row.player === 'emperor' && row.fulfilled));
assert.deepEqual(inventory(game),f.originalCards);
});