Combine Basic bidding and movement commitments
Verify and publish checkpoint container / container (push) Successful in 10m49s

This commit is contained in:
Quintine committed 2026-11-16 15:03:09 +11:00
1 parent b03efd2371
commit 235696263a
9 files changed
+404 -17

No files matched your search

@@ -0,0 +1,62 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { type Game } from '../game/engine';
import {
actMentatBribe as act, createMentatBribeFixture as fixture,
mentatBribeInventory as inventory, mentatBribePlayer as player,
} from './fixture-mentat-bribes';
/** Real Basic setup and Mentat; both separate four-spice debts are accepted
* through public offers and votes before the controlled external loss. */
function withTwoDebts() {
const f = fixture();
let game: Game = f.game;
const debts: string[] = [];
for (let n = 0; n < 2; n++) {
game = act(game, f.asker, {type:'dealOffer', target:f.target, terms:'Pay four spice.',
payment:{kind:'deferredBribe', payer:f.target, recipient:f.asker, amount:4, dueTurn:game.turn}});
const id = game.deals?.at(-1)?.id; assert.ok(id); debts.push(id);
game = act(game, f.target, {type:'dealRespond', deal:id, accept:true});
}
return {f, game, debts};
}
void test('an unrelated insolvency does not block a funded multi-payment deal', () => {
const {f, game:accepted, debts} = withTwoDebts();
const staged = structuredClone(accepted);
const beforeTotal = staged.players.reduce((sum, seat) => sum + seat.spice + seat.bribes, 0);
// Transfer five existing spice to represent a settled external loss. Each
// debt remains individually payable, while their sum no longer fits.
player(staged,f.target).spice -= 5;
player(staged,f.asker).spice += 5;
let game = act(staged, f.opponent, {type:'ready'});
assert.deepEqual(debts.map(id => game.deals!.find(deal => deal.id === id)!.paymentStatus), ['pending','pending']);
const payerBefore = player(game,f.asker).spice, recipientBefore = player(game,f.opponent).bribes;
game = act(game,f.asker,{type:'dealOffer',target:f.opponent,terms:'Two immediate payments.',
payment:{kind:'immediateBribe',payer:f.asker,recipient:f.opponent,amount:1},
additionalImmediatePayments:[{kind:'immediateBribe',payer:f.asker,recipient:f.opponent,amount:1}]});
const id = game.deals?.at(-1)?.id; assert.ok(id);
game = act(game,f.opponent,{type:'dealRespond',deal:id,accept:true});
assert.equal(game.deals!.find(deal => deal.id === id)!.status,'active');
assert.equal(player(game,f.asker).spice,payerBefore-2);
assert.equal(player(game,f.opponent).bribes,recipientBefore+2);
assert.equal(player(game,f.target).spice,5);
assert.deepEqual(debts.map(debt => game.deals!.find(deal => deal.id === debt)!.paymentStatus), ['pending','pending']);
assert.equal(game.players.reduce((sum, seat) => sum + seat.spice + seat.bribes, 0),beforeTotal);
assert.deepEqual(inventory(game),f.originalCards);
});
void test('a payer cannot use the same spice for due debts and immediate payments', () => {
const {f, game:accepted, debts} = withTwoDebts();
const offered = act(accepted,f.asker,{type:'dealOffer',target:f.target,terms:'Two immediate payments.',
payment:{kind:'immediateBribe',payer:f.target,recipient:f.asker,amount:1},
additionalImmediatePayments:[{kind:'immediateBribe',payer:f.target,recipient:f.asker,amount:2}]});
const id = offered.deals?.at(-1)?.id; assert.ok(id);
const before = structuredClone(offered);
assert.throws(() => act(offered,f.target,{type:'dealRespond',deal:id,accept:true}));
assert.deepEqual(offered,before);
assert.equal(offered.deals!.find(deal => deal.id === id)!.status,'offered');
assert.deepEqual(debts.map(debt => offered.deals!.find(deal => deal.id === debt)!.paymentStatus), ['pending','pending']);
assert.equal(player(offered,f.target).spice,10);
assert.deepEqual(inventory(offered),f.originalCards);
});
@@ -69,7 +69,8 @@ void test('controlled Silent ally funding keeps the full pledge locked and resol
game = act(game, 'richese', { type: 'richeseBid', event, amount: loses ? 4 : 0, allyPayment: 0 });
game = advance(game, g => g.phase === 4 && clean(g), [], auction);
assert.equal(owner(game).spice, loses ? 14 : 10 - allyPayment);
assert.equal(game.movementPromises![0].released, !loses && allyPayment === 3 ? true : undefined);
assert.equal(game.movementPromises![0].released, !loses && allyPayment === 3 ? true : undefined,
`loses=${loses}, allyPayment=${allyPayment}`);
}
});
@@ -0,0 +1,45 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { viewGame } from '../game/engine';
import { createTruthMovementNativeEarlyFixture as fixture, actTruthMovementNativeEarly as act,
advanceTruthMovementNativeEarly as advance, truthMovementNativeEarlyClean as clean,
truthMovementNativeEarlyPlayer as player } from './fixture-truth-movement-native-early';
void test('a positive final Silent bid keeps an affordable movement promise through the allied gift window', () => {
const f = fixture(), source = structuredClone(f.game), auction = { method: 'silent' as const };
player(source, f.target).ally = 'choam';
player(source, 'choam').ally = f.target;
let game = act(source, f.asker, f.declarationStep.action);
while (game.truthtrance?.stage === 'priority') {
const seat = game.players.find(p => !game.truthtrance!.passed.includes(p.id));
assert.ok(seat);
game = act(game, seat.id, { type: 'truthPass' });
}
game = act(game, f.asker, { type: 'truthAsk', question: f.claim });
assert.ok(viewGame(game, f.target).truthMovementAnswers!.includes('yes'));
game = advance(act(game, f.target, { type: 'truthAnswer', answer: 'yes' }), clean);
game = advance(game, g => g.phase === 3 && clean(g) && !!g.richeseAuction &&
!g.richeseAuction.outcome, [], auction);
game = act(game, f.target, { type: 'pledgeAid', amount: 8 });
const lot = game.richeseAuction!;
assert.ok(['choam', 'richese', f.target].every(id => lot.eligible.includes(id)));
game = act(game, 'choam', { type: 'richeseBid', event: lot.event, amount: 3, allyPayment: 1 });
for (const id of lot.eligible.filter(id => id !== 'choam' && id !== f.target))
game = act(game, id, { type: 'richeseBid', event: lot.event, amount: 0, allyPayment: 0 });
assert.equal(game.movementPromises![0].released, undefined);
game = act(game, f.target, { type: 'richeseBid', event: lot.event, amount: 1, allyPayment: 0 });
assert.deepEqual(game.richeseAuction?.outcome, { kind: 'sold', winner: 'choam', amount: 3 });
assert.equal(game.pendingEmperorAuctionGift?.owner, f.target);
assert.equal(game.movementPromises![0].released, undefined);
const event = game.pendingEmperorAuctionGift!.event;
game = act(game, f.target, { type: 'emperorAuctionGiftContinue', event });
assert.equal(player(game, f.target).spice, 2);
assert.equal(game.aid[f.target]?.amount, 7);
assert.equal(game.movementPromises![0].released, undefined);
game = advance(game, g => g.phase === 5 && clean(g) && g.active === f.target, [], auction);
assert.equal(player(game, f.target).spice, 9);
game = act(game, f.target, f.shipment);
game = advance(game, clean, [], auction);
game = act(game, f.target, f.move);
assert.equal(game.movementPromises![0].fulfilled, true);
});
@@ -0,0 +1,177 @@
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 and actual opening. Only the
* existing unopened Spice cards are reordered; both Truthtrances are dealt. */
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 kind of ['movement','travel'] as const)
for (const first of ['bid','movement'] as const)
for (const affordable of [true,false]) {
void test(`Basic phase bid and ${kind} 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 move = kind === 'movement'
? {kind:'movement',target:f.target,territory:'carthag',minimum:4}
: {kind:'travel',target:f.target,turn:initial.turn,mixed:{kind:'and',terms:[
{kind:'action',action:{kind:'ship',territory:'arrakeen',minimum:4}},
{kind:'action',action:{kind:'move',territory:'carthag',minimum:4}},
]}};
const questions = first === 'bid' ? [bid,move] : [move,bid];
const movementAnswers = (state:Game) => kind === 'movement'
? viewGame(state,f.target).truthMovementAnswers : viewGame(state,f.target).truthTravelAnswers;
let game = ask(initial,f.asker,f.truths[0],questions[0]);
const firstAnswers = first === 'bid' ? viewGame(game,f.target).truthPhaseBidAnswers : movementAnswers(game);
assert.ok(firstAnswers?.includes('yes'),'Either single commitment is feasible');
game = act(game,f.target,{type:'truthAnswer',answer:'yes'});
game = ask(game,f.asker,f.truths[1],questions[1]);
const answers = first === 'bid' ? movementAnswers(game) : viewGame(game,f.target).truthPhaseBidAnswers;
assert.ok(answers?.includes('no'));
assert.equal(answers?.includes('yes'),affordable,'Bid and physical shipment share the same 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);
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);
const done = applyAction(game,f.target,action);
assert.equal(done.phaseBidPromises?.some(row => row.player === f.target && row.fulfilled),true,
`${difficulty} makes the required legal bid`);
}
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 real winning invoice is paid once');
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} can begin legal travel`);
}
game = advance(act(game,f.target,{type:'ship',territory:'arrakeen',sector:10,amount:4,elite:0,allyPayment:0}),clean);
assert.equal(player(game,f.target).spice,0);
game = advance(act(game,f.target,{type:'move',from:'arrakeen:10',territory:'carthag',sector:11,amount:4}),clean);
assert.equal(player(game,f.target).forces['carthag:11'],4);
assert.equal(kind === 'movement' ? game.movementPromises?.[0]?.fulfilled : game.travelPromises?.[0]?.fulfilled,true);
assert.deepEqual(inventory(game),f.originalCards);
});
}
for (const first of ['bid','expression'] as const) {
void test(`Basic phase bid and grouped movement in ${first}-first order keep a legal bot guide`, () => {
const {f,game:initial} = fixture();
const bid = {kind:'phaseBid',target:f.target,turn:initial.turn,minimum:6};
const expression = {kind:'movementExpression',target:f.target,turn:initial.turn,claim:{kind:'or',terms:[
{kind:'move',territory:'carthag',minimum:4},
{kind:'move',territory:'imperial_basin',minimum:4},
]}};
const questions = first === 'bid' ? [bid,expression] : [expression,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).truthMovementExpressionAnswers;
assert.ok(firstAnswers?.includes('yes'));
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).truthMovementExpressionAnswers
: viewGame(game,f.target).truthPhaseBidAnswers;
assert.ok(answers?.includes('yes'));
game = act(game,f.target,{type:'truthAnswer',answer:'yes'});
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);
const done = applyAction(game,f.target,action);
assert.equal(done.phaseBidPromises?.some(row => row.player === f.target && row.fulfilled),true,
`${difficulty} follows a legal required bid`);
}
game = act(game,f.target,{type:'bid',amount:6,allyPayment:0});
game = advance(game,state => clean(state) && state.phase === 5 && state.active === f.target);
game = advance(act(game,f.target,{type:'ship',territory:'arrakeen',sector:10,amount:4,elite:0,allyPayment:0}),clean);
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} can make a legal movement choice`);
}
game = advance(act(game,f.target,{type:'move',from:'arrakeen:10',territory:'carthag',sector:11,amount:4}),clean);
assert.equal(game.movementExpressionPromises?.[0]?.fulfilled,true);
assert.equal(player(game,f.target).spice,0);
assert.deepEqual(inventory(game),f.originalCards);
});
}
/** The public deal and both Truthtrance answers are real. Only three of the
* Emperor's existing reserve forces are staged into Tanks to create a paid
* Revival need; no cards, spice, accepted promises or force counters are added. */
for (const first of ['bid','revival'] as const) {
void test(`Basic public travel deal, bid and Revival in ${first}-first order retain legal native bot actions`, () => {
const {f,game:initial} = fixture();
player(initial,f.target).reserves -= 3; player(initial,f.target).tanks += 3;
let game = act(initial,f.asker,{type:'dealOffer',target:f.target,terms:'Ship two forces to Arrakeen.',
travel:{kind:'ship',territory:'arrakeen',minimum:2,answer:true}});
const deal = game.deals?.at(-1); assert.ok(deal);
game = act(game,f.target,{type:'dealRespond',deal:deal.id,accept:true});
assert.equal(viewGame(game,f.target).dealTravelStatus[deal.id],'pending');
const bid = {kind:'phaseBid',target:f.target,turn:game.turn,minimum:4};
const revival = {kind:'revival',target:f.target,turn:game.turn,counter:'total',minimum:3};
const questions = first === 'bid' ? [bid,revival] : [revival,bid];
game = ask(game,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'));
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('yes'),'Four bid, four paid Revival and two shipment share ten spice');
game = act(game,f.target,{type:'truthAnswer',answer:'yes'});
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.equal(applyAction(game,f.target,action).phaseBidPromises?.some(row => row.fulfilled),true);
}
game = act(game,f.target,{type:'bid',amount:4,allyPayment:0});
game = advance(game,state => clean(state) && state.phase === 4);
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.equal(action.type,'revive');
assert.equal(applyAction(game,f.target,action).revivalPromises?.some(row => row.fulfilled),true);
}
game = act(game,f.target,{type:'revive',amount:3,elite:0});
game = advance(game,state => clean(state) && state.phase === 5 && state.active === f.target);
game = advance(act(game,f.target,{type:'ship',territory:'arrakeen',sector:10,amount:2,elite:0,allyPayment:0}),clean);
assert.equal(viewGame(game,f.target).dealTravelStatus[deal.id],'fulfilled');
assert.equal(player(game,f.target).spice,0);
assert.deepEqual(inventory(game),f.originalCards);
});
}