Offer Semuta before Ix-deck Thumper Spice Blow

This commit is contained in:
Quintine committed 2026-09-30 10:04:48 +10:00
1 parent dd6d3a89ca
commit f0eafc175e
11 files changed
+313 -48

No files matched your search

+68 -2
View File
@@ -3,6 +3,7 @@ import assert from 'node:assert/strict';
import { applyAction, createGame, initializeSemutaGameForAudit, joinGame, newPlayer, normalizeAutomaticGame, viewGame, type Game } from '../game/engine';
import { botActions } from '../game/bots';
import { SEMUTA_DRUG_ID } from '../game/semuta-drug';
import { spiceDeck } from '../game/cards';
const reload = (g: Game): Game => JSON.parse(JSON.stringify(g));
const player = (g: Game, id: string) => g.players.find(p => p.id === id)!;
@@ -19,8 +20,8 @@ function inventory(g: Game) {
assert.equal(new Set(ids).size, ids.length);
return ids;
}
function fixture() {
let g = createGame('SEMUTAQ2', newPlayer('r', 'Richese', 'richese'), false, ['choam']);
function fixture(ix = false) {
let g = createGame('SEMUTAQ2', newPlayer('r', 'Richese', 'richese'), false, ix ? ['choam', 'ix'] : ['choam']);
joinGame(g, newPlayer('a', 'Atreides', 'atreides'));
joinGame(g, newPlayer('e', 'Emperor', 'emperor'));
for (const p of g.players) { p.bot = 'Medium'; p.ready = true; }
@@ -747,3 +748,68 @@ void test('a mutual-traitor battle offers one mixed-owner mandatory batch with o
for (const p of selected.players)
assert.deepEqual(viewGame(reload(selected), p.id), viewGame(selected, p.id));
});
void test('a clean Thumper discard pauses before its injected worm and resumes one Spice Blow', () => {
const { g, semuta, hajr } = fixture(true);
player(g, 'a').hand = [];
g.deck.push(hajr);
const thumper = take(g, 'thumper');
player(g, 'a').hand.push(thumper);
const lands = spiceDeck().filter(card => 'territory' in card);
const prior = lands[0], next = lands[1];
if (!('territory' in prior) || !('territory' in next))
throw Error('Missing real spice territory cards');
player(g, 'e').forces = { [`${prior.territory}:${prior.sector}`]: 3 };
player(g, 'e').reserves = 17;
g.spice = { [`${prior.territory}:${prior.sector}`]: 8 };
g.spiceDiscard = [[prior], []];
g.spiceDeck = [next, ...spiceDeck().filter(card => 'worm' in card)];
Object.assign(g, { phase: 1, turn: 2, active: null, ready: [],
decision: null, response: null, phaseOpening: null,
spiceWindow: null, spiceResolution: null, spiceSequence: null, nexus: false });
const original = inventory(g), deck = reload(g).spiceDeck;
const pending = applyAction(g, 'a', { type: 'card', card: thumper.id });
assert.equal(pending.pendingTreacheryDiscard?.reaction?.stage, 'offer');
assert.equal(pending.spiceWindow, null);
assert.deepEqual(pending.spiceDeck, deck);
assert.equal(player(pending, 'e').tanks, 0);
assert.equal(pending.spice[`${prior.territory}:${prior.sector}`], 8);
assert.equal(pending.discard.filter(card => card.id === thumper.id).length, 1);
const event = pending.pendingTreacheryDiscard!.batch.event;
assert.equal(viewGame(pending, 'r').semutaReaction?.canCommit, true);
assert.deepEqual(normalizeAutomaticGame(reload(pending)), reload(pending));
const profile = reload(pending);
profile.advanced = !profile.advanced;
assert.throws(() => viewGame(profile, 'r'));
const custody = reload(pending);
player(custody, 'r').noField = undefined;
assert.throws(() => normalizeAutomaticGame(custody));
const expansion = reload(pending);
expansion.expansions = ['choam'];
assert.throws(() => viewGame(expansion, 'r'));
const placement = reload(pending);
placement.wormPlacementCanceledTurn = pending.turn;
assert.throws(() => normalizeAutomaticGame(placement));
let declined = reload(pending);
for (const id of ['e', 'a', 'r'])
declined = applyAction(declined, id, { type: 'semutaPass', event });
assert.equal(declined.pendingTreacheryDiscard, null);
assert.equal(player(declined, 'e').tanks, 3);
assert.equal(declined.spice[`${prior.territory}:${prior.sector}`], undefined);
assert.equal(declined.spiceWindow?.territory, next.territory);
assert.equal(declined.discard.filter(card => card.id === thumper.id).length, 1);
assert.deepEqual(inventory(declined), original);
const claimed = applyAction(reload(pending), 'r', botActions(viewGame(pending, 'r'))[0]!);
assert.equal(claimed.pendingTreacheryDiscard, null);
assert.equal(player(claimed, 'e').tanks, 3);
assert.equal(claimed.spiceWindow?.territory, next.territory);
assert.deepEqual(claimed.spiceDeck, declined.spiceDeck);
assert.deepEqual(claimed.spiceDiscard, declined.spiceDiscard);
assert.equal(player(claimed, 'r').hand.filter(card => card.id === thumper.id).length, 1);
assert.equal(claimed.discard.filter(card => card.id === semuta.id).length, 1);
assert.equal(claimed.discard.some(card => card.id === thumper.id), false);
assert.deepEqual(inventory(claimed), original);
for (const p of claimed.players)
assert.deepEqual(viewGame(reload(claimed), p.id), viewGame(claimed, p.id));
assert.throws(() => applyAction(claimed, 'r', { type: 'semutaCommit', event }));
});
+77
View File
@@ -4,6 +4,7 @@ import { startPrototypeRoom } from '../tools/prototype-room';
import { botActions } from '../game/bots';
import { viewGame, type Game, type Action } from '../game/engine';
import { SEMUTA_DRUG_ID } from '../game/semuta-drug';
import { spiceDeck } from '../game/cards';
import { unitStore } from './fixture-nexus-room-store';
const clock = { now: () => 10000, sleep: async () => {} };
@@ -543,3 +544,79 @@ void test('authenticated clean Semuta producers claim once through restart and r
assert.deepEqual(await f.restart().readSeatView(code, auth), viewGame(mixedClaim, auth.playerId));
} finally { f.sqlite.close(); }
});
void test('an authenticated Ix-deck Thumper pause retains the undrawn blow through restart', async () => {
const f = unitStore();
try {
const created = await f.rooms.createRoom('Semuta Thumper QA', 'richese', false, ['choam', 'ix']);
const code = created.view.code;
const second = await f.rooms.joinRoom(code, 'Atreides', 'atreides');
const third = await f.rooms.joinRoom(code, 'Emperor', 'emperor');
const auths = await Promise.all([created.token!, second.token!, third.token!]
.map(token => f.restart().authenticate(code, token)));
const ids = auths.map(auth => auth.playerId);
const act = async (index: number, action: Action) => {
const before = await f.restart().readRoom(code);
await f.restart().act(code, auths[index], before.version, action, clock);
return f.restart().readRoom(code);
};
for (let index = 0; index < auths.length; index++) await act(index, { type: 'ready' });
let game = await f.restart().readRoom(code);
startPrototypeRoom(f.sqlite, code, game.version, 'semuta');
game = await f.restart().readRoom(code);
for (let step = 0; game.status === 'setup' && step < 80; step++) {
let moved = false;
for (let index = 0; index < auths.length; index++) {
const view = viewGame(game, ids[index]);
view.players.find(p => p.id === view.me)!.bot = 'Medium';
const choice = botActions(view)[0];
if (choice) { game = await act(index, choice); moved = true; break; }
}
assert.ok(moved, 'genuine Ix-deck setup needs a legal AI choice');
}
assert.equal(game.status, 'playing');
const originalSeats = f.sqlite.prepare('SELECT * FROM seats').all();
const semuta = take(game, SEMUTA_DRUG_ID), thumper = take(game, 'thumper');
game.deck.push(...game.players.flatMap(p => p.hand));
for (const p of game.players) p.hand = [];
seat(game, ids[0]).hand.push(semuta);
seat(game, ids[1]).hand.push(thumper);
const lands = spiceDeck().filter(card => 'territory' in card);
const prior = lands[0], next = lands[1];
if (!('territory' in prior) || !('territory' in next))
throw Error('Missing real spice territories');
seat(game, ids[2]).forces = { [`${prior.territory}:${prior.sector}`]: 3 };
seat(game, ids[2]).reserves = 17;
Object.assign(game, { turn: 2, phase: 1, active: null, ready: [],
decision: null, response: null, phaseOpening: null,
spiceWindow: null, spiceResolution: null, spiceSequence: null, nexus: false,
spice: { [`${prior.territory}:${prior.sector}`]: 8 },
spiceDiscard: [[prior], []], spiceDeck: [next, ...spiceDeck().filter(card => 'worm' in card)] });
const beforeDeck = structuredClone(game.spiceDeck);
game.version++;
assert.equal(f.sqlite.prepare('UPDATE rooms SET state=?,version=? WHERE code=? AND version=?')
.run(JSON.stringify(game), game.version, code, game.version - 1).changes, 1);
const pending = await act(1, { type: 'card', card: thumper.id });
assert.equal(pending.pendingTreacheryDiscard?.reaction?.stage, 'offer');
assert.deepEqual(pending.spiceDeck, beforeDeck);
assert.equal(seat(pending, ids[2]).tanks, 0);
await f.restart().continueRoomAutomatic(code, clock);
assert.equal((await f.restart().readRoom(code)).version, pending.version);
const holder = await f.restart().readSeatView(code, auths[0]);
const rival = await f.restart().readSeatView(code, auths[2]);
assert.equal(holder.semutaReaction?.canCommit, true);
assert.equal(rival.semutaReaction?.canCommit, false);
const claimed = await act(0, { type: 'semutaCommit',
event: pending.pendingTreacheryDiscard!.batch.event });
assert.equal(claimed.pendingTreacheryDiscard, null);
assert.equal(seat(claimed, ids[2]).tanks, 3);
assert.equal(claimed.spiceWindow?.territory, next.territory);
assert.equal(claimed.spiceDeck.length, beforeDeck.length - 1);
assert.equal(seat(claimed, ids[0]).hand.filter(card => card.id === thumper.id).length, 1);
assert.equal(claimed.discard.filter(card => card.id === SEMUTA_DRUG_ID).length, 1);
assert.equal(claimed.discard.some(card => card.id === thumper.id), false);
assert.deepEqual(f.sqlite.prepare('SELECT * FROM seats').all(), originalSeats);
for (const auth of auths)
assert.deepEqual(await f.restart().readSeatView(code, auth), viewGame(claimed, auth.playerId));
} finally { f.sqlite.close(); }
});