134 lines
7.4 KiB
TypeScript
134 lines
7.4 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import { botActions } from '../game/bots';
|
|
import { DIFFICULTIES } from '../game/bot-profiles';
|
|
import { createGame, joinGame, newPlayer, viewGame, type Action, type Game } from '../game/engine';
|
|
import { beforeIxSpiceDraw, orderIxSpiceCards } from './fixture-ix-spice-cards';
|
|
import { actTruthMovementNativeEarly as act, nextTruthMovementNativeEarlyStep } from './fixture-truth-movement-native-early';
|
|
import { truthMovementInventory as inventory } from './fixture-truth-movement';
|
|
|
|
const richese = 'richese', choam = 'choam', atreides = 'atreides';
|
|
function seat(game: Game, id: string) {
|
|
const player = game.players.find(row => row.id === id); assert.ok(player); return player;
|
|
}
|
|
const clean = (g: Game) => !g.response && !g.decision && !g.phaseOpening &&
|
|
!g.truthtrance && !g.pendingRevival && !g.pendingTreacheryDiscard;
|
|
function next(game: Game) {
|
|
if (game.turn === 1 && game.phase === 5 && game.active === richese && clean(game)) {
|
|
const player = seat(game, richese);
|
|
if (!player.shipped) {
|
|
const token = player.noField!.tokens.find(row => row.value === 3); assert.ok(token);
|
|
return { actor:richese, action:{ type:'ship', noField:token.id, event:player.noFieldEvent,
|
|
territory:'polar_sink', sector:0, allyPayment:0 } satisfies Action };
|
|
}
|
|
return { actor:richese, action:{type:'endMovement'} satisfies Action };
|
|
}
|
|
if (game.phase === 5 && game.active && clean(game))
|
|
return { actor:game.active, action:{type:'endMovement'} satisfies Action };
|
|
return nextTruthMovementNativeEarlyStep(game, { position:'first', method:'onceAround', direction:'clockwise' });
|
|
}
|
|
function reach(game: Game, until: (state: Game) => boolean) {
|
|
for (let i = 0; i < 2400; i++) {
|
|
if (until(game)) return game;
|
|
assert.notEqual(game.status, 'finished');
|
|
const step = next(game); assert.ok(step, `Original action missing at ${game.turn}/${game.phase}/${game.decision?.kind}`);
|
|
game = act(game, step.actor, step.action);
|
|
}
|
|
throw Error('Native game did not reach the requested Revival control');
|
|
}
|
|
|
|
/** Genuine Basic Ix/CHOAM public setup, paid marker and actual Sandtrout draw.
|
|
* Only unopened Spice order, physical prior casualties/board placement, and a
|
|
* physical La La La card location are staged. */
|
|
function source() {
|
|
let game = createGame('REVEALSANDTROUT', newPlayer(richese, 'Richese', 'richese'), false, ['ix', 'choam']);
|
|
joinGame(game, newPlayer(choam, 'CHOAM', 'choam'));
|
|
joinGame(game, newPlayer(atreides, 'Atreides', 'atreides'));
|
|
game = act(game, richese, {type:'moduleOption', module:'kullPreview', enabled:false});
|
|
for (const player of game.players) game = act(game, player.id, {type:'ready'});
|
|
game = act(game, richese, {type:'start'});
|
|
game = reach(game, state => state.status === 'playing');
|
|
game = reach(game, beforeIxSpiceDraw);
|
|
orderIxSpiceCards(game, ['land', 'land']);
|
|
game = reach(game, state => state.turn === 2 && beforeIxSpiceDraw(state));
|
|
assert.ok(seat(game, richese).noField?.deployed, 'The marker was shipped in the original first turn');
|
|
orderIxSpiceCards(game, ['sandtrout', 'land']);
|
|
game = reach(game, state => state.turn === 2 && state.phase === 4 && clean(state));
|
|
assert.equal(game.sandtrout, true, 'The original Sandtrout draw remains waiting');
|
|
const owner = seat(game, richese), marker = owner.noField?.deployed, event = owner.noFieldEvent;
|
|
assert.ok(marker); assert.ok(event);
|
|
assert.ok(owner.reserves >= 3);
|
|
owner.reserves -= 3; owner.tanks += 3;
|
|
const moved = owner.reserves - 1; assert.ok(moved >= 0);
|
|
owner.reserves -= moved; owner.forces['polar_sink:0'] = (owner.forces['polar_sink:0'] ?? 0) + moved;
|
|
const physical = inventory(game);
|
|
const c = seat(game, choam);
|
|
if (!c.hand.some(card => card.name === 'La La La')) {
|
|
let index = game.deck.findIndex(card => card.name === 'La La La');
|
|
if (index >= 0) c.hand.push(game.deck.splice(index, 1)[0]);
|
|
else {
|
|
const holder = game.players.find(player => player.hand.some(card => card.name === 'La La La'));
|
|
if (holder) {
|
|
index = holder.hand.findIndex(card => card.name === 'La La La');
|
|
c.hand.push(holder.hand.splice(index, 1)[0]);
|
|
} else {
|
|
index = game.discard.findIndex(card => card.name === 'La La La'); assert.ok(index >= 0);
|
|
c.hand.push(game.discard.splice(index, 1)[0]);
|
|
}
|
|
}
|
|
}
|
|
assert.deepEqual(inventory(game), physical);
|
|
game = act(game, richese, {type:'revive', amount:2, elite:0});
|
|
assert.ok(game.decision?.kind === 'choamFreeRevival');
|
|
assert.equal(game.decision.recipient, richese);
|
|
return {game, token:marker.tokenId, event, physical};
|
|
}
|
|
|
|
for (const deny of [false, true]) void test(
|
|
`Richese reveals its marker with waiting Sandtrout before CHOAM ${deny ? 'prevents' : 'allows'} its free return`, () => {
|
|
const f = source(), before = structuredClone(f.game), p = seat(f.game, richese);
|
|
const field = p.forces['polar_sink:0'] ?? 0, tanks = p.tanks, revived = p.revived;
|
|
const forceCount = (g: Game) => {
|
|
const owner = seat(g, richese);
|
|
return owner.reserves + owner.tanks + Object.values(owner.forces).reduce((sum, amount) => sum + amount, 0);
|
|
};
|
|
assert.equal(p.reserves, 1); assert.equal(forceCount(f.game), 20);
|
|
const ownerView = viewGame(f.game, richese);
|
|
assert.equal(ownerView.richeseNoField?.canReveal, true);
|
|
let game = act(f.game, richese, {type:'revealNoField', token:f.token, event:f.event});
|
|
assert.deepEqual(f.game, before);
|
|
assert.deepEqual(game.decision, before.decision);
|
|
assert.deepEqual(game.pendingRevival, before.pendingRevival);
|
|
assert.equal(game.sandtrout, true);
|
|
assert.equal(seat(game, richese).reserves, 0);
|
|
assert.equal(seat(game, richese).forces['polar_sink:0'], field + 1);
|
|
assert.equal(forceCount(game), 20);
|
|
for (const difficulty of DIFFICULTIES) {
|
|
const view = viewGame(game, choam); view.players.find(row => row.id === choam)!.bot = difficulty;
|
|
const action = botActions(view)[0]; assert.ok(action, difficulty);
|
|
assert.doesNotThrow(() => act(game, choam, action), difficulty);
|
|
}
|
|
if (deny) {
|
|
const card = seat(game, choam).hand.find(row => row.name === 'La La La'); assert.ok(card);
|
|
game = act(game, choam, {type:'card', mode:'choam', card:card.id});
|
|
} else game = act(game, choam, {type:'decision', decline:true});
|
|
for (let i = 0; (game.response || game.pendingTreacheryDiscard) && i < 40; i++) {
|
|
if (game.pendingTreacheryDiscard?.reaction) {
|
|
const reaction = game.pendingTreacheryDiscard.reaction; assert.ok(reaction.stage === 'offer');
|
|
const player = game.players.find(row => !reaction.passed.includes(row.id)); assert.ok(player);
|
|
game = act(game, player.id, {type:'semutaPass', event:game.pendingTreacheryDiscard.batch.event});
|
|
} else if (game.response) {
|
|
const player = game.players.find(row => !game.response!.passed.includes(row.id)); assert.ok(player);
|
|
game = act(game, player.id, {type:'passResponse'});
|
|
} else break;
|
|
}
|
|
assert.equal(game.pendingRevival, null);
|
|
assert.equal(seat(game, richese).tanks, tanks - (deny ? 0 : 2));
|
|
assert.equal(seat(game, richese).reserves, deny ? 0 : 2);
|
|
assert.equal(seat(game, richese).revived, revived + (deny ? 0 : 2));
|
|
assert.equal(seat(game, richese).forces['polar_sink:0'], field + 1);
|
|
assert.equal(game.sandtrout, true); assert.equal(forceCount(game), 20);
|
|
assert.deepEqual(inventory(game), f.physical);
|
|
},
|
|
);
|