Preserve Basic Emperor gifts while Sandtrout waits
Verify and publish checkpoint container / container (push) Successful in 11m36s
Verify and publish checkpoint container / container (push) Successful in 11m36s
This commit is contained in:
1 parent
c86102583f
commit
fac4915cb7
7 files changed
+321
-4
No files matched your search
@@ -0,0 +1,160 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { applyAction, createGame, joinGame, newPlayer, viewGame, type Action, type Game } from '../game/engine';
|
||||
import { territory } from '../game/board';
|
||||
import { beforeIxSpiceDraw, orderIxSpiceCards } from './fixture-ix-spice-cards';
|
||||
import { nextSemutaNexusTradeNativeStep } from './fixture-semuta-nexus-trade';
|
||||
|
||||
const act = (game: Game, actor: string, action: Action) => applyAction(game, actor, action);
|
||||
function seat(game: Game, id: string) { const player = game.players.find(p => p.id === id); assert.ok(player); return player; }
|
||||
const clean = (game: Game) => !game.response && !game.decision && !game.phaseOpening && !game.truthtrance && !game.pendingTreacheryDiscard;
|
||||
function cards(game: Game) {
|
||||
const ids = [...game.deck, ...game.discard, ...(game.richeseCache ?? []), ...(game.richeseRemoved ?? []),
|
||||
...(game.auction?.cards.slice(game.auction.index + Number(game.currentAuctionSale?.origin === 'normal')) ?? []),
|
||||
...(game.ixAuction?.cards ?? []), ...game.players.flatMap(p => p.hand)].map(card => card.id).sort();
|
||||
assert.equal(new Set(ids).size, ids.length); return ids;
|
||||
}
|
||||
function advance(state: Game, until: (game: Game) => boolean): Game {
|
||||
let game = state;
|
||||
for (let n = 0; n < 2000; n++) {
|
||||
if (until(game)) return game;
|
||||
assert.notEqual(game.status, 'finished', 'Native journey must reach the auction');
|
||||
if (game.status === 'setup' && game.setupStage === 'forces' && seat(game, 'ecaz').reserves === 20)
|
||||
game = act(game, 'ecaz', { type: 'ecazSetup', placements: { 'imperial_basin:9': 6 } });
|
||||
else if (game.decision?.kind === 'ecazPlacement' && !game.response && !game.phaseOpening)
|
||||
game = act(game, 'ecaz', { type: 'decision', decline: true });
|
||||
else {
|
||||
const next = nextSemutaNexusTradeNativeStep(game);
|
||||
game = act(game, next.actor, next.action);
|
||||
}
|
||||
}
|
||||
throw Error('Native journey did not reach its auction boundary');
|
||||
}
|
||||
function passResponse(state: Game): Game {
|
||||
let game = state;
|
||||
while (game.response) {
|
||||
const player = game.players.find(p => !game.response!.passed.includes(p.id)); assert.ok(player);
|
||||
game = act(game, player.id, { type: 'passResponse' });
|
||||
}
|
||||
return game;
|
||||
}
|
||||
/** A real first-turn Sandtrout breaks alliances. An Ecaz Ambassador then forms
|
||||
* the Emperor alliance; a land-only second Spice Blow leaves Sandtrout waiting.
|
||||
* Unopened Spice order, conserved board forces, cards and wallets are staged. */
|
||||
function alliance() {
|
||||
let game = createGame('AUCTION-SANDTROUT', newPlayer('ecaz', 'Ecaz', 'ecaz'), false, ['choam', 'ix', 'ecaz']);
|
||||
for (const faction of ['emperor', 'richese', 'choam', 'atreides'] as const)
|
||||
joinGame(game, newPlayer(faction, faction, faction));
|
||||
for (const p of game.players) game = act(game, p.id, { type: 'ready' });
|
||||
game = act(game, 'ecaz', { type: 'start' });
|
||||
game = advance(game, g => g.status === 'playing');
|
||||
const original = cards(game);
|
||||
for (const p of game.players) { p.reserves += Object.values(p.forces).reduce((a, b) => a + b, 0); p.forces = {}; }
|
||||
game = advance(game, beforeIxSpiceDraw); orderIxSpiceCards(game, ['sandtrout', 'land']);
|
||||
game = advance(game, g => g.phase === 4 && !g.response && !g.phaseOpening && g.decision?.kind === 'ecazPlacement');
|
||||
assert.equal(game.sandtrout, true);
|
||||
const location = ['habbanya_ridge_sietch', 'sietch_tabr', 'carthag', 'arrakeen', 'tueks_sietch']
|
||||
.map(id => ({ territory: id, sector: territory(id).sectors.find(s => s !== game.storm) }))
|
||||
.find((row): row is { territory: string; sector: number } => row.sector !== undefined);
|
||||
assert.ok(location);
|
||||
const token = game.ecazAmbassadors!.tokens.find(row => row.effect === 'ecaz'); assert.ok(token);
|
||||
game = act(game, 'ecaz', { type: 'decision', token: token.id, territory: location.territory });
|
||||
game = advance(game, g => g.phase === 5 && clean(g) && g.active === 'emperor');
|
||||
game = act(game, 'emperor', { type: 'ship', amount: 1, ...location });
|
||||
game = advance(game, g => !g.response && g.pendingAmbassador?.stage === 'offer');
|
||||
const event = game.pendingAmbassador!.event;
|
||||
game = act(game, 'ecaz', { type: 'decision', event, trigger: true, beneficiary: 'ecaz', choice: 'alliance' });
|
||||
game = act(game, 'emperor', { type: 'decision', event, accept: true });
|
||||
game = act(game, 'ecaz', { type: 'decision', event, loan: false });
|
||||
assert.equal(seat(game, 'ecaz').ally, 'emperor'); assert.equal(seat(game, 'emperor').ally, 'ecaz');
|
||||
game = advance(game, g => g.turn === 2 && beforeIxSpiceDraw(g));
|
||||
orderIxSpiceCards(game, ['land', 'land']);
|
||||
game = advance(game, g => g.phase === 3 && g.phaseOpening?.initialize === true);
|
||||
assert.equal(game.sandtrout, true);
|
||||
assert.equal(seat(game, 'ecaz').ally, 'emperor');
|
||||
// Leave room for a purchased card and allocate a distinct physical Karama to the countering seat.
|
||||
for (const p of game.players) game.deck.push(...p.hand.splice(0));
|
||||
const index = game.deck.findIndex(card => card.effect === 'karama'); assert.ok(index >= 0);
|
||||
const [counter] = game.deck.splice(index, 1); seat(game, 'atreides').hand.push(counter);
|
||||
seat(game, 'ecaz').spice = 7; seat(game, 'emperor').spice = 8;
|
||||
assert.deepEqual(cards(game), original);
|
||||
return { game, counter: counter.id, original };
|
||||
}
|
||||
function fixture(source: 'onceAround' | 'silent' | 'ordinary') {
|
||||
const result = alliance(); let game = result.game;
|
||||
if (source !== 'ordinary') {
|
||||
game = advance(game, g => g.decision?.kind === 'richeseCache');
|
||||
const card = game.richeseCache![0]; assert.ok(card);
|
||||
game = act(game, 'richese', { type: 'decision', event: game.richeseBidding!.event, card: card.id, method: source,
|
||||
...(source === 'onceAround' ? { direction: 'clockwise' as const } : {}) });
|
||||
game = act(game, 'emperor', { type: 'pledgeAid', amount: 1 });
|
||||
let bid = false;
|
||||
for (let n = 0; !game.pendingEmperorAuctionGift && n < 300; n++) {
|
||||
const lot = game.richeseAuction;
|
||||
if (lot && !lot.outcome && !game.response && !game.decision && lot.method === 'onceAround' && lot.active) {
|
||||
const buyer = lot.active === 'ecaz' && !bid;
|
||||
game = act(game, lot.active, { type: 'richeseBid', event: lot.event, amount: buyer ? 3 : null,
|
||||
...(buyer ? { allyPayment: 1 } : {}) });
|
||||
if (buyer) bid = true;
|
||||
} else if (lot && !lot.outcome && !game.response && !game.decision && lot.method === 'silent') {
|
||||
const actor = lot.eligible.find(id => !Object.hasOwn(lot.sealed, id)); assert.ok(actor);
|
||||
const buyer = actor === 'ecaz' && !bid;
|
||||
game = act(game, actor, { type: 'richeseBid', event: lot.event, amount: buyer ? 3 : 0,
|
||||
...(buyer ? { allyPayment: 1 } : {}) });
|
||||
if (buyer) bid = true;
|
||||
} else { const next = nextSemutaNexusTradeNativeStep(game); game = act(game, next.actor, next.action); }
|
||||
}
|
||||
assert.ok(bid); assert.ok(game.pendingEmperorAuctionGift, 'The original cache sale exposes an Emperor opportunity');
|
||||
return { ...result, game, card: card.id };
|
||||
}
|
||||
game = advance(game, g => g.phase === 3 && !!g.auction && !g.richeseAuction && clean(g));
|
||||
while (game.auction!.active !== 'ecaz') game = act(game, game.auction!.active, { type: 'passBid' });
|
||||
const card = game.auction!.cards[game.auction!.index].id;
|
||||
game = act(game, 'emperor', { type: 'pledgeAid', amount: 1 });
|
||||
game = act(game, 'ecaz', { type: 'bid', amount: 3, allyPayment: 1 });
|
||||
for (let n = 0; game.auction && !game.response && !game.decision && n < 15; n++)
|
||||
game = act(game, game.auction.active, { type: 'passBid' });
|
||||
assert.equal(game.decision?.kind, 'auctionPayment');
|
||||
assert.ok(game.pendingEmperorAuctionGift, 'The original ordinary auction exposes an Emperor opportunity');
|
||||
return { ...result, game, card };
|
||||
}
|
||||
|
||||
for (const source of ['onceAround', 'silent', 'ordinary'] as const) for (const cancel of [false, true]) void test(
|
||||
`Basic ${source} auction Emperor gift with genuine waiting Sandtrout ${cancel ? 'cancels' : 'allows'} and continues`, () => {
|
||||
const f = fixture(source), before = structuredClone(f.game);
|
||||
const offer = viewGame(f.game, 'emperor').emperorAuctionGift; assert.ok(offer);
|
||||
assert.equal(offer.recipient, 'ecaz');
|
||||
assert.equal(before.aid.emperor?.amount, 1);
|
||||
if (source === 'ordinary') {
|
||||
assert.equal(before.auction?.bid, 3); assert.equal(before.auction?.allyPayment, 1);
|
||||
} else assert.ok(before.richeseFunding?.ecaz);
|
||||
let game = act(f.game, 'emperor', { type: 'emperorGift', amount: 2 });
|
||||
if (cancel) {
|
||||
game = act(game, 'atreides', { type: 'card', mode: 'cancel', card: f.counter });
|
||||
if (game.pendingKull) game = act(game, 'choam', { type: 'kullDecision', event: game.pendingKull.event, decline: true });
|
||||
while (game.pendingTreacheryDiscard?.reaction?.stage === 'offer') {
|
||||
const reaction = game.pendingTreacheryDiscard.reaction;
|
||||
const player = game.players.find(p => !reaction.passed.includes(p.id)); assert.ok(player);
|
||||
game = act(game, player.id, { type: 'semutaPass', event: game.pendingTreacheryDiscard.batch.event });
|
||||
}
|
||||
} else game = passResponse(game);
|
||||
assert.equal(game.sandtrout, true);
|
||||
assert.equal(seat(game, 'ecaz').spice, seat(before, 'ecaz').spice + (cancel ? 0 : 2));
|
||||
assert.equal(seat(game, 'emperor').spice, seat(before, 'emperor').spice - (cancel ? 0 : 2));
|
||||
assert.deepEqual(game.richeseAuction, before.richeseAuction); assert.deepEqual(game.auction, before.auction);
|
||||
assert.deepEqual(game.richeseFunding, before.richeseFunding); assert.deepEqual(game.aid, before.aid);
|
||||
assert.equal(viewGame(game, 'emperor').emperorAuctionGift?.event, offer.event);
|
||||
game = act(game, 'emperor', { type: 'emperorAuctionGiftContinue', event: offer.event });
|
||||
if (game.decision?.kind === 'auctionPayment') game = act(game, 'ecaz', { type: 'decision', karama: false });
|
||||
game = passResponse(game);
|
||||
assert.ok(seat(game, 'ecaz').hand.some(card => card.id === f.card));
|
||||
assert.equal(seat(game, 'ecaz').spice, seat(before, 'ecaz').spice + (cancel ? 0 : 2) - 2);
|
||||
assert.equal(game.aid.emperor?.amount ?? 0, 0);
|
||||
if (source === 'ordinary')
|
||||
assert.equal(seat(game, 'emperor').spice, seat(before, 'emperor').spice - (cancel ? 0 : 2) + 3);
|
||||
else {
|
||||
assert.equal(seat(game, 'emperor').spice, seat(before, 'emperor').spice - (cancel ? 0 : 2));
|
||||
assert.equal(seat(game, 'richese').spice, seat(before, 'richese').spice + 3);
|
||||
}
|
||||
assert.equal(game.sandtrout, true); assert.deepEqual(cards(game), f.original);
|
||||
});
|
||||
@@ -0,0 +1,123 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { applyAction, createGame, joinGame, newPlayer, viewGame, type Action, type Game } from '../game/engine';
|
||||
import { territory } from '../game/board';
|
||||
import { botActions, runBots } from '../game/bots';
|
||||
import { DIFFICULTIES } from '../game/bot-profiles';
|
||||
import { beforeIxSpiceDraw, orderIxSpiceCards } from './fixture-ix-spice-cards';
|
||||
import { nextStrongholdFactionsNativeStep } from './fixture-stronghold-factions';
|
||||
import { truthTurnAmalInventory as inventory } from './fixture-truth-turn-amal';
|
||||
|
||||
const act = (game: Game, id: string, action: Action) => applyAction(game, id, action);
|
||||
function seat(game: Game, id: string) {
|
||||
const player = game.players.find(row => row.id === id); assert.ok(player); return player;
|
||||
}
|
||||
function advance(game: Game, until: (state: Game) => boolean): Game {
|
||||
for (let n = 0; n < 2000; n++) {
|
||||
if (until(game)) return game;
|
||||
assert.notEqual(game.status, 'finished');
|
||||
if (game.status === 'setup' && game.setupStage === 'forces' && seat(game, 'ecaz').reserves === 20)
|
||||
game = act(game, 'ecaz', {type:'ecazSetup', placements:{'imperial_basin:9':6}});
|
||||
else if (game.decision?.kind === 'ecazPlacement' && !game.response && !game.phaseOpening)
|
||||
game = act(game, 'ecaz', {type:'decision', decline:true});
|
||||
else {
|
||||
const next = nextStrongholdFactionsNativeStep(game); assert.ok(next, `No continuation at ${game.phase}/${game.decision?.kind}`);
|
||||
game = act(game, next.actor, next.action);
|
||||
}
|
||||
}
|
||||
throw Error('Did not reach the requested native opening');
|
||||
}
|
||||
function passResponses(game: Game): Game {
|
||||
for (let n = 0; game.response && n < 20; n++) {
|
||||
const actor = game.players.find(player => !game.response!.passed.includes(player.id)); assert.ok(actor);
|
||||
game = act(game, actor.id, {type:'passResponse'});
|
||||
}
|
||||
assert.equal(game.response, null); return game;
|
||||
}
|
||||
|
||||
/** Original public Basic Ecaz/Ix setup, real Sandtrout draw and actual Ecaz
|
||||
* Ambassador alliance before the next opening. Only the unopened Spice prefix,
|
||||
* conserved initial board forces and the counter card's physical custody are
|
||||
* staged; neither the waiting flag nor the alliance is installed directly. */
|
||||
function fixture() {
|
||||
let game = createGame('OPENINGSANDTROUT', newPlayer('ecaz','Ecaz','ecaz'), false, ['ecaz','ix']);
|
||||
for (const id of ['emperor','atreides','guild'] as const) joinGame(game, newPlayer(id,id,id));
|
||||
for (const player of game.players) game = act(game, player.id, {type:'ready'});
|
||||
game = act(game, 'ecaz', {type:'start'});
|
||||
game = advance(game, state => state.status === 'playing');
|
||||
for (const player of game.players) {
|
||||
player.reserves += Object.values(player.forces).reduce((sum, count) => sum + count, 0);
|
||||
player.forces = {};
|
||||
}
|
||||
game = advance(game, beforeIxSpiceDraw);
|
||||
orderIxSpiceCards(game, ['sandtrout','land']);
|
||||
game = advance(game, state => state.phase === 4 && !state.response && !state.phaseOpening && state.decision?.kind === 'ecazPlacement');
|
||||
assert.equal(game.sandtrout, true);
|
||||
const spot = ['habbanya_ridge_sietch','sietch_tabr','carthag','arrakeen','tueks_sietch']
|
||||
.map(id => ({territory:id, sector:territory(id).sectors.find(sector => sector !== game.storm)}))
|
||||
.find((row): row is {territory:string; sector:number} => row.sector !== undefined);
|
||||
assert.ok(spot);
|
||||
const ambassador = game.ecazAmbassadors!.tokens.find(row => row.effect === 'ecaz'); assert.ok(ambassador);
|
||||
game = act(game, 'ecaz', {type:'decision', token:ambassador.id, territory:spot.territory});
|
||||
game = advance(game, state => !state.response && state.decision?.kind === 'ecazPlacement');
|
||||
game = act(game, 'ecaz', {type:'decision', decline:true});
|
||||
game = advance(game, state => state.phase === 5 && state.active === 'emperor' && !state.response && !state.decision && !state.phaseOpening);
|
||||
game = act(game, 'emperor', {type:'ship', amount:1, territory:spot.territory, sector:spot.sector});
|
||||
game = advance(game, state => !state.response && state.pendingAmbassador?.stage === 'offer');
|
||||
const event = game.pendingAmbassador!.event;
|
||||
game = act(game, 'ecaz', {type:'decision', event, trigger:true, beneficiary:'ecaz', choice:'alliance'});
|
||||
game = act(game, 'emperor', {type:'decision', event, accept:true});
|
||||
assert.equal(game.pendingAmbassador?.stage, 'loan');
|
||||
game = act(game, 'ecaz', {type:'decision', event, loan:false});
|
||||
assert.equal(seat(game, 'ecaz').ally, 'emperor'); assert.equal(seat(game, 'emperor').ally, 'ecaz');
|
||||
game = advance(game, state => state.phase === 6 && !!state.phaseOpening);
|
||||
assert.equal(game.sandtrout, true); assert.ok(game.phaseOpening);
|
||||
const original = inventory(game), guild = seat(game, 'guild');
|
||||
let counter = guild.hand.find(card => card.effect === 'karama');
|
||||
if (!counter) {
|
||||
const source = game.players.find(player => player.id !== 'guild' && player.hand.some(card => card.effect === 'karama'))?.hand ?? game.deck;
|
||||
const index = source.findIndex(card => card.effect === 'karama'); assert.ok(index >= 0);
|
||||
if (guild.hand.length >= 4) game.deck.push(guild.hand.pop()!);
|
||||
[counter] = source.splice(index, 1); guild.hand.push(counter);
|
||||
}
|
||||
assert.deepEqual(inventory(game), original);
|
||||
game = act(game, 'emperor', {type:'ready'});
|
||||
game = act(game, 'ecaz', {type:'ready'});
|
||||
return {game, original, counter:counter.id};
|
||||
}
|
||||
|
||||
for (const cancel of [false, true]) void test(`Basic phase-opening gift with waiting Sandtrout ${cancel ? 'cancels' : 'settles'} and resumes`, () => {
|
||||
const f = fixture(), before = structuredClone(f.game), opening = structuredClone(f.game.phaseOpening);
|
||||
const owner = seat(f.game, 'emperor').spice, ally = seat(f.game, 'ecaz').spice;
|
||||
assert.ok(owner >= 1);
|
||||
assert.deepEqual(viewGame(f.game, 'emperor').emperorPhaseOpeningGift, {recipient:'ecaz', maximum:owner});
|
||||
assert.equal(viewGame(f.game, 'ecaz').emperorPhaseOpeningGift, null);
|
||||
assert.equal(viewGame(f.game, 'guild').emperorPhaseOpeningGift, null);
|
||||
let game = act(f.game, 'emperor', {type:'emperorGift', amount:1});
|
||||
assert.equal(game.response?.kind, 'emperorGift'); assert.equal(game.phaseOpening, null);
|
||||
game = cancel ? act(game, 'guild', {type:'card', card:f.counter, mode:'cancel'}) : passResponses(game);
|
||||
assert.deepEqual(game.phaseOpening, opening);
|
||||
assert.equal(game.phase, before.phase); assert.equal(game.turn, before.turn);
|
||||
assert.equal(seat(game, 'emperor').spice, owner - Number(!cancel));
|
||||
assert.equal(seat(game, 'ecaz').spice, ally + Number(!cancel));
|
||||
assert.equal(game.sandtrout, true); assert.deepEqual(inventory(game), f.original);
|
||||
game = act(game, 'atreides', {type:'ready'});
|
||||
game = act(game, 'guild', {type:'ready'});
|
||||
assert.notEqual(game.phase, before.phase); assert.equal(game.sandtrout, true);
|
||||
});
|
||||
|
||||
void test('all bot levels preserve the human Emperor opening opportunity while Sandtrout waits', () => {
|
||||
const f = fixture();
|
||||
const initial = act(f.game, 'atreides', {type:'ready'});
|
||||
for (const difficulty of DIFFICULTIES) {
|
||||
let game = structuredClone(initial); seat(game, 'guild').bot = difficulty;
|
||||
const priority = viewGame(game, 'emperor').emperorPhaseOpeningPriority;
|
||||
assert.ok(priority?.canContinue); assert.equal(priority.recipient, 'ecaz');
|
||||
assert.ok(!botActions(viewGame(game, 'guild')).some(action => action.type === 'ready'));
|
||||
const waiting = runBots(game, 2); assert.deepEqual(waiting.phaseOpening, game.phaseOpening);
|
||||
game = act(game, 'emperor', {type:'emperorPhaseOpeningContinue', event:priority.event});
|
||||
const action = botActions(viewGame(game, 'guild')).find(row => row.type === 'ready');
|
||||
assert.ok(action, difficulty); game = act(game, 'guild', action);
|
||||
assert.notEqual(game.phase, initial.phase); assert.equal(game.sandtrout, true);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user