Allow battle cards while Sandtrout waits
Verify and publish checkpoint container / container (push) Successful in 10m47s
Verify and publish checkpoint container / container (push) Successful in 10m47s
This commit is contained in:
1 parent
2cea251afd
commit
338f2d8980
13 files changed
+471
-19
No files matched your search
@@ -14,8 +14,9 @@ void test('bare Basic E3 and mixed native families admit Mirror without adding o
|
||||
players: (['ecaz', 'ixians', 'choam', 'richese', 'moritani', 'tleilaxu'] as const).map(faction => ({ faction })) } as const;
|
||||
assert.equal(mirrorWeaponModeBlock(native), null);
|
||||
assert.equal(mirrorWeaponModeBlock({ ...native, expansions: ['choam', 'ecaz'] }), null);
|
||||
for (const selectedModule of ['homeworlds', 'nexusCards', 'leaderSkills', 'discoveries', 'sandtrout'] as const)
|
||||
for (const selectedModule of ['homeworlds', 'nexusCards', 'leaderSkills', 'discoveries'] as const)
|
||||
assert.ok(mirrorWeaponModeBlock({ ...native, [selectedModule]: true }));
|
||||
assert.equal(mirrorWeaponModeBlock({ ...native, sandtrout: true }), null);
|
||||
assert.ok(mirrorWeaponModeBlock({ ...native, techTokens: {} }));
|
||||
assert.ok(mirrorWeaponModeBlock({ ...native, expansions: ['choam', 'ecaz'], techTokens: {} }));
|
||||
assert.equal(mirrorWeaponModeBlock({ ...native, expansions: ['choam', 'ecaz'], advanced: true, techTokens: {} }), null);
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { applyAction, createGame, joinGame, newPlayer, viewGame, type Action, type Game } from '../game/engine';
|
||||
import { botActions } from '../game/bots';
|
||||
import { DIFFICULTIES } from '../game/bot-profiles';
|
||||
import { battlePlanCardOptions } from '../components/battle-preparation';
|
||||
import { beforeIxSpiceDraw, orderIxSpiceCards } from './fixture-ix-spice-cards';
|
||||
import { advanceSemutaNexusTrade } from './fixture-semuta-nexus-trade';
|
||||
import { finishBattleOutcomeWindow } from './fixture-battle-outcome-window';
|
||||
|
||||
const act = (g: Game, id: string, action: Action) => applyAction(g, id, action);
|
||||
const seat = (g: Game, id: string) => { const p = g.players.find(row => row.id === id); assert.ok(p); return p; };
|
||||
const clean = (g: Game) => !g.response && !g.decision && !g.phaseOpening && !g.truthtrance && !g.pendingTreacheryDiscard;
|
||||
function inventory(g: Game) {
|
||||
const ids = [...g.deck, ...g.discard, ...(g.richeseCache ?? []), ...(g.richeseRemoved ?? []),
|
||||
...(g.auction?.cards.slice(g.auction.index) ?? []), ...(g.ixAuction?.cards ?? []),
|
||||
...g.players.flatMap(player => player.hand)].map(card => card.id).sort();
|
||||
assert.equal(new Set(ids).size, ids.length); return ids;
|
||||
}
|
||||
|
||||
/** Genuine Basic public setup and native first Spice Blow. Only unopened Spice
|
||||
* order, physical board counters and held card locations are staged. */
|
||||
function fixture(kind: 'mirrorWeapon' | 'stoneBurner' = 'mirrorWeapon') {
|
||||
let g = createGame('WAITINGMIRROR', newPlayer('p', 'Emperor', 'emperor'), false, ['ix', 'choam']);
|
||||
joinGame(g, newPlayer('q', 'Guild', 'guild'));
|
||||
joinGame(g, newPlayer('r', 'Richese', 'richese'));
|
||||
for (const player of g.players) g = act(g, player.id, {type:'ready'});
|
||||
g = act(g, 'p', {type:'start'});
|
||||
g = advanceSemutaNexusTrade(g, state => state.status === 'playing');
|
||||
const cards = inventory(g);
|
||||
g = advanceSemutaNexusTrade(g, beforeIxSpiceDraw);
|
||||
orderIxSpiceCards(g, ['sandtrout', 'land']);
|
||||
g = advanceSemutaNexusTrade(g, state => state.phase === 5 && clean(state));
|
||||
assert.equal(g.sandtrout, true);
|
||||
assert.ok(g.log.some(entry => String(entry.text ?? '').includes('Sandtrout')));
|
||||
const position = g.storm === 5 ? {territory:'hagga_basin', sector:12} : {territory:'pasty_mesa', sector:5};
|
||||
for (const player of g.players) {
|
||||
player.reserves += Object.values(player.forces).reduce((sum, amount) => sum + amount, 0);
|
||||
player.forces = {};
|
||||
}
|
||||
for (const id of ['p', 'q']) { seat(g, id).reserves -= 5; seat(g, id).forces[`${position.territory}:${position.sector}`] = 5; }
|
||||
g = advanceSemutaNexusTrade(g, state => state.phase === 6 && clean(state));
|
||||
const choice = viewGame(g, g.active!).battleChoices.find(row => row.territory === position.territory);
|
||||
assert.ok(choice);
|
||||
g = act(g, choice.chooser, {type:'chooseBattle', territory:position.territory,
|
||||
target:choice.chooser === choice.attacker ? choice.defender : choice.attacker});
|
||||
g = advanceSemutaNexusTrade(g, state => !!state.battle && !state.battle.preparation &&
|
||||
state.battle.preLeader?.closed !== false && clean(state));
|
||||
const place = (id: string, wanted: (card: Game['deck'][number]) => boolean) => {
|
||||
const player = seat(g, id);
|
||||
let card: Game['deck'][number] | undefined;
|
||||
const cache = g.richeseCache?.findIndex(wanted) ?? -1;
|
||||
if (cache >= 0) card = g.richeseCache!.splice(cache, 1)[0];
|
||||
else {
|
||||
const fromDeck = g.deck.findIndex(wanted);
|
||||
if (fromDeck >= 0) card = g.deck.splice(fromDeck, 1)[0];
|
||||
else {
|
||||
const fromDiscard = g.discard.findIndex(wanted);
|
||||
if (fromDiscard >= 0) card = g.discard.splice(fromDiscard, 1)[0];
|
||||
else {
|
||||
const holder = g.players.find(row => row.hand.some(wanted)); assert.ok(holder);
|
||||
card = holder.hand.splice(holder.hand.findIndex(wanted), 1)[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
assert.ok(card);
|
||||
if (player.hand.length >= 4) g.deck.push(player.hand.shift()!);
|
||||
player.hand.push(card); return card.id;
|
||||
};
|
||||
const weapon = place('p', card => card.effect === kind);
|
||||
const projectile = place('q', card => card.kind === 'projectile');
|
||||
assert.deepEqual(inventory(g), cards);
|
||||
return { g, weapon, projectile, cards };
|
||||
}
|
||||
|
||||
void test('waiting Sandtrout does not stop a physical Mirror from copying an ordinary attack', () => {
|
||||
const f = fixture(), view = viewGame(f.g, 'p');
|
||||
assert.equal(f.g.sandtrout, true);
|
||||
const mirror = seat(f.g, 'p').hand.find(card => card.id === f.weapon)!;
|
||||
const options = battlePlanCardOptions(view, 'weapon', seat(f.g, 'p').leaders[0].id, '', '');
|
||||
assert.ok(options.some(option => option.id === mirror.id));
|
||||
for (const difficulty of DIFFICULTIES) {
|
||||
const botView = viewGame(f.g, 'p'); botView.players.find(p => p.id === 'p')!.bot = difficulty;
|
||||
const action = botActions(botView).find(row => row.type === 'battlePlan' && row.weapon === f.weapon);
|
||||
assert.ok(action, difficulty); assert.doesNotThrow(() => act(f.g, 'p', action));
|
||||
}
|
||||
let g = act(f.g, 'p', {type:'battlePlan', dial:2, support:0,
|
||||
leader:seat(f.g, 'p').leaders[0].id, weapon:f.weapon});
|
||||
g = act(g, 'q', {type:'battlePlan', dial:2, support:0,
|
||||
leader:seat(g, 'q').leaders[0].id, weapon:f.projectile});
|
||||
assert.equal(g.battle?.revealed, true);
|
||||
for (const id of ['q', 'p']) g = act(g, id, {type:'traitorCall', call:false});
|
||||
g = finishBattleOutcomeWindow(g);
|
||||
assert.equal(seat(g, 'p').leaders[0].dead, true);
|
||||
assert.equal(seat(g, 'q').leaders[0].dead, true);
|
||||
assert.ok(g.lastBattleContext?.winner);
|
||||
assert.equal(g.sandtrout, true);
|
||||
assert.deepEqual(inventory(g), f.cards);
|
||||
});
|
||||
|
||||
void test('waiting Sandtrout does not stop Stone Burner from resolving an ordinary battle', () => {
|
||||
const f = fixture('stoneBurner'), view = viewGame(f.g, 'p');
|
||||
assert.equal(f.g.sandtrout, true);
|
||||
assert.ok(battlePlanCardOptions(view, 'weapon', seat(f.g, 'p').leaders[0].id, '', '')
|
||||
.some(card => card.id === f.weapon));
|
||||
for (const difficulty of DIFFICULTIES) {
|
||||
const botView = viewGame(f.g, 'p'); botView.players.find(p => p.id === 'p')!.bot = difficulty;
|
||||
const action = botActions(botView).find(row => row.type === 'battlePlan' && row.weapon === f.weapon);
|
||||
assert.ok(action, difficulty); assert.doesNotThrow(() => act(f.g, 'p', action));
|
||||
}
|
||||
let g = act(f.g, 'p', {type:'battlePlan', dial:1, support:0,
|
||||
leader:seat(f.g, 'p').leaders[0].id, weapon:f.weapon});
|
||||
g = act(g, 'q', {type:'battlePlan', dial:2, support:0,
|
||||
leader:seat(g, 'q').leaders[0].id, weapon:f.projectile});
|
||||
assert.equal(g.decision?.kind, 'stoneBurner');
|
||||
g = act(g, 'p', {type:'decision', event:g.battle!.event, mode:'kill'});
|
||||
for (const id of ['q', 'p']) g = act(g, id, {type:'traitorCall', call:false});
|
||||
g = finishBattleOutcomeWindow(g);
|
||||
assert.equal(seat(g, 'p').leaders[0].dead, true);
|
||||
assert.equal(seat(g, 'q').leaders[0].dead, true);
|
||||
assert.equal(g.lastBattleContext?.winner, 'p');
|
||||
assert.equal(g.sandtrout, true);
|
||||
assert.deepEqual(inventory(g), f.cards);
|
||||
});
|
||||
@@ -46,7 +46,8 @@ void test('Reinforcements consumes exactly three own normal reserves in either c
|
||||
for (const advanced of [false, true]) for (const slot of ['weapon', 'defense'] as const) {
|
||||
const start = fixture(advanced);
|
||||
const owner = viewGame(start, 'a');
|
||||
assert.deepEqual(owner.battle?.reinforcements, { blocked: null, normal: 3, elite: 0 });
|
||||
assert.deepEqual(owner.battle?.reinforcements, { blocked: null, normal: 3, elite: 0,
|
||||
eliteOptions: advanced ? [0, 1, 2, 3] : [0] });
|
||||
assert.equal(viewGame(start, 'd').battle?.reinforcements, null);
|
||||
assert.equal(viewGame(start, 't').battle?.reinforcements, null);
|
||||
const privatePlan = applyAction(start, 'a', {
|
||||
@@ -75,7 +76,7 @@ void test('paired Ecaz/Moritani battles spend one physical Reinforcements cost w
|
||||
let g = harassWithdrawGame({ advanced, factions: [owner, owner === 'ecaz' ? 'moritani' : 'ecaz', 'atreides'] });
|
||||
takeHarassCard(g, 'a', cardId);
|
||||
harassCustody(g);
|
||||
assert.deepEqual(viewGame(g, 'a').battle?.reinforcements, { blocked: null, normal: 3, elite: 0 });
|
||||
assert.deepEqual(viewGame(g, 'a').battle?.reinforcements, { blocked: null, normal: 3, elite: 0, eliteOptions: [0] });
|
||||
assert.equal(viewGame(g, 'd').battle?.reinforcements, null);
|
||||
g = applyAction(JSON.parse(JSON.stringify(g)) as Game, 'a', {
|
||||
type: 'battlePlan', dial: 1, support: advanced ? 1 : 0,
|
||||
@@ -129,7 +130,7 @@ void test('Reinforcements normal-first cost preserves elite subpool and is paid
|
||||
p.elites!.reserves = 2;
|
||||
p.elites!.tanks = 3;
|
||||
harassCustody(g);
|
||||
assert.deepEqual(viewGame(g, 'a').battle?.reinforcements, { blocked: null, normal: 1, elite: 2 });
|
||||
assert.deepEqual(viewGame(g, 'a').battle?.reinforcements, { blocked: null, normal: 1, elite: 2, eliteOptions: [2] });
|
||||
// Give Atreides the Emperor's selected leader as a real traitor, preserving the deck's identities.
|
||||
const target = 'emperor-0';
|
||||
const old = g.players[1].traitors[0];
|
||||
@@ -146,7 +147,7 @@ void test('Reinforcements normal-first cost preserves elite subpool and is paid
|
||||
assert.equal(done.discard.filter(c => c.id === cardId).length, 1);
|
||||
});
|
||||
|
||||
void test('insufficient reserves and unsupported modules reject without mutating the original game', () => {
|
||||
void test('insufficient reserves reject without mutating the original game', () => {
|
||||
const g = fixture(true);
|
||||
const p = g.players[0];
|
||||
p.reserves = 2;
|
||||
@@ -156,11 +157,4 @@ void test('insufficient reserves and unsupported modules reject without mutating
|
||||
harassCustody(g);
|
||||
assert.match(viewGame(g, 'a').battle!.reinforcements!.blocked!, /three physical forces/);
|
||||
reject(g, 'a', { type: 'battlePlan', dial: 1, leader: 'emperor-0', weapon: cardId }, /three own forces/);
|
||||
p.reserves = 15;
|
||||
p.tanks = 0;
|
||||
p.elites!.reserves = 5;
|
||||
p.elites!.tanks = 0;
|
||||
g.sandtrout = {} as Game['sandtrout'];
|
||||
assert.throws(() => applyAction(g, 'a',
|
||||
{ type: 'battlePlan', dial: 1, leader: 'emperor-0', weapon: cardId }), RuleError);
|
||||
});
|
||||
@@ -0,0 +1,94 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { applyAction, createGame, joinGame, newPlayer, viewGame, type Game, type Action } from '../game/engine';
|
||||
import { botActions } from '../game/bots';
|
||||
import { DIFFICULTIES } from '../game/bot-profiles';
|
||||
import { beforeIxSpiceDraw, orderIxSpiceCards } from './fixture-ix-spice-cards';
|
||||
import { advanceSemutaNexusTrade, nextSemutaNexusTradeNativeStep } from './fixture-semuta-nexus-trade';
|
||||
|
||||
const act = (g: Game, actor: string, action: Action) => applyAction(g, actor, action);
|
||||
const seat = (g: Game, actor: string) => { const p = g.players.find(row => row.id === actor); assert.ok(p); return p; };
|
||||
const cards = (g: Game) => [...g.deck, ...g.discard, ...(g.auction?.cards.slice(g.auction.index) ?? []),
|
||||
...(g.ixAuction?.cards ?? []), ...g.players.flatMap(p => p.hand)].map(c => c.id).sort();
|
||||
const clean = (g: Game) => !g.response && !g.phaseOpening && !g.decision && !g.truthtrance && !g.pendingTreacheryDiscard;
|
||||
|
||||
/** Real public Basic setup and Sandtrout draw. The unopened Spice prefix,
|
||||
* later armies and one physical battle card are deliberately staged. */
|
||||
function fixture() {
|
||||
let g = createGame('REINFORCEMENTSTROUT', newPlayer('a', 'Atreides', 'atreides'), false, ['ix']);
|
||||
joinGame(g, newPlayer('e', 'Emperor', 'emperor'));
|
||||
joinGame(g, newPlayer('g', 'Guild', 'guild'));
|
||||
g = act(g, 'a', { type: 'moduleOption', module: 'ecazTreachery', enabled: true });
|
||||
for (const p of g.players) g = act(g, p.id, { type: 'ready' });
|
||||
g = act(g, 'a', { type: 'start' });
|
||||
g = advanceSemutaNexusTrade(g, state => state.status === 'playing');
|
||||
const inventory = cards(g);
|
||||
g = advanceSemutaNexusTrade(g, beforeIxSpiceDraw);
|
||||
orderIxSpiceCards(g, ['sandtrout', 'land', 'land']);
|
||||
g = advanceSemutaNexusTrade(g, state => state.turn === 1 && state.phase === 5 && clean(state));
|
||||
assert.equal(g.sandtrout, true);
|
||||
assert.ok(g.log.some(row => row.text.includes('Sandtrout broke all alliances')));
|
||||
assert.ok(g.players.every(p => p.ally === null));
|
||||
const territory = g.storm === 10 ? 'carthag' : 'arrakeen';
|
||||
const sector = territory === 'arrakeen' ? 10 : 11, location = `${territory}:${sector}`;
|
||||
for (const p of g.players) {
|
||||
p.reserves += Object.values(p.forces).reduce((sum, n) => sum + n, 0);
|
||||
p.forces = {};
|
||||
}
|
||||
for (const [id, amount] of [['a', 4], ['e', 2]] as const) {
|
||||
const p = seat(g, id); p.reserves -= amount; p.forces[location] = amount;
|
||||
}
|
||||
const id = 'ecaz-reinforcements';
|
||||
const holder = g.players.find(p => p.hand.some(c => c.id === id));
|
||||
let card;
|
||||
if (holder) card = holder.hand.splice(holder.hand.findIndex(c => c.id === id), 1)[0];
|
||||
else {
|
||||
const pile = [g.deck, g.discard].find(source => source.some(c => c.id === id)); assert.ok(pile);
|
||||
card = pile.splice(pile.findIndex(c => c.id === id), 1)[0];
|
||||
}
|
||||
const owner = seat(g, 'a');
|
||||
if (owner.hand.length >= 4) g.deck.push(owner.hand.shift()!);
|
||||
owner.hand.push(card);
|
||||
assert.deepEqual(cards(g), inventory);
|
||||
g = advanceSemutaNexusTrade(g, state => state.turn === 1 && state.phase === 6 && !state.battle && clean(state));
|
||||
const choice = viewGame(g, g.active!).battleChoices.find(row => row.territory === territory); assert.ok(choice);
|
||||
g = act(g, choice.chooser, { type: 'chooseBattle', territory,
|
||||
target: choice.chooser === choice.attacker ? choice.defender : choice.attacker });
|
||||
for (let n = 0; n < 100 && (!g.battle || g.battle.preparation || g.battle.preLeader?.closed === false || !clean(g)); n++) {
|
||||
const step = nextSemutaNexusTradeNativeStep(g); g = act(g, step.actor, step.action);
|
||||
}
|
||||
assert.ok(g.battle && !g.battle.revealed && clean(g));
|
||||
assert.equal(g.sandtrout, true);
|
||||
return { g, inventory, location };
|
||||
}
|
||||
|
||||
for (const slot of ['weapon', 'defense'] as const) void test(
|
||||
`Basic Reinforcements in the ${slot} slot remains usable while genuine Sandtrout waits`, () => {
|
||||
const f = fixture(), before = structuredClone(f.g), owner = seat(f.g, 'a'), opponent = seat(f.g, 'e');
|
||||
const quote = viewGame(f.g, 'a').battle?.reinforcements;
|
||||
assert.ok(quote); assert.equal(quote.blocked, null); assert.equal(quote.normal, 3);
|
||||
for (const difficulty of DIFFICULTIES) {
|
||||
const view = viewGame(f.g, 'a'); view.players.find(p => p.id === 'a')!.bot = difficulty;
|
||||
const action = botActions(view).find(row => row.type === 'battlePlan'); assert.ok(action, difficulty);
|
||||
assert.doesNotThrow(() => act(f.g, 'a', action), difficulty);
|
||||
}
|
||||
const ourLeader = owner.leaders.find(l => !l.dead && !l.usedAt); assert.ok(ourLeader);
|
||||
const enemyLeader = opponent.leaders.find(l => !l.dead && !l.usedAt); assert.ok(enemyLeader);
|
||||
let g = act(f.g, 'a', { type:'battlePlan', dial: 1, support: 0, leader:ourLeader.id,
|
||||
weapon:slot === 'weapon' ? 'ecaz-reinforcements' : null,
|
||||
defense:slot === 'defense' ? 'ecaz-reinforcements' : null });
|
||||
assert.deepEqual(f.g, before);
|
||||
assert.equal(viewGame(g, 'e').battle!.plans.a, undefined);
|
||||
g = act(g, 'e', { type:'battlePlan', dial:0, support:0, leader:enemyLeader.id });
|
||||
assert.equal(g.battle?.revealed, true);
|
||||
for (let n = 0; n < 160 && (g.battle || !clean(g)); n++) {
|
||||
const step = nextSemutaNexusTradeNativeStep(g); g = act(g, step.actor, step.action);
|
||||
}
|
||||
assert.equal(g.battle, null); assert.equal(g.sandtrout, true);
|
||||
assert.equal(seat(g, 'a').reserves, owner.reserves - 3);
|
||||
assert.ok(seat(g, 'a').tanks >= owner.tanks + 3);
|
||||
assert.equal(g.discard.filter(c => c.id === 'ecaz-reinforcements').length, 1);
|
||||
assert.deepEqual(cards(g), f.inventory);
|
||||
for (const p of g.players) assert.equal(p.reserves + p.tanks + Object.values(p.forces).reduce((a,b) => a+b,0), 20);
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,173 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { createGame, joinGame, newPlayer, viewGame, type Game } from '../game/engine';
|
||||
import { botActions } from '../game/bots';
|
||||
import { DIFFICULTIES } from '../game/bot-profiles';
|
||||
import { richeseRevealInterruptSupported } from '../game/richese-reveal-interruption';
|
||||
import { actTruthMovementNativeEarly as act, nextTruthMovementNativeEarlyStep } from './fixture-truth-movement-native-early';
|
||||
import { truthMovementInventory as inventory } from './fixture-truth-movement';
|
||||
|
||||
const richese = 'richese', guild = 'guild', atreides = 'atreides';
|
||||
function player(game: Game, id: string) {
|
||||
const seat = game.players.find(row => row.id === id); assert.ok(seat); return seat;
|
||||
}
|
||||
const clean = (game: Game) => !game.response && !game.decision && !game.phaseOpening &&
|
||||
!game.truthtrance && !game.pendingTreacheryDiscard;
|
||||
|
||||
/** Original public Basic setup and native actions. Only an actual Truthtrance's
|
||||
* held location and the order of unopened Spice cards are staged. */
|
||||
type QuestionMode = 'fact' | 'knownFreeform' | 'unknownFreeform' | 'future';
|
||||
function source(answer: 'yes' | 'no', mode: QuestionMode = 'fact') {
|
||||
let game = createGame('REVEALAFTERFACT', newPlayer(richese, 'Richese', 'richese'), false, ['choam']);
|
||||
joinGame(game, newPlayer(guild, 'Guild', 'guild'));
|
||||
joinGame(game, newPlayer(atreides, 'Atreides', 'atreides'));
|
||||
for (const seat of game.players) game = act(game, seat.id, { type: 'ready' });
|
||||
game = act(game, game.host, { type: 'start' });
|
||||
const reach = (until: (state: Game) => boolean) => {
|
||||
for (let count = 0; count < 2000; count++) {
|
||||
if (until(game)) return;
|
||||
assert.notEqual(game.status, 'finished');
|
||||
const step = nextTruthMovementNativeEarlyStep(game, {
|
||||
position: 'first', method: 'onceAround', direction: 'clockwise', keepUnbid: false,
|
||||
});
|
||||
assert.ok(step, `Missing native action at ${game.turn}/${game.phase}/${game.decision?.kind}`);
|
||||
game = act(game, step.actor, step.action);
|
||||
}
|
||||
throw Error('The genuine Basic parent was not reached');
|
||||
};
|
||||
reach(state => state.status === 'playing');
|
||||
const original = inventory(game);
|
||||
for (const position of [0, 1]) {
|
||||
const from = game.spiceDeck.findIndex((card, i) => i >= position && 'territory' in card && !card.discovery);
|
||||
assert.ok(from >= position); [game.spiceDeck[position], game.spiceDeck[from]] = [game.spiceDeck[from], game.spiceDeck[position]];
|
||||
}
|
||||
reach(state => state.turn === 1 && state.phase === 5 && state.active === richese && clean(state));
|
||||
const owner = player(game, richese), marker = owner.noField!.tokens.find(token => token.value === 3);
|
||||
assert.ok(marker); assert.ok(owner.noFieldEvent);
|
||||
game = act(game, richese, { type: 'ship', noField: marker.id, event: owner.noFieldEvent,
|
||||
territory: 'polar_sink', sector: 0, allyPayment: 0 });
|
||||
reach(clean);
|
||||
const asker = player(game, atreides);
|
||||
let truth = asker.hand.find(card => card.effect === 'truthtrance');
|
||||
if (!truth) {
|
||||
const held = game.players.find(seat => seat.id !== atreides && seat.hand.some(card => card.effect === 'truthtrance'));
|
||||
if (held) {
|
||||
const from = held.hand.findIndex(card => card.effect === 'truthtrance');
|
||||
truth = held.hand.splice(from, 1)[0];
|
||||
const replacement = asker.hand.pop();
|
||||
if (replacement) held.hand.push(replacement);
|
||||
} else {
|
||||
const from = game.deck.findIndex(card => card.effect === 'truthtrance'); assert.ok(from >= 0);
|
||||
truth = game.deck.splice(from, 1)[0];
|
||||
if (asker.hand.length >= 4) game.deck.push(asker.hand.pop()!);
|
||||
}
|
||||
asker.hand.push(truth);
|
||||
}
|
||||
// Avoid creating a separate simultaneous Truthtrance order question.
|
||||
for (const seat of game.players.filter(row => row.id !== atreides)) {
|
||||
for (let i = seat.hand.length - 1; i >= 0; i--) if (seat.hand[i].effect === 'truthtrance') {
|
||||
game.deck.push(...seat.hand.splice(i, 1));
|
||||
const replacement = game.deck.findIndex(card => card.effect !== 'truthtrance');
|
||||
assert.ok(replacement >= 0); seat.hand.push(game.deck.splice(replacement, 1)[0]);
|
||||
}
|
||||
}
|
||||
assert.deepEqual(inventory(game), original);
|
||||
game = act(game, atreides, { type: 'card', card: truth.id });
|
||||
while (game.truthtrance?.stage === 'priority') {
|
||||
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');
|
||||
const fact = { kind: 'spice', compare: 'gte', value: answer === 'yes' ? 0 : Number.MAX_SAFE_INTEGER } as const;
|
||||
const question = mode === 'future'
|
||||
? { kind: 'freeform', scope: 'currentTurn', target: guild, text: 'Will you ship six forces later this turn?' }
|
||||
: mode === 'knownFreeform'
|
||||
? { kind: 'freeform', scope: 'fact', target: guild, text: `Do you have at least ${fact.value} spice?` }
|
||||
: mode === 'unknownFreeform'
|
||||
? { kind: 'freeform', scope: 'fact', target: guild, text: 'Are you thinking of a sandworm right now?' }
|
||||
: { kind: 'fact', target: guild, fact };
|
||||
game = act(game, atreides, { type: 'truthAsk', question });
|
||||
if (mode === 'fact' || mode === 'knownFreeform') assert.equal(viewGame(game, guild).truthAnswer, answer);
|
||||
if (mode === 'unknownFreeform') assert.equal(viewGame(game, guild).truthAnswer, null);
|
||||
game = act(game, guild, { type: 'truthAnswer', answer });
|
||||
reach(clean);
|
||||
assert.equal(game.truthHistory!.at(-1)!.question.kind, mode === 'fact' ? 'fact' : 'freeform');
|
||||
assert.equal(game.truthHistory!.at(-1)!.answer, answer);
|
||||
assert.deepEqual(inventory(game), original);
|
||||
// A real held Karama keeps the Guild-rate response open for inspection.
|
||||
if (!player(game, atreides).hand.some(card => card.effect === 'karama')) {
|
||||
const holder = game.players.find(seat => seat.id !== atreides && seat.hand.some(card => card.effect === 'karama'));
|
||||
const from = holder ? holder.hand : game.deck;
|
||||
const index = from.findIndex(card => card.effect === 'karama'); assert.ok(index >= 0);
|
||||
const card = from.splice(index, 1)[0];
|
||||
if (player(game, atreides).hand.length >= 4) from.push(player(game, atreides).hand.pop()!);
|
||||
player(game, atreides).hand.push(card);
|
||||
}
|
||||
assert.deepEqual(inventory(game), original);
|
||||
game = act(game, richese, { type: 'endMovement' });
|
||||
reach(state => state.phase === 5 && state.active === guild && clean(state) && !player(state, guild).shipped);
|
||||
const event = player(game, richese).noFieldEvent; assert.ok(event);
|
||||
game = act(game, guild, { type: 'ship', territory: 'arrakeen', sector: 10, amount: 3, allyPayment: 0 });
|
||||
assert.equal(game.response?.kind, 'guildRate'); assert.equal(game.pendingShipment?.player, guild);
|
||||
return { game, event, marker: marker.id, original };
|
||||
}
|
||||
|
||||
for (const answer of ['yes', 'no'] as const) void test(
|
||||
`A public current-fact Truthtrance ${answer} allows Richese to reveal while Guild's original rate is pending`, () => {
|
||||
const { game, event, marker, original } = source(answer), before = structuredClone(game);
|
||||
assert.equal(viewGame(game, richese).richeseNoField?.canReveal, true);
|
||||
const next = act(game, richese, { type: 'revealNoField', token: marker, event });
|
||||
assert.deepEqual(game, before);
|
||||
assert.deepEqual(next.response, before.response); assert.deepEqual(next.pendingShipment, before.pendingShipment);
|
||||
assert.deepEqual(next.truthHistory, before.truthHistory);
|
||||
assert.equal(player(next, richese).noField?.deployed, null);
|
||||
assert.equal(player(next, richese).forces['polar_sink:0'], 3);
|
||||
assert.deepEqual(inventory(next), original);
|
||||
let done = next;
|
||||
for (let count = 0; done.response?.kind === 'guildRate' && count < done.players.length; count++) {
|
||||
const seat = done.players.find(row => !done.response!.passed.includes(row.id)); assert.ok(seat);
|
||||
done = act(done, seat.id, { type: 'passResponse' });
|
||||
}
|
||||
assert.equal(done.pendingShipment, null); assert.equal(player(done, guild).forces['arrakeen:10'], 3);
|
||||
assert.deepEqual(inventory(done), original);
|
||||
},
|
||||
);
|
||||
|
||||
void test('all four bot profiles can respond to the original rate after a factual answer and reveal', () => {
|
||||
const { game, event, marker } = source('yes');
|
||||
const revealed = act(game, richese, { type: 'revealNoField', token: marker, event });
|
||||
for (const difficulty of DIFFICULTIES) {
|
||||
const view = viewGame(revealed, atreides); view.players.find(seat => seat.id === atreides)!.bot = difficulty;
|
||||
const action = botActions(view)[0]; assert.ok(action, difficulty);
|
||||
assert.doesNotThrow(() => act(revealed, atreides, action), difficulty);
|
||||
}
|
||||
});
|
||||
|
||||
void test('a real current-turn freeform promise retains the public history fence', () => {
|
||||
const { game, event, marker } = source('no', 'future'), before = structuredClone(game);
|
||||
assert.equal(game.truthHistory!.at(-1)!.question.kind, 'freeform');
|
||||
assert.equal(richeseRevealInterruptSupported(game), false);
|
||||
assert.equal(viewGame(game, richese).richeseNoField?.canReveal, false);
|
||||
assert.throws(() => act(game, richese, { type: 'revealNoField', token: marker, event }));
|
||||
assert.deepEqual(game, before);
|
||||
});
|
||||
|
||||
for (const mode of ['knownFreeform', 'unknownFreeform'] as const)
|
||||
for (const answer of ['yes', 'no'] as const) void test(
|
||||
`A ${mode === 'knownFreeform' ? 'recognized' : 'unrecognized'} current-fact freeform ${answer} retains the reveal and Guild-rate continuation`, () => {
|
||||
const { game, event, marker, original } = source(answer, mode);
|
||||
const record = game.truthHistory!.at(-1)!;
|
||||
assert.ok(record.question.kind === 'freeform');
|
||||
assert.equal(record.question.scope, 'fact');
|
||||
assert.equal(!!record.question.interpreted, mode === 'knownFreeform');
|
||||
assert.equal(viewGame(game, richese).richeseNoField?.canReveal, true);
|
||||
let next = act(game, richese, { type: 'revealNoField', token: marker, event });
|
||||
assert.deepEqual(next.response, game.response); assert.deepEqual(next.pendingShipment, game.pendingShipment);
|
||||
while (next.response?.kind === 'guildRate') {
|
||||
const seat = next.players.find(row => !next.response!.passed.includes(row.id)); assert.ok(seat);
|
||||
next = act(next, seat.id, { type: 'passResponse' });
|
||||
}
|
||||
assert.equal(next.pendingShipment, null); assert.equal(player(next, guild).forces['arrakeen:10'], 3);
|
||||
assert.deepEqual(inventory(next), original);
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user