107 lines
6.1 KiB
TypeScript
107 lines
6.1 KiB
TypeScript
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 { DISCOVERY_CARD_PLACEMENTS, validateDiscoveryState } from '../game/discoveries';
|
|
import { discoveryStormActions } from '../game/discovery-storm-options';
|
|
import { validateLeaderSkills } from '../game/leader-skills';
|
|
import { SEMUTA_DRUG_ID } from '../game/semuta-drug';
|
|
import { selectedDiscoverySkillsStart } from './selected-discovery-skills-fixture';
|
|
import { advanceTestingStationContest } from './fixture-testing-station-contest';
|
|
import { moveSemutaEmperorCard } from './fixture-semuta-emperor-share';
|
|
import { reactSemutaSpecial } from './fixture-semuta-special-karama';
|
|
|
|
const SAPHO = 'richese-juice-of-sapho';
|
|
const STATION = 'ecological-testing-station';
|
|
const cards = (game: Game) => [...game.deck, ...game.discard, ...(game.richeseCache ?? []),
|
|
...(game.richeseRemoved ?? []), ...game.players.flatMap(player => player.hand)].map(card => card.id).sort();
|
|
function player(game: Game, id: string) {
|
|
const seat = game.players.find(candidate => candidate.id === id);
|
|
assert.ok(seat); return seat;
|
|
}
|
|
|
|
/** Public lobby, original native setup and all14 training. The rare revealed
|
|
* Station, physical occupants and the two singleton cards are staged by
|
|
* conserved transfers; the ordinary first Storm opens the real priority. */
|
|
function fixture(advanced: boolean, mixed: boolean) {
|
|
const started = selectedDiscoverySkillsStart({advanced,
|
|
factions: mixed ? ['richese', 'ixians', 'atreides', 'emperor'] : ['richese', 'atreides', 'emperor'],
|
|
expansions: mixed ? ['choam', 'ix', 'ecaz'] : ['choam']});
|
|
let game = started.game;
|
|
assert.equal(game.semutaPreview, true, 'The public Discovery/Skills start must enable the connected Semuta reaction');
|
|
assert.equal(game.leaderSkills!.assignments.length, game.players.length);
|
|
validateLeaderSkills(game.leaderSkills!, game.players);
|
|
assert.ok(!game.nexusCards && !game.ecazTreachery);
|
|
const inventory = cards(game);
|
|
for (const seat of game.players) game.deck.push(...seat.hand.splice(0));
|
|
const token = game.discoveries!.tokens.find(candidate => candidate.face === STATION);
|
|
assert.ok(token && token.status === 'supply');
|
|
const position = Object.values(DISCOVERY_CARD_PLACEMENTS).find(candidate => candidate.type === token.type);
|
|
assert.ok(position);
|
|
Object.assign(token, {status:'placed', territory:position.territory, sector:position.sector, revealedTurn:game.turn});
|
|
validateDiscoveryState(game.discoveries!);
|
|
for (const id of ['atreides', 'emperor']) {
|
|
const seat = player(game, id); assert.ok(seat.reserves > 0);
|
|
seat.reserves--; seat.forces[`${STATION}:0`] = (seat.forces[`${STATION}:0`] ?? 0) + 1;
|
|
}
|
|
moveSemutaEmperorCard(game, SEMUTA_DRUG_ID, 'richese');
|
|
game = advanceTestingStationContest(game, state => !!state.saphoStationPriority &&
|
|
state.decision?.kind === 'ecologicalStorm');
|
|
const order = game.ecologicalStorm!.queue!.order;
|
|
assert.equal(order.length, 2);
|
|
const holder = order[1];
|
|
moveSemutaEmperorCard(game, SAPHO, holder);
|
|
assert.deepEqual(cards(game), inventory);
|
|
return {game, holder, first:order[0], order:[...order], inventory};
|
|
}
|
|
|
|
for (const advanced of [false, true]) for (const mixed of [false, true])
|
|
for (const claim of [false, true]) void test(
|
|
`${advanced ? 'Advanced' : 'Basic'} ${mixed ? 'mixed' : 'CHOAM'} Discovery/Skills restores Station after Semuta ${claim ? 'claim' : 'pass'}`, () => {
|
|
const f = fixture(advanced, mixed);
|
|
let game = f.game;
|
|
const priority = game.saphoStationPriority!;
|
|
game = applyAction(game, f.first, {type:'saphoStationPass', event:priority.event});
|
|
const option = viewGame(game, f.holder).saphoOptions.find(row => row.scope === 'testingStation' && row.mode === 'first');
|
|
assert.ok(option);
|
|
game = applyAction(game, f.holder, {type:'card', card:SAPHO, scope:option.scope, event:option.event, mode:option.mode});
|
|
assert.ok(!game.saphoStationPriority);
|
|
assert.equal(game.pendingTreacheryDiscard?.batch.cause, 'sapho:station');
|
|
assert.equal(game.pendingTreacheryDiscard?.continuation.kind, 'saphoStationDiscard');
|
|
assert.deepEqual(game.ecologicalStorm?.queue?.order, [...f.order].reverse());
|
|
assert.equal(game.ecologicalStorm?.queue?.choices.length, 0);
|
|
for (const difficulty of DIFFICULTIES) {
|
|
const view = viewGame(game, 'richese');
|
|
view.players.find(seat => seat.id === 'richese')!.bot = difficulty;
|
|
const action = botActions(view).find(row => row.type === 'semutaCommit' || row.type === 'semutaPass');
|
|
assert.ok(action, difficulty);
|
|
assert.doesNotThrow(() => applyAction(game, 'richese', action));
|
|
}
|
|
game = reactSemutaSpecial(game, 'richese', claim);
|
|
assert.equal(game.pendingTreacheryDiscard, null);
|
|
assert.equal(game.decision?.kind, 'ecologicalStorm');
|
|
assert.equal(game.decision?.player, f.holder);
|
|
assert.equal(player(game, 'richese').hand.some(card => card.id === SAPHO), claim);
|
|
assert.equal(player(game, 'richese').hand.some(card => card.id === SEMUTA_DRUG_ID), !claim);
|
|
for (let i = 0; i < 2; i++) {
|
|
const owner = game.ecologicalStorm!.owner;
|
|
const action = discoveryStormActions(viewGame(game, owner)).find(choice => choice.delta === 0);
|
|
assert.ok(action);
|
|
game = applyAction(game, owner, action);
|
|
}
|
|
assert.equal(game.ecologicalStorm?.stage, 'complete');
|
|
assert.equal(game.ecologicalStorm.queue?.choices.length, 2);
|
|
if (mixed) {
|
|
// A real first Storm with Ixians must place the HMS before Spice Blow.
|
|
const decision = game.decision;
|
|
assert.ok(decision?.kind === 'mobileStronghold' && decision.placement);
|
|
game = applyAction(game, decision.player, {type:'decision', location:'polar_sink:0'});
|
|
assert.equal(game.mobileStronghold?.location, 'polar_sink:0');
|
|
}
|
|
assert.equal(game.phase, 1);
|
|
assert.deepEqual(cards(game), f.inventory);
|
|
validateLeaderSkills(game.leaderSkills!, game.players);
|
|
validateDiscoveryState(game.discoveries!);
|
|
});
|