Offer Semuta after printed Karama auction payment

This commit is contained in:
Quintine committed 2026-09-30 13:47:37 +10:00
1 parent eede77a3e3
commit 8f6b1c8463
8 files changed
+230 -47

No files matched your search

+62
View File
@@ -48,6 +48,68 @@ function fixture(ix = false) {
return { g, semuta, hajr };
}
void test('printed Karama auction payment offers its card before the winning lot settles', () => {
const { g, semuta, hajr } = fixture();
player(g, 'a').hand = [take(g, 'karama')];
g.deck.push(hajr);
const karama = player(g, 'a').hand[0], lot = g.deck.shift()!;
Object.assign(g, { phase: 3, active: 'a', order: ['a', 'e', 'r'],
movementRemaining: [], auction: { cards: [lot], index: 0, bid: 0,
bidder: null, active: 'a', passed: [], opener: 0 } });
g.richeseBidding = { owner: 'r', event: 'richese-normal:2', turn: g.turn,
stage: 'normal', position: 'last', normalCount: 1,
blackMarketSold: false, cacheCanceled: false, opener: 0 };
g.richeseFunding = {};
const startingSpice = player(g, 'a').spice;
const original = [...inventory(g), lot.id].sort();
let bidding = applyAction(g, 'a', { type: 'bid', amount: startingSpice + 2 });
for (const id of ['e', 'r'])
bidding = applyAction(bidding, id, { type: 'passBid' });
assert.equal(bidding.decision?.kind, 'auctionPayment');
assert.equal(bidding.auction?.bidder, 'a');
const pending = applyAction(bidding, 'a',
{ type: 'decision', karama: true, card: karama.id });
const event = pending.pendingTreacheryDiscard!.batch.event;
assert.equal(pending.pendingTreacheryDiscard?.continuation.kind, 'karamaPaymentDiscard');
assert.equal(pending.pendingTreacheryDiscard?.reaction?.stage, 'offer');
assert.equal(player(pending, 'a').spice, startingSpice);
assert.equal(player(pending, 'a').hand.some(card => card.id === lot.id), false);
assert.equal(pending.auction?.bidder, 'a');
assert.equal(viewGame(pending, 'r').semutaReaction?.canCommit, true);
assert.deepEqual(normalizeAutomaticGame(reload(pending)), reload(pending));
for (const mutate of [
(state: Game) => { state.auction!.bidder = 'e'; },
(state: Game) => { state.richeseBidding!.position = 'first'; },
(state: Game) => {
const c = state.pendingTreacheryDiscard!.continuation;
if (c.kind === 'karamaPaymentDiscard') c.stateSignature = 'wrong';
},
]) {
const altered = reload(pending);
mutate(altered);
const before = JSON.stringify(altered);
assert.throws(() => applyAction(altered, 'r', { type: 'semutaCommit', event }));
assert.equal(JSON.stringify(altered), before);
}
let declined = reload(pending);
for (const id of ['a', 'r', 'e'])
declined = applyAction(declined, id, { type: 'semutaPass', event });
const claimed = applyAction(reload(pending), 'r', botActions(viewGame(pending, 'r'))[0]!);
for (const state of [declined, claimed]) {
assert.equal(state.pendingTreacheryDiscard, null);
assert.equal(state.auction, null);
assert.equal(state.richeseBidding?.stage, 'cacheOffer');
assert.equal(state.decision?.kind, 'richeseCache');
assert.equal(player(state, 'a').spice, startingSpice);
assert.equal(player(state, 'a').hand.filter(card => card.id === lot.id).length, 1);
assert.deepEqual([...inventory(state)].sort(), original);
assert.throws(() => applyAction(state, 'r', { type: 'semutaCommit', event }));
}
assert.equal(declined.discard.filter(card => card.id === karama.id).length, 1);
assert.equal(player(claimed, 'r').hand.filter(card => card.id === karama.id).length, 1);
assert.equal(claimed.discard.filter(card => card.id === semuta.id).length, 1);
});
void test('printed Karama purchase offers its spent card before one normal auction settlement', () => {
const { g, semuta, hajr } = fixture();
player(g, 'a').hand = [take(g, 'karama')];
+71
View File
@@ -728,6 +728,77 @@ void test('authenticated pre-plan Sapho discard restores one aggressor choice be
} finally { f.sqlite.close(); }
});
void test('authenticated printed Karama auction payment resumes one saved Richese cache offer', async () => {
const f = unitStore();
try {
const made = await f.rooms.createRoom('Semuta Payment', 'richese', false, ['choam']);
const code = made.view.code;
const buyer = await f.rooms.joinRoom(code, 'Atreides', 'atreides');
const third = await f.rooms.joinRoom(code, 'Emperor', 'emperor');
const auths = await Promise.all([made.token!, buyer.token!, third.token!]
.map(token => f.restart().authenticate(code, token)));
const existing = await f.restart().readRoom(code);
const g = createGame(code, newPlayer(auths[0].playerId, 'Richese', 'richese'), false, ['choam']);
g.players.push(newPlayer(auths[1].playerId, 'Atreides', 'atreides'),
newPlayer(auths[2].playerId, 'Emperor', 'emperor'));
Object.assign(g, { status: 'playing', phase: 3, active: auths[1].playerId,
order: auths.map(auth => auth.playerId), deck: baseDeck(),
richeseCache: richeseCards(), semutaPreview: true });
for (const p of g.players) {
p.hand = [];
p.traitors = p.leaders.length ? [p.leaders[0].id] : [];
p.traitorChoices = [];
}
const karama = take(g, 'karama'), semuta = take(g, SEMUTA_DRUG_ID);
const lot = g.deck.shift()!;
seat(g, auths[1].playerId).hand.push(karama);
seat(g, auths[0].playerId).hand.push(semuta);
g.auction = { cards: [lot], index: 0, bid: 0, bidder: null,
active: auths[1].playerId, passed: [], opener: 0 };
g.richeseBidding = { owner: auths[0].playerId, event: 'richese-normal:1',
turn: g.turn, stage: 'normal', position: 'last', normalCount: 1,
blackMarketSold: false, cacheCanceled: false, opener: 0 };
g.richeseFunding = {};
g.version = existing.version + 1;
assert.equal(f.sqlite.prepare('UPDATE rooms SET state=?,version=? WHERE code=? AND version=?')
.run(JSON.stringify(g), g.version, code, existing.version).changes, 1);
const seats = f.sqlite.prepare('SELECT * FROM seats').all();
const act = async (index: number, action: Action) => {
const state = await f.restart().readRoom(code);
await f.restart().act(code, auths[index], state.version, action, clock);
return f.restart().readRoom(code);
};
const initialSpice = seat(g, auths[1].playerId).spice;
await act(1, { type: 'bid', amount: initialSpice + 2 });
await act(2, { type: 'passBid' });
const payment = await act(0, { type: 'passBid' });
assert.equal(payment.decision?.kind, 'auctionPayment');
const pending = await act(1, { type: 'decision', karama: true, card: karama.id });
assert.equal(pending.pendingTreacheryDiscard?.continuation.kind, 'karamaPaymentDiscard');
assert.equal(pending.pendingTreacheryDiscard?.reaction?.stage, 'offer');
assert.equal(pending.auction?.cards[0].id, lot.id);
assert.equal(seat(pending, auths[1].playerId).spice, initialSpice);
await f.restart().continueRoomAutomatic(code, clock);
assert.equal((await f.restart().readRoom(code)).version, pending.version);
assert.equal((await f.restart().readSeatView(code, auths[0])).semutaReaction?.canCommit, true);
const event = pending.pendingTreacheryDiscard!.batch.event;
const claimed = await act(0, { type: 'semutaCommit', event });
assert.equal(claimed.pendingTreacheryDiscard, null);
assert.equal(claimed.auction, null);
assert.equal(claimed.richeseBidding?.stage, 'cacheOffer');
assert.equal(claimed.decision?.kind, 'richeseCache');
assert.equal(seat(claimed, auths[1].playerId).spice, initialSpice);
assert.equal(seat(claimed, auths[1].playerId).hand.filter(card => card.id === lot.id).length, 1);
assert.equal(seat(claimed, auths[0].playerId).hand.filter(card => card.id === karama.id).length, 1);
assert.equal(claimed.discard.filter(card => card.id === semuta.id).length, 1);
await assert.rejects(f.restart().act(code, auths[0], pending.version,
{ type: 'semutaCommit', event }, clock));
assert.deepEqual(f.sqlite.prepare('SELECT * FROM seats').all(), seats);
for (const auth of auths)
assert.deepEqual(await f.restart().readSeatView(code, auth), viewGame(claimed, auth.playerId));
} finally { f.sqlite.close(); }
});
void test('authenticated printed Karama purchase preserves the lot across a saved Semuta claim', async () => {
const f = unitStore();
try {