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
@@ -17,6 +17,15 @@ open mode gates.
|
||||
|
||||
## Current checkpoint and work
|
||||
|
||||
**Basic phase-bid, Revival and Shipment commitments — 16 November. Prototyped /
|
||||
Partial.** The owned-cash witness now composes supported leader and grouped
|
||||
Revival with Shipment; planned returns use the same actual purse and physical
|
||||
reserves. Minimal bots follow the required bid guide. A future-Shipment fixture
|
||||
now continues the Emperor's existing auction-gift window. Twenty related files
|
||||
pass 157 cases; type checking and lint pass. Other timing,
|
||||
factions and commitment envelopes remain provisional.
|
||||
[Scope](TRUTHTRANCE_BID_PROMISES.md#basic-bid-with-revival-and-shipment--16-november-2026).
|
||||
|
||||
**Basic phase-bid and force Revival Truthtrance commitments — 16 November.
|
||||
Prototyped / Partial.** Both answer orders now use a shared owned-spice witness
|
||||
before Bidding; affordable commitments continue through actual bidding and
|
||||
|
||||
@@ -1,5 +1,33 @@
|
||||
# Truthtrance ordinary bid commitments
|
||||
|
||||
## Basic bid with Revival and Shipment — 16 November 2026
|
||||
|
||||
**Prototyped / Partial.** The classic Basic pre-Bidding owned-cash witness
|
||||
now also considers a named leader, supported grouped force-and-leader Revival,
|
||||
and a later reserve Shipment. Required returns are materially applied to the
|
||||
detached native Revival state before the shipment quote, so one purse and the
|
||||
actual Tanks/reserves fund all three stages. It checks one specific bid amount,
|
||||
assumes no Charity, income, allied pledge refund, ally payment or Karama, and
|
||||
never treats a missing conservative witness as exhaustive impossibility.
|
||||
Negative expressions which require additional Revival actions remain guarded
|
||||
until their complete continuation can be materialized.
|
||||
|
||||
Public Basic tests cover both answer orders, real paid bids, named-leader and
|
||||
grouped force/leader returns, paid Shipment and unaffordable commitments.
|
||||
The three-commitment test stages the earlier Shipment promise, because Basic
|
||||
has only two physical Truthtrance cards; its later questions, payments and
|
||||
force actions are real. The usual original leader/Tanks and unopened Spice
|
||||
fixture supplements are explicit in the tests. Automated bidding now follows
|
||||
the server's required bid guide instead of the Shipment policy's pass. The
|
||||
future-Shipment test driver also acknowledges the existing Emperor auction
|
||||
gift opportunity before resuming the parked payment.
|
||||
|
||||
Evidence: [leader and expression](../tests/truth-phase-bid-leader-joint.test.ts),
|
||||
[bid and Shipment](../tests/truth-phase-bid-shipment-joint.test.ts) and
|
||||
[three commitments](../tests/truth-phase-bid-revival-shipment-joint.test.ts).
|
||||
Advanced, expansion factions, Movement, bribes, Charity, other combined
|
||||
promises, later lots, complete games and deployed acceptance remain open.
|
||||
|
||||
## Basic phase-wide bid with force Revival — 16 November 2026
|
||||
|
||||
**Prototyped / Partial.** In a Basic classic-faction game before Bidding,
|
||||
|
||||
+33
-14
@@ -18442,24 +18442,27 @@ function phaseBidHonorsTurnActions(g: Game, p: Player, lot: BidOpportunity, acti
|
||||
* promises awaits their combined planner; do not invent those resources. */
|
||||
function phaseBidFuturePlannerUnsupported(g: Game, p: Player): boolean {
|
||||
return liveEarlyRicheseBidPromises(g.earlyRicheseBidPromises ?? [],p.id,g.turn).some(row => row.answer) ||
|
||||
liveShipmentPromises(g.shipmentPromises ?? [],p.id,g.turn).some(row => row.answer) ||
|
||||
liveShipmentPromises(g.shipmentPromises ?? [],p.id,g.turn).some(row => matchesShipment(row,null) !== row.answer) ||
|
||||
hasMovementPromises(g,p.id,true) || liveRevivalPromises(g.revivalPromises ?? [],p.id,g.turn).some(row => row.answer) ||
|
||||
liveLeaderRevivalPromises(g.leaderRevivalPromises ?? [],p.id,g.turn).some(row => row.answer) ||
|
||||
liveRevivalExpressionPromises(g.revivalExpressionPromises ?? [],p.id,g.turn).some(row => row.answer) ||
|
||||
liveRevivalExpressionPromises(g.revivalExpressionPromises ?? [],p.id,g.turn).length > 0 ||
|
||||
liveTurnActionPromises(g.turnActionPromises ?? [],p.id,g.turn).length > 0 ||
|
||||
(!!bidOpportunity(g) && hasBribePromises(g,p.id,true));
|
||||
}
|
||||
/** A conservative owned-cash witness for a future Basic bid followed by
|
||||
* ordinary force Revival. Other joint obligations keep their own guards.
|
||||
* The detached forecast does not assume Charity, income, an ally, or a
|
||||
* Karama payment; failure to find this witness is not proof of impossibility. */
|
||||
function phaseBidRevivalWitness(g: Game, p: Player, promises: readonly PhaseBidPromise[],
|
||||
* native Revival and Shipment commitments. Other obligations keep their own
|
||||
* guards. No pledged refund, Charity, income, ally or Karama is assumed;
|
||||
* failure to find this witness is not proof of impossibility. */
|
||||
function phaseBidRevivalShipmentWitness(g: Game, p: Player, promises: readonly PhaseBidPromise[],
|
||||
witness: PhaseBidOpportunity): PhaseBidOpportunity | null {
|
||||
const revivals = liveRevivalPromises(g.revivalPromises ?? [],p.id,g.turn);
|
||||
const leaders = liveLeaderRevivalPromises(g.leaderRevivalPromises ?? [],p.id,g.turn);
|
||||
const expressions = liveRevivalExpressionPromises(g.revivalExpressionPromises ?? [],p.id,g.turn);
|
||||
const shipments = liveShipmentPromises(g.shipmentPromises ?? [],p.id,g.turn);
|
||||
if (g.advanced || g.expansions.length || g.phase >= 3 || g.auction ||
|
||||
!liveRevivalPromises(g.revivalPromises ?? [],p.id,g.turn).some(row => row.answer) ||
|
||||
liveLeaderRevivalPromises(g.leaderRevivalPromises ?? [],p.id,g.turn).length ||
|
||||
liveRevivalExpressionPromises(g.revivalExpressionPromises ?? [],p.id,g.turn).length ||
|
||||
liveShipmentPromises(g.shipmentPromises ?? [],p.id,g.turn).length || hasMovementPromises(g,p.id) ||
|
||||
(![...revivals,...leaders].some(row => row.answer) && !expressions.length &&
|
||||
!shipments.some(row => matchesShipment(row,null) !== row.answer)) ||
|
||||
hasMovementPromises(g,p.id) ||
|
||||
liveEarlyRicheseBidPromises(g.earlyRicheseBidPromises ?? [],p.id,g.turn).length || hasBribePromises(g,p.id) ||
|
||||
g.charityPromises?.some(row => row.player === p.id && row.turn === g.turn && !row.fulfilled && !row.released)) return null;
|
||||
const range = phaseBidCompletionRange(promises,witness);
|
||||
@@ -18467,13 +18470,28 @@ function phaseBidRevivalWitness(g: Game, p: Player, promises: readonly PhaseBidP
|
||||
const source = structuredClone(g);
|
||||
source.truthtrance = null;
|
||||
source.phaseBidPromises = (source.phaseBidPromises ?? []).filter(row => row.player !== p.id);
|
||||
// The donor's pledged spice can be spent by its ally; an unknown refund is
|
||||
// not personal cash available for this witness. This changes only the probe.
|
||||
delete source.aid[p.id];
|
||||
for (const seed of earlyRevivalCompletionSeeds(structuredClone(source),source,p.id)) {
|
||||
if (seed.early.length) continue;
|
||||
const owner = getPlayer(seed.game,p.id);
|
||||
if (owner.spice < range.minimum) continue;
|
||||
owner.spice -= range.minimum;
|
||||
if (currentRevivalPromiseCompletion(seed.game,owner,seed.game.revivalPromises ?? []))
|
||||
return {...witness,minimum:range.minimum,maximum:range.minimum};
|
||||
const completed = completeTurnActionRevivalSeed(seed,p.id);
|
||||
if (!completed || currentRevivalPromiseCompletion(completed.game,getPlayer(completed.game,p.id),
|
||||
completed.game.revivalPromises ?? [])?.type !== 'ready') continue;
|
||||
if (shipments.some(row => matchesShipment(row,null) !== row.answer)) {
|
||||
const future = completed.game;
|
||||
future.phase = 5;
|
||||
future.ready = [];
|
||||
delete future.revivalOrder;
|
||||
resetGroundMovementForecast(future,p.id);
|
||||
future.active = p.id;
|
||||
const shipment = findShipmentCompletion(future,getPlayer(future,p.id),shipments);
|
||||
if (!shipment || shipment.early?.length || shipment.actions.some(action => action.type !== 'ship')) continue;
|
||||
}
|
||||
return {...witness,minimum:range.minimum,maximum:range.minimum};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -18484,7 +18502,7 @@ function viablePhaseBidWitnesses(g: Game, p: Player, promises: readonly PhaseBid
|
||||
return phaseBidWitnesses(g,p).flatMap(witness => {
|
||||
if (witness.kind === 'future') {
|
||||
if (otherCommitments) {
|
||||
const joint = phaseBidRevivalWitness(g,p,promises,witness);
|
||||
const joint = phaseBidRevivalShipmentWitness(g,p,promises,witness);
|
||||
return joint ? [joint] : [];
|
||||
}
|
||||
if (hasBribePromises(g,p.id,true)) {
|
||||
@@ -34256,7 +34274,8 @@ function earlyShipmentGuidance(g: Game, p: Player): { preparation: { actions: Ac
|
||||
if (lot) return {preparation:null,policy:!lot.outcome && lot.eligible.includes(p.id) &&
|
||||
(lot.method === 'silent' ? !Object.hasOwn(lot.sealed,p.id) : lot.active === p.id)
|
||||
? [{type:'richeseBid',event:lot.event,amount:lot.method === 'silent' ? 0 : null,allyPayment:0}] : []};
|
||||
return { preparation: null, policy: g.auction?.active === p.id ? [{ type: 'passBid' }] : [] };
|
||||
const bidGuide = projectedPhaseBidGuide(g,p.id)?.action ?? projectedBidPromiseGuide(g,p.id)?.action;
|
||||
return { preparation: null, policy: g.auction?.active === p.id ? [bidGuide ?? { type: 'passBid' }] : [] };
|
||||
}
|
||||
if (g.phase === 4 && nativeRevivalOrderBlock(g,p.id)) return {preparation:null,policy:[]};
|
||||
if (g.phase === 2 && nativeCharityOrderBlock(g,p.id)) return {preparation:null,policy:[]};
|
||||
|
||||
@@ -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