Offer Semuta before private Ixian ally replacement
This commit is contained in:
1 parent
8f6b1c8463
commit
9bfc3ec037
8 files changed
+246
-34
No files matched your search
@@ -22,10 +22,11 @@ function inventory(g: Game) {
|
||||
assert.equal(new Set(ids).size, ids.length);
|
||||
return ids;
|
||||
}
|
||||
function fixture(ix = false) {
|
||||
function fixture(ix = false, ixianAlly = 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'));
|
||||
joinGame(g, newPlayer('e', ixianAlly ? 'Ixians' : 'Emperor',
|
||||
ixianAlly ? 'ixians' : 'emperor'));
|
||||
for (const p of g.players) { p.bot = 'Medium'; p.ready = true; }
|
||||
g = initializeSemutaGameForAudit(g);
|
||||
for (let step = 0; g.status === 'setup' && step < 80; step++) {
|
||||
@@ -48,6 +49,74 @@ function fixture(ix = false) {
|
||||
return { g, semuta, hajr };
|
||||
}
|
||||
|
||||
void test('private Ixian ally discard offers Semuta before replacement without revealing its face', () => {
|
||||
const { g, semuta, hajr } = fixture(true, true);
|
||||
player(g, 'a').hand = [];
|
||||
g.deck.push(hajr);
|
||||
player(g, 'a').ally = 'e';
|
||||
player(g, 'e').ally = 'a';
|
||||
const 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 absent = reload(g);
|
||||
player(absent, 'r').hand = [take(absent, 'richese-distrans')];
|
||||
absent.richeseCache!.push(semuta);
|
||||
const original = [...inventory(g), lot.id].sort();
|
||||
const offer = (state: Game) => {
|
||||
let next = applyAction(state, 'a', { type: 'bid', amount: 2 });
|
||||
for (const id of ['e', 'r']) next = applyAction(next, id, { type: 'passBid' });
|
||||
if (next.decision?.kind === 'auctionPayment')
|
||||
next = applyAction(next, 'a', { type: 'decision', karama: false });
|
||||
assert.equal(next.decision?.kind, 'ixAllyCard');
|
||||
next = applyAction(next, 'a', { type: 'decision', accept: true });
|
||||
for (let i = 0; next.response?.kind === 'ixAllyCard' && i < 3; i++) {
|
||||
const other = next.players.find(p => !next.response!.passed.includes(p.id))!;
|
||||
next = applyAction(next, other.id, { type: 'passResponse' });
|
||||
}
|
||||
return next;
|
||||
};
|
||||
const pending = offer(g), neutral = offer(absent);
|
||||
const event = pending.pendingTreacheryDiscard!.batch.event;
|
||||
assert.equal(pending.pendingTreacheryDiscard?.continuation.kind, 'ixAllyCard');
|
||||
assert.equal(pending.pendingTreacheryDiscard?.reaction?.stage, 'offer');
|
||||
assert.equal(neutral.pendingTreacheryDiscard?.reaction?.stage, 'offer');
|
||||
assert.equal(pending.pendingTreacheryDiscard?.batch.entries[0].publicFace, false);
|
||||
assert.equal(pending.discard.filter(card => card.id === lot.id).length, 1);
|
||||
assert.equal(pending.deck[0].id, neutral.deck[0].id);
|
||||
assert.equal(player(pending, 'a').hand.some(card => card.id === lot.id), false);
|
||||
assert.deepEqual(viewGame(pending, 'a'), viewGame(neutral, 'a'));
|
||||
assert.deepEqual(viewGame(pending, 'e'), viewGame(neutral, 'e'));
|
||||
assert.equal(viewGame(pending, 'r').semutaReaction?.canCommit, true);
|
||||
assert.deepEqual(normalizeAutomaticGame(reload(pending)), reload(pending));
|
||||
const corrupted = reload(pending);
|
||||
corrupted.pendingTreacheryDiscard!.batch.entries[0].card.name = 'Forged face';
|
||||
const before = JSON.stringify(corrupted);
|
||||
assert.throws(() => applyAction(corrupted, 'r', { type: 'semutaCommit', event }));
|
||||
assert.equal(JSON.stringify(corrupted), before);
|
||||
let declined = reload(pending);
|
||||
for (const id of ['a', 'e', 'r'])
|
||||
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.deepEqual(inventory(state), original);
|
||||
assert.equal(player(state, 'a').spice, player(pending, 'a').spice);
|
||||
assert.equal(player(state, 'a').hand.length, 1);
|
||||
assert.throws(() => applyAction(state, 'r', { type: 'semutaCommit', event }));
|
||||
}
|
||||
assert.equal(declined.discard.filter(card => card.id === lot.id).length, 1);
|
||||
assert.equal(player(claimed, 'r').hand.filter(card => card.id === lot.id).length, 1);
|
||||
assert.equal(claimed.discard.filter(card => card.id === semuta.id).length, 1);
|
||||
});
|
||||
|
||||
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')];
|
||||
|
||||
@@ -4,7 +4,7 @@ import { startPrototypeRoom } from '../tools/prototype-room';
|
||||
import { botActions } from '../game/bots';
|
||||
import { applyAction, createGame, newPlayer, viewGame, type Game, type Action } from '../game/engine';
|
||||
import { SEMUTA_DRUG_ID } from '../game/semuta-drug';
|
||||
import { baseDeck, spiceDeck } from '../game/cards';
|
||||
import { baseDeck, spiceDeck, treacheryDeck } from '../game/cards';
|
||||
import { richeseCards } from '../game/richese-cards';
|
||||
import { unitStore } from './fixture-nexus-room-store';
|
||||
import { saphoAggressorGame, aggressorAction } from './fixture-sapho-aggressor';
|
||||
@@ -728,6 +728,86 @@ void test('authenticated pre-plan Sapho discard restores one aggressor choice be
|
||||
} finally { f.sqlite.close(); }
|
||||
});
|
||||
|
||||
void test('authenticated private Ixian ally discard waits for Semuta before its replacement', async () => {
|
||||
const f = unitStore();
|
||||
try {
|
||||
const made = await f.rooms.createRoom('Semuta Ix ally', 'richese', false, ['choam', 'ix']);
|
||||
const code = made.view.code;
|
||||
const buyer = await f.rooms.joinRoom(code, 'Atreides', 'atreides');
|
||||
const ixians = await f.rooms.joinRoom(code, 'Ixians', 'ixians');
|
||||
const auths = await Promise.all([made.token!, buyer.token!, ixians.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', 'ix']);
|
||||
g.players.push(newPlayer(auths[1].playerId, 'Atreides', 'atreides'),
|
||||
newPlayer(auths[2].playerId, 'Ixians', 'ixians'));
|
||||
Object.assign(g, { status: 'playing', phase: 3, active: auths[1].playerId,
|
||||
order: auths.map(auth => auth.playerId), deck: treacheryDeck(['ix']),
|
||||
richeseCache: richeseCards(), semutaPreview: true });
|
||||
for (const p of g.players) {
|
||||
p.hand = [];
|
||||
p.spice = 20;
|
||||
p.traitors = p.leaders.length ? [p.leaders[0].id] : [];
|
||||
p.traitorChoices = [];
|
||||
}
|
||||
const semuta = take(g, SEMUTA_DRUG_ID), lot = g.deck.shift()!;
|
||||
seat(g, auths[0].playerId).hand.push(semuta);
|
||||
seat(g, auths[1].playerId).ally = auths[2].playerId;
|
||||
seat(g, auths[2].playerId).ally = auths[1].playerId;
|
||||
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 current = await f.restart().readRoom(code);
|
||||
await f.restart().act(code, auths[index], current.version, action, clock);
|
||||
return f.restart().readRoom(code);
|
||||
};
|
||||
await act(1, { type: 'bid', amount: 2 });
|
||||
await act(2, { type: 'passBid' });
|
||||
let next = await act(0, { type: 'passBid' });
|
||||
if (next.decision?.kind === 'auctionPayment')
|
||||
next = await act(1, { type: 'decision', karama: false });
|
||||
assert.equal(next.decision?.kind, 'ixAllyCard');
|
||||
next = await act(1, { type: 'decision', accept: true });
|
||||
for (let i = 0; next.response?.kind === 'ixAllyCard' && i < 3; i++) {
|
||||
const index = auths.findIndex(auth => !next.response!.passed.includes(auth.playerId));
|
||||
next = await act(index, { type: 'passResponse' });
|
||||
}
|
||||
const event = next.pendingTreacheryDiscard!.batch.event;
|
||||
assert.equal(next.pendingTreacheryDiscard?.reaction?.stage, 'offer');
|
||||
assert.equal(next.pendingTreacheryDiscard?.batch.entries[0].publicFace, false);
|
||||
assert.equal(next.discard.filter(card => card.id === lot.id).length, 1);
|
||||
const deckTop = next.deck[0]?.id;
|
||||
const buyerView = await f.restart().readSeatView(code, auths[1]);
|
||||
assert.equal(buyerView.semutaReaction?.canCommit, false);
|
||||
assert.deepEqual(buyerView.semutaReaction?.candidates, []);
|
||||
await f.restart().continueRoomAutomatic(code, clock);
|
||||
assert.equal((await f.restart().readRoom(code)).version, next.version);
|
||||
assert.equal((await f.restart().readSeatView(code, auths[0])).semutaReaction?.canCommit, true);
|
||||
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[0].playerId).hand.filter(card => card.id === lot.id).length, 1);
|
||||
assert.equal(seat(claimed, auths[1].playerId).hand.filter(card => card.id === deckTop).length, 1);
|
||||
assert.equal(claimed.discard.filter(card => card.id === semuta.id).length, 1);
|
||||
await assert.rejects(f.restart().act(code, auths[0], next.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 auction payment resumes one saved Richese cache offer', async () => {
|
||||
const f = unitStore();
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user