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 { placeAmbassador, validateAmbassadors } from '../game/ecaz-ambassadors'; import { deployRicheseNoField } from '../game/richese-no-field'; import { validateEcazLoyalty } from '../game/ecaz-loyalty'; import { createSelectedDeckSkillsSetup, assertSelectedDeckSkillsInventory } from './fixture-selected-deck-skills'; const player = (game: Game, id: string) => { const result = game.players.find(seat => seat.id === id); assert.ok(result); return result; }; /** The shared fixture predates Advanced Ecaz Loyalty: count its unique public * card alongside circulating Traitors, after validating its real custody. */ function assertInventory(game: Game) { validateEcazLoyalty(game); const inventory = structuredClone(game); if (inventory.ecazLoyalty?.card) { (inventory.traitorReserve ??= []).push(inventory.ecazLoyalty.card); delete inventory.ecazLoyalty; } assertSelectedDeckSkillsInventory(inventory); } /** Genuine public setup and Sandmaster assignment. Controlled supplements * relocate original forces to reserves/board, place the original Ambassador, * deploy the actual marker, set the alliance/phase boundary and destination * piles. No card, skill, leader, Ambassador or No-Field identity is minted. */ function source(advanced: boolean, value: 0 | 3 | 5, withForces: boolean) { const setup = createSelectedDeckSkillsSetup({advanced, factions:['richese','ecaz','atreides'], expansions:['choam','ecaz'],skill:'sandmaster'}); let game = structuredClone(setup.afterSetup); assert.equal(game.players[0].faction,'richese'); assert.equal(game.leaderSkills!.assignments.find(row => row.owner === 'richese')?.skill,'sandmaster'); const beforeSkills = structuredClone(game.leaderSkills); for (const seat of game.players) { const returned = Object.values(seat.forces).reduce((sum,n) => sum+n,0); seat.reserves += returned; seat.forces = {}; seat.shipped = false; seat.moved = 0; } const entrant = player(game,'atreides'), richese = player(game,'richese'), ecaz = player(game,'ecaz'); entrant.reserves--; entrant.forces = {'imperial_basin:10':1}; entrant.shipped = true; if (withForces) { richese.reserves -= 2; richese.forces = {'red_chasm:7':2}; } richese.ally = 'ecaz'; ecaz.ally = 'richese'; assert.ok(richese.noField); const marker = richese.noField.tokens.find(token => token.value === value); assert.ok(marker); richese.noField = deployRicheseNoField(richese.noField, {tokenId:marker.id,controller:richese.id, location:{territory:'red_chasm',sector:7}}); richese.noFieldEvent = 'staged-marker-event'; assert.ok(game.ecazAmbassadors); const ambassadors = structuredClone(game.ecazAmbassadors); const token = ambassadors.tokens.find(row => row.effect === 'fremen'); assert.ok(token); if (!ambassadors.cohort.includes(token.id)) { const replaced = ambassadors.tokens.find(row => row.id === ambassadors.cohort[0]); assert.ok(replaced); replaced.zone = 'pool'; token.zone = 'supply'; ambassadors.cohort[0] = token.id; } game.ecazAmbassadors = placeAmbassador(ambassadors,token.id,{turn:1,availableSpice:ecaz.spice, destination:{id:'arrakeen',stronghold:true,inStorm:false,allowed:true}}).state; validateAmbassadors(game.ecazAmbassadors); Object.assign(game,{turn:2,phase:5,storm:18,active:'atreides',ready:[],response:null,decision:null, phaseOpening:null,stormResolution:null,stormPending:null,movementRemaining:['atreides','richese','ecaz'], spice:{'south_mesa:4':4,'south_mesa:5':2}}); delete game.stormMovementSource; assert.deepEqual(game.leaderSkills,beforeSkills); assertInventory(game); game = applyAction(game,'atreides',{type:'move',forces:{'imperial_basin:10':1},territory:'arrakeen',sector:10}); assert.equal(game.pendingAmbassador?.stage,'offer'); game = applyAction(game,'ecaz',{type:'decision',event:game.pendingAmbassador!.event, trigger:true,beneficiary:'richese'}); assert.equal(game.pendingAmbassador?.stage,'move'); return {game,marker:marker.id}; } 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'} marker ${value}${withForces ? ' with forces' : ' alone'} collects on actual Ambassador relocation`, () => { const {game,marker} = source(advanced,value,withForces); const before = structuredClone(game), richese = player(game,'richese'); const publicMarker = viewGame(game,'atreides').players.find(seat => seat.id === 'richese')!.noField; assert.ok(publicMarker); assert.ok(!JSON.stringify(publicMarker).includes(marker), 'A rival does not receive the private token identity'); const own = viewGame(game,'richese'); const offered = own.ambassadorEntry?.movement?.sources.find(row => row.territory === 'red_chasm'); assert.equal(offered?.marker?.tokenId,marker); const done = applyAction(game,'richese',{type:'decision',event:game.pendingAmbassador!.event, forces:withForces ? {'red_chasm:7':2} : {},noField:{tokenId:marker,event:richese.noFieldEvent!}, territory:'south_mesa',sector:4,sandmasterCollect:true,sandmasterPile:'south_mesa:5'}); const moved = player(done,'richese'); assert.equal(moved.spice,richese.spice+1); assert.equal(done.spice['south_mesa:4'],4); assert.equal(done.spice['south_mesa:5'],1); assert.deepEqual(moved.noField?.deployed?.location,{territory:'south_mesa',sector:4}); assert.equal(moved.noField?.deployed?.tokenId,marker); assert.notEqual(moved.noFieldEvent,richese.noFieldEvent); assert.equal(moved.reserves,richese.reserves); assert.equal(moved.forces['south_mesa:4'] ?? 0,withForces ? 2 : 0); assert.equal(moved.moved,richese.moved); assert.equal(moved.shipped,richese.shipped); assert.equal(done.log.filter(row => row.automatic?.name === 'Sandmaster collection').length, before.log.filter(row => row.automatic?.name === 'Sandmaster collection').length + 1); assertInventory(done); }); void test('four bot profiles can legally relocate the sole marker in the real Ambassador window', () => { const {game} = source(false,0,false); for (const difficulty of DIFFICULTIES) { const view = viewGame(game,'richese'); view.players.find(seat => seat.id === 'richese')!.bot = difficulty; const choice = botActions(view).find(action => action.type === 'decision' && action.noField); assert.ok(choice,difficulty); assert.doesNotThrow(() => applyAction(structuredClone(game),'richese',choice),difficulty); } });