60 lines
3.5 KiB
TypeScript
60 lines
3.5 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import { createGame, joinGame, newPlayer, type Game } from '../game/engine';
|
|
import { actTruthMovementNativeEarly as act } from './fixture-truth-movement-native-early';
|
|
import { nextStrongholdFactionsNativeStep as next } from './fixture-stronghold-factions';
|
|
import { truthTurnAmalInventory as inventory } from './fixture-truth-turn-amal';
|
|
|
|
const seat = (game: Game, id: string) => {
|
|
const player = game.players.find(row => row.id === id); assert.ok(player); return player;
|
|
};
|
|
|
|
/** Public Advanced Ix setup reaches its native opening. Only the reciprocal
|
|
* alliance and conserved original card custody are staged; the gift, BG
|
|
* conversion, passes, cancellation and opening continuation use real actions. */
|
|
void test('Advanced BG conversion cancels an opening gift and restores the original passes', () => {
|
|
let game = createGame('ADVOPENBG',newPlayer('emperor','Emperor','emperor'),true,['ix']);
|
|
joinGame(game,newPlayer('atreides','Atreides','atreides'));
|
|
joinGame(game,newPlayer('beneGesserit','Bene Gesserit','beneGesserit'));
|
|
for (const player of game.players) game = act(game,player.id,{type:'ready'});
|
|
game = act(game,'emperor',{type:'start',advancedPreview:true});
|
|
for (let count = 0; game.status === 'setup' && count < 100; count++) {
|
|
const step = next(game); assert.ok(step); game = act(game,step.actor,step.action);
|
|
}
|
|
assert.equal(game.status,'playing'); assert.ok(game.phaseOpening);
|
|
const original = inventory(game), emperor = seat(game,'emperor'), ally = seat(game,'atreides'), bg = seat(game,'beneGesserit');
|
|
emperor.ally = ally.id; ally.ally = emperor.id;
|
|
// Use real unique cards. Return a displaced card to the deck if needed.
|
|
const obtain = (owner: typeof bg, match: (card: typeof bg.hand[number]) => boolean) => {
|
|
const held = owner.hand.find(match); if (held) return held;
|
|
const index = game.deck.findIndex(match); assert.ok(index >= 0);
|
|
const [card] = game.deck.splice(index,1);
|
|
if (owner.hand.length >= 4) game.deck.push(owner.hand.pop()!);
|
|
owner.hand.push(card); return card;
|
|
};
|
|
const worthless = obtain(bg,card => card.kind === 'worthless');
|
|
obtain(ally,card => card.effect === 'karama');
|
|
assert.deepEqual(inventory(game),original);
|
|
game = act(game,'emperor',{type:'ready'});
|
|
game = act(game,'atreides',{type:'ready'});
|
|
const opening = structuredClone(game.phaseOpening), emperorSpice = seat(game,'emperor').spice,
|
|
allySpice = seat(game,'atreides').spice;
|
|
let pending = act(game,'emperor',{type:'emperorGift',amount:2});
|
|
assert.equal(pending.response?.kind,'emperorGift');
|
|
pending = act(pending,'beneGesserit',{type:'card',card:worthless.id,mode:'cancel'});
|
|
assert.equal(pending.response?.kind,'worthlessKarama');
|
|
for (let count = 0; pending.response && count < 16; count++) {
|
|
const player = pending.players.find(row => !pending.response!.passed.includes(row.id)); assert.ok(player);
|
|
pending = act(pending,player.id,{type:'passResponse'});
|
|
}
|
|
assert.equal(pending.response,null);
|
|
assert.deepEqual(pending.phaseOpening,opening);
|
|
assert.equal(seat(pending,'emperor').spice,emperorSpice);
|
|
assert.equal(seat(pending,'atreides').spice,allySpice);
|
|
assert.equal(pending.discard.filter(card => card.id === worthless.id).length,1);
|
|
assert.ok(!seat(pending,'beneGesserit').hand.some(card => card.id === worthless.id));
|
|
assert.deepEqual(inventory(pending),original);
|
|
pending = act(pending,'beneGesserit',{type:'ready'});
|
|
assert.equal(pending.phaseOpening,null);
|
|
});
|