Support Advanced Truthtrance ally funding
Verify and publish checkpoint container / container (push) Successful in 11m4s
Verify and publish checkpoint container / container (push) Successful in 11m4s
This commit is contained in:
1 parent
e1209083e6
commit
b3843bf18e
10 files changed
+383
-11
No files matched your search
@@ -0,0 +1,58 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {registerHooks} from 'node:module';
|
||||
import {readFileSync} from 'node:fs';
|
||||
import {createElement} from 'react';
|
||||
import {renderToStaticMarkup} from 'react-dom/server';
|
||||
import {viewGame, type Game} from '../game/engine';
|
||||
import {actTruthAlliance as act, advanceTruthAlliance as advance, createTruthAllianceFixture,
|
||||
truthAllianceClean as clean, truthAlliancePlayer as player} from './fixture-truth-alliance';
|
||||
import {declareTruthBribe} from './fixture-truth-bribe';
|
||||
|
||||
const aliases = registerHooks({
|
||||
resolve(specifier, context, next) {
|
||||
return next(specifier === 'next/image' ? 'vinext/shims/image' :
|
||||
specifier === 'next/link' ? 'vinext/shims/link' : specifier, context);
|
||||
},
|
||||
load(url, context, next) {
|
||||
if (!url.endsWith('.module.css')) return next(url, context);
|
||||
const css = readFileSync(new URL(url), 'utf8');
|
||||
const classes = Object.fromEntries([...css.matchAll(/\.([a-zA-Z_][\w-]*)/g)].map(match => [match[1], match[1]]));
|
||||
return {format:'module', source:`export default ${JSON.stringify(classes)}`, shortCircuit:true};
|
||||
},
|
||||
});
|
||||
const {Truthtrance} = await import('../components/truthtrance');
|
||||
aliases.deregister();
|
||||
|
||||
/** Native Advanced setup, ordinary worm and consensual alliance. The only
|
||||
* staged inputs are the fixture's unopened physical deal and Spice order. */
|
||||
function asked(phase: 3 | 5, tooMuch: boolean) {
|
||||
const f = createTruthAllianceFixture({advanced:true, consent:'allied'});
|
||||
let game = advance(f.game, state => state.phase === phase && (phase !== 3 || !!state.auction) && clean(state));
|
||||
const minimum = tooMuch ? player(game, f.target).spice + (game.aid[f.target]?.amount ?? 0) + 1 : 1;
|
||||
game = declareTruthBribe(f, game).game;
|
||||
assert.ok(viewGame(game, f.asker).truthPledgeTargets.includes(f.target));
|
||||
game = act(game, f.asker, {type:'truthAsk', question:{kind:'pledgeAid',target:f.target,
|
||||
turn:game.turn,phase,ally:f.partner,minimum}});
|
||||
return {game, target:f.target, asker:f.asker};
|
||||
}
|
||||
|
||||
function markup(game:Game, actor:string, busy = false) {
|
||||
return renderToStaticMarkup(createElement(Truthtrance, {game:viewGame(game,actor),busy,act() {
|
||||
assert.fail('Rendering must not send an answer');
|
||||
}}));
|
||||
}
|
||||
|
||||
for (const phase of [3,5] as const) void test(`Advanced phase ${phase} shows only legal Truthtrance funding answers`, () => {
|
||||
const available = asked(phase,false);
|
||||
const view = viewGame(available.game,available.target);
|
||||
assert.ok(view.truthPledgeAnswers?.includes('yes')); assert.ok(view.truthPledgeAnswers?.includes('no'));
|
||||
assert.equal(viewGame(available.game,available.asker).truthPledgeAnswers,null);
|
||||
const html = markup(available.game,available.target);
|
||||
assert.match(html,/Answer Yes/); assert.match(html,/Answer No/);
|
||||
assert.match(html,/future funding update/);
|
||||
const unavailable = asked(phase,true);
|
||||
assert.deepEqual(viewGame(unavailable.game,unavailable.target).truthPledgeAnswers,['no']);
|
||||
const noOnly = markup(unavailable.game,unavailable.target);
|
||||
assert.doesNotMatch(noOnly,/Answer Yes/); assert.match(noOnly,/Answer No/);
|
||||
});
|
||||
@@ -0,0 +1,87 @@
|
||||
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 {actTruthAlliance as act, advanceTruthAlliance as advance,
|
||||
truthAllianceClean as clean, truthAllianceInventory as inventory,
|
||||
truthAllianceNexus, truthAlliancePlayer as player} from './fixture-truth-alliance';
|
||||
import {createTruthBidFixture} from './fixture-truth-bid';
|
||||
import {declareTruthBribe} from './fixture-truth-bribe';
|
||||
import {beforeIxSpiceDraw, orderIxSpiceCards} from './fixture-ix-spice-cards';
|
||||
|
||||
/** Public Advanced setup and real turn-one Polar shipment, then a natural
|
||||
* second-turn worm and reciprocal Emperor/Guild alliance. Selected unopened
|
||||
* setup and Spice order are inherited from the native fixture; one actual
|
||||
* Karama is moved between physical card zones to keep permission open. */
|
||||
function fixture() {
|
||||
const base=createTruthBidFixture({advanced:true,window:'waiting',extraGuild:true});
|
||||
let game=advance(base.game,state=>state.turn===1 && state.phase===5 && state.active===base.target && clean(state));
|
||||
assert.ok(!player(game,base.target).shipped);
|
||||
game=act(game,base.target,{type:'ship',territory:'polar_sink',sector:0,amount:2,allyPayment:0});
|
||||
game=advance(game,state=>state.turn===2 && beforeIxSpiceDraw(state));
|
||||
assert.equal(player(game,base.target).forces['polar_sink:0'],2);
|
||||
orderIxSpiceCards(game,['worm','land','land']);
|
||||
game=advance(game,truthAllianceNexus);
|
||||
game=act(game,'guild',{type:'alliance',target:base.target});
|
||||
game=act(game,base.target,{type:'alliance',target:'guild'});
|
||||
game=advance(game,state=>state.phase===5 && state.active===base.target && clean(state));
|
||||
assert.equal(player(game,base.target).ally,'guild');
|
||||
assert.equal(player(game,'guild').ally,base.target);
|
||||
assert.equal(player(game,base.target).forces['polar_sink:0'],2);
|
||||
assert.ok(!player(game,base.target).shipped);
|
||||
const recipient=player(game,base.opponent);
|
||||
if(!recipient.hand.some(card=>card.effect==='karama')) {
|
||||
const index=game.deck.findIndex(card=>card.effect==='karama');assert.ok(index>=0);
|
||||
if(recipient.hand.length>=4)game.deck.push(recipient.hand.pop()!);
|
||||
recipient.hand.push(...game.deck.splice(index,1));
|
||||
}
|
||||
assert.deepEqual(inventory(game),base.originalCards);
|
||||
const sector=territory('red_chasm').sectors.find(value=>value!==game.storm);assert.notEqual(sector,undefined);
|
||||
const transport:Action={type:'guildShip',from:'polar_sink:0',amount:2,
|
||||
territory:'red_chasm',sector,allyPayment:0};
|
||||
return {...base,game,ally:'guild',transport,physical:inventory(game)};
|
||||
}
|
||||
function answerYes(f:ReturnType<typeof fixture>, minimum:number) {
|
||||
let game=declareTruthBribe(f,f.game).game;
|
||||
game=act(game,f.asker,{type:'truthAsk',question:{kind:'pledgeAid',target:f.target,
|
||||
turn:game.turn,phase:5,ally:f.ally,minimum}});
|
||||
assert.ok(viewGame(game,f.target).truthPledgeAnswers?.includes('yes'));
|
||||
game=act(game,f.target,{type:'truthAnswer',answer:'yes'});
|
||||
return game;
|
||||
}
|
||||
function passResponses(game:Game):Game {
|
||||
for(let i=0;game.response && i<20;i++) {
|
||||
const actor=game.players.find(row=>!game.response!.passed.includes(row.id));assert.ok(actor);
|
||||
game=act(game,actor.id,{type:'passResponse'});
|
||||
}
|
||||
return game;
|
||||
}
|
||||
|
||||
void test('Advanced pledge Yes rejects a Guild cross-shipment that consumes its last completion funds',()=>{
|
||||
const f=fixture(), available=player(f.game,f.target).spice;assert.ok(available>=3);
|
||||
const game=answerYes(f,available-1), before=structuredClone(game);
|
||||
assert.throws(()=>act(game,f.target,f.transport));
|
||||
assert.deepEqual(game,before);
|
||||
assert.equal(game.pendingGuildTransport??null,null);
|
||||
assert.ok(!game.pledgePromises?.at(-1)?.fulfilled && !game.pledgePromises?.at(-1)?.released);
|
||||
assert.deepEqual(inventory(game),f.physical);
|
||||
});
|
||||
|
||||
void test('Advanced pledge Yes permits a funded Guild cross-shipment and its native responses',()=>{
|
||||
const f=fixture(), available=player(f.game,f.target).spice;assert.ok(available>=3);
|
||||
let game=answerYes(f,available-2);
|
||||
game=act(game,f.target,f.transport);
|
||||
assert.equal(game.response?.kind,'guildTransportPermission');
|
||||
assert.equal(game.pendingGuildTransport?.cost,2);
|
||||
assert.equal(player(game,f.target).spice,available);
|
||||
game=passResponses(game);
|
||||
// Allow the native rate response too, if one remains after permission.
|
||||
game=passResponses(game);
|
||||
assert.equal(game.pendingGuildTransport??null,null);
|
||||
assert.equal(player(game,f.target).spice,available-2);
|
||||
assert.equal(player(game,f.target).forces['polar_sink:0']??0,0);
|
||||
const guide=viewGame(game,f.target).pledgePromiseGuide;assert.ok(guide);
|
||||
game=act(game,f.target,guide.action);
|
||||
assert.equal(game.pledgePromises?.at(-1)?.fulfilled,true);
|
||||
assert.deepEqual(inventory(game),f.physical);
|
||||
});
|
||||
@@ -0,0 +1,168 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { viewGame, type Action, type Game } from '../game/engine';
|
||||
import { botActions } from '../game/bots';
|
||||
import { DIFFICULTIES } from '../game/bot-profiles';
|
||||
import { actTruthAlliance as act, advanceTruthAlliance as advance, createTruthAllianceFixture,
|
||||
truthAllianceClean as clean, truthAllianceInventory as inventory,
|
||||
truthAlliancePlayer as player } from './fixture-truth-alliance';
|
||||
import { declareTruthBribe } from './fixture-truth-bribe';
|
||||
import { createTruthBidFixture } from './fixture-truth-bid';
|
||||
import { truthAllianceNexus } from './fixture-truth-alliance';
|
||||
import { beforeIxSpiceDraw, orderIxSpiceCards } from './fixture-ix-spice-cards';
|
||||
|
||||
/** Genuine public Advanced start, actual turn-two worm and reciprocal alliance.
|
||||
* Only unopened setup/deck/Spice order and scalar lotteries are selected by
|
||||
* the shared fixture; wallets, alliances, auctions and commitments are earned. */
|
||||
function fixture(phase: 3 | 5 = 3) {
|
||||
const base = createTruthAllianceFixture({advanced:true, consent:'allied'});
|
||||
const game = advance(base.game, state => state.phase === phase &&
|
||||
(phase !== 3 || !!state.auction) && clean(state));
|
||||
assert.equal(player(game,base.target).ally,base.partner);
|
||||
assert.equal(player(game,base.partner).ally,base.target);
|
||||
assert.deepEqual(inventory(game),base.originalCards);
|
||||
return {...base, game, ally:base.partner, physical:inventory(game)};
|
||||
}
|
||||
/** A public four-seat Advanced game with the Guild. Its original second-turn
|
||||
* worm opens the actual Nexus; Atreides and Emperor explicitly consent before
|
||||
* the Emperor's native Shipment and Movement turn. */
|
||||
function guildShipmentFixture() {
|
||||
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,base.opponent,{type:'alliance',target:base.target});
|
||||
game=act(game,base.target,{type:'alliance',target:base.opponent});
|
||||
game=advance(game,state=>state.phase===5&&state.active===base.target&&clean(state));
|
||||
assert.equal(player(game,base.target).ally,base.opponent);
|
||||
assert.equal(player(game,base.opponent).ally,base.target);
|
||||
assert.ok(!player(game,base.target).shipped);
|
||||
assert.deepEqual(inventory(game),base.originalCards);
|
||||
return {...base,game,ally:base.opponent,physical:inventory(game)};
|
||||
}
|
||||
function ask(f:{game:Game;asker:string;target:string;ally:string;truths:string[]}, source:Game, minimum:number) {
|
||||
let game=declareTruthBribe(f,source).game;
|
||||
assert.ok(viewGame(game,f.asker).truthPledgeTargets.includes(f.target));
|
||||
game=act(game,f.asker,{type:'truthAsk',question:{kind:'pledgeAid',target:f.target,
|
||||
turn:game.turn,phase:game.phase,ally:f.ally,minimum}});
|
||||
return game;
|
||||
}
|
||||
function rejected(game:Game, id:string, action:Action) {
|
||||
const before=structuredClone(game);
|
||||
assert.throws(()=>act(game,id,action));assert.deepEqual(game,before);
|
||||
}
|
||||
function promise(game:Game) {
|
||||
const row=game.pledgePromises?.at(-1);assert.ok(row);return row;
|
||||
}
|
||||
function passResponse(game:Game) {
|
||||
for(let n=0;game.response&&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'});
|
||||
}
|
||||
assert.equal(game.response,null);return game;
|
||||
}
|
||||
|
||||
for(const phase of [3,5] as const) void test(`Advanced phase ${phase} pledge Yes preserves native escrow and bot continuation`,()=>{
|
||||
const f=fixture(phase);
|
||||
let game=act(f.game,f.target,{type:'pledgeAid',amount:1});
|
||||
const before=structuredClone(game),recipientSpice=player(game,f.ally).spice;
|
||||
game=ask(f,game,4);
|
||||
assert.ok(viewGame(game,f.target).truthPledgeAnswers?.includes('yes'));
|
||||
game=act(game,f.target,{type:'truthAnswer',answer:'yes'});
|
||||
assert.ok(!promise(game).fulfilled);
|
||||
const guide=viewGame(game,f.target).pledgePromiseGuide;assert.ok(guide);
|
||||
assert.equal(guide.action.type,'pledgeAid');assert.equal(guide.action.amount,4);
|
||||
for(const difficulty of DIFFICULTIES) {
|
||||
const view=viewGame(game,f.target);view.players.find(row=>row.id===f.target)!.bot=difficulty;
|
||||
const action=botActions(view)[0];assert.ok(action,difficulty);
|
||||
assert.doesNotThrow(()=>act(game,f.target,action),difficulty);
|
||||
}
|
||||
game=act(game,f.target,guide.action);
|
||||
assert.equal(promise(game).fulfilled,true);
|
||||
assert.equal(game.aid[f.target].recipient,f.ally);assert.equal(game.aid[f.target].amount,4);
|
||||
assert.equal(player(game,f.target).spice,player(before,f.target).spice-3);
|
||||
assert.equal(player(game,f.ally).spice,recipientSpice);
|
||||
assert.deepEqual(inventory(game),f.physical);
|
||||
});
|
||||
|
||||
for(const phase of [3,5] as const) void test(`Advanced phase ${phase} pledge No prevents qualifying future updates`,()=>{
|
||||
const f=fixture(phase);let game=ask(f,f.game,3);
|
||||
assert.ok(viewGame(game,f.target).truthPledgeAnswers?.includes('no'));
|
||||
game=act(game,f.target,{type:'truthAnswer',answer:'no'});
|
||||
game=act(game,f.target,{type:'pledgeAid',amount:2});
|
||||
const aid=structuredClone(game.aid[f.target]),spice=player(game,f.target).spice;
|
||||
rejected(game,f.target,{type:'pledgeAid',amount:3});
|
||||
assert.deepEqual(game.aid[f.target],aid);assert.equal(player(game,f.target).spice,spice);
|
||||
assert.deepEqual(inventory(game),f.physical);
|
||||
});
|
||||
|
||||
void test('Advanced pledge excludes an unaffordable Yes without mutating native resources',()=>{
|
||||
const f=fixture(), game=ask(f,f.game,player(f.game,f.target).spice+1);
|
||||
assert.deepEqual(viewGame(game,f.target).truthPledgeAnswers,['no']);
|
||||
rejected(game,f.target,{type:'truthAnswer',answer:'yes'});
|
||||
});
|
||||
|
||||
void test('Advanced pledge Yes blocks voluntary spending that would make its update impossible',()=>{
|
||||
const f=fixture();let game=ask(f,f.game,4);
|
||||
game=act(game,f.target,{type:'truthAnswer',answer:'yes'});
|
||||
const available=player(game,f.target).spice;
|
||||
rejected(game,f.target,{type:'bribe',target:f.asker,amount:available-1});
|
||||
assert.ok(!promise(game).fulfilled&&!promise(game).released);
|
||||
const guide=viewGame(game,f.target).pledgePromiseGuide;assert.ok(guide);
|
||||
game=act(game,f.target,guide.action);assert.equal(promise(game).fulfilled,true);
|
||||
assert.deepEqual(inventory(game),f.physical);
|
||||
});
|
||||
|
||||
void test('Advanced Yes rejects an unaffordable pending Guild shipment without mutating state',()=>{
|
||||
const f=guildShipmentFixture(),available=player(f.game,f.target).spice;
|
||||
assert.ok(available>=4);
|
||||
let game=ask(f,f.game,available-1);
|
||||
game=act(game,f.target,{type:'truthAnswer',answer:'yes'});
|
||||
const ship:Action={type:'ship',amount:1,territory:'polar_sink',sector:0,allyPayment:0};
|
||||
rejected(game,f.target,ship);
|
||||
assert.ok(!promise(game).fulfilled&&!promise(game).released);
|
||||
assert.equal(game.pendingShipment??null,null);
|
||||
assert.deepEqual(inventory(game),f.physical);
|
||||
});
|
||||
|
||||
void test('Advanced Yes permits a funded Guild shipment and its original continuation',()=>{
|
||||
const f=guildShipmentFixture(),available=player(f.game,f.target).spice;
|
||||
assert.ok(available>=4);
|
||||
let game=ask(f,f.game,available-2);
|
||||
game=act(game,f.target,{type:'truthAnswer',answer:'yes'});
|
||||
const before=structuredClone(game);
|
||||
game=act(game,f.target,{type:'ship',amount:1,territory:'polar_sink',sector:0,allyPayment:0});
|
||||
assert.equal(game.decision?.kind,'guildShipment');assert.ok(game.pendingShipment);
|
||||
assert.equal(player(game,f.target).spice,player(before,f.target).spice);
|
||||
game=act(game,'guild',{type:'decision',allow:true});
|
||||
game=passResponse(game);
|
||||
assert.equal(game.pendingShipment??null,null);
|
||||
assert.equal(player(game,f.target).spice,available-2);
|
||||
assert.equal(player(game,f.target).reserves,player(before,f.target).reserves-1);
|
||||
const guide=viewGame(game,f.target).pledgePromiseGuide;assert.ok(guide);
|
||||
game=act(game,f.target,guide.action);assert.equal(promise(game).fulfilled,true);
|
||||
assert.deepEqual(inventory(game),f.physical);
|
||||
});
|
||||
|
||||
void test('Advanced No remains available with a locked winning bid and rejects a qualifying update',()=>{
|
||||
const f=fixture();let game=act(f.game,f.target,{type:'pledgeAid',amount:4});
|
||||
game=advance(game,state=>state.auction?.active===f.ally && clean(state));
|
||||
game=act(game,f.ally,{type:'bid',amount:5,allyPayment:4});
|
||||
assert.equal(game.auction?.bidder,f.ally);assert.equal(game.auction?.allyPayment,4);
|
||||
game=ask(f,game,4);
|
||||
assert.ok(viewGame(game,f.target).truthPledgeAnswers?.includes('no'));
|
||||
game=act(game,f.target,{type:'truthAnswer',answer:'no'});
|
||||
const bid=structuredClone(game.auction), aid=structuredClone(game.aid[f.target]);
|
||||
rejected(game,f.target,{type:'pledgeAid',amount:4});
|
||||
rejected(game,f.target,{type:'pledgeAid',amount:5});
|
||||
assert.deepEqual(game.auction,bid);assert.deepEqual(game.aid[f.target],aid);
|
||||
const owner=player(game,f.target).spice,buyer=player(game,f.ally).spice;
|
||||
game=advance(game,state=>state.decision?.kind==='auctionPayment');
|
||||
if(game.pendingEmperorAuctionGift)game=act(game,f.target,{type:'emperorAuctionGiftContinue',event:game.pendingEmperorAuctionGift.event});
|
||||
if(game.decision?.kind==='auctionPayment')game=act(game,f.ally,{type:'decision',karama:false});
|
||||
game=passResponse(game);
|
||||
assert.equal(game.aid[f.target]?.amount??0,0);
|
||||
assert.equal(player(game,f.ally).spice,buyer-1);
|
||||
assert.equal(player(game,f.target).spice,owner+1,'Advanced sends the ally-funded portion to the bank');
|
||||
assert.deepEqual(inventory(game),f.physical);
|
||||
});
|
||||
Reference in new issue
Block a user