Compose Basic bid revival and shipment commitments
Verify and publish checkpoint container / container (push) Successful in 10m33s
Verify and publish checkpoint container / container (push) Successful in 10m33s
This commit is contained in:
1 parent
c3e13a2525
commit
9536c77062
7 files changed
+328
-15
No files matched your search
@@ -10,7 +10,7 @@ export const futureShipmentPlayer = (game: Game, actor = 'emperor') => {
|
||||
const player = game.players.find(player => player.id === actor); assert.ok(player); return player;
|
||||
};
|
||||
export const futureShipmentClean = (game: Game) => !game.response && !game.phaseOpening &&
|
||||
!game.decision && !game.truthtrance && !game.pendingTreacheryDiscard;
|
||||
!game.decision && !game.truthtrance && !game.pendingTreacheryDiscard && !game.pendingEmperorAuctionGift;
|
||||
export function actFutureShipment(game: Game, actor: string, action: Action, actions: FutureShipmentStep[] = []): Game {
|
||||
const next = withClassicDiscoveryNexusLottery(() => applyAction(game, actor, action));
|
||||
actions.push({ actor, action: structuredClone(action) }); return next;
|
||||
@@ -23,6 +23,10 @@ export function nextFutureShipmentStep(game: Game): FutureShipmentStep | null {
|
||||
const actor = game.players.find(player => !game.truthtrance!.passed.includes(player.id)); assert.ok(actor);
|
||||
return { actor: actor.id, action: { type: 'truthPass' } };
|
||||
}
|
||||
if (game.pendingEmperorAuctionGift && !game.response && !game.pendingKarama && !game.pendingKull)
|
||||
return { actor: game.pendingEmperorAuctionGift.owner, action: {
|
||||
type: 'emperorAuctionGiftContinue', event: game.pendingEmperorAuctionGift.event,
|
||||
} };
|
||||
if (!game.response && !game.phaseOpening && !game.pendingTreacheryDiscard && game.decision?.kind === 'guildTiming')
|
||||
return { actor: game.decision.player, action: { type: 'decision', take: false } };
|
||||
return nextStrongholdFactionsNativeStep(game);
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { viewGame, type Game } from '../game/engine';
|
||||
import { actTruthBid as act, advanceTruthBid as advance, truthBidClean as clean,
|
||||
truthBidInventory as inventory, truthBidPlayer as player } from './fixture-truth-bid';
|
||||
import { advanceTruthRevival, truthRevivalClean } from './fixture-truth-revival';
|
||||
import { createTruthTurnBidFixture } from './fixture-truth-turn-bid';
|
||||
|
||||
/** Real public Harkonnen/Atreides/Emperor setup. The unopened Spice order is
|
||||
* staged; Emperor's existing leader discs are all moved to their first death
|
||||
* cohort and three existing reserve forces to Tanks. */
|
||||
function fixture() {
|
||||
const f = createTruthTurnBidFixture();
|
||||
let game = structuredClone(f.afterSetup);
|
||||
for (const {position, from, card} of f.spiceOrder) {
|
||||
const [selected] = game.spiceDeck.splice(from, 1);
|
||||
assert.deepEqual(selected, card);
|
||||
game.spiceDeck.splice(position, 0, selected);
|
||||
}
|
||||
game = advance(game, state => state.turn === 1 && state.phase === 2 && clean(state));
|
||||
const emperor = player(game, f.target);
|
||||
assert.equal(emperor.spice, 10);
|
||||
const leader = emperor.leaders.find(row => row.strength === 2); assert.ok(leader);
|
||||
for (const disc of emperor.leaders) { disc.dead = true; disc.deaths = 1; }
|
||||
emperor.reserves -= 3; emperor.tanks += 3;
|
||||
assert.deepEqual(inventory(game), f.originalCards);
|
||||
return { f, game, leader: leader.id };
|
||||
}
|
||||
|
||||
function ask(game: Game, asker: string, card: string, question: object): Game {
|
||||
game = act(game, asker, {type:'card', card});
|
||||
for (let count = 0; game.truthtrance?.stage === 'priority' && count < game.players.length; count++) {
|
||||
const seat = game.players.find(row => !game.truthtrance!.passed.includes(row.id)); assert.ok(seat);
|
||||
game = act(game, seat.id, {type:'truthPass'});
|
||||
}
|
||||
assert.equal(game.truthtrance?.stage, 'ask');
|
||||
return act(game, asker, {type:'truthAsk', question});
|
||||
}
|
||||
|
||||
for (const mode of ['leader', 'expression'] as const)
|
||||
for (const first of ['bid', 'revival'] as const)
|
||||
for (const affordable of [true, false]) {
|
||||
void test(`Basic phase bid and ${mode} in ${first}-first order ${affordable ? 'share enough spice' : 'cannot overcommit spice'}`, () => {
|
||||
const { f, game: initial, leader } = fixture();
|
||||
const minimum = (mode === 'leader' ? 8 : 4) + Number(!affordable);
|
||||
const bid = {kind:'phaseBid', target:f.target, turn:initial.turn, minimum};
|
||||
const revival = mode === 'leader'
|
||||
? {kind:'leaderRevival', target:f.target, turn:initial.turn, leader}
|
||||
: {kind:'revivalExpression', target:f.target, turn:initial.turn, claim: {kind:'and', terms:[
|
||||
{kind:'forces', counter:'total', minimum:3}, {kind:'leader', leader},
|
||||
]}};
|
||||
const questions = first === 'bid' ? [bid, revival] : [revival, bid];
|
||||
const revivalAnswers = (state: Game) => mode === 'leader'
|
||||
? viewGame(state,f.target).truthLeaderRevivalAnswers
|
||||
: viewGame(state,f.target).truthRevivalExpressionAnswers;
|
||||
let game = ask(initial, f.asker, f.truths[0], questions[0]);
|
||||
const firstAnswers = first === 'bid' ? viewGame(game,f.target).truthPhaseBidAnswers : revivalAnswers(game);
|
||||
assert.ok(firstAnswers?.includes('yes'), 'Each single commitment is independently feasible');
|
||||
game = act(game,f.target,{type:'truthAnswer',answer:'yes'});
|
||||
game = ask(game,f.asker,f.truths[1],questions[1]);
|
||||
const secondAnswers = first === 'bid' ? revivalAnswers(game) : viewGame(game,f.target).truthPhaseBidAnswers;
|
||||
assert.ok(secondAnswers?.includes('no'));
|
||||
assert.equal(secondAnswers?.includes('yes'), affordable, 'Bid and full return share the same owned spice');
|
||||
if (!affordable) {
|
||||
const before = structuredClone(game);
|
||||
assert.throws(() => act(game,f.target,{type:'truthAnswer',answer:'yes'}));
|
||||
assert.deepEqual(game,before);
|
||||
return;
|
||||
}
|
||||
game = act(game,f.target,{type:'truthAnswer',answer:'yes'});
|
||||
game = advance(game,state => clean(state) && state.phase === 3 && state.auction?.active === f.target);
|
||||
game = act(game,f.target,{type:'bid',amount:minimum,allyPayment:0});
|
||||
game = advance(game,state => clean(state) && state.phase === 4);
|
||||
assert.equal(player(game,f.target).spice, mode === 'leader' ? 2 : 6);
|
||||
game = act(game,f.target,{type:'reviveLeader',leader});
|
||||
game = advanceTruthRevival(game,truthRevivalClean);
|
||||
assert.equal(player(game,f.target).leaders.find(row => row.id === leader)?.dead,false);
|
||||
if (mode === 'expression') {
|
||||
game = act(game,f.target,{type:'revive',amount:3,elite:0});
|
||||
game = advanceTruthRevival(game,truthRevivalClean);
|
||||
assert.ok(game.revivalExpressionPromises?.some(row => row.player === f.target && row.fulfilled));
|
||||
assert.equal(player(game,f.target).tanks,0);
|
||||
} else assert.ok(game.leaderRevivalPromises?.some(row => row.player === f.target && row.fulfilled));
|
||||
assert.equal(player(game,f.target).spice,0);
|
||||
assert.ok(game.phaseBidPromises?.some(row => row.player === f.target && row.fulfilled));
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { viewGame, type Game } from '../game/engine';
|
||||
import { actTruthBid as act, advanceTruthBid as advance, truthBidClean as clean,
|
||||
truthBidInventory as inventory, truthBidPlayer as player } from './fixture-truth-bid';
|
||||
import { advanceTruthRevival, truthRevivalClean } from './fixture-truth-revival';
|
||||
import { createTruthTurnBidFixture } from './fixture-truth-turn-bid';
|
||||
|
||||
/** Public H/A/E Basic setup and real turn-1 Charity. Because Basic has only
|
||||
* two physical Truthtrances, one earlier shipment Yes is explicitly staged;
|
||||
* the bid and revival commitments are asked and answered through real cards.
|
||||
* Three existing reserves are moved to Tanks, and unopened Spice is ordered. */
|
||||
function fixture() {
|
||||
const f = createTruthTurnBidFixture();
|
||||
let game = structuredClone(f.afterSetup);
|
||||
for (const {position, from, card} of f.spiceOrder) {
|
||||
const [selected] = game.spiceDeck.splice(from, 1);
|
||||
assert.deepEqual(selected, card);
|
||||
game.spiceDeck.splice(position, 0, selected);
|
||||
}
|
||||
game = advance(game,state => state.turn === 1 && state.phase === 2 && clean(state));
|
||||
const emperor = player(game,f.target);
|
||||
assert.equal(emperor.spice,10); assert.ok(emperor.reserves >= 3);
|
||||
emperor.reserves -= 3; emperor.tanks += 3;
|
||||
game.shipmentPromises = [{turn:game.turn,player:f.target,asker:f.asker,
|
||||
territory:'carthag',minimum:2,answer:true}];
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
return {f,game};
|
||||
}
|
||||
|
||||
function ask(game: Game, asker: string, card: string, question: object): Game {
|
||||
game = act(game,asker,{type:'card',card});
|
||||
for (let count = 0; game.truthtrance?.stage === 'priority' && count < game.players.length; count++) {
|
||||
const seat = game.players.find(row => !game.truthtrance!.passed.includes(row.id)); assert.ok(seat);
|
||||
game = act(game,seat.id,{type:'truthPass'});
|
||||
}
|
||||
assert.equal(game.truthtrance?.stage,'ask');
|
||||
return act(game,asker,{type:'truthAsk',question});
|
||||
}
|
||||
|
||||
for (const first of ['bid','revival'] as const) for (const affordable of [true,false]) {
|
||||
void test(`Basic pre-Bidding bid, Revival and staged shipment share a purse in ${first}-first order (${affordable ? 'funded' : 'one short'})`, () => {
|
||||
const {f,game:initial} = fixture();
|
||||
const minimum = affordable ? 4 : 5;
|
||||
const bid = {kind:'phaseBid',target:f.target,turn:initial.turn,minimum};
|
||||
const revival = {kind:'revival',target:f.target,turn:initial.turn,counter:'total',minimum:3};
|
||||
const questions = first === 'bid' ? [bid,revival] : [revival,bid];
|
||||
let game = ask(initial,f.asker,f.truths[0],questions[0]);
|
||||
const firstAnswers = first === 'bid' ? viewGame(game,f.target).truthPhaseBidAnswers : viewGame(game,f.target).truthRevivalAnswers;
|
||||
assert.ok(firstAnswers?.includes('yes'), 'The first answer and earlier shipment fit the purse');
|
||||
game = act(game,f.target,{type:'truthAnswer',answer:'yes'});
|
||||
game = ask(game,f.asker,f.truths[1],questions[1]);
|
||||
const answers = first === 'bid' ? viewGame(game,f.target).truthRevivalAnswers : viewGame(game,f.target).truthPhaseBidAnswers;
|
||||
assert.ok(answers?.includes('no'));
|
||||
assert.equal(answers?.includes('yes'),affordable, 'A bid, two paid returns and two shipped forces cost the same 10-spice purse');
|
||||
if (!affordable) {
|
||||
const before = structuredClone(game);
|
||||
assert.throws(() => act(game,f.target,{type:'truthAnswer',answer:'yes'}));
|
||||
assert.deepEqual(game,before);
|
||||
return;
|
||||
}
|
||||
game = act(game,f.target,{type:'truthAnswer',answer:'yes'});
|
||||
game = advance(game,state => clean(state) && state.phase === 3 && state.auction?.active === f.target);
|
||||
game = act(game,f.target,{type:'bid',amount:4,allyPayment:0});
|
||||
assert.ok(game.phaseBidPromises?.some(row => row.player === f.target && row.fulfilled));
|
||||
game = advance(game,state => clean(state) && state.phase === 4);
|
||||
assert.equal(player(game,f.target).spice,6);
|
||||
game = act(game,f.target,{type:'revive',amount:3,elite:0});
|
||||
game = advanceTruthRevival(game,truthRevivalClean);
|
||||
assert.equal(player(game,f.target).spice,2);
|
||||
assert.ok(game.revivalPromises?.some(row => row.player === f.target && row.fulfilled));
|
||||
game = advance(game,state => clean(state) && state.phase === 5 && state.active === f.target);
|
||||
const ship = viewGame(game,f.target).shipmentCompletion?.actions.at(-1);
|
||||
assert.ok(ship && ship.type === 'ship'); assert.equal(ship.amount,2);
|
||||
game = act(game,f.target,ship);
|
||||
game = advance(game,state => clean(state) && !!state.shipmentPromises?.some(row => row.player === f.target && row.fulfilled));
|
||||
assert.equal(player(game,f.target).spice,0);
|
||||
assert.equal(player(game,f.target).forces['carthag:11'],2);
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { applyAction, viewGame, type Game } from '../game/engine';
|
||||
import { botActions } from '../game/bots';
|
||||
import { DIFFICULTIES } from '../game/bot-profiles';
|
||||
import { actTruthBid as act, advanceTruthBid as advance, truthBidClean as clean,
|
||||
truthBidInventory as inventory, truthBidPlayer as player } from './fixture-truth-bid';
|
||||
import { createTruthTurnBidFixture } from './fixture-truth-turn-bid';
|
||||
|
||||
/** Public Basic Harkonnen/Atreides/Emperor setup. The two Truthtrances and
|
||||
* initial purses are genuinely dealt; only unopened Spice order is staged. */
|
||||
function fixture() {
|
||||
const f = createTruthTurnBidFixture();
|
||||
let game = structuredClone(f.afterSetup);
|
||||
for (const {position, from, card} of f.spiceOrder) {
|
||||
const [selected] = game.spiceDeck.splice(from, 1);
|
||||
assert.deepEqual(selected, card);
|
||||
game.spiceDeck.splice(position, 0, selected);
|
||||
}
|
||||
game = advance(game, state => state.turn === 1 && state.phase === 2 && clean(state));
|
||||
assert.equal(player(game, f.target).spice, 10);
|
||||
assert.ok(player(game, f.target).reserves >= 4);
|
||||
assert.deepEqual(inventory(game), f.originalCards);
|
||||
return {f, game};
|
||||
}
|
||||
|
||||
function ask(game: Game, asker: string, card: string, question: object): Game {
|
||||
game = act(game, asker, {type:'card', card});
|
||||
for (let count = 0; game.truthtrance?.stage === 'priority' && count < game.players.length; count++) {
|
||||
const seat = game.players.find(row => !game.truthtrance!.passed.includes(row.id)); assert.ok(seat);
|
||||
game = act(game, seat.id, {type:'truthPass'});
|
||||
}
|
||||
assert.equal(game.truthtrance?.stage, 'ask');
|
||||
return act(game, asker, {type:'truthAsk', question});
|
||||
}
|
||||
|
||||
for (const first of ['bid', 'shipment'] as const) for (const affordable of [true, false]) {
|
||||
void test(`Basic phase bid and paid shipment in ${first}-first order ${affordable ? 'share enough spice' : 'cannot overcommit spice'}`, () => {
|
||||
const {f, game: initial} = fixture();
|
||||
const bid = {kind:'phaseBid', target:f.target, turn:initial.turn, minimum:affordable ? 6 : 7};
|
||||
const shipment = {kind:'shipment', target:f.target, territory:'carthag', minimum:4};
|
||||
const questions = first === 'bid' ? [bid, shipment] : [shipment, bid];
|
||||
let game = ask(initial, f.asker, f.truths[0], questions[0]);
|
||||
const firstAnswers = first === 'bid' ? viewGame(game, f.target).truthPhaseBidAnswers : viewGame(game, f.target).truthShipmentAnswers;
|
||||
assert.ok(firstAnswers?.includes('yes'), 'Each single obligation is feasible by itself');
|
||||
game = act(game, f.target, {type:'truthAnswer', answer:'yes'});
|
||||
game = ask(game, f.asker, f.truths[1], questions[1]);
|
||||
const secondAnswers = first === 'bid' ? viewGame(game, f.target).truthShipmentAnswers : viewGame(game, f.target).truthPhaseBidAnswers;
|
||||
assert.ok(secondAnswers?.includes('no'));
|
||||
assert.equal(secondAnswers?.includes('yes'), affordable, 'The same spice cannot fund the bid and shipment twice');
|
||||
if (!affordable) {
|
||||
const before = structuredClone(game);
|
||||
assert.throws(() => act(game, f.target, {type:'truthAnswer', answer:'yes'}));
|
||||
assert.deepEqual(game, before);
|
||||
return;
|
||||
}
|
||||
game = act(game, f.target, {type:'truthAnswer', answer:'yes'});
|
||||
assert.equal(game.truthtrance, null);
|
||||
const withoutPromises = structuredClone(game);
|
||||
withoutPromises.phaseBidPromises = [];
|
||||
withoutPromises.shipmentPromises = [];
|
||||
assert.doesNotThrow(() => act(withoutPromises, f.target, {type:'bribe', target:f.asker, amount:1}));
|
||||
const beforeSpend = structuredClone(game);
|
||||
assert.throws(() => act(game, f.target, {type:'bribe', target:f.asker, amount:1}));
|
||||
assert.deepEqual(game, beforeSpend);
|
||||
game = advance(game, state => clean(state) && state.phase === 3 && state.auction?.active === f.target);
|
||||
for (const difficulty of DIFFICULTIES) {
|
||||
const view = viewGame(game, f.target); view.players.find(row => row.id === f.target)!.bot = difficulty;
|
||||
const action = botActions(view)[0]; assert.ok(action);
|
||||
assert.doesNotThrow(() => applyAction(game, f.target, action), `${difficulty} retains a legal bid response`);
|
||||
}
|
||||
game = act(game, f.target, {type:'bid', amount:6, allyPayment:0});
|
||||
assert.ok(game.phaseBidPromises?.some(row => row.player === f.target && row.fulfilled));
|
||||
game = advance(game, state => clean(state) && state.phase === 5 && state.active === f.target);
|
||||
assert.equal(player(game, f.target).spice, 4, 'The original winning bid is paid once');
|
||||
const action = viewGame(game, f.target).shipmentCompletion?.actions.at(-1);
|
||||
assert.ok(action && action.type === 'ship'); assert.equal(action.amount, 4);
|
||||
game = act(game, f.target, action);
|
||||
game = advance(game, state => clean(state) && !!state.shipmentPromises?.some(row => row.player === f.target && row.fulfilled));
|
||||
assert.equal(player(game, f.target).spice, 0);
|
||||
assert.equal(player(game, f.target).forces['carthag:11'], 4);
|
||||
assert.deepEqual(inventory(game), f.originalCards);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user