Allow recovered Sapho at Testing Station
Verify and publish checkpoint container / container (push) Successful in 11m20s
Verify and publish checkpoint container / container (push) Successful in 11m20s
This commit is contained in:
1 parent
1ff520a9fc
commit
05f7fc8f20
12 files changed
+371
-33
No files matched your search
@@ -36,7 +36,9 @@ for (const mode of ['first', 'last'] as const) void test(
|
||||
assert.equal(frame.owner, frame.queue!.order[0]);
|
||||
assert.deepEqual(frame.sapho, {event: original.event, nextEvent: 'sapho-fresh-event',
|
||||
originalOrder: original.queue!.order, holder, mode});
|
||||
assert.deepEqual(discoveryStormSaphoModes(game, frame, holder), []);
|
||||
// The helper quotes the current order; the engine separately requires
|
||||
// that a later player physically reacquire the spent Sapho card.
|
||||
assert.deepEqual(discoveryStormSaphoModes(game, frame, holder), [mode === 'first' ? 'last' : 'first']);
|
||||
assert.throws(() => chooseDiscoveryStorm(game, frame, frame.owner, original.event, 0));
|
||||
let next = chooseDiscoveryStorm(game, frame, frame.owner, frame.event, 0);
|
||||
assert.equal(next.event, 'sapho-fresh-event:1');
|
||||
@@ -64,7 +66,7 @@ void test('stale, ineffective, replayed and tampered station reorder requests fa
|
||||
const reordered = reorderDiscoveryStorm(game, frame,
|
||||
{holder: first, event: frame.event, mode: 'last', nextEvent: 'fresh'});
|
||||
assert.throws(() => reorderDiscoveryStorm(game, reordered,
|
||||
{holder: second, event: 'fresh', mode: 'last', nextEvent: 'again'}));
|
||||
{holder: second, event: 'fresh', mode: 'first', nextEvent: 'again'}));
|
||||
const changed = structuredClone(reordered);
|
||||
changed.sapho!.originalOrder.reverse();
|
||||
changed.signature = discoveryStormSignature(changed);
|
||||
@@ -72,3 +74,54 @@ void test('stale, ineffective, replayed and tampered station reorder requests fa
|
||||
const afterFirst = chooseDiscoveryStorm(game, frame, first, frame.event, 0);
|
||||
assert.deepEqual(discoveryStormSaphoModes(game, afterFirst, second), []);
|
||||
});
|
||||
|
||||
void test('recovered Sapho reorders keep a linked event and order history without replaying choices', () => {
|
||||
const game = source(), original = structuredClone(game.ecologicalStorm!);
|
||||
const [first, second] = original.queue!.order;
|
||||
const one = reorderDiscoveryStorm(game, original,
|
||||
{holder:first, event:original.event, mode:'last', nextEvent:'first-reorder'});
|
||||
const oneBefore = structuredClone(one);
|
||||
const two = reorderDiscoveryStorm(game, one,
|
||||
{holder:second, event:one.event, mode:'last', nextEvent:'second-reorder'});
|
||||
assert.deepEqual(one, oneBefore);
|
||||
assert.deepEqual(two.queue!.order, original.queue!.order);
|
||||
assert.deepEqual(two.saphoHistory, [one.sapho]);
|
||||
assert.deepEqual(two.sapho, {event:'first-reorder', nextEvent:'second-reorder',
|
||||
originalOrder:one.queue!.order, holder:second, mode:'last'});
|
||||
assert.equal(two.owner, first);
|
||||
assert.equal(two.queue!.choices.length, 0);
|
||||
validateDiscoveryStorm(game, two);
|
||||
|
||||
const three = reorderDiscoveryStorm(game, two,
|
||||
{holder:first, event:two.event, mode:'last', nextEvent:'third-reorder'});
|
||||
assert.deepEqual(three.saphoHistory, [one.sapho, two.sapho]);
|
||||
assert.deepEqual(three.queue!.order, [...original.queue!.order].reverse());
|
||||
validateDiscoveryStorm(game, three);
|
||||
|
||||
for (const input of [
|
||||
{holder:second, event:one.event, mode:'last' as const, nextEvent:'unused'},
|
||||
{holder:first, event:two.event, mode:'last' as const, nextEvent:original.event},
|
||||
{holder:first, event:two.event, mode:'last' as const, nextEvent:one.event},
|
||||
]) assert.throws(() => reorderDiscoveryStorm(game, two, input));
|
||||
|
||||
for (const mutate of [
|
||||
(changed:typeof three) => { changed.saphoHistory![0].nextEvent = 'broken-chain'; },
|
||||
(changed:typeof three) => { changed.saphoHistory![1].originalOrder.reverse(); },
|
||||
(changed:typeof three) => { changed.sapho!.event = one.sapho!.event; },
|
||||
(changed:typeof three) => { changed.sapho!.nextEvent = one.sapho!.event; },
|
||||
]) {
|
||||
const changed = structuredClone(three);
|
||||
mutate(changed);
|
||||
changed.signature = discoveryStormSignature(changed);
|
||||
assert.throws(() => validateDiscoveryStorm(game, changed));
|
||||
}
|
||||
|
||||
const afterFirst = chooseDiscoveryStorm(game, three, three.owner, three.event, 0);
|
||||
assert.deepEqual(discoveryStormSaphoModes(game, afterFirst, afterFirst.owner), []);
|
||||
assert.throws(() => reorderDiscoveryStorm(game, afterFirst,
|
||||
{holder:afterFirst.owner, event:afterFirst.event, mode:'first', nextEvent:'too-late'}));
|
||||
const afterSecond = chooseDiscoveryStorm(game, afterFirst, afterFirst.owner, afterFirst.event, 0);
|
||||
assert.deepEqual(afterSecond.queue!.choices.map(choice => choice.owner), three.queue!.order);
|
||||
assert.deepEqual(afterSecond.saphoHistory, three.saphoHistory);
|
||||
validateDiscoveryStorm(game, afterSecond);
|
||||
});
|
||||
@@ -80,6 +80,8 @@ for (const advanced of [false, true]) void test(
|
||||
for (const player of game.players) game = applyAction(game, player.id, {type:'semutaPass', event:discardEvent});
|
||||
assert.equal(game.decision?.player, f.holder);
|
||||
assert.equal(game.discard.filter(card => card.id === CARD).length, 1);
|
||||
for (const occupant of game.ecologicalStorm!.queue!.order)
|
||||
game = applyAction(game, occupant, {type:'saphoStationPass',event:game.ecologicalStorm!.event});
|
||||
for (const delta of [1, -1]) {
|
||||
const actor = game.ecologicalStorm!.owner;
|
||||
const action = discoveryStormActions(viewGame(game, actor)).find(row => row.delta === delta);
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { applyAction, createGame, joinGame, newPlayer, 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 { SEMUTA_DRUG_ID } from '../game/semuta-drug';
|
||||
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 seat = (game: Game, id: string) => {
|
||||
const player = game.players.find(row => row.id === id); assert.ok(player); return player;
|
||||
};
|
||||
|
||||
/** Public setup followed by a controlled physical Station placement, reserve
|
||||
* counters and conserved original Sapho/Semuta transfers. The pending discard
|
||||
* is produced by the real card action and native Station queue. */
|
||||
function pendingStationDiscard() {
|
||||
let game = createGame('SAPHOSTATIONCOMPAT', newPlayer('richese', 'Richese', 'richese'), false, ['choam']);
|
||||
for (const faction of ['atreides', 'emperor'] as const)
|
||||
joinGame(game, newPlayer(faction, faction, faction));
|
||||
game = applyAction(game, game.host, {type:'moduleOption', module:'discoveries', enabled:true});
|
||||
for (const player of game.players) game = applyAction(game, player.id, {type:'ready'});
|
||||
game = applyAction(game, game.host, {type:'start'});
|
||||
game = advanceTestingStationContest(game, state => state.status === 'playing');
|
||||
const token = game.discoveries!.tokens.find(row => row.face === STATION);
|
||||
assert.ok(token && token.status === 'supply');
|
||||
const placement = Object.values(DISCOVERY_CARD_PLACEMENTS).find(row => row.type === token.type);
|
||||
assert.ok(placement);
|
||||
Object.assign(token, {status:'placed', territory:placement.territory, sector:placement.sector, revealedTurn:game.turn});
|
||||
validateDiscoveryState(game.discoveries!);
|
||||
for (const id of ['richese', 'emperor']) {
|
||||
const player = seat(game, id); assert.ok(player.reserves > 0);
|
||||
player.reserves--;
|
||||
player.forces[`${STATION}:0`] = (player.forces[`${STATION}:0`] ?? 0) + 1;
|
||||
while (player.hand.length >= 4) game.deck.push(player.hand.pop()!);
|
||||
}
|
||||
moveSemutaEmperorCard(game, SAPHO, 'emperor');
|
||||
moveSemutaEmperorCard(game, SEMUTA_DRUG_ID, 'richese');
|
||||
game = advanceTestingStationContest(game, state => state.decision?.kind === 'ecologicalStorm');
|
||||
const option = viewGame(game, 'emperor').saphoOptions.find(row => row.scope === 'testingStation');
|
||||
assert.ok(option);
|
||||
game = applyAction(game, 'emperor', {type:'card', card:SAPHO, scope:option.scope,
|
||||
event:option.event, mode:option.mode});
|
||||
assert.equal(game.pendingTreacheryDiscard?.continuation.kind, 'saphoStationDiscard');
|
||||
return game;
|
||||
}
|
||||
|
||||
void test('legacy saved pending Sapho discard resumes without installing the new replay-priority window', () => {
|
||||
const game = pendingStationDiscard();
|
||||
const pending = game.pendingTreacheryDiscard; assert.ok(pending);
|
||||
const continuation = pending.continuation;
|
||||
assert.equal(continuation.kind, 'saphoStationDiscard');
|
||||
if (continuation.kind !== 'saphoStationDiscard') throw Error('Expected the station continuation');
|
||||
assert.equal(continuation.stationReplayPriority, true);
|
||||
// The old signature has exactly the same ordered JSON fields except the
|
||||
// new optional marker; no historic station frame or pending parent changes.
|
||||
const signature = JSON.parse(continuation.stateSignature) as Record<string, unknown>;
|
||||
delete signature.stationReplayPriority;
|
||||
delete continuation.stationReplayPriority;
|
||||
continuation.stateSignature = JSON.stringify(signature);
|
||||
const resumed = reactSemutaSpecial(game, 'richese', true);
|
||||
assert.equal(resumed.pendingTreacheryDiscard, null);
|
||||
assert.equal(resumed.saphoStationPriority, undefined);
|
||||
assert.equal(resumed.decision?.kind, 'ecologicalStorm');
|
||||
assert.ok(seat(resumed, 'richese').hand.some(card => card.id === SAPHO));
|
||||
assert.ok(viewGame(resumed, 'richese').saphoOptions.some(row => row.scope === 'testingStation'));
|
||||
});
|
||||
|
||||
void test('all minimal bot profiles legally pass each reopened Station priority', () => {
|
||||
const game = reactSemutaSpecial(pendingStationDiscard(), 'richese', true);
|
||||
assert.ok(game.saphoStationPriority);
|
||||
const order = game.ecologicalStorm!.queue!.order;
|
||||
for (const occupant of order) for (const difficulty of DIFFICULTIES) {
|
||||
const bot = viewGame(game, occupant);
|
||||
bot.players.find(row => row.id === occupant)!.bot = difficulty;
|
||||
const action = botActions(bot)[0];
|
||||
assert.deepEqual(action, {type:'saphoStationPass', event:game.saphoStationPriority.event});
|
||||
let resumed = applyAction(game, occupant, action);
|
||||
const other = order.find(id => id !== occupant); assert.ok(other);
|
||||
resumed = applyAction(resumed, other, {type:'saphoStationPass', event:game.saphoStationPriority.event});
|
||||
assert.equal(resumed.saphoStationPriority, undefined);
|
||||
assert.equal(resumed.decision?.kind, 'ecologicalStorm');
|
||||
assert.equal(resumed.ecologicalStorm?.queue?.choices.length, 0);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,117 @@
|
||||
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 { DISCOVERY_CARD_PLACEMENTS, validateDiscoveryState } from '../game/discoveries';
|
||||
import { discoveryStormActions } from '../game/discovery-storm-options';
|
||||
import { discoveryStormDistance } from '../game/discovery-storm';
|
||||
import { SEMUTA_DRUG_ID } from '../game/semuta-drug';
|
||||
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 seat = (game: Game, id: string) => {
|
||||
const player = game.players.find(candidate => candidate.id === id);
|
||||
assert.ok(player); return player;
|
||||
};
|
||||
const inventory = (game: Game) => [...game.deck, ...game.discard, ...(game.richeseCache ?? []),
|
||||
...(game.richeseRemoved ?? []), ...game.players.flatMap(player => player.hand)].map(card => card.id).sort();
|
||||
|
||||
/** Public lobby and original faction setup, then a controlled physical Station
|
||||
* placement and two real reserve counters. Sapho and Semuta are moved from their
|
||||
* existing physical zones. The station queue and Storm are reached by normal
|
||||
* actions; no completed choice, reaction, receipt or replay is fabricated. */
|
||||
function fixture(advanced: boolean) {
|
||||
let game = createGame('SAPHOSTATIONREPLAY', newPlayer('richese', 'Richese', 'richese'), advanced, ['choam']);
|
||||
for (const faction of ['atreides', 'emperor'] as const)
|
||||
joinGame(game, newPlayer(faction, faction, faction));
|
||||
game = applyAction(game, game.host, {type:'moduleOption', module:'discoveries', enabled:true});
|
||||
for (const player of game.players) game = applyAction(game, player.id, {type:'ready'});
|
||||
game = applyAction(game, game.host, {type:'start', ...(advanced ? {advancedPreview:true} : {})});
|
||||
game = advanceTestingStationContest(game, state => state.status === 'playing');
|
||||
assert.equal(game.phase, 0);
|
||||
const beforeCards = inventory(game);
|
||||
assert.equal(beforeCards.filter(card => card === SAPHO).length, 1);
|
||||
assert.equal(beforeCards.filter(card => card === SEMUTA_DRUG_ID).length, 1);
|
||||
const token = game.discoveries!.tokens.find(candidate => candidate.face === STATION);
|
||||
assert.ok(token && token.status === 'supply');
|
||||
const placement = Object.values(DISCOVERY_CARD_PLACEMENTS).find(candidate => candidate.type === token.type);
|
||||
assert.ok(placement);
|
||||
Object.assign(token, {status:'placed', territory:placement.territory, sector:placement.sector, revealedTurn:game.turn});
|
||||
validateDiscoveryState(game.discoveries!);
|
||||
for (const id of ['richese', 'emperor']) {
|
||||
const player = seat(game, id); assert.ok(player.reserves > 0);
|
||||
player.reserves--;
|
||||
player.forces[`${STATION}:0`] = (player.forces[`${STATION}:0`] ?? 0) + 1;
|
||||
}
|
||||
for (const id of ['richese', 'emperor']) {
|
||||
const player = seat(game, id);
|
||||
while (player.hand.length >= 4) game.deck.push(player.hand.pop()!);
|
||||
}
|
||||
moveSemutaEmperorCard(game, SAPHO, 'emperor');
|
||||
moveSemutaEmperorCard(game, SEMUTA_DRUG_ID, 'richese');
|
||||
assert.deepEqual(inventory(game), beforeCards);
|
||||
game = advanceTestingStationContest(game, state => state.decision?.kind === 'ecologicalStorm');
|
||||
assert.equal(game.semutaPreview, true);
|
||||
assert.deepEqual(game.ecologicalStorm!.queue!.order, game.order.filter(id => id === 'richese' || id === 'emperor'));
|
||||
return {game, beforeCards};
|
||||
}
|
||||
|
||||
function option(game: Game, holder: string) {
|
||||
const result = viewGame(game, holder).saphoOptions.find(choice => choice.scope === 'testingStation');
|
||||
assert.ok(result, `${holder} must have a legal physical Sapho order`);
|
||||
return {type:'card', card:SAPHO, scope:result.scope, event:result.event, mode:result.mode} as Action;
|
||||
}
|
||||
|
||||
for (const advanced of [false, true]) void test(
|
||||
`${advanced ? 'Advanced' : 'Basic'} recovered Sapho can reorder the same Station a second time`, () => {
|
||||
const f = fixture(advanced);
|
||||
let game = f.game;
|
||||
const originalOrder = [...game.ecologicalStorm!.queue!.order];
|
||||
const originalEvent = game.ecologicalStorm!.event;
|
||||
const base = game.stormPending!;
|
||||
const firstAction = option(game, 'emperor');
|
||||
game = applyAction(game, 'emperor', firstAction);
|
||||
const firstReceipt = structuredClone(game.ecologicalStorm!.sapho);
|
||||
assert.ok(firstReceipt);
|
||||
assert.deepEqual(game.ecologicalStorm!.queue!.order, [...originalOrder].reverse());
|
||||
assert.equal(game.pendingTreacheryDiscard?.batch.cause, 'sapho:station');
|
||||
assert.equal(game.pendingTreacheryDiscard?.continuation.kind, 'saphoStationDiscard');
|
||||
game = reactSemutaSpecial(game, 'richese', true);
|
||||
assert.ok(seat(game, 'richese').hand.some(card => card.id === SAPHO));
|
||||
assert.ok(!seat(game, 'richese').hand.some(card => card.id === SEMUTA_DRUG_ID));
|
||||
assert.equal(game.ecologicalStorm!.queue!.choices.length, 0);
|
||||
const secondAction = option(game, 'richese');
|
||||
assert.notEqual(secondAction.event, originalEvent);
|
||||
const secondEvent = secondAction.event;
|
||||
game = applyAction(game, 'richese', secondAction);
|
||||
assert.deepEqual(game.ecologicalStorm!.queue!.order, originalOrder);
|
||||
assert.deepEqual(game.ecologicalStorm!.saphoHistory, [firstReceipt]);
|
||||
assert.equal(game.ecologicalStorm!.sapho?.event, secondEvent);
|
||||
assert.equal(game.ecologicalStorm!.sapho?.holder, 'richese');
|
||||
assert.equal(game.pendingTreacheryDiscard?.batch.cause, 'sapho:station');
|
||||
game = reactSemutaSpecial(game, 'richese', false);
|
||||
assert.equal(game.pendingTreacheryDiscard, null);
|
||||
assert.equal(game.saphoStationPriority?.event, game.ecologicalStorm!.event);
|
||||
assert.equal(game.discard.filter(card => card.id === SAPHO).length, 1);
|
||||
assert.equal(game.discard.filter(card => card.id === SEMUTA_DRUG_ID).length, 1);
|
||||
const stale = structuredClone(game);
|
||||
assert.throws(() => applyAction(game, 'richese', secondAction));
|
||||
assert.deepEqual(game, stale);
|
||||
for (const occupant of game.ecologicalStorm!.queue!.order)
|
||||
game = applyAction(game, occupant, {type:'saphoStationPass', event:game.ecologicalStorm!.event});
|
||||
const firstDelta = base < 40 ? 1 : -1;
|
||||
for (const delta of [firstDelta, -firstDelta]) {
|
||||
const actor = game.ecologicalStorm!.owner;
|
||||
const choice = discoveryStormActions(viewGame(game, actor)).find(candidate => candidate.delta === delta);
|
||||
assert.ok(choice);
|
||||
game = applyAction(game, actor, choice);
|
||||
}
|
||||
assert.equal(game.ecologicalStorm!.stage, 'complete');
|
||||
assert.deepEqual(game.ecologicalStorm!.queue!.choices.map(choice => choice.owner), originalOrder);
|
||||
assert.equal(discoveryStormDistance(game.ecologicalStorm!), base);
|
||||
assert.equal(game.phase, 1);
|
||||
assert.deepEqual(inventory(game), f.beforeCards);
|
||||
},
|
||||
);
|
||||
@@ -84,6 +84,8 @@ for (const advanced of [false, true]) for (const mixed of [false, true])
|
||||
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 (const occupant of game.ecologicalStorm!.queue!.order)
|
||||
game = applyAction(game, occupant, {type:'saphoStationPass',event:game.ecologicalStorm!.event});
|
||||
for (let i = 0; i < 2; i++) {
|
||||
const owner = game.ecologicalStorm!.owner;
|
||||
const action = discoveryStormActions(viewGame(game, owner)).find(choice => choice.delta === 0);
|
||||
|
||||
@@ -83,6 +83,9 @@ for (const advanced of [false, true]) for (const mode of ['first', 'last'] as co
|
||||
assert.equal(seat(resumed, 'r').hand.some(card => card.id === SAPHO), claim);
|
||||
assert.equal(seat(resumed, 'r').hand.some(card => card.id === SEMUTA_DRUG_ID), !claim);
|
||||
assert.throws(() => applyAction(copy(resumed), 'r', {type:'semutaCommit', event:pendingEvent}));
|
||||
assert.equal(resumed.saphoStationPriority?.event, resumed.ecologicalStorm?.event);
|
||||
for (const occupant of resumed.ecologicalStorm!.queue!.order)
|
||||
resumed = applyAction(resumed, occupant, {type:'saphoStationPass', event:resumed.ecologicalStorm!.event});
|
||||
for (const delta of [1, -1]) {
|
||||
const owner = resumed.ecologicalStorm!.owner;
|
||||
const choice = discoveryStormActions(viewGame(resumed, owner)).find(row => row.delta === delta);
|
||||
|
||||
Reference in new issue
Block a user