Allow bribes during native Basic response windows
This commit is contained in:
1 parent
de7fe7d64a
commit
812fe9d6e0
10 files changed
+346
-2
No files matched your search
@@ -0,0 +1,66 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { viewGame, type Game } from '../game/engine';
|
||||
import { truthFactAnswer } from '../game/truthtrance';
|
||||
import {
|
||||
actTruthMixedBattle as act,
|
||||
bindTruthMixedBattle as bind,
|
||||
createTruthMixedBattleFixture as fixture,
|
||||
truthMixedBattleAction as action,
|
||||
truthMixedBattleFact as fact,
|
||||
truthMixedBattleGroup as group,
|
||||
truthMixedBattleInventory as inventory,
|
||||
truthMixedBattlePlayer as player,
|
||||
} from './fixture-truth-mixed-battle';
|
||||
|
||||
/** The native setup, movement, physical battle and Prescience opportunity are
|
||||
* real. Place one existing Karama from the unopened deck in Emperor's hand in
|
||||
* both branches so the actual Prescience response stays open. The residual
|
||||
* branch swaps Emperor's original projectile for an existing shield; both
|
||||
* branches have the same public hand count and conserved physical inventory. */
|
||||
function sources() {
|
||||
const f = fixture({window:'preparation'});
|
||||
const constant = structuredClone(f.game);
|
||||
const hand = player(constant,f.target).hand;
|
||||
const karama = constant.deck.findIndex(card => card.effect === 'karama');
|
||||
assert.ok(karama >= 0);
|
||||
hand.push(...constant.deck.splice(karama,1));
|
||||
const residual = structuredClone(constant), differentHand = player(residual,f.target).hand;
|
||||
const projectile = differentHand.findIndex(card => card.id === f.ordinary);
|
||||
const shield = residual.deck.findIndex(card => card.kind === 'shield');
|
||||
assert.ok(projectile >= 0 && shield >= 0);
|
||||
[differentHand[projectile],residual.deck[shield]] = [residual.deck[shield],differentHand[projectile]];
|
||||
assert.deepEqual(inventory(constant),f.originalCards);
|
||||
assert.deepEqual(inventory(residual),f.originalCards);
|
||||
assert.equal(player(constant,f.target).hand.length,player(residual,f.target).hand.length);
|
||||
assert.equal(truthFactAnswer(player(constant,f.target),f.heldFact),'yes');
|
||||
assert.equal(truthFactAnswer(player(residual,f.target),f.heldFact),'no');
|
||||
return {f,constant,residual};
|
||||
}
|
||||
|
||||
void test('a hidden mixed battle fact cannot change public bribe availability during Prescience', () => {
|
||||
const {f,constant,residual} = sources();
|
||||
// Same announced question and Yes answer: a held projectile makes the OR
|
||||
// already true; without it, the native unarmed plan satisfies the answer.
|
||||
const mixed = group('or',fact(f.heldFact),action({kind:'weapon',name:null}));
|
||||
const build = (source: Game) => {
|
||||
let game = bind(f,'yes',mixed,source).game;
|
||||
assert.equal(game.battle?.preparation?.kind,'prescience');
|
||||
game = act(game,f.asker,{type:'prescience',field:'weapon'});
|
||||
assert.equal(game.response?.kind,'prescience');
|
||||
return game;
|
||||
};
|
||||
const a = build(constant), b = build(residual);
|
||||
assert.equal(a.mixedBattleQuestions?.at(-1)?.binding,false);
|
||||
assert.equal(b.mixedBattleQuestions?.at(-1)?.binding,true);
|
||||
assert.equal(a.battle?.truthPromises?.length ?? 0,0);
|
||||
assert.equal(b.battle?.truthPromises?.length,1);
|
||||
assert.deepEqual(viewGame(a,f.asker).truthHistory,viewGame(b,f.asker).truthHistory);
|
||||
assert.deepEqual(a.response,b.response);
|
||||
for (const seat of a.players) {
|
||||
const aView = viewGame(a,seat.id), bView = viewGame(b,seat.id);
|
||||
assert.equal(aView.bribeOptions.blocked,bView.bribeOptions.blocked,
|
||||
`${seat.id} must not infer the private fact from bribe availability`);
|
||||
assert.ok(aView.bribeOptions.blocked,'Mixed answers remain outside this interruption prototype');
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,150 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { applyAction, createGame, joinGame, newPlayer, viewGame, type Action, type Game } from '../game/engine';
|
||||
import { nextStrongholdFactionsNativeStep } from './fixture-stronghold-factions';
|
||||
import {
|
||||
actFremenRevivalGrant as actBattle, advanceFremenRevivalGrant as advanceBattle,
|
||||
createFremenRevivalGrantFixture, fremenRevivalGrantPlayer as battlePlayer,
|
||||
fremenRevivalGrantInventory as battleInventory,
|
||||
} from './fixture-fremen-revival-grant';
|
||||
import {
|
||||
actSemutaDisasterWorm as actWorm, allowSemutaDisasterWorm,
|
||||
createSemutaDisasterWormFixture, semutaDisasterWormPlayer as wormPlayer,
|
||||
semutaDisasterWormInventory as wormInventory,
|
||||
} from './fixture-semuta-disaster-worm';
|
||||
|
||||
const player = (game: Game, id: string) => {
|
||||
const seat = game.players.find(candidate => candidate.id === id); assert.ok(seat); return seat;
|
||||
};
|
||||
const clean = (game: Game) => !game.phaseOpening && !game.response && !game.decision &&
|
||||
!game.pendingTreacheryDiscard && !game.truthtrance;
|
||||
function reject(game: Game, act: (game: Game, id: string, action: Action) => Game, id: string, action: Action) {
|
||||
const before = structuredClone(game);
|
||||
assert.throws(() => act(game, id, action));
|
||||
assert.deepEqual(game, before, 'A rejected payment must not mutate its input or pending parent');
|
||||
}
|
||||
function expectEscrow(before: Game, after: Game, payer: string, recipient: string, amount: number) {
|
||||
assert.equal(player(after, payer).spice, player(before, payer).spice - amount);
|
||||
assert.equal(player(after, recipient).spice, player(before, recipient).spice);
|
||||
assert.equal(player(after, recipient).bribes, player(before, recipient).bribes + amount);
|
||||
}
|
||||
|
||||
/** Genuine public Basic Atreides/Guild/Emperor setup and native phase controls.
|
||||
* Only unopened Treachery and Spice card positions are selected. Atreides pays
|
||||
* to ship one real reserve into Polar Sink; Emperor's original dealt Karama
|
||||
* keeps the native Guild-income response open. No game state is installed. */
|
||||
function guildIncomeSource() {
|
||||
let game = createGame('BRIBEGUILDINCOME', newPlayer('atreides', 'Atreides', 'atreides'), false);
|
||||
joinGame(game, newPlayer('guild', 'Guild', 'guild'));
|
||||
joinGame(game, newPlayer('emperor', 'Emperor', 'emperor'));
|
||||
for (const seat of game.players) game = applyAction(game, seat.id, { type: 'ready' });
|
||||
game = applyAction(game, game.host, { type: 'start' });
|
||||
assert.equal(game.status, 'setup');
|
||||
const ordinary = game.deck.filter(card => ['projectile', 'poison', 'shield', 'snooper'].includes(card.kind)).slice(0, 2);
|
||||
const karama = game.deck.find(card => card.effect === 'karama');
|
||||
assert.equal(ordinary.length, 2); assert.ok(karama);
|
||||
for (const [position, card] of [...ordinary, karama].entries()) {
|
||||
const from = game.deck.findIndex(candidate => candidate.id === card.id); assert.ok(from >= position);
|
||||
[game.deck[position], game.deck[from]] = [game.deck[from], game.deck[position]];
|
||||
}
|
||||
const reach = (until: (game: Game) => boolean) => {
|
||||
for (let count = 0; count < 1200 && !until(game); count++) {
|
||||
const step = nextStrongholdFactionsNativeStep(game); assert.ok(step);
|
||||
game = applyAction(game, step.actor, step.action);
|
||||
}
|
||||
assert.ok(until(game), 'The original Basic game must reach its native source');
|
||||
};
|
||||
reach(state => state.status === 'playing');
|
||||
assert.ok(player(game, 'emperor').hand.some(card => card.id === karama.id));
|
||||
for (const position of [0, 1]) {
|
||||
const from = game.spiceDeck.findIndex((card, index) => index >= position && 'territory' in card);
|
||||
assert.ok(from >= position);
|
||||
[game.spiceDeck[position], game.spiceDeck[from]] = [game.spiceDeck[from], game.spiceDeck[position]];
|
||||
}
|
||||
reach(state => state.phase === 5 && state.active === 'atreides' && clean(state));
|
||||
game = applyAction(game, 'atreides', {type:'ship', territory:'polar_sink', sector:0, amount:1, elite:0, allyPayment:0});
|
||||
assert.equal(game.response?.kind, 'guildIncome');
|
||||
assert.equal(game.response?.owner, 'guild');
|
||||
return game;
|
||||
}
|
||||
|
||||
void test('a Basic paid Guild shipment preserves its income response while a nonparticipant pays a bribe', () => {
|
||||
const source = guildIncomeSource(), payer = 'emperor', recipient = 'atreides';
|
||||
const response = structuredClone(source.response), active = source.active;
|
||||
const shipmentForces = structuredClone(player(source, recipient).forces);
|
||||
const pendingShipment = structuredClone(source.pendingShipment), aid = structuredClone(source.aid);
|
||||
const auction = structuredClone(source.auction);
|
||||
assert.equal(viewGame(source, payer).bribeOptions.blocked, null);
|
||||
reject(source, applyAction, payer, {type:'bribe', target:payer, amount:1});
|
||||
reject(source, applyAction, payer, {type:'bribe', target:recipient, amount:player(source, payer).spice + 1});
|
||||
const paid = applyAction(source, payer, {type:'bribe', target:recipient, amount:1});
|
||||
assert.deepEqual(paid.response, response);
|
||||
assert.equal(paid.active, active);
|
||||
assert.deepEqual(paid.pendingShipment, pendingShipment);
|
||||
assert.deepEqual(paid.aid, aid, 'Prepaid ally credit must not be rewritten');
|
||||
assert.deepEqual(paid.auction, auction, 'Any original reserved lot and bid stay in place');
|
||||
assert.deepEqual(player(paid, recipient).forces, shipmentForces);
|
||||
expectEscrow(source, paid, payer, recipient, 1);
|
||||
const control = applyAction(source, payer, {type:'passResponse'});
|
||||
const continued = applyAction(paid, payer, {type:'passResponse'});
|
||||
assert.deepEqual(continued.response, control.response);
|
||||
assert.equal(player(continued, 'guild').spice, player(control, 'guild').spice);
|
||||
assert.deepEqual(player(continued, recipient).forces, player(control, recipient).forces);
|
||||
assert.equal(player(continued, recipient).bribes, player(source, recipient).bribes + 1);
|
||||
});
|
||||
|
||||
/** Original classic Fremen/Atreides/Emperor paid Tabr battle. Atreides uses
|
||||
* its native Prescience against Fremen, with Emperor's originally dealt Karama
|
||||
* retaining the original cancellation opportunity. */
|
||||
function prescienceSource() {
|
||||
const fixture = createFremenRevivalGrantFixture();
|
||||
let game = actBattle(fixture.beforeBattle, fixture.battleStep.actor, fixture.battleStep.action);
|
||||
game = advanceBattle(game, state => !!state.battle && !state.phaseOpening && !state.response && !state.decision &&
|
||||
state.battle.preparation?.kind === 'prescience' && state.battle.preparation.owner === fixture.ally);
|
||||
game = actBattle(game, fixture.ally, {type:'prescience', field:'weapon'});
|
||||
assert.equal(game.response?.kind, 'prescience');
|
||||
return {fixture, game};
|
||||
}
|
||||
|
||||
void test('Basic Prescience keeps its original battle and response while another faction pays a bribe', () => {
|
||||
const {fixture:f, game:source} = prescienceSource(), payer = f.observer, recipient = f.fremen;
|
||||
const response = structuredClone(source.response), battle = structuredClone(source.battle);
|
||||
const cards = battleInventory(source);
|
||||
assert.equal(viewGame(source, payer).bribeOptions.blocked, null);
|
||||
const paid = actBattle(source, payer, {type:'bribe', target:recipient, amount:1});
|
||||
assert.deepEqual(paid.response, response);
|
||||
assert.deepEqual(paid.battle, battle);
|
||||
assert.deepEqual(battleInventory(paid), cards);
|
||||
expectEscrow(source, paid, payer, recipient, 1);
|
||||
const control = actBattle(source, payer, {type:'passResponse'});
|
||||
const continued = actBattle(paid, payer, {type:'passResponse'});
|
||||
assert.deepEqual(continued.response, control.response);
|
||||
assert.deepEqual(continued.battle, control.battle);
|
||||
assert.equal(battlePlayer(continued, recipient).bribes, battlePlayer(source, recipient).bribes + 1);
|
||||
assert.deepEqual(battleInventory(continued), cards);
|
||||
});
|
||||
|
||||
/** Public Basic selected-CHOAM setup and actual paid cache, native second-turn
|
||||
* Spice draw and natural Fremen protection response. The original fixture only
|
||||
* selects unopened card positions and original lotteries. */
|
||||
void test('Basic worm survival keeps its natural source and outcome through an out-of-turn bribe', () => {
|
||||
const f = createSemutaDisasterWormFixture({advanced:false, kind:'wormSurvival'});
|
||||
const source = f.game, payer = f.spender, recipient = f.guild;
|
||||
assert.equal(source.response?.kind, 'wormSurvival');
|
||||
const response = structuredClone(source.response), cards = wormInventory(source);
|
||||
assert.equal(viewGame(source, payer).bribeOptions.blocked, null);
|
||||
const paid = actWorm(source, payer, {type:'bribe', target:recipient, amount:1});
|
||||
assert.deepEqual(paid.response, response);
|
||||
assert.deepEqual(paid.spiceSequence, source.spiceSequence);
|
||||
assert.deepEqual(paid.wormRides, source.wormRides);
|
||||
assert.deepEqual(wormInventory(paid), cards);
|
||||
expectEscrow(source, paid, payer, recipient, 1);
|
||||
const control = allowSemutaDisasterWorm(source);
|
||||
const continued = allowSemutaDisasterWorm(paid);
|
||||
assert.deepEqual(continued.response, control.response);
|
||||
assert.deepEqual(continued.decision, control.decision);
|
||||
assert.deepEqual(continued.wormRides, control.wormRides);
|
||||
assert.deepEqual(wormPlayer(continued, f.owner).forces, wormPlayer(control, f.owner).forces);
|
||||
assert.equal(wormPlayer(continued, recipient).bribes, wormPlayer(source, recipient).bribes + 1);
|
||||
assert.deepEqual(wormInventory(continued), cards);
|
||||
});
|
||||
@@ -0,0 +1,52 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { applyAction, viewGame, type Action } from '../game/engine';
|
||||
import {
|
||||
createTruthTurnPowerFixture, truthTurnPowerInventory, truthTurnPowerPlayer,
|
||||
} from './fixture-truth-turn-power';
|
||||
|
||||
/** Public Basic setup and a paid shipment produce the native Arrakeen battle;
|
||||
* Emperor buys its original Karama in an ordinary auction. The source fixture
|
||||
* selects unopened draw order but does not assign a battle, hand or purse. */
|
||||
void test('a Basic combatant may bribe while Voice awaits its native Karama response', () => {
|
||||
const f = createTruthTurnPowerFixture({power: 'voice', remote: false});
|
||||
let game = applyAction(f.game, f.bg, {type: 'voice', kind: 'shield', must: false});
|
||||
assert.equal(game.response?.kind, 'voice');
|
||||
assert.ok(game.battle && [game.battle.attacker, game.battle.defender].includes(f.atreides));
|
||||
assert.ok(truthTurnPowerPlayer(game, f.emperor).hand.some(card => card.id === f.karama));
|
||||
const payer = truthTurnPowerPlayer(game, f.atreides);
|
||||
const recipient = truthTurnPowerPlayer(game, f.emperor);
|
||||
assert.ok(payer.spice > 0);
|
||||
assert.notEqual(payer.ally, recipient.id);
|
||||
const options = viewGame(game, payer.id).bribeOptions;
|
||||
assert.equal(options.blocked, null);
|
||||
const limit = options.targets.find(target => target.id === recipient.id)?.maximum;
|
||||
assert.ok(limit && limit >= 1);
|
||||
const illegal: Action = {type: 'bribe', target: recipient.id, amount: limit + 1};
|
||||
const unchanged = structuredClone(game);
|
||||
assert.throws(() => applyAction(game, payer.id, illegal));
|
||||
assert.deepEqual(game, unchanged, 'An over-limit payment cannot alter the declared Voice or response');
|
||||
|
||||
const originalBattle = structuredClone(game.battle), originalResponse = structuredClone(game.response);
|
||||
const originalCards = truthTurnPowerInventory(game);
|
||||
const amount = 1, balance = payer.spice, income = recipient.bribes;
|
||||
const paid = applyAction(game, payer.id, {type: 'bribe', target: recipient.id, amount});
|
||||
assert.deepEqual(paid.response, originalResponse);
|
||||
assert.deepEqual(paid.battle, originalBattle);
|
||||
assert.equal(truthTurnPowerPlayer(paid, payer.id).spice, balance - amount);
|
||||
assert.equal(truthTurnPowerPlayer(paid, recipient.id).spice, recipient.spice);
|
||||
assert.equal(truthTurnPowerPlayer(paid, recipient.id).bribes, income + amount);
|
||||
assert.deepEqual(truthTurnPowerInventory(paid), originalCards);
|
||||
|
||||
// The same physical Karama must cancel the original declared Voice once;
|
||||
// the payment neither spends that card nor grants the recipient its escrow.
|
||||
const cancel: Action = {type: 'card', card: f.karama, mode: 'cancel'};
|
||||
const expected = applyAction(game, f.emperor, cancel);
|
||||
game = applyAction(paid, f.emperor, cancel);
|
||||
assert.equal(game.battle?.voice, undefined);
|
||||
assert.deepEqual(game.battle, expected.battle);
|
||||
assert.deepEqual(game.response, expected.response);
|
||||
assert.equal(game.discard.filter(card => card.id === f.karama).length, 1);
|
||||
assert.equal(truthTurnPowerPlayer(game, recipient.id).bribes, income + amount);
|
||||
assert.deepEqual(truthTurnPowerInventory(game), originalCards);
|
||||
});
|
||||
@@ -48,6 +48,8 @@ void test('Recruits owner has an accessible physical-card action; rivals cannot
|
||||
assert.equal(viewGame(g, 'fr').recruitsPreview?.play, null);
|
||||
const card = g.players[0].hand.find((c) => c.id === 'ecaz-recruits')!;
|
||||
assert.ok(cardPresentation(card).topics.some((topic) => topic.id === 'card-recruits'));
|
||||
assert.match(cardPresentation(card).availability ?? '', /recovered.*played again/);
|
||||
assert.doesNotMatch(cardPresentation(card).availability ?? '', /replay remain guarded|Fremen grants.*guarded/);
|
||||
});
|
||||
|
||||
void test('late-paid controls allow provisional Recruits without refunding prior paid returns', () => {
|
||||
|
||||
Reference in new issue
Block a user