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
@@ -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);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user