import assert from 'node:assert/strict'; import test from 'node:test'; import { botActions } from '../game/bots'; import { DIFFICULTIES } from '../game/bot-profiles'; import { viewGame, type Game } from '../game/engine'; import { actIxSpice as act, advanceIxSpice as advance, createIxSpiceFixture, orderIxSpiceCards } from './fixture-ix-spice-cards'; const seat = (game: Game, id: string) => { const player = game.players.find(row => row.id === id); assert.ok(player); return player; }; /** Native Basic Ix setup and actual Sandtrout draw; only unopened Spice order * is selected by the existing fixture. */ function source() { const f = createIxSpiceFixture(); let game = f.game; orderIxSpiceCards(game, ['sandtrout', 'land']); game = advance(game, state => state.turn === 1 && state.phase === 2 && !!state.phaseOpening); assert.equal(game.sandtrout, true); assert.ok(game.log.some(entry => String(entry.text ?? '').includes('Sandtrout'))); return game; } void test('an actual waiting Sandtrout does not block a bribe during the next Ix phase opening', () => { const game = source(), before = structuredClone(game); const opening = structuredClone(game.phaseOpening); const payer = seat(game, 'fremen').spice, recipient = seat(game, 'atreides').spice; const owed = seat(game, 'atreides').bribes; const options = viewGame(game, 'fremen').bribeOptions; assert.equal(options.blocked, null); assert.ok(options.targets.some(target => target.id === 'atreides')); let after = act(game, 'fremen', {type:'bribe', target:'atreides', amount:1}); assert.deepEqual(game, before); assert.deepEqual(after.phaseOpening, opening); assert.equal(seat(after, 'fremen').spice, payer - 1); assert.equal(seat(after, 'atreides').spice, recipient); assert.equal(seat(after, 'atreides').bribes, owed + 1); assert.equal(after.sandtrout, true); for (const difficulty of DIFFICULTIES) { const view = viewGame(after, 'harkonnen'); view.players.find(row => row.id === 'harkonnen')!.bot = difficulty; const ready = botActions(view).find(action => action.type === 'ready'); assert.ok(ready, difficulty); assert.doesNotThrow(() => act(after, 'harkonnen', ready), difficulty); } for (const player of after.players) after = act(after, player.id, {type:'ready'}); assert.equal(after.phaseOpening, null); assert.equal(after.sandtrout, true); assert.equal(seat(after, 'atreides').bribes, owed + 1); }); void test('without Sandtrout the same Basic Ix opening still accepts a bribe', () => { const f = createIxSpiceFixture(); let game = f.game; orderIxSpiceCards(game, ['land']); game = advance(game, state => state.turn === 1 && state.phase === 2 && !!state.phaseOpening); assert.equal(!!game.sandtrout, false); assert.equal(viewGame(game, 'fremen').bribeOptions.blocked, null); const next = act(game, 'fremen', {type:'bribe', target:'atreides', amount:1}); assert.deepEqual(next.phaseOpening, game.phaseOpening); assert.equal(seat(next, 'atreides').bribes, seat(game, 'atreides').bribes + 1); });