import assert from 'node:assert/strict'; import test from 'node:test'; import { createGame, newPlayer, type Action, type Game } from '../game/engine'; import { createLeaderSkills } from '../game/leader-skills'; import { createRicheseNoField, deployRicheseNoField } from '../game/richese-no-field'; import { quoteFremenAmbassadorMove } from '../game/fremen-ambassador'; /** Controlled board position; all marker denominations use the same public * movement and Sandmaster calculation. No card or physical unit is invented. */ function source(value: 0 | 3 | 5, advanced: boolean, withForces: boolean) { const game = createGame('SAMARKER', newPlayer('r', 'Richese', 'richese'), advanced, ['choam', 'ecaz']); game.players.push(newPlayer('e', 'Ecaz', 'ecaz'), newPlayer('a', 'Atreides', 'atreides')); Object.assign(game, {status:'playing',turn:2,phase:5,storm:18,order:['e','a','r'],active:'a'}); const richese = game.players[0]; richese.spice = 5; richese.forces = withForces ? {'red_chasm:7':2} : {}; richese.reserves = withForces ? 18 : 20; richese.noField = deployRicheseNoField(createRicheseNoField(['nf0','nf3','nf5']), { tokenId:`nf${value}`,controller:'r',location:{territory:'red_chasm',sector:7}, }); richese.noFieldEvent = 'marker-event'; const skills = createLeaderSkills(() => 0.2); skills.deck = skills.deck.filter(skill => skill !== 'sandmaster'); skills.assignments = [{skill:'sandmaster',owner:'r',leader:richese.leaders[0].id}]; game.leaderSkills = skills; game.spice = {'south_mesa:4':4,'south_mesa:5':2}; const action: Action = {type:'decision',event:'ambassador-event', forces:withForces ? {'red_chasm:7':2} : {},noField:{tokenId:`nf${value}`,event:'marker-event'}, territory:'south_mesa',sector:4,sandmasterCollect:true,sandmasterPile:'south_mesa:5'}; return {game,action}; } for (const advanced of [false,true]) for (const value of [0,3,5] as const) for (const withForces of [false,true]) void test( `${advanced ? 'Advanced' : 'Basic'} concealed ${value}${withForces ? ' with forces' : ' alone'} quotes one Sandmaster collection`, () => { const {game,action} = source(value,advanced,withForces); const before = structuredClone(game), priorAction = structuredClone(action); const result = quoteFremenAmbassadorMove(game,'r',action); assert.equal(result.total,withForces ? 3 : 1); assert.deepEqual(result.noField,{tokenId:`nf${value}`,event:'marker-event',from:'red_chasm:7'}); assert.deepEqual(result.ambassadorSandmaster,{leader:game.players[0].leaders[0].id,key:'south_mesa:5',before:2}); assert.deepEqual(game,before); assert.deepEqual(action,priorAction); }); void test('marker quote requires a live token, an eligible trainer and an actual destination pile', () => { const {game,action} = source(0,false,false); const before: Game = structuredClone(game); assert.throws(() => quoteFremenAmbassadorMove(game,'r',{ ...action,noField:{tokenId:'nf0',event:'stale'}, })); assert.throws(() => quoteFremenAmbassadorMove(game,'r',{ ...action,sandmasterPile:'false_wall_west:13', })); const denied = structuredClone(game); denied.players[0].leaders[0].dead = true; assert.throws(() => quoteFremenAmbassadorMove(denied,'r',action)); assert.deepEqual(game,before); assert.equal(quoteFremenAmbassadorMove(game,'r',{...action,sandmasterCollect:false,sandmasterPile:undefined}) .ambassadorSandmaster,undefined); });