102 lines
6.2 KiB
TypeScript
102 lines
6.2 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import {territory} from '../game/board';
|
|
import {type Action, type Game, viewGame} from '../game/engine';
|
|
import {createTruthBidFixture} from './fixture-truth-bid';
|
|
import {actTruthAlliance as act, advanceTruthAlliance as advance,
|
|
truthAllianceClean as clean, truthAllianceInventory as inventory,
|
|
truthAllianceNexus, truthAlliancePlayer as player} from './fixture-truth-alliance';
|
|
import {beforeIxSpiceDraw, orderIxSpiceCards} from './fixture-ix-spice-cards';
|
|
|
|
function passKind(game:Game, kind:string):Game {
|
|
for(let n=0;game.response?.kind===kind&&n<20;n++) {
|
|
const responder=game.players.find(row=>!game.response!.passed.includes(row.id));assert.ok(responder);
|
|
game=act(game,responder.id,{type:'passResponse'});
|
|
}
|
|
return game;
|
|
}
|
|
function rejected(game:Game,id:string,action:Action) {
|
|
const before=structuredClone(game);assert.throws(()=>act(game,id,action));assert.deepEqual(game,before);
|
|
}
|
|
|
|
/** Public Advanced setup and an actual first-turn Guild shipment to Polar
|
|
* Sink; an actual second-turn worm and reciprocal consent create the alliance.
|
|
* Only unopened Spice order, purses and physical Karama locations are staged. */
|
|
function fixture(destination:'cross'|'return') {
|
|
const base=createTruthBidFixture({advanced:true,window:'waiting',extraGuild:true});
|
|
let game=advance(base.game,state=>state.turn===1&&state.phase===5&&state.active==='guild'&&clean(state));
|
|
game=act(game,'guild',{type:'ship',territory:'polar_sink',sector:0,amount:2,allyPayment:0});
|
|
if(game.decision?.kind==='guildShipment')game=act(game,'guild',{type:'decision',allow:true});
|
|
game=passKind(game,'guildRate');
|
|
game=advance(game,state=>state.turn===2&&beforeIxSpiceDraw(state));
|
|
assert.equal(player(game,'guild').forces['polar_sink:0'],2);
|
|
orderIxSpiceCards(game,['worm','land','land']);
|
|
game=advance(game,truthAllianceNexus);
|
|
game=act(game,'guild',{type:'alliance',target:'emperor'});
|
|
game=act(game,'emperor',{type:'alliance',target:'guild'});
|
|
game=advance(game,state=>state.phase===5&&state.active==='guild'&&clean(state));
|
|
assert.equal(player(game,'guild').ally,'emperor');assert.equal(player(game,'emperor').ally,'guild');
|
|
assert.equal(player(game,'guild').forces['polar_sink:0'],2);
|
|
const original=inventory(game);
|
|
for(const seat of game.players) {
|
|
game.deck.push(...seat.hand.filter(card=>card.effect==='karama'));
|
|
seat.hand=seat.hand.filter(card=>card.effect!=='karama');
|
|
}
|
|
const counters:string[]=[];
|
|
for(let n=0;n<2;n++) {
|
|
const index=game.deck.findIndex(card=>card.effect==='karama');assert.ok(index>=0);
|
|
const [card]=game.deck.splice(index,1);player(game,'atreides').hand.push(card);counters.push(card.id);
|
|
}
|
|
assert.deepEqual(inventory(game),original);
|
|
const sector=territory('red_chasm').sectors.find(value=>value!==game.storm);assert.notEqual(sector,undefined);
|
|
const action:Action=destination==='cross'
|
|
? {type:'guildShip',from:'polar_sink:0',territory:'red_chasm',sector,amount:2,allyPayment:0}
|
|
: {type:'guildShip',from:'polar_sink:0',territory:'reserves',sector:0,amount:2,allyPayment:0};
|
|
const half=destination==='cross'?2:1;
|
|
player(game,'guild').spice=half;player(game,'emperor').spice=8;
|
|
game=act(game,'guild',action);
|
|
assert.equal(game.response?.kind,'guildTransportPermission');assert.equal(game.pendingGuildTransport?.cost,half);
|
|
game=passKind(game,'guildTransportPermission');
|
|
assert.equal(game.response?.kind,'guildRate');assert.equal(game.pendingGuildTransport?.cost,half);
|
|
return {game,original,counters,half,sector};
|
|
}
|
|
|
|
for(const destination of ['cross','return'] as const) void test(
|
|
`Advanced Emperor gift preserves native Guild ${destination} transport through rate cancellation`,()=>{
|
|
const f=fixture(destination);let game=f.game;
|
|
const original=structuredClone(game.response),frame=structuredClone(game.pendingGuildTransport);
|
|
const oldReserves=player(game,'guild').reserves, priority=viewGame(game,'emperor').emperorGuildRatePriority;
|
|
assert.ok(priority?.canContinue);assert.equal(priority.recipient,'guild');
|
|
assert.deepEqual(viewGame(game,'emperor').emperorGuildRateGift,{recipient:'guild',maximum:8});
|
|
rejected(game,'atreides',{type:'card',mode:'cancel',card:f.counters[0]});
|
|
game=act(game,'emperor',{type:'emperorGift',amount:f.half});
|
|
assert.equal(game.response?.kind,'emperorGift');game=passKind(game,'emperorGift');
|
|
assert.deepEqual(game.response,original);assert.deepEqual(game.pendingGuildTransport,frame);
|
|
assert.equal(player(game,'guild').spice,2*f.half);
|
|
game=act(game,'atreides',{type:'card',mode:'cancel',card:f.counters[0]});
|
|
assert.equal(game.pendingGuildTransport,null);assert.equal(player(game,'guild').spice,0);
|
|
assert.equal(player(game,'guild').forces['polar_sink:0']??0,0);
|
|
if(destination==='cross') {
|
|
assert.equal(player(game,'guild').forces[`red_chasm:${f.sector}`],2);
|
|
assert.equal(player(game,'guild').reserves,oldReserves);
|
|
} else assert.equal(player(game,'guild').reserves,oldReserves+2);
|
|
assert.deepEqual(inventory(game),f.original);
|
|
});
|
|
|
|
for(const destination of ['cross','return'] as const) void test(
|
|
`Advanced canceled gift retains native Guild ${destination} transport until its unfunded rate cancellation`,()=>{
|
|
const f=fixture(destination);let game=f.game;
|
|
const original=structuredClone(game.response),frame=structuredClone(game.pendingGuildTransport);
|
|
const oldReserves=player(game,'guild').reserves;
|
|
assert.ok(viewGame(game,'emperor').emperorGuildRatePriority?.canContinue);
|
|
game=act(game,'emperor',{type:'emperorGift',amount:f.half});
|
|
game=act(game,'atreides',{type:'card',mode:'cancel',card:f.counters[0]});
|
|
assert.deepEqual(game.response,original);assert.deepEqual(game.pendingGuildTransport,frame);
|
|
assert.equal(player(game,'guild').spice,f.half);assert.equal(player(game,'emperor').spice,8);
|
|
game=act(game,'atreides',{type:'card',mode:'cancel',card:f.counters[1]});
|
|
assert.equal(game.pendingGuildTransport,null);assert.equal(player(game,'guild').spice,f.half);
|
|
assert.equal(player(game,'guild').forces['polar_sink:0'],2);
|
|
assert.equal(player(game,'guild').reserves,oldReserves);assert.equal(player(game,'guild').shipped,false);
|
|
assert.ok(game.guildRateBlocked);assert.deepEqual(inventory(game),f.original);
|
|
});
|