154 lines
9.2 KiB
TypeScript
154 lines
9.2 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import { applyAction, createGame, handLimit, joinGame, newPlayer, viewGame, type Game } from '../game/engine';
|
|
import { botActions } from '../game/bots';
|
|
import { DIFFICULTIES } from '../game/bot-profiles';
|
|
import { SEMUTA_DRUG_ID } from '../game/semuta-drug';
|
|
import { advanceSemutaNexusTrade } from './fixture-semuta-nexus-trade';
|
|
|
|
const BOX = 'richese-nullentropy-box';
|
|
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.phaseOpening && !game.decision &&
|
|
!game.pendingTreacheryDiscard && !game.pendingNullentropy && !game.truthtrance;
|
|
function inventory(game: Game) {
|
|
const ids = [...game.deck, ...game.discard, ...(game.richeseCache ?? []), ...(game.richeseRemoved ?? []),
|
|
...(game.auction?.cards.slice(game.auction.index + Number(game.currentAuctionSale?.origin === 'normal')) ?? []),
|
|
...(game.ixAuction?.cards ?? []), ...game.players.flatMap(player => player.hand)].map(card => card.id).sort();
|
|
assert.equal(new Set(ids).size, ids.length); return ids;
|
|
}
|
|
function hold(game: Game, owner: string, id: string) {
|
|
const player = seat(game, owner);
|
|
if (player.hand.some(card => card.id === id)) return;
|
|
assert.ok(player.hand.length < handLimit(player));
|
|
const zones = [game.deck, game.discard, game.richeseCache ?? [], game.richeseRemoved ?? [],
|
|
...game.players.filter(row => row.id !== owner).map(row => row.hand)];
|
|
const zone = zones.find(cards => cards.some(card => card.id === id));
|
|
assert.ok(zone, `The original ${id} must be available for conserved staging`);
|
|
player.hand.push(zone.splice(zone.findIndex(card => card.id === id), 1)[0]);
|
|
}
|
|
|
|
/** Real selected-module start and native first Richese cache lot. Only the two
|
|
* physical held specials and two search candidates are relocated after setup. */
|
|
function fixture(nexus: boolean) {
|
|
let game = createGame('BOXKULLSKILLS', newPlayer('c', 'CHOAM', 'choam'), false, ['ix', 'choam']);
|
|
for (const [id, faction] of [['r', 'richese'], ['a', 'atreides'], ['g', 'guild']] as const)
|
|
joinGame(game, newPlayer(id, faction, faction));
|
|
for (const moduleName of [...(nexus ? ['nexusCards'] : []), 'leaderSkills', 'kullPreview'])
|
|
game = applyAction(game, 'c', { type: 'moduleOption', module: moduleName, enabled: true });
|
|
for (const player of game.players) game = applyAction(game, player.id, { type: 'ready' });
|
|
game = applyAction(game, 'c', { type: 'start' });
|
|
assert.ok(game.leaderSkills && game.kullPreview && game.semutaPreview);
|
|
assert.equal(!!game.nexusCards, nexus);
|
|
game = advanceSemutaNexusTrade(game, state => state.status === 'playing');
|
|
assert.equal(game.leaderSkills!.assignments.length, game.players.length);
|
|
game = advanceSemutaNexusTrade(game, state => clean(state) && !!state.richeseAuction && !state.richeseAuction.outcome);
|
|
assert.equal(game.richeseAuction!.source, 'cache');
|
|
assert.equal(game.richeseAuction!.method, 'onceAround');
|
|
assert.notEqual(game.richeseAuction!.cardId, BOX);
|
|
hold(game, 'a', BOX);
|
|
hold(game, 'r', SEMUTA_DRUG_ID);
|
|
const candidates = game.deck.splice(0, 2);
|
|
assert.equal(candidates.length, 2);
|
|
game.discard.push(...candidates);
|
|
assert.ok(seat(game, 'a').spice >= 2);
|
|
const lot = game.richeseAuction!, actor = lot.active;
|
|
assert.ok(actor);
|
|
game = applyAction(game, actor, { type: 'richeseBid', event: lot.event, amount: 1, allyPayment: 0 });
|
|
assert.ok(clean(game) && game.richeseAuction && !game.richeseAuction.outcome);
|
|
return { game, target: candidates[0].id, cards: inventory(game), lot: structuredClone(game.richeseAuction),
|
|
funding: structuredClone(game.richeseFunding), spice: seat(game, 'a').spice };
|
|
}
|
|
|
|
/** The real cache sale continues into the first native bank lot. The same
|
|
* already-conserved Box, Semuta and discard candidates remain in their zones. */
|
|
function bankFixture(nexus: boolean) {
|
|
const source = fixture(nexus);
|
|
let game = advanceSemutaNexusTrade(source.game, state => clean(state) && !!state.auction &&
|
|
!state.richeseAuction && !state.currentAuctionSale);
|
|
const actor = game.auction!.active;
|
|
assert.ok(actor);
|
|
game = applyAction(game, actor, { type: 'bid', amount: 1, allyPayment: 0 });
|
|
assert.ok(clean(game) && game.auction && !game.currentAuctionSale);
|
|
assert.ok(seat(game, 'a').spice >= 2);
|
|
return { game, target: source.target, cards: inventory(game), lot: structuredClone(game.auction),
|
|
aid: structuredClone(game.aid), spice: seat(game, 'a').spice };
|
|
}
|
|
|
|
function assertBotResponses(game: Game) {
|
|
for (const difficulty of DIFFICULTIES) {
|
|
const view = viewGame(game, 'r');
|
|
view.players.find(player => player.id === 'r')!.bot = difficulty;
|
|
const action = botActions(view).find(candidate =>
|
|
candidate.type === 'semutaCommit' || candidate.type === 'semutaPass');
|
|
assert.ok(action, `Semuta must have a legal ${difficulty} response`);
|
|
assert.doesNotThrow(() => applyAction(game, 'r', action));
|
|
}
|
|
}
|
|
|
|
for (const nexus of [false, true]) for (const claim of [false, true]) {
|
|
void test(`Basic Kull/Skills${nexus ? '/Nexus' : ''}: Semuta ${claim ? 'claims' : 'passes'} Box during a Richese lot`, () => {
|
|
const f = fixture(nexus), skills = structuredClone(f.game.leaderSkills);
|
|
let game = applyAction(f.game, 'a', { type: 'card', card: BOX });
|
|
assert.equal(seat(game, 'a').spice, f.spice - 2);
|
|
assert.ok(game.pendingNullentropy);
|
|
game = applyAction(game, 'a', { type: 'decision', event: game.pendingNullentropy.event, card: f.target });
|
|
assert.equal(game.pendingTreacheryDiscard?.continuation.kind, 'nullentropyDiscard');
|
|
assert.equal(game.pendingTreacheryDiscard?.reaction?.stage, 'offer');
|
|
assert.deepEqual(game.richeseAuction, f.lot); assert.deepEqual(game.richeseFunding, f.funding);
|
|
assert.equal(viewGame(game, 'r').semutaReaction?.canCommit, true);
|
|
assert.deepEqual(viewGame(game, 'r').semutaReaction?.candidates, []);
|
|
if (claim) assertBotResponses(game);
|
|
assert.equal(seat(game, 'a').hand.filter(card => card.id === f.target).length, 1);
|
|
assert.deepEqual(inventory(game), f.cards);
|
|
const event = game.pendingTreacheryDiscard!.batch.event;
|
|
if (claim) game = applyAction(game, 'r', { type: 'semutaCommit', event });
|
|
else for (const player of game.players) game = applyAction(game, player.id, { type: 'semutaPass', event });
|
|
assert.equal(game.pendingTreacheryDiscard, null);
|
|
assert.equal(seat(game, 'r').hand.some(card => card.id === BOX), claim);
|
|
assert.equal(game.discard.some(card => card.id === BOX), !claim);
|
|
assert.equal(seat(game, 'a').spice, f.spice - 2);
|
|
assert.deepEqual(game.richeseAuction, f.lot); assert.deepEqual(game.richeseFunding, f.funding);
|
|
assert.deepEqual(game.leaderSkills, skills); assert.deepEqual(inventory(game), f.cards);
|
|
const oldEvent = game.richeseAuction!.event;
|
|
game = advanceSemutaNexusTrade(game, state => !state.richeseAuction ||
|
|
state.richeseAuction.event !== oldEvent || !!state.richeseAuction.outcome);
|
|
assert.equal(seat(game, 'a').hand.some(card => card.id === f.target), true);
|
|
assert.deepEqual(inventory(game), f.cards);
|
|
});
|
|
}
|
|
|
|
for (const nexus of [false, true]) for (const claim of [false, true]) {
|
|
void test(`Basic Kull/Skills${nexus ? '/Nexus' : ''}: Semuta ${claim ? 'claims' : 'passes'} Box during a bank lot`, () => {
|
|
const f = bankFixture(nexus), skills = structuredClone(f.game.leaderSkills);
|
|
let game = applyAction(f.game, 'a', { type: 'card', card: BOX });
|
|
assert.equal(seat(game, 'a').spice, f.spice - 2);
|
|
assert.ok(game.pendingNullentropy);
|
|
game = applyAction(game, 'a', { type: 'decision', event: game.pendingNullentropy.event, card: f.target });
|
|
assert.equal(game.pendingTreacheryDiscard?.continuation.kind, 'nullentropyDiscard');
|
|
assert.equal(game.pendingTreacheryDiscard?.reaction?.stage, 'offer');
|
|
assert.deepEqual(game.auction, f.lot); assert.deepEqual(game.aid, f.aid);
|
|
assert.equal(viewGame(game, 'r').semutaReaction?.canCommit, true);
|
|
assert.deepEqual(viewGame(game, 'r').semutaReaction?.candidates, []);
|
|
if (claim) assertBotResponses(game);
|
|
assert.equal(seat(game, 'a').hand.filter(card => card.id === f.target).length, 1);
|
|
assert.deepEqual(inventory(game), f.cards);
|
|
const event = game.pendingTreacheryDiscard!.batch.event;
|
|
if (claim) game = applyAction(game, 'r', { type: 'semutaCommit', event });
|
|
else for (const player of game.players) game = applyAction(game, player.id, { type: 'semutaPass', event });
|
|
assert.equal(game.pendingTreacheryDiscard, null);
|
|
assert.equal(seat(game, 'r').hand.some(card => card.id === BOX), claim);
|
|
assert.equal(game.discard.some(card => card.id === BOX), !claim);
|
|
assert.equal(seat(game, 'a').spice, f.spice - 2);
|
|
assert.deepEqual(game.auction, f.lot); assert.deepEqual(game.aid, f.aid);
|
|
assert.deepEqual(game.leaderSkills, skills); assert.deepEqual(inventory(game), f.cards);
|
|
const active = game.auction!.active;
|
|
const continued = applyAction(game, active, { type: 'passBid' });
|
|
assert.notDeepEqual(continued.auction, f.lot, 'The native bank lot continues after Semuta.');
|
|
assert.equal(seat(continued, 'a').hand.some(card => card.id === f.target), true);
|
|
assert.deepEqual(inventory(continued), f.cards);
|
|
});
|
|
}
|