Allow Advanced Emperor gifts during Guild rate responses
Verify and publish checkpoint container / container (push) Successful in 11m3s
Verify and publish checkpoint container / container (push) Successful in 11m3s
This commit is contained in:
1 parent
b3843bf18e
commit
5e7f7b45e4
14 files changed
+475
-6
No files matched your search
@@ -0,0 +1,118 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {botActions, runBots} from '../game/bots';
|
||||
import {DIFFICULTIES} from '../game/bot-profiles';
|
||||
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';
|
||||
|
||||
/** Genuine public Advanced setup, actual second-turn worm, reciprocal consent
|
||||
* and Guild shipment. Only unopened Spice order, personal purses and physical
|
||||
* counter cards are staged; the alliance, payment and original rate window
|
||||
* are reached through native actions. */
|
||||
function fixture(counters: number) {
|
||||
const base=createTruthBidFixture({advanced:true,window:'waiting',extraGuild:true});
|
||||
let game=advance(base.game,state=>state.turn===2&&beforeIxSpiceDraw(state));
|
||||
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');
|
||||
const cards=inventory(game);
|
||||
// Keep all counters in one public responder's actual hand; the no-counter
|
||||
// case genuinely removes every playable physical Karama from all hands.
|
||||
for(const seat of game.players) {
|
||||
const keep=seat.hand.filter(card=>card.effect!=='karama');
|
||||
game.deck.push(...seat.hand.filter(card=>card.effect==='karama'));
|
||||
seat.hand=keep;
|
||||
}
|
||||
const counterIds:string[]=[];
|
||||
for(let n=0;n<counters;n++) {
|
||||
const index=game.deck.findIndex(card=>card.effect==='karama');assert.ok(index>=0);
|
||||
const [card]=game.deck.splice(index,1);counterIds.push(card.id);
|
||||
player(game,'atreides').hand.push(card);
|
||||
}
|
||||
assert.deepEqual(inventory(game),cards);
|
||||
player(game,'guild').spice=2;player(game,'emperor').spice=8;
|
||||
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});
|
||||
assert.equal(game.response?.kind,'guildRate');assert.equal(game.pendingShipment?.cost,2);
|
||||
return {game,cards,counterIds};
|
||||
}
|
||||
function passResponse(game:Game):Game {
|
||||
for(let n=0;game.response&&n<20;n++) {
|
||||
const actor=game.players.find(row=>!game.response!.passed.includes(row.id));assert.ok(actor);
|
||||
game=act(game,actor.id,{type:'passResponse'});
|
||||
}
|
||||
return game;
|
||||
}
|
||||
function reject(game:Game,id:string,action:Action) {
|
||||
const before=structuredClone(game);assert.throws(()=>act(game,id,action));assert.deepEqual(game,before);
|
||||
}
|
||||
function priority(game:Game) {
|
||||
const view=viewGame(game,'emperor');
|
||||
const opportunity=view.emperorGuildRatePriority;assert.ok(opportunity?.canContinue);
|
||||
assert.equal(opportunity.recipient,'guild');return opportunity;
|
||||
}
|
||||
|
||||
void test('Advanced Emperor gift preserves original Guild rate and funds the unchanged full-price shipment',()=>{
|
||||
const f=fixture(1);let game=f.game;
|
||||
const before=structuredClone(game),original=structuredClone(game.response),shipment=structuredClone(game.pendingShipment);
|
||||
assert.deepEqual(viewGame(game,'emperor').emperorGuildRateGift,{recipient:'guild',maximum:8});
|
||||
assert.equal(viewGame(game,'atreides').emperorGuildRateGift,null);
|
||||
priority(game);reject(game,'atreides',{type:'card',mode:'cancel',card:f.counterIds[0]});
|
||||
game=act(game,'emperor',{type:'emperorGift',amount:2});
|
||||
assert.equal(game.response?.kind,'emperorGift');
|
||||
while(game.response?.kind==='emperorGift') {
|
||||
const actor=game.players.find(row=>!game.response!.passed.includes(row.id));assert.ok(actor);
|
||||
game=act(game,actor.id,{type:'passResponse'});
|
||||
}
|
||||
assert.deepEqual(game.response,original);assert.deepEqual(game.pendingShipment,shipment);
|
||||
assert.equal(player(game,'emperor').spice,player(before,'emperor').spice-2);
|
||||
assert.equal(player(game,'guild').spice,player(before,'guild').spice+2);
|
||||
game=act(game,'atreides',{type:'card',mode:'cancel',card:f.counterIds[0]});
|
||||
assert.equal(game.pendingShipment,null);assert.equal(player(game,'guild').spice,0);
|
||||
assert.equal(player(game,'guild').forces['polar_sink:0'],2);
|
||||
assert.deepEqual(inventory(game),f.cards);
|
||||
});
|
||||
|
||||
void test('canceling the gift restores its original rate window and unfunded rate cancellation withdraws shipment',()=>{
|
||||
const f=fixture(2);let game=f.game;
|
||||
const before=structuredClone(game),original=structuredClone(game.response),shipment=structuredClone(game.pendingShipment);
|
||||
priority(game);game=act(game,'emperor',{type:'emperorGift',amount:2});
|
||||
game=act(game,'atreides',{type:'card',mode:'cancel',card:f.counterIds[0]});
|
||||
assert.deepEqual(game.response,original);assert.deepEqual(game.pendingShipment,shipment);
|
||||
assert.equal(player(game,'emperor').spice,player(before,'emperor').spice);
|
||||
assert.equal(player(game,'guild').spice,player(before,'guild').spice);
|
||||
game=act(game,'atreides',{type:'card',mode:'cancel',card:f.counterIds[1]});
|
||||
assert.equal(game.pendingShipment,null);assert.equal(player(game,'guild').spice,2);
|
||||
assert.equal(player(game,'guild').shipped,false);assert.ok(game.guildRateBlocked);
|
||||
assert.deepEqual(inventory(game),f.cards);
|
||||
});
|
||||
|
||||
void test('a counter-free rate window waits for the human Emperor and every bot may continue',()=>{
|
||||
const f=fixture(0), initial=f.game;const opportunity=priority(initial);
|
||||
assert.equal(initial.response?.kind,'guildRate');
|
||||
const empty=structuredClone(initial);player(empty,'emperor').spice=0;
|
||||
assert.deepEqual(viewGame(empty,'guild').emperorGuildRatePriority,viewGame(initial,'guild').emperorGuildRatePriority);
|
||||
assert.equal(viewGame(empty,'emperor').emperorGuildRateGift,null);
|
||||
for(const difficulty of DIFFICULTIES) {
|
||||
let game=structuredClone(initial);player(game,'guild').bot=difficulty;
|
||||
const waiting=runBots(game,2);assert.deepEqual(waiting.response,game.response);
|
||||
const view=viewGame(game,'emperor');view.players.find(row=>row.id==='emperor')!.bot=difficulty;
|
||||
const action=botActions(view).find(row=>row.type==='emperorGuildRateContinue');assert.ok(action,difficulty);
|
||||
assert.equal(action.event,opportunity.event);
|
||||
const automated=structuredClone(game);player(automated,'emperor').bot=difficulty;
|
||||
const resumed=runBots(automated,1);
|
||||
assert.equal(resumed.pendingShipment??null,null,`${difficulty} bot releases the original rate`);
|
||||
assert.equal(player(resumed,'guild').forces['polar_sink:0'],2);
|
||||
game=act(game,'emperor',action);
|
||||
game=passResponse(game);
|
||||
assert.equal(player(game,'guild').spice,0);assert.equal(player(game,'guild').forces['polar_sink:0'],2);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,54 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {Children, createElement, isValidElement} from 'react';
|
||||
import {renderToStaticMarkup} from 'react-dom/server';
|
||||
import {EmperorTimingGift} from '../components/emperor-timing-gift';
|
||||
import {EmperorGuildRatePriority} from '../components/emperor-guild-rate-priority';
|
||||
import type {Action, GameView} from '../game/engine';
|
||||
|
||||
function priorityProps() {
|
||||
const sent:Action[] = [];
|
||||
const game = {emperorGuildRatePriority:{event:'rate-event',recipient:'guild',canContinue:true},
|
||||
players:[{id:'guild',name:'Guild'}]} as unknown as Pick<GameView,'emperorGuildRatePriority'|'players'>;
|
||||
return {game, busy:false, sent, act:(action:Action) => sent.push(action)};
|
||||
}
|
||||
function button(props:ReturnType<typeof priorityProps>) {
|
||||
const panel = EmperorGuildRatePriority(props); assert.ok(panel);
|
||||
const row = Children.toArray(panel.props.children).find(child => isValidElement(child) && child.type === 'button');
|
||||
assert.ok(isValidElement<{onClick:()=>void;disabled:boolean}>(row)); return row;
|
||||
}
|
||||
|
||||
void test('Guild rate opportunity offers a persistent Continue to the Emperor', () => {
|
||||
const props=priorityProps();
|
||||
const html=renderToStaticMarkup(createElement(EmperorGuildRatePriority,props));
|
||||
assert.match(html,/Emperor may share spice with Guild/);
|
||||
assert.match(html,/Continue to Guild rate/);
|
||||
button(props).props.onClick();
|
||||
assert.deepEqual(props.sent,[{type:'emperorGuildRateContinue',event:'rate-event'}]);
|
||||
});
|
||||
|
||||
void test('other seats see a neutral wait and stale or busy Continue controls do not submit', () => {
|
||||
const other=priorityProps();other.game.emperorGuildRatePriority!.canContinue=false;
|
||||
assert.match(renderToStaticMarkup(createElement(EmperorGuildRatePriority,other)),/Waiting for the Emperor/);
|
||||
for(const variant of ['busy','event','permission','replace','close'] as const) {
|
||||
const props=priorityProps();if(variant==='busy')props.busy=true;const control=button(props);
|
||||
if(variant==='event')props.game.emperorGuildRatePriority!.event='another-event';
|
||||
if(variant==='permission')props.game.emperorGuildRatePriority!.canContinue=false;
|
||||
if(variant==='replace')props.game.emperorGuildRatePriority={...props.game.emperorGuildRatePriority!};
|
||||
if(variant==='close')props.game.emperorGuildRatePriority=null;
|
||||
control.props.onClick();assert.deepEqual(props.sent,[],variant);
|
||||
}
|
||||
});
|
||||
|
||||
void test('the private Guild rate quote shows the existing gift form and amount limits', () => {
|
||||
const game={emperorPhaseOpeningGift:null,emperorExtortionGift:null,emperorGuildTimingGift:null,
|
||||
emperorGuildRateGift:{recipient:'guild',maximum:4},players:[{id:'guild',name:'Guild'}]} as unknown as GameView;
|
||||
const render=(view:GameView,busy=false)=>renderToStaticMarkup(createElement(EmperorTimingGift,{game:view,busy,act(){}}));
|
||||
const html=render(game);
|
||||
assert.match(html,/Share spice with Guild/);
|
||||
assert.match(html,/original Guild rate response resumes/);
|
||||
assert.match(html,/type="number"[^>]*min="1"[^>]*max="4"/);
|
||||
assert.match(html,/<button\b(?![^>]*disabled)[^>]*>Share spice<\/button>/);
|
||||
assert.match(render(game,true),/<button\b[^>]*disabled=""[^>]*>Share spice<\/button>/);
|
||||
assert.equal(render({...game,emperorGuildRateGift:null}),'');
|
||||
});
|
||||
@@ -0,0 +1,101 @@
|
||||
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);
|
||||
});
|
||||
@@ -48,6 +48,8 @@ function declare(g: Game, id: 'g' | 'e', amount: number, destination = 'arrakeen
|
||||
}
|
||||
function cancel(g: Game, card: string): Game {
|
||||
assert.equal(g.response?.kind, 'guildRate');
|
||||
const priority = viewGame(g, 'e').emperorGuildRatePriority;
|
||||
if (priority?.canContinue) g = applyAction(g, 'e', {type:'emperorGuildRateContinue', event:priority.event});
|
||||
return applyAction(reload(g), 'a', { type: 'card', mode: 'cancel', card });
|
||||
}
|
||||
function reject(g: Game, actor: string, action: Action) {
|
||||
@@ -197,6 +199,17 @@ void test('the Advanced Guild stop decision precedes the separate Karama rate re
|
||||
assert.equal(player(done, 'e').forces['arrakeen:10'], 3);
|
||||
});
|
||||
|
||||
void test('an Advanced Emperor shipper cannot gift spice reserved for its pending Guild-rate payment', () => {
|
||||
const {g:initial} = fixture('e', true);
|
||||
const declared = declare(initial, 'e', 3);
|
||||
const offered = applyAction(declared, 'g', {type:'decision',allow:true});
|
||||
const gift = viewGame(offered, 'e').emperorGuildRateGift; assert.ok(gift);
|
||||
assert.equal(gift.maximum, player(offered, 'e').spice - offered.pendingShipment!.cost);
|
||||
reject(offered, 'e', {type:'emperorGift',amount:gift.maximum + 1});
|
||||
const accepted = applyAction(offered, 'e', {type:'emperorGift',amount:gift.maximum});
|
||||
assert.equal(accepted.response?.kind, 'emperorGift');
|
||||
});
|
||||
|
||||
void test('an unstamped saved Advanced declaration gains a turn stamp before its new rate response', () => {
|
||||
const { g: initial, karama } = fixture('e', true);
|
||||
const legacy = declare(initial, 'e', 3);
|
||||
|
||||
@@ -51,6 +51,11 @@ function answerYes(f:ReturnType<typeof fixture>, minimum:number) {
|
||||
}
|
||||
function passResponses(game:Game):Game {
|
||||
for(let i=0;game.response && i<20;i++) {
|
||||
const priority=viewGame(game,'emperor').emperorGuildRatePriority;
|
||||
if(priority?.canContinue) {
|
||||
game=act(game,'emperor',{type:'emperorGuildRateContinue',event:priority.event});
|
||||
continue;
|
||||
}
|
||||
const actor=game.players.find(row=>!game.response!.passed.includes(row.id));assert.ok(actor);
|
||||
game=act(game,actor.id,{type:'passResponse'});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user