70 lines
4.0 KiB
TypeScript
70 lines
4.0 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
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 { RECRUITS_CARD_ID } from '../game/recruits';
|
|
import { SEMUTA_DRUG_ID } from '../game/semuta-drug';
|
|
import { takeKullCard } from './fixture-choam-kull';
|
|
import { advanceSemutaNexusTrade } from './fixture-semuta-nexus-trade';
|
|
import { basicSemutaAmbassadorClean as clean, basicSemutaAmbassadorInventory as inventory,
|
|
basicSemutaAmbassadorPlayer as seat } from './fixture-basic-semuta-ambassador';
|
|
|
|
const act = (game: Game, actor: string, action: Action) => applyAction(game, actor, action);
|
|
|
|
/** A real public selected-module start and native play up to Revival. Only
|
|
* original hand positions are staged at that point; no cards are created. */
|
|
function fixture() {
|
|
let game = createGame('RECRUITSNEXKULL', 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 ['ecazTreachery', 'nexusCards', 'kullPreview'] as const)
|
|
game = act(game, 'c', { type: 'moduleOption', module: moduleName, enabled: true });
|
|
for (const player of game.players) game = act(game, player.id, { type: 'ready' });
|
|
game = act(game, 'c', { type: 'start' });
|
|
assert.equal(game.ecazTreachery, true);
|
|
assert.equal(game.kullPreview, true);
|
|
assert.equal(game.nexusKullPreview, true);
|
|
assert.equal(game.semutaPreview, true);
|
|
game = advanceSemutaNexusTrade(game, state => state.status === 'playing');
|
|
game = advanceSemutaNexusTrade(game, state => state.phase === 4 && clean(state));
|
|
const original = inventory(game);
|
|
for (const id of ['a', 'r']) game.deck.push(...seat(game, id).hand.splice(0));
|
|
seat(game, 'a').hand.push(takeKullCard(game, RECRUITS_CARD_ID));
|
|
seat(game, 'r').hand.push(takeKullCard(game, SEMUTA_DRUG_ID));
|
|
assert.deepEqual(inventory(game), original);
|
|
return { game, original };
|
|
}
|
|
|
|
for (const claim of [false, true]) {
|
|
void test(`Basic independent Nexus Kull Recruits offers Semuta ${claim ? 'claim' : 'pass'} and retains Revival`, () => {
|
|
const { game, original } = fixture();
|
|
assert.ok(viewGame(game, 'a').recruitsPreview?.play && !viewGame(game, 'a').recruitsPreview!.play!.blocked);
|
|
let pending = act(game, 'a', { type: 'card', card: RECRUITS_CARD_ID });
|
|
const frame = pending.pendingTreacheryDiscard; assert.ok(frame);
|
|
assert.equal(frame.continuation.kind, 'ordinaryCardDiscard');
|
|
assert.equal(frame.reaction?.stage, 'offer');
|
|
assert.deepEqual(frame.batch.entries.map(entry => entry.card.id), [RECRUITS_CARD_ID]);
|
|
assert.equal(pending.recruits?.turn, pending.turn);
|
|
for (const difficulty of DIFFICULTIES) {
|
|
const view = viewGame(pending, 'r'); view.players.find(player => player.id === 'r')!.bot = difficulty;
|
|
assert.ok(botActions(view).some(action => action.type === 'semutaCommit' || action.type === 'semutaPass'));
|
|
}
|
|
const event = frame.batch.event;
|
|
if (claim) {
|
|
pending = act(pending, 'r', { type: 'semutaCommit', event });
|
|
if (pending.pendingTreacheryDiscard?.reaction?.stage === 'select')
|
|
pending = act(pending, 'r', { type: 'semutaSelect', event, card: RECRUITS_CARD_ID });
|
|
} else {
|
|
for (const player of game.players) pending = act(pending, player.id, { type: 'semutaPass', event });
|
|
}
|
|
assert.equal(pending.pendingTreacheryDiscard, null);
|
|
assert.equal(viewGame(pending, 'a').revival.freeRemaining, 4);
|
|
assert.equal(viewGame(pending, 'a').revival.limit, 7);
|
|
assert.equal(seat(pending, 'r').hand.some(card => card.id === RECRUITS_CARD_ID), claim);
|
|
assert.equal(pending.discard.some(card => card.id === RECRUITS_CARD_ID), !claim);
|
|
assert.equal(pending.discard.some(card => card.id === SEMUTA_DRUG_ID), claim);
|
|
assert.deepEqual(inventory(pending), original);
|
|
});
|
|
}
|