Offer Semuta after clean pre-plan Sapho aggressor discard

This commit is contained in:
Quintine committed 2026-09-30 10:45:56 +10:00
1 parent dffbe7b9f7
commit 9872efcc1d
11 files changed
+297 -61

No files matched your search

+3 -1
View File
@@ -3,6 +3,7 @@ import {
applyAction,
createGame,
initializeFactionExpansionsGameForAudit,
initializeSemutaGameForAudit,
joinGame,
newPlayer,
viewGame,
@@ -39,6 +40,7 @@ export function saphoBattleOrderGame({
holder = 'c',
seatIds = ['a', 'b', 'c', 'r'] as readonly [string, string, string, string],
geometry = 'shared' as 'shared' | 'separate',
semutaPreview = false,
} = {}): Game {
const factions = ['emperor', 'guild', 'atreides', 'richese'] as const;
let g = createGame(
@@ -50,7 +52,7 @@ export function saphoBattleOrderGame({
for (let i = 1; i < seatIds.length; i++)
joinGame(g, newPlayer(seatIds[i], factions[i], factions[i]));
for (const p of g.players) g = applyAction(g, p.id, { type: 'ready' });
g = initializeFactionExpansionsGameForAudit(g);
g = semutaPreview ? initializeSemutaGameForAudit(g) : initializeFactionExpansionsGameForAudit(g);
for (let step = 0; g.status === 'setup' && step < 100; step++) {
const next = nextSaphoBattleAction(g);
assert.ok(next, 'Genuine setup must have an owned action.');
+37
View File
@@ -4,6 +4,8 @@ import { applyAction, createGame, initializeSemutaGameForAudit, joinGame, newPla
import { botActions } from '../game/bots';
import { SEMUTA_DRUG_ID } from '../game/semuta-drug';
import { spiceDeck } from '../game/cards';
import { saphoAggressorGame, aggressorAction, prepareAggressorPlans } from './fixture-sapho-aggressor';
import { takeSaphoBattleCard } from './fixture-sapho-battle-order';
const reload = (g: Game): Game => JSON.parse(JSON.stringify(g));
const player = (g: Game, id: string) => g.players.find(p => p.id === id)!;
@@ -869,3 +871,38 @@ void test('a clean Ix-deck Amal discard pauses after halving spice but before ph
assert.deepEqual(inventory(after), original);
assert.throws(() => applyAction(claimed, 'r', { type: 'semutaCommit', event }));
});
void test('clean pre-plan Sapho aggressor discard offers Semuta before battle readiness resumes', () => {
const g = saphoAggressorGame({ semutaPreview: true });
takeSaphoBattleCard(g, 'r', SEMUTA_DRUG_ID);
const original = inventory(g), battleEvent = g.battle!.event;
const action = aggressorAction(g);
const pending = applyAction(g, 'b', action);
assert.equal(pending.pendingTreacheryDiscard?.reaction?.stage, 'offer');
assert.equal(pending.battle?.event, battleEvent);
assert.equal(pending.battle?.preLeader?.closed, false);
assert.equal(pending.battle?.saphoAggressor?.uses.length, 1);
assert.equal(pending.discard.filter(card => card.id === action.card).length, 1);
const event = pending.pendingTreacheryDiscard!.batch.event;
assert.equal(viewGame(pending, 'r').semutaReaction?.canCommit, true);
assert.deepEqual(normalizeAutomaticGame(reload(pending)), reload(pending));
let declined = reload(pending);
for (const id of ['a', 'b', 'c', 'r'])
declined = applyAction(declined, id, { type: 'semutaPass', event });
assert.equal(declined.pendingTreacheryDiscard, null);
assert.equal(declined.battle?.saphoAggressor?.uses.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(claimed.battle?.event, battleEvent);
assert.equal(claimed.battle?.saphoAggressor?.uses.length, 1);
assert.equal(viewGame(claimed, 'a').battle?.aggressor, 'b');
assert.equal(player(claimed, 'r').hand.filter(card => card.id === action.card).length, 1);
assert.equal(claimed.discard.filter(card => card.id === SEMUTA_DRUG_ID).length, 1);
assert.equal(claimed.discard.some(card => card.id === action.card), false);
assert.deepEqual(inventory(claimed), original);
const prepared = prepareAggressorPlans(reload(claimed));
assert.equal(prepared.battle?.preLeader?.closed, true);
assert.equal(prepared.battle?.saphoAggressor?.uses.length, 1);
assert.throws(() => applyAction(claimed, 'r', { type: 'semutaCommit', event }));
});
+59
View File
@@ -6,6 +6,8 @@ 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';
import { saphoAggressorGame, aggressorAction } from './fixture-sapho-aggressor';
import { takeSaphoBattleCard } from './fixture-sapho-battle-order';
const clock = { now: () => 10000, sleep: async () => {} };
const seat = (g: Game, id: string) => g.players.find(p => p.id === id)!;
@@ -667,3 +669,60 @@ void test('an authenticated Ix-deck Thumper pause retains the undrawn blow throu
assert.deepEqual(await f.restart().readSeatView(code, auth), viewGame(resumedAmal, auth.playerId));
} finally { f.sqlite.close(); }
});
void test('authenticated pre-plan Sapho discard restores one aggressor choice before battle plans', async () => {
const f = unitStore();
try {
const created = await f.rooms.createRoom('Semuta Sapho QA', 'emperor', false, ['choam']);
const code = created.view.code;
const joined = [
await f.rooms.joinRoom(code, 'Guild', 'guild'),
await f.rooms.joinRoom(code, 'Atreides', 'atreides'),
await f.rooms.joinRoom(code, 'Richese', 'richese'),
];
const auths = await Promise.all([created.token!, ...joined.map(row => row.token!)]
.map(token => f.restart().authenticate(code, token)));
const ids = auths.map(auth => auth.playerId);
const originalSeats = f.sqlite.prepare('SELECT * FROM seats').all();
const initial = await f.restart().readRoom(code);
const battle = saphoAggressorGame({
semutaPreview: true, seatIds: ids as [string, string, string, string],
});
takeSaphoBattleCard(battle, ids[3], SEMUTA_DRUG_ID);
battle.code = code;
battle.version = initial.version + 1;
assert.equal(f.sqlite.prepare('UPDATE rooms SET state=?,version=? WHERE code=? AND version=?')
.run(JSON.stringify(battle), battle.version, code, initial.version).changes, 1);
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);
};
const option = aggressorAction(battle, ids[1]);
const offered = await act(1, option);
assert.equal(offered.pendingTreacheryDiscard?.reaction?.stage, 'offer');
assert.equal(offered.battle?.preLeader?.closed, false);
assert.equal(offered.battle?.saphoAggressor?.uses.length, 1);
await f.restart().continueRoomAutomatic(code, clock);
assert.equal((await f.restart().readRoom(code)).version, offered.version);
const holder = await f.restart().readSeatView(code, auths[3]);
const rival = await f.restart().readSeatView(code, auths[0]);
assert.equal(holder.semutaReaction?.canCommit, true);
assert.equal(rival.semutaReaction?.canCommit, false);
const claimed = await act(3, { type: 'semutaCommit',
event: offered.pendingTreacheryDiscard!.batch.event });
assert.equal(claimed.pendingTreacheryDiscard, null);
assert.equal(claimed.battle?.event, battle.battle?.event);
assert.equal(claimed.battle?.saphoAggressor?.uses.length, 1);
assert.equal(seat(claimed, ids[3]).hand.filter(card => card.id === option.card).length, 1);
assert.equal(claimed.discard.filter(card => card.id === SEMUTA_DRUG_ID).length, 1);
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));
let prepared = claimed;
for (const index of [0, 1])
prepared = await act(index, { type: 'battlePreparationReady', event: claimed.battle!.event });
assert.equal(prepared.battle?.preLeader?.closed, true);
assert.equal(prepared.battle?.saphoAggressor?.uses.length, 1);
} finally { f.sqlite.close(); }
});