Files
Dune/tests/mixed-discovery-only-runtime.test.ts
T
Quintine c8dbd44975
Verify and publish checkpoint container / container (push) Failing after 11m29s
Enable mixed selected-deck Discovery previews
2026-10-29 20:14:11 +11:00

83 lines
5.0 KiB
TypeScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { viewGame } from '../game/engine';
import { botActions } from '../game/bots';
import { DIFFICULTIES } from '../game/bot-profiles';
import { reserveShipmentCost } from '../game/shipment-price';
import { act, advance, mixedDiscoveryOnlyFixture, player } from './fixture-mixed-discovery-only';
for (const advanced of [false, true]) void test(
`${advanced ? 'Advanced' : 'Basic'} selected E3, Ix and CHOAM Discovery opens its native paired entry`, () => {
const f = mixedDiscoveryOnlyFixture(advanced, 'guild');
assert.equal(f.lobby.discoveryEnabled, true);
assert.ok(f.setup.discoveries);
assert.equal(f.setup.discoveries!.tokens.length, 8);
assert.equal(f.setup.spiceDeck.filter(card => 'discovery' in card && card.discovery).length, 6);
assert.ok(!f.setup.nexusCards && !f.setup.ecazTreachery);
assert.ok(f.beforeMarkers.spiceDiscard.flat().some(card =>
'territory' in card && card.discovery === 'discovery-hagga-basin'));
assert.equal(f.beforeMarkers.discoveries!.tokens.filter(token => token.status === 'placed').length, 1);
assert.ok(player(f.game, 'ixians').hand.length > 0, 'The native Ixian setup dealt its original card');
assert.ok(f.game.mobileStronghold, 'The original Ixian mobile stronghold exists');
assert.ok(player(f.game, 'choam'), 'CHOAM remains a real native faction in this configuration');
const price = reserveShipmentCost({faction:'guild', halfRate:true}, 'stronghold', 1);
const originalSpice = player(f.game, 'guild').spice;
const moritaniSpice = player(f.game, 'moritani').spice;
const stolen = Math.ceil((originalSpice - price) / 2);
const duke = structuredClone(f.game.dukeVidal!.leader);
let game = act(f.game, 'guild', f.shipment);
game = advance(game, state => !!state.pendingArrivalOverlap);
assert.equal(player(game, 'guild').spice, originalSpice - price);
assert.equal(player(game, 'guild').forces[`${f.destination}:${f.sector}`], 1);
const first = game.pendingArrivalOverlap!.first;
const responder = first === 'ambassador' ? 'ecaz' : 'moritani';
for (const difficulty of DIFFICULTIES) {
const view = viewGame(game, responder);
view.players.find(row => row.id === responder)!.bot = difficulty;
const choice = botActions(view)[0]; assert.ok(choice, difficulty);
assert.doesNotThrow(() => act(game, responder, choice), difficulty);
}
if (first === 'ambassador') {
const entry = game.pendingAmbassador; assert.ok(entry);
assert.equal(entry.token, f.token);
game = act(game, 'ecaz', {type:'decision', event:entry.event, trigger:true, beneficiary:'ecaz', choice:'duke'});
assert.equal(game.pendingTerrorEntry?.token, f.terror);
game = act(game, 'moritani', {type:'decision', reveal:true});
game = act(game, 'moritani', {type:'decision', choice:'spice'});
} else {
assert.equal(game.pendingTerrorEntry?.token, f.terror);
game = act(game, 'moritani', {type:'decision', reveal:true});
game = act(game, 'moritani', {type:'decision', choice:'spice'});
const entry = game.pendingAmbassador; assert.ok(entry);
assert.equal(entry.token, f.token);
game = act(game, 'ecaz', {type:'decision', event:entry.event, trigger:true, beneficiary:'ecaz', choice:'duke'});
}
assert.equal(game.pendingArrivalOverlap ?? null, null);
assert.equal(game.pendingAmbassador ?? null, null);
assert.equal(game.pendingTerrorEntry ?? null, null);
assert.equal(player(game, 'guild').spice, originalSpice - price - stolen);
assert.equal(player(game, 'moritani').spice, moritaniSpice + stolen);
assert.equal(player(game, 'guild').forces[`${f.destination}:${f.sector}`], 1);
assert.equal(game.moritaniTerror!.tokens.find(row => row.id === f.terror)?.status, 'removed');
assert.equal(game.ecazAmbassadors!.tokens.find(row => row.id === f.token)?.zone, 'supply');
assert.deepEqual([game.dukeVidal?.controller, game.dukeVidal?.source], ['ecaz', 'ecaz']);
assert.deepEqual(game.dukeVidal?.leader, duke);
});
for (const advanced of [false, true]) void test(
`${advanced ? 'Advanced' : 'Basic'} mixed Discovery retains an actual Ixian shipment`, () => {
const f = mixedDiscoveryOnlyFixture(advanced, 'ixians');
const before = player(f.game, 'ixians');
const spice = before.spice, reserves = before.reserves;
const eliteReserves = before.elites?.reserves ?? 0;
let game = act(f.game, 'ixians', {type:'ship', territory:'polar_sink', sector:0, amount:1,
elite:eliteReserves > 0 ? 1 : 0});
game = advance(game, state => !state.response && !state.decision && !state.phaseOpening);
assert.equal(player(game, 'ixians').reserves, reserves - 1);
assert.equal(player(game, 'ixians').spice, spice - 2);
assert.equal(player(game, 'ixians').forces['polar_sink:0'], 1);
if (eliteReserves > 0) assert.equal(player(game, 'ixians').elites!.reserves, eliteReserves - 1);
assert.ok(game.discoveries && game.mobileStronghold);
assert.ok(!game.nexusCards && !game.ecazTreachery);
});