Offer Semuta after clean Ix-deck Amal discard

This commit is contained in:
Quintine committed 2026-09-30 10:25:04 +10:00
1 parent f0eafc175e
commit dffbe7b9f7
9 files changed
+249 -26

No files matched your search

+56
View File
@@ -813,3 +813,59 @@ void test('a clean Thumper discard pauses before its injected worm and resumes o
assert.deepEqual(viewGame(reload(claimed), p.id), viewGame(claimed, p.id));
assert.throws(() => applyAction(claimed, 'r', { type: 'semutaCommit', event }));
});
void test('a clean Ix-deck Amal discard pauses after halving spice but before phase initialization', () => {
const { g, semuta, hajr } = fixture(true);
player(g, 'a').hand = [];
g.deck.push(hajr);
const amal = take(g, 'amal');
player(g, 'a').hand.push(amal);
player(g, 'r').spice = 11;
player(g, 'a').spice = 9;
player(g, 'e').spice = 7;
Object.assign(g, { phase: 2, active: null, ready: [],
decision: null, response: null, phaseOpening: null, auction: null });
const original = inventory(g);
let opening = g;
for (const id of ['a', 'e', 'r'])
opening = applyAction(opening, id, { type: 'ready' });
assert.equal(opening.phase, 3);
assert.ok(opening.phaseOpening);
opening = applyAction(opening, 'e', { type: 'ready' });
assert.deepEqual(opening.phaseOpening?.passed, ['e']);
const deck = reload(opening).deck;
const pending = applyAction(opening, 'a', { type: 'card', card: amal.id });
assert.equal(pending.pendingTreacheryDiscard?.reaction?.stage, 'offer');
assert.equal(pending.phaseOpening, null);
assert.equal(pending.auction, null);
assert.deepEqual(pending.deck, deck);
assert.deepEqual(pending.players.map(p => p.spice), [5, 4, 3]);
assert.equal(pending.discard.filter(card => card.id === amal.id).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 ['e', 'a', 'r'])
declined = applyAction(declined, id, { type: 'semutaPass', event });
assert.equal(declined.pendingTreacheryDiscard, null);
assert.deepEqual(declined.phaseOpening?.passed, []);
assert.deepEqual(declined.players.map(p => p.spice), [5, 4, 3]);
assert.deepEqual(inventory(declined), original);
const claimed = applyAction(reload(pending), 'r', botActions(viewGame(pending, 'r'))[0]!);
assert.equal(claimed.pendingTreacheryDiscard, null);
assert.deepEqual(claimed.phaseOpening?.passed, []);
assert.deepEqual(claimed.players.map(p => p.spice), [5, 4, 3]);
assert.equal(player(claimed, 'r').hand.filter(card => card.id === amal.id).length, 1);
assert.equal(claimed.discard.filter(card => card.id === semuta.id).length, 1);
assert.equal(claimed.discard.some(card => card.id === amal.id), false);
for (const p of claimed.players)
assert.deepEqual(viewGame(reload(claimed), p.id), viewGame(claimed, p.id));
let after = reload(claimed);
for (const id of ['a', 'e', 'r'])
after = applyAction(after, id, { type: 'ready' });
assert.equal(after.phaseOpening, null);
assert.equal(after.richeseBidding?.turn, after.turn);
assert.deepEqual(after.players.map(p => p.spice), [5, 4, 3]);
assert.deepEqual(inventory(after), original);
assert.throws(() => applyAction(claimed, 'r', { type: 'semutaCommit', event }));
});
+47
View File
@@ -618,5 +618,52 @@ void test('an authenticated Ix-deck Thumper pause retains the undrawn blow throu
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));
const bidding = structuredClone(claimed);
const again = take(bidding, SEMUTA_DRUG_ID);
bidding.deck.push(take(bidding, thumper.id));
seat(bidding, ids[0]).hand.push(again);
const amal = take(bidding, 'amal');
seat(bidding, ids[1]).hand.push(amal);
seat(bidding, ids[0]).spice = 11;
seat(bidding, ids[1]).spice = 9;
seat(bidding, ids[2]).spice = 7;
Object.assign(bidding, { turn: 3, phase: 2, active: null, ready: [],
decision: null, response: null, phaseOpening: null, auction: null,
spiceWindow: null, spiceResolution: null, spiceSequence: null, nexus: false });
bidding.version = claimed.version + 1;
assert.equal(f.sqlite.prepare('UPDATE rooms SET state=?,version=? WHERE code=? AND version=?')
.run(JSON.stringify(bidding), bidding.version, code, claimed.version).changes, 1);
for (let index = 0; index < auths.length; index++)
await act(index, { type: 'ready' });
const opening = await f.restart().readRoom(code);
assert.equal(opening.phase, 3);
assert.ok(opening.phaseOpening);
assert.deepEqual((await act(2, { type: 'ready' })).phaseOpening?.passed, [ids[2]]);
const deckBefore = structuredClone(opening.deck);
const offeredAmal = await act(1, { type: 'card', card: amal.id });
assert.equal(offeredAmal.pendingTreacheryDiscard?.reaction?.stage, 'offer');
assert.deepEqual(offeredAmal.players.map(p => p.spice), [5, 4, 3]);
assert.deepEqual(offeredAmal.deck, deckBefore);
assert.equal(offeredAmal.phaseOpening, null);
await f.restart().continueRoomAutomatic(code, clock);
assert.equal((await f.restart().readRoom(code)).version, offeredAmal.version);
assert.equal((await f.restart().readSeatView(code, auths[0])).semutaReaction?.canCommit, true);
const recoveredAmal = await act(0, { type: 'semutaCommit',
event: offeredAmal.pendingTreacheryDiscard!.batch.event });
assert.equal(recoveredAmal.pendingTreacheryDiscard, null);
assert.deepEqual(recoveredAmal.phaseOpening?.passed, []);
assert.deepEqual(recoveredAmal.players.map(p => p.spice), [5, 4, 3]);
assert.equal(seat(recoveredAmal, ids[0]).hand.filter(card => card.id === amal.id).length, 1);
assert.equal(recoveredAmal.discard.filter(card => card.id === SEMUTA_DRUG_ID).length, 1);
for (let index = 0; index < auths.length; index++)
await act(index, { type: 'ready' });
const resumedAmal = await f.restart().readRoom(code);
assert.equal(resumedAmal.phaseOpening, null);
assert.equal(resumedAmal.richeseBidding?.turn, resumedAmal.turn);
assert.deepEqual(resumedAmal.players.map(p => p.spice), [5, 4, 3]);
assert.deepEqual(f.sqlite.prepare('SELECT * FROM seats').all(), originalSeats);
for (const auth of auths)
assert.deepEqual(await f.restart().readSeatView(code, auth), viewGame(resumedAmal, auth.playerId));
} finally { f.sqlite.close(); }
});