Connect Kull bid answers and group transport
Verify and publish checkpoint container / container (push) Successful in 12m6s

This commit is contained in:
Quintine committed 2026-10-29 00:17:48 +11:00
1 parent 420943b890
commit f667383565
16 files changed
+438 -26

No files matched your search

@@ -0,0 +1,91 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { baseDeck } from '../game/cards';
import { coalitionOf, emptyCoalitionState } from '../game/coalition-alliance';
import { applyAction, createGame, newPlayer, type Action, type Game } from '../game/engine';
const send = (game: Game, id: string, action: Action) => applyAction(game, id, action);
const seat = (game: Game, id: string) => game.players.find(player => player.id === id)!;
/** The group is formed through actual Nexus actions. The turn, forces and
* unrelated accepted Truthtrance No answer are staged for this interaction. */
function fixture() {
let game = createGame('GROUPTRUTHSHIP', newPlayer('g', 'Guild', 'guild'), false);
game.players.push(newPlayer('e', 'Emperor', 'emperor'), newPlayer('f', 'Fremen', 'fremen'),
newPlayer('h', 'Harkonnen', 'harkonnen'));
Object.assign(game, {status:'playing', phase:1, turn:2, nexus:true, order:['g','e','f','h'],
ready:[], storm:18, deck:baseDeck(), response:null, decision:null, phaseOpening:null});
game.coalitionState = emptyCoalitionState();
game = send(game, 'g', {type:'alliance', target:'e'});
game = send(game, 'e', {type:'alliance', target:'g'});
const pair = coalitionOf(game.players, game.coalitionState, 'g'); assert.ok(pair);
game = send(game, 'g', {type:'coalitionPropose', groupId:pair.id, entrant:'f',
expectedRevision:game.coalitionState!.revision});
for (const id of ['e', 'f']) {
const offer = game.coalitionState!.proposal!;
game = send(game, id, {type:'coalitionAnswer', event:offer.event, nexus:offer.nexus,
turn:offer.turn, accept:true, expectedRevision:game.coalitionState!.revision});
}
Object.assign(game, {phase:5, nexus:false, active:'e', ready:[],
movementRemaining:['e','g','f','h'], guildTimingGranted:false, guildTimingLocked:false});
for (const player of game.players) {
player.forces = {}; player.reserves = 20; player.tanks = 0; player.spice = 10;
player.hand = []; player.traitors = []; player.traitorChoices = [];
player.shipped = false; player.moved = 0;
}
seat(game, 'e').forces = {'imperial_basin:10':3}; seat(game, 'e').reserves = 17;
const index = game.deck.findIndex(card => card.effect === 'karama'); assert.ok(index >= 0);
const [karama] = game.deck.splice(index, 1); seat(game, 'h').hand.push(karama);
game.bribePromises = [{event:'other-player-no', player:'h', asker:'e', turn:game.turn,
recipient:'f', minimum:1, answer:false, progress:0}];
return {game, karama};
}
function passKind(game: Game, kind: string): Game {
for (let count = 0; game.response?.kind === kind && count < 24; count++) {
const next = game.players.find(player => !game.response!.passed.includes(player.id));
assert.ok(next); game = send(game, next.id, {type:'passResponse'});
}
assert.notEqual(game.response?.kind, kind);
return game;
}
function passAll(game: Game): Game {
for (let count = 0; game.response && count < 32; count++) {
const next = game.players.find(player => !game.response!.passed.includes(player.id));
assert.ok(next); game = send(game, next.id, {type:'passResponse'});
}
assert.equal(game.response ?? null, null);
return game;
}
const transport: Action = {type:'guildShip', forces:{'imperial_basin:10':3},
territory:'red_chasm', sector:7, allyPayment:0};
void test('an unrelated Truthtrance No retains self-funded group Guild transport and both response windows', () => {
let {game} = fixture();
game = send(game, 'e', transport);
assert.equal(game.response?.kind, 'guildTransportPermission');
assert.equal(seat(game, 'e').forces['imperial_basin:10'], 3);
game = passKind(game, 'guildTransportPermission');
assert.equal(game.response?.kind, 'guildRate');
assert.equal(game.pendingGuildTransport?.cost, 3);
game = passAll(game);
assert.equal(seat(game, 'e').forces['red_chasm:7'], 3);
assert.equal(seat(game, 'e').spice, 7);
assert.equal(seat(game, 'g').spice, 13);
assert.ok(game.bribePromises?.some(row => row.event === 'other-player-no' && !row.fulfilled && !row.released));
});
void test('Karama still cancels the native group Guild rate when another player has an unrelated commitment', () => {
const fixtureState = fixture();
let game = fixtureState.game;
const {karama} = fixtureState;
game = send(game, 'e', transport);
game = passKind(game, 'guildTransportPermission');
assert.equal(game.response?.kind, 'guildRate');
game = send(game, 'h', {type:'card', mode:'cancel', card:karama.id});
game = passAll(game);
assert.equal(seat(game, 'e').forces['red_chasm:7'], 3);
assert.equal(seat(game, 'e').spice, 4, 'The shipper pays the full six-spice rate.');
assert.equal(seat(game, 'g').spice, 16);
assert.equal(game.discard.filter(card => card.id === karama.id).length, 1);
assert.ok(game.bribePromises?.some(row => row.event === 'other-player-no' && !row.fulfilled && !row.released));
});
+1 -1
View File
@@ -16,7 +16,7 @@ void test('Basic printed Kull admits native bid commitments only in its supporte
const scope = { advanced: false, expansions: ['choam', 'ix'],
players: [{ faction: 'choam' }, { faction: 'emperor' }], kullPreview: true };
assert.equal(bidPromiseModeSupported(scope), true);
assert.equal(phaseBidPromiseModeSupported(scope), false);
assert.equal(phaseBidPromiseModeSupported(scope), true);
assert.equal(bidPromiseModeSupported({ ...scope, advanced: true }), false);
assert.equal(bidPromiseModeSupported({ ...scope, expansions: ['choam'] }), false);
assert.equal(bidPromiseModeSupported({ ...scope, semutaPreview: true }), false);
+131
View File
@@ -0,0 +1,131 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { viewGame, type Game } from '../game/engine';
import { DIFFICULTIES } from '../game/bot-profiles';
import { botActions } from '../game/bots';
import { phaseBidPromiseModeSupported } from '../game/turn-bid-promises';
import { act, advance, clean, createKullBribeFixture, inventory, player } from './fixture-kull-bribe';
/** The fixture selects physical cards in the unopened deal; the Truthtrance,
* Kull and auction actions below all use the genuine public Basic start. */
function bound(answer: 'yes' | 'no') {
const f = createKullBribeFixture();
let game = advance(structuredClone(f.charity), state =>
state.phase === 3 && clean(state) && state.auction?.active === f.actor);
game = act(game, f.asker, {type:'card', card:f.truth});
while (game.truthtrance?.stage === 'priority') {
const actor = game.players.find(seat => !game.truthtrance!.passed.includes(seat.id));
assert.ok(actor);
game = act(game, actor.id, {type:'truthPass'});
}
game = act(game, f.asker, {type:'truthAsk', question:{
kind:'phaseBid', target:f.actor, turn:game.turn, minimum:4,
}});
assert.ok(viewGame(game, f.actor).truthPhaseBidAnswers?.includes(answer));
for (const difficulty of DIFFICULTIES) {
const view = viewGame(game, f.actor);
view.players.find(seat => seat.id === f.actor)!.bot = difficulty;
const choice = botActions(view)[0];
assert.equal(choice?.type, 'truthAnswer');
assert.ok(view.truthPhaseBidAnswers!.includes(choice.answer as 'yes' | 'no' | 'unknown'));
}
game = act(game, f.actor, {type:'truthAnswer', answer});
assert.deepEqual(inventory(game), f.originalCards);
return {f, game};
}
function offered(source: Game, f: ReturnType<typeof createKullBribeFixture>) {
const before = structuredClone(source.phaseBidPromises);
const lot = source.auction!.cards[source.auction!.index].id;
const game = act(source, f.counterOwner, {type:'card', mode:'purchase', card:f.counter});
assert.equal(game.pendingKull?.stage, 'offer');
assert.deepEqual(game.phaseBidPromises, before);
assert.equal(viewGame(game, f.actor).phaseBidPromiseGuide, null);
const reaction = viewGame(game, f.reactor).kullReaction; assert.ok(reaction);
return {game, reaction, before, lot};
}
void test('pre-bidding phase Yes cannot rely on an unfunded Karama bid in Kull preview', () => {
const f = createKullBribeFixture();
let game = structuredClone(f.charity);
// Controlled wallet supplement: the original physical Karama remains in
// Emperor's hand, but its only spice cannot fund the promised four bid.
player(game, f.actor).spice = 1;
assert.ok(player(game, f.actor).hand.some(card => card.id === f.karama));
game = act(game, f.asker, {type:'card', card:f.truth});
while (game.truthtrance?.stage === 'priority') {
const actor = game.players.find(seat => !game.truthtrance!.passed.includes(seat.id)); assert.ok(actor);
game = act(game, actor.id, {type:'truthPass'});
}
game = act(game, f.asker, {type:'truthAsk', question:{
kind:'phaseBid', target:f.actor, turn:game.turn, minimum:4,
}});
assert.ok(!viewGame(game, f.actor).truthPhaseBidAnswers?.includes('yes'),
'A non-CHOAM Karama cannot witness the Kull-fenced unfunded overbid.');
const before = structuredClone(game);
assert.throws(() => act(game, f.actor, {type:'truthAnswer', answer:'yes'}));
assert.deepEqual(game, before);
assert.deepEqual(inventory(game), f.originalCards);
});
void test('phase-wide Kull questions remain fenced with native Richese and Semuta', () => {
const scope = {advanced:false, expansions:['choam','ix'], kullPreview:true,
semutaPreview:true, players:[{faction:'choam'}, {faction:'richese'}]};
assert.equal(phaseBidPromiseModeSupported(scope), false);
});
void test('phase-wide Yes survives a real Kull interception and completes its original bid', () => {
const {f, game: source} = bound('yes');
const pending = offered(source, f);
let game = act(pending.game, f.reactor, {type:'kullDecision', event:pending.reaction.event,
source:'printed', card:f.kull});
assert.equal(game.pendingKull?.stage, 'counter');
assert.deepEqual(game.phaseBidPromises, pending.before);
game = advance(game, clean);
assert.equal(game.auction!.cards[game.auction!.index].id, pending.lot);
assert.deepEqual(game.phaseBidPromises, pending.before);
const guide = viewGame(game, f.actor).phaseBidPromiseGuide; assert.ok(guide);
assert.equal(guide.action.type, 'bid'); assert.equal(guide.action.amount, 4);
game = act(game, f.actor, guide.action);
assert.ok(game.phaseBidPromises?.some(row => row.player === f.actor && row.fulfilled));
assert.ok(player(game, f.counterOwner).hand.some(card => card.id === f.counter));
assert.deepEqual(inventory(game), f.originalCards);
});
void test('phase-wide No still caps a bid after the Kull interception', () => {
const {f, game: source} = bound('no');
const pending = offered(source, f);
let game = act(pending.game, f.reactor, {type:'kullDecision', event:pending.reaction.event,
source:'printed', card:f.kull});
game = advance(game, clean);
assert.deepEqual(game.phaseBidPromises, pending.before);
const before = structuredClone(game);
assert.throws(() => act(game, f.actor, {type:'bid', amount:4, allyPayment:0}));
assert.deepEqual(game, before);
game = act(game, f.actor, {type:'bid', amount:3, allyPayment:0});
assert.equal(game.auction?.bid, 3);
assert.deepEqual(inventory(game), f.originalCards);
});
void test('countering Kull keeps a phase Yes for a real later lot', () => {
const {f, game: source} = bound('yes');
const pending = offered(source, f);
const originalIndex = source.auction!.index;
assert.ok(source.auction!.cards[originalIndex + 1], 'The real auction has another physical lot.');
let game = act(pending.game, f.reactor, {type:'kullDecision', event:pending.reaction.event,
source:'printed', card:f.kull});
assert.equal(game.pendingKull?.stage, 'counter');
assert.ok(viewGame(game, f.actor).responseControls?.cancelCards?.includes(f.karama));
game = act(game, f.actor, {type:'card', mode:'cancel', card:f.karama});
game = advance(game, state => clean(state) && !!state.auction &&
state.auction.index > originalIndex && state.auction.active === f.actor);
const promise = game.phaseBidPromises?.find(row => row.player === f.actor);
assert.ok(promise && !promise.fulfilled && !promise.released,
'A real future lot keeps the original phase-wide answer binding.');
assert.ok(player(game, f.counterOwner).hand.some(card => card.id === pending.lot));
const guide = viewGame(game, f.actor).phaseBidPromiseGuide; assert.ok(guide);
assert.equal(guide.action.type, 'bid'); assert.equal(guide.action.amount, 4);
game = act(game, f.actor, guide.action);
assert.ok(game.phaseBidPromises?.some(row => row.player === f.actor && row.fulfilled));
assert.deepEqual(inventory(game), f.originalCards);
});
+2 -2
View File
@@ -31,7 +31,7 @@ void test('public host lobby shows the explicitly selected Kull preview and its
assert.equal(host.lobbyModules?.kullPreview,true);
assert.match(html,/Kull Wahad · Basic development preview/);
assert.match(html,/Printed Kull is enabled by default/);
assert.match(html,/Phase-wide bid and combined turn-action Truthtrance questions are unavailable/);
assert.match(html,/Combined turn-action Truthtrance questions are unavailable/);
assert.match(html,/Unfunded non-CHOAM Karama-dependent bids remain deferred/);
assert.match(html,/When Richese is seated, structured bid, alliance, Revival and bribe commitments are also unavailable/);
const off = act(f.lobby,f.lobby.host,{type:'moduleOption',module:'kullPreview',enabled:false});
@@ -39,7 +39,7 @@ void test('public host lobby shows the explicitly selected Kull preview and its
assert.equal(unselected.lobbyModules?.kullPreview,false);
assert.match(table(unselected),/Kull Wahad · Basic development preview/);
assert.match(table(unselected),/The host has turned off the printed Kull preview/);
assert.doesNotMatch(table(unselected),/Phase-wide bid and combined turn-action Truthtrance questions are unavailable/);
assert.doesNotMatch(table(unselected),/Combined turn-action Truthtrance questions are unavailable/);
const nonhost = table(viewGame(f.lobby,f.actor));
assert.match(nonhost,/disabled=""[^>]*type="checkbox"|type="checkbox"[^>]*disabled=""/);
});
+118
View File
@@ -0,0 +1,118 @@
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 { RosterAlliance } from '../components/roster-alliance';
import { baseDeck } from '../game/cards';
import { coalitionOf, emptyCoalitionState } from '../game/coalition-alliance';
import { applyAction, createGame, newPlayer, viewGame, type Game } from '../game/engine';
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 {GameTable} = await import('../components/game-table');
aliases.deregister();
function fixture(staged: boolean): Game {
const game = createGame('ROSTER', newPlayer('a', 'A', 'atreides'), false);
game.players.push(newPlayer('b', 'B', 'emperor'), newPlayer('c', 'C', 'fremen'),
newPlayer('d', 'D', 'harkonnen'));
Object.assign(game, {status:'playing', phase:1, turn:2, nexus:true,
order:['a', 'b', 'c', 'd'], ready:[]});
if (staged) game.coalitionState = emptyCoalitionState();
return game;
}
function pair(game: Game): Game {
game = applyAction(game, 'a', {type:'alliance', target:'b'});
return applyAction(game, 'b', {type:'alliance', target:'a'});
}
function rendered(game: Game, playerId: string): string {
return renderToStaticMarkup(createElement(RosterAlliance, {game:viewGame(game, 'd'), playerId}));
}
function formedGroup(): Game {
let game = pair(fixture(true));
const group = coalitionOf(game.players, game.coalitionState, 'a'); assert.ok(group);
game = applyAction(game, 'a', {type:'coalitionPropose', groupId:group.id,
entrant:'c', expectedRevision:game.coalitionState!.revision});
for (const id of ['b', 'c']) {
const proposal = game.coalitionState!.proposal!;
game = applyAction(game, id, {type:'coalitionAnswer', event:proposal.event,
nexus:proposal.nexus, turn:proposal.turn, accept:true,
expectedRevision:game.coalitionState!.revision});
}
game.nexus = false; game.phase = 5;
return game;
}
void test('the roster retains legacy pair labels and omits an unallied seat', () => {
const game = pair(fixture(false));
assert.match(rendered(game, 'a'), /Allied with (?:<!-- -->)?Emperor/);
assert.match(rendered(game, 'b'), /Allied with (?:<!-- -->)?Atreides/);
assert.equal(rendered(game, 'c'), '');
});
void test('the public roster names both allies after a real staged group formation', () => {
const game = formedGroup();
// Membership is projected publicly even after the Nexus ends.
assert.match(rendered(game, 'a'), /Allied with (?:<!-- -->)?Emperor and Fremen/);
assert.match(rendered(game, 'b'), /Allied with (?:<!-- -->)?Atreides and Fremen/);
assert.match(rendered(game, 'c'), /Allied with (?:<!-- -->)?Atreides and Emperor/);
assert.equal(rendered(game, 'd'), '');
});
void test('the actual game table roster displays public group membership after Nexus', () => {
const game = formedGroup();
const markup = renderToStaticMarkup(createElement(GameTable, {
game:viewGame(game, 'd'), busy:false, send:async () => {}, onExit() {},
}));
assert.match(markup, /Allied with (?:<!-- -->)?Emperor and Fremen/);
assert.match(markup, /Allied with (?:<!-- -->)?Atreides and Fremen/);
assert.match(markup, /Allied with (?:<!-- -->)?Atreides and Emperor/);
});
void test('the game table offers group Guild transport while an unrelated commitment hides group funding', () => {
let game = createGame('GROUPTRANSPORTVIEW', newPlayer('g', 'Guild', 'guild'), false);
game.players.push(newPlayer('e', 'Emperor', 'emperor'), newPlayer('f', 'Fremen', 'fremen'),
newPlayer('h', 'Harkonnen', 'harkonnen'));
Object.assign(game, {status:'playing', phase:1, turn:2, nexus:true, order:['g','e','f','h'],
ready:[], storm:18, deck:baseDeck(), response:null, decision:null, phaseOpening:null});
game.coalitionState = emptyCoalitionState();
game = applyAction(game, 'g', {type:'alliance', target:'e'});
game = applyAction(game, 'e', {type:'alliance', target:'g'});
const group = coalitionOf(game.players, game.coalitionState, 'g'); assert.ok(group);
game = applyAction(game, 'g', {type:'coalitionPropose', groupId:group.id, entrant:'f',
expectedRevision:game.coalitionState!.revision});
for (const id of ['e', 'f']) {
const offer = game.coalitionState!.proposal!;
game = applyAction(game, id, {type:'coalitionAnswer', event:offer.event, nexus:offer.nexus,
turn:offer.turn, accept:true, expectedRevision:game.coalitionState!.revision});
}
Object.assign(game, {phase:5, nexus:false, active:'e', ready:[],
movementRemaining:['e','g','f','h'], guildTimingGranted:false, guildTimingLocked:false});
for (const player of game.players) {
player.forces = {}; player.reserves = 20; player.tanks = 0; player.spice = 10;
player.hand = []; player.traitors = []; player.traitorChoices = [];
player.shipped = false; player.moved = 0;
}
game.players.find(player => player.id === 'e')!.forces = {'imperial_basin:10':3};
game.players.find(player => player.id === 'e')!.reserves = 17;
game.bribePromises = [{event:'other-player-no', player:'h', asker:'e', turn:game.turn,
recipient:'f', minimum:1, answer:false, progress:0}];
const view = viewGame(game, 'e');
assert.equal(view.coalitionFunding, null);
const markup = renderToStaticMarkup(createElement(GameTable, {
game:view, busy:false, send:async () => {}, onExit() {},
}));
assert.match(markup, /<button\b[^>]*>(?:(?!<\/button>)[\s\S])*Guild transport(?:(?!<\/button>)[\s\S])*<\/button>/);
});