69 lines
3.6 KiB
TypeScript
69 lines
3.6 KiB
TypeScript
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';
|
|
|
|
/** Real public Basic setup and Truthtrances. Stage unopened Spice order and
|
|
* move existing force/leader pieces into Tanks for the requested Revival. */
|
|
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 ['forces', 'leader', 'expression'] as const) {
|
|
for (const first of ['bid', 'revival'] as const) {
|
|
void test(`Basic ${mode} and phase-bid commitments give all bot difficulties a legal bid (${first} first)`, () => {
|
|
const {f, game:initial, leader} = fixture();
|
|
const bid = {kind:'phaseBid', target:f.target, turn:initial.turn, minimum:4};
|
|
const revival = mode === 'forces'
|
|
? {kind:'revival', target:f.target, turn:initial.turn, counter:'total', minimum:3}
|
|
: 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];
|
|
let game = ask(initial, f.asker, f.truths[0], questions[0]);
|
|
game = act(game, f.target, {type:'truthAnswer', answer:'yes'});
|
|
game = ask(game, f.asker, f.truths[1], questions[1]);
|
|
game = act(game, f.target, {type:'truthAnswer', answer:'yes'});
|
|
game = advance(game, state => clean(state) && state.phase === 3 && state.auction?.active === f.target);
|
|
assert.ok(viewGame(game, f.target).phaseBidPromiseGuide, 'The server has a legal qualifying bid guide');
|
|
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, 'bid', `${difficulty} must honor the outstanding phase bid`);
|
|
assert.doesNotThrow(() => applyAction(game, f.target, action));
|
|
}
|
|
});
|
|
}
|
|
}
|