Allow recovered Recruits replay and more bribe windows
Verify and publish checkpoint container / container (push) Successful in 10m51s
Verify and publish checkpoint container / container (push) Successful in 10m51s
This commit is contained in:
1 parent
bd8377d87b
commit
de7fe7d64a
13 files changed
+394
-22
No files matched your search
@@ -0,0 +1,111 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { viewGame, type Action, type Game } from '../game/engine';
|
||||
import {
|
||||
actFremenRevivalGrant as actBattle, advanceFremenRevivalGrant as advanceBattle,
|
||||
createFremenRevivalGrantFixture, fremenRevivalGrantClean,
|
||||
fremenRevivalGrantInventory as battleInventory, fremenRevivalGrantPlayer as battlePlayer,
|
||||
} from './fixture-fremen-revival-grant';
|
||||
import {
|
||||
actSemutaDisasterWorm as actWorm, advanceSemutaDisasterWorm as advanceWorm,
|
||||
allowSemutaDisasterWorm, createSemutaDisasterWormFixture,
|
||||
semutaDisasterWormPlayer as wormPlayer,
|
||||
} from './fixture-semuta-disaster-worm';
|
||||
|
||||
function rejected(game: Game, act: (game: Game, actor: string, action: Action) => Game,
|
||||
actor: string, action: Action) {
|
||||
const original = structuredClone(game);
|
||||
assert.throws(() => act(game, actor, action));
|
||||
assert.deepEqual(game, original, 'A rejected bribe preserves its native parent and resources');
|
||||
}
|
||||
|
||||
/** Actual public Basic selected-deck setup, purchase and original Fremen
|
||||
* shipment; the natural second-turn worm and survival response create this
|
||||
* ride. No decision, army, spice balance or phase is assigned by this test. */
|
||||
function wormRideSource() {
|
||||
const fixture = createSemutaDisasterWormFixture({ advanced: false });
|
||||
let game = allowSemutaDisasterWorm(fixture.game);
|
||||
game = advanceWorm(game, state => state.decision?.kind === 'wormRide' &&
|
||||
!state.response && !state.phaseOpening && !state.pendingTreacheryDiscard);
|
||||
assert.equal(game.decision?.player, fixture.owner);
|
||||
assert.equal(game.decision?.kind === 'wormRide' && game.decision.territory, 'funeral_plain');
|
||||
return {fixture, game};
|
||||
}
|
||||
|
||||
void test('a Basic worm rider and another seat can negotiate while the original unpaid ride waits', () => {
|
||||
const {fixture:f, game} = wormRideSource();
|
||||
const actor = f.spender, target = f.guild, originalDecision = structuredClone(game.decision);
|
||||
const oldPurse = wormPlayer(game, actor).spice, oldCash = wormPlayer(game, target).spice;
|
||||
const oldEscrow = wormPlayer(game, target).bribes;
|
||||
assert.ok(oldPurse >= 4); assert.notEqual(wormPlayer(game, actor).ally, target);
|
||||
assert.equal(viewGame(game, actor).bribeOptions.blocked, null);
|
||||
rejected(game, actWorm, actor, {type:'bribe', target, amount:oldPurse + 1});
|
||||
rejected(game, actWorm, actor, {type:'bribe', target:actor, amount:1});
|
||||
const paid = actWorm(game, actor, {type:'bribe', target, amount:4});
|
||||
assert.deepEqual(paid.decision, originalDecision);
|
||||
assert.deepEqual(paid.wormRides, game.wormRides);
|
||||
assert.deepEqual(paid.spiceSequence, game.spiceSequence);
|
||||
assert.equal(wormPlayer(paid, actor).spice, oldPurse - 4);
|
||||
assert.equal(wormPlayer(paid, target).spice, oldCash);
|
||||
assert.equal(wormPlayer(paid, target).bribes, oldEscrow + 4);
|
||||
const decline: Action = {type:'decision', accept:false};
|
||||
const control = actWorm(game, f.owner, decline);
|
||||
const continued = actWorm(paid, f.owner, decline);
|
||||
assert.deepEqual(continued.decision, control.decision);
|
||||
assert.deepEqual(continued.wormRides, control.wormRides);
|
||||
assert.equal(wormPlayer(continued, target).bribes, oldEscrow + 4);
|
||||
});
|
||||
|
||||
/** The original public Basic Fremen/Atreides invasion and real battle produce
|
||||
* the winner's optional card disposal. One actually dealt Fremen card is
|
||||
* exchanged with an original shield in another hand or the deck before battle
|
||||
* when needed, conserving the physical cards and hand sizes. */
|
||||
function battleCardsSource() {
|
||||
const f = createFremenRevivalGrantFixture();
|
||||
let game = structuredClone(f.beforeBattle);
|
||||
const hand = battlePlayer(game, f.fremen).hand;
|
||||
assert.ok(hand.length);
|
||||
let shield = hand.find(card => card.kind === 'shield');
|
||||
if (!shield) {
|
||||
const zone = [game.deck, ...game.players.filter(seat => seat.id !== f.fremen).map(seat => seat.hand)]
|
||||
.find(cards => cards.some(card => card.kind === 'shield'));
|
||||
assert.ok(zone);
|
||||
const index = zone.findIndex(card => card.kind === 'shield');
|
||||
[hand[0], zone[index]] = [zone[index], hand[0]];
|
||||
shield = hand[0];
|
||||
}
|
||||
const shieldId = shield.id, original = battleInventory(game);
|
||||
game = actBattle(game, f.battleStep.actor, f.battleStep.action);
|
||||
for (const step of f.plans) {
|
||||
game = advanceBattle(game, state => !!state.battle && fremenRevivalGrantClean(state) &&
|
||||
!state.battle.preparation && (!state.battle.preLeader || state.battle.preLeader.closed));
|
||||
game = actBattle(game, step.actor, step.actor === f.fremen
|
||||
? {...step.action, defense:shieldId} : step.action);
|
||||
}
|
||||
game = advanceBattle(game, state => !state.response && !state.phaseOpening &&
|
||||
state.decision?.kind === 'battleCards');
|
||||
assert.equal(game.decision?.player, f.fremen);
|
||||
assert.ok(game.decision?.kind === 'battleCards' && game.decision.cards.includes(shieldId));
|
||||
return {f, game, shield:shieldId, original};
|
||||
}
|
||||
|
||||
void test('a Basic winner can retain the same played card after an out-of-turn bribe', () => {
|
||||
const {f, game, shield, original} = battleCardsSource();
|
||||
const actor = f.observer, target = f.ally, decision = structuredClone(game.decision);
|
||||
const purse = battlePlayer(game, actor).spice, cash = battlePlayer(game, target).spice;
|
||||
const escrow = battlePlayer(game, target).bribes;
|
||||
assert.ok(purse >= 1); assert.notEqual(battlePlayer(game, actor).ally, target);
|
||||
assert.equal(viewGame(game, actor).bribeOptions.blocked, null);
|
||||
rejected(game, actBattle, actor, {type:'bribe', target, amount:purse + 1});
|
||||
const paid = actBattle(game, actor, {type:'bribe', target, amount:1});
|
||||
assert.deepEqual(paid.decision, decision);
|
||||
assert.deepEqual(paid.lastBattleContext, game.lastBattleContext);
|
||||
assert.equal(battlePlayer(paid, actor).spice, purse - 1);
|
||||
assert.equal(battlePlayer(paid, target).spice, cash);
|
||||
assert.equal(battlePlayer(paid, target).bribes, escrow + 1);
|
||||
assert.deepEqual(battleInventory(paid), original);
|
||||
const retained = actBattle(paid, f.fremen, {type:'decision', discard:[]});
|
||||
assert.ok(battlePlayer(retained, f.fremen).hand.some(card => card.id === shield));
|
||||
assert.equal(battlePlayer(retained, target).bribes, escrow + 1);
|
||||
assert.deepEqual(battleInventory(retained), original);
|
||||
});
|
||||
@@ -79,7 +79,7 @@ void test('late-paid controls allow provisional Recruits without refunding prior
|
||||
assert.equal(viewGame(free, 'at').revival.forcesRemaining, 2);
|
||||
});
|
||||
|
||||
void test('missing and inconsistent ledgers, pending transactions, wrong phase and replay remain immutable guards', () => {
|
||||
void test('missing and inconsistent ledgers, pending transactions, wrong phase and missing card remain immutable guards', () => {
|
||||
const paid = allowRevival(applyAction(ownerGame(), 'at', { type: 'revive', amount: 3 }));
|
||||
const missing = structuredClone(paid);
|
||||
delete missing.players[0].freeForcesRevived;
|
||||
@@ -90,16 +90,11 @@ void test('missing and inconsistent ledgers, pending transactions, wrong phase a
|
||||
const wrongPhase = ownerGame();
|
||||
wrongPhase.phase = 5;
|
||||
const active = applyAction(ownerGame(), 'at', { type: 'card', card: 'ecaz-recruits' });
|
||||
const recovered = structuredClone(active);
|
||||
const [card] = recovered.discard.splice(recovered.discard.findIndex((held) => held.id === 'ecaz-recruits'), 1);
|
||||
assert.ok(card);
|
||||
recovered.players[0].hand.push(card);
|
||||
for (const [label, g] of [
|
||||
['missing ledger', missing],
|
||||
['inconsistent ledger', inconsistent],
|
||||
['pending transaction', pending],
|
||||
['wrong phase', wrongPhase],
|
||||
['already-active recovered copy', recovered],
|
||||
] as const) {
|
||||
const before = structuredClone(g);
|
||||
const preview = viewGame(g, 'at').recruitsPreview;
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { Children, createElement, isValidElement, type ReactElement, type ReactNode } from 'react';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import { Recruits } from '../components/recruits';
|
||||
import { Button } from '../components/ui/button';
|
||||
import { viewGame, type Action, type GameView } from '../game/engine';
|
||||
import { recruitsGame } from './fixture-recruits';
|
||||
|
||||
type ButtonProps = { onClick?: () => void; disabled?: boolean };
|
||||
function findButton(node: ReactNode): ReactElement<ButtonProps> | undefined {
|
||||
for (const child of Children.toArray(node)) {
|
||||
if (!isValidElement(child)) continue;
|
||||
if (child.type === Button) return child as ReactElement<ButtonProps>;
|
||||
const found = findButton((child.props as { children?: ReactNode }).children);
|
||||
if (found) return found;
|
||||
}
|
||||
}
|
||||
|
||||
/** The actual game view supplies the roster and legal card shape. The rates and
|
||||
* replay offer are projected explicitly because this isolates the control from
|
||||
* the independent engine implementation and its Semuta flow. */
|
||||
function replayView(): GameView {
|
||||
const game = recruitsGame(false);
|
||||
const owner = game.players.find(player => player.hand.some(card => card.id === 'ecaz-recruits'))!;
|
||||
const view = viewGame(game, owner.id);
|
||||
assert.ok(view.recruitsPreview?.play);
|
||||
return {
|
||||
...view,
|
||||
recruitsPreview: {
|
||||
...view.recruitsPreview,
|
||||
active: true,
|
||||
plays: 2,
|
||||
play: {...view.recruitsPreview.play, blocked: null},
|
||||
rates: view.recruitsPreview.rates.map(rate => rate.player === 'tl'
|
||||
? {...rate, freeRate: 8, limit: 20}
|
||||
: {...rate, freeRate: 7, limit: 7}),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
void test('a recovered physical Recruits exposes the server-approved replay and current rates', () => {
|
||||
const game = replayView(), actions: Action[] = [];
|
||||
const element = Recruits({ game, busy: false, act: action => actions.push(action) });
|
||||
assert.ok(element);
|
||||
const html = renderToStaticMarkup(element);
|
||||
assert.match(html, /played 2 times this turn/);
|
||||
assert.match(html, /Each play doubles the current free revival rates/);
|
||||
assert.match(html, />8<\/td>/);
|
||||
assert.match(html, />Unlimited<\/td>/);
|
||||
assert.match(html, /Play Recruits again · Discard card/);
|
||||
const button = findButton(element); assert.ok(button);
|
||||
assert.equal(button.props.disabled, false);
|
||||
button.props.onClick?.();
|
||||
assert.deepEqual(actions, [{type:'card', card:'ecaz-recruits'}]);
|
||||
});
|
||||
|
||||
void test('replay obeys busy and server block and never appears without a held offer', () => {
|
||||
const original = replayView(), offer = original.recruitsPreview!;
|
||||
const busyActions: Action[] = [];
|
||||
const busy = Recruits({ game: original, busy: true, act: action => busyActions.push(action) });
|
||||
assert.ok(busy);
|
||||
const busyButton = findButton(busy); assert.ok(busyButton);
|
||||
assert.equal(busyButton.props.disabled, true);
|
||||
busyButton.props.onClick?.();
|
||||
assert.deepEqual(busyActions, []);
|
||||
|
||||
const blocked = {...original, recruitsPreview: {...offer, play: {...offer.play!, blocked:'Finish the current transaction.'}}};
|
||||
const blockedActions: Action[] = [];
|
||||
const blockedElement = Recruits({ game: blocked, busy: false, act: action => blockedActions.push(action) });
|
||||
assert.ok(blockedElement);
|
||||
assert.match(renderToStaticMarkup(blockedElement), /Finish the current transaction/);
|
||||
const blockedButton = findButton(blockedElement); assert.ok(blockedButton);
|
||||
assert.equal(blockedButton.props.disabled, true);
|
||||
blockedButton.props.onClick?.();
|
||||
assert.deepEqual(blockedActions, []);
|
||||
|
||||
const publicOnly = {...original, recruitsPreview: {...offer, play: null}};
|
||||
const html = renderToStaticMarkup(createElement(Recruits, {game:publicOnly, busy:false, act() {}}));
|
||||
assert.match(html, /played 2 times this turn/);
|
||||
assert.doesNotMatch(html, /Play Recruits again/);
|
||||
});
|
||||
|
||||
void test('an active legacy projection without a play count displays one use', () => {
|
||||
const game = replayView(), legacy = {...game.recruitsPreview!};
|
||||
delete legacy.plays;
|
||||
const html = renderToStaticMarkup(createElement(Recruits, {
|
||||
game: {...game, recruitsPreview: legacy}, busy:false, act() {},
|
||||
}));
|
||||
assert.match(html, /played 1 time this turn/);
|
||||
});
|
||||
@@ -0,0 +1,87 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { applyAction, viewGame, type Game } from '../game/engine';
|
||||
import { recruitsPlayAction, recruitsRevivalAllowance, type RecruitsRevivalFacts } from '../game/recruits';
|
||||
import {
|
||||
actSemutaRecruits as act, createSemutaRecruitsFixture as fixture,
|
||||
semutaRecruitsInventory as inventory, semutaRecruitsPlayer as player,
|
||||
} from './fixture-semuta-recruits';
|
||||
|
||||
const facts: RecruitsRevivalFacts = {
|
||||
currentFreeRate: 2, currentLimit: 3, revived: 0, freeAllowanceUsed: 0, freeRateCap: 20,
|
||||
};
|
||||
|
||||
void test('each actual Recruits use provisionally doubles the current native free rate, with one ordinary cap', () => {
|
||||
const scope = (uses?: number) => ({ turn: 2, recruits: { turn: 2, ...(uses === undefined ? {} : { uses }) } });
|
||||
assert.equal(recruitsRevivalAllowance(scope(), facts).freeRate, 4, 'old receipt means one use');
|
||||
assert.equal(recruitsRevivalAllowance(scope(1), facts).freeRate, 4);
|
||||
const second = recruitsRevivalAllowance(scope(2), facts);
|
||||
assert.equal(second.freeRate, 7);
|
||||
assert.equal(second.limit, 7, 'the normal seven-force limit does not multiply');
|
||||
const used = recruitsRevivalAllowance(scope(2), { ...facts, revived: 3, freeAllowanceUsed: 2 });
|
||||
assert.equal(used.remaining, 4);
|
||||
assert.equal(used.freeRemaining, 4, 'earlier free and paid returns remain in their respective ledgers');
|
||||
const unlimited = recruitsRevivalAllowance(scope(2), {
|
||||
...facts, currentFreeRate: 4, currentLimit: 20,
|
||||
});
|
||||
assert.equal(unlimited.freeRate, 16);
|
||||
assert.equal(unlimited.limit, 20);
|
||||
assert.equal(recruitsRevivalAllowance(scope(100), { ...facts, currentLimit: 20 }).freeRate, 20);
|
||||
assert.equal(recruitsRevivalAllowance(scope(100), { ...facts, currentFreeRate: 0 }).freeRate, 0);
|
||||
assert.equal(recruitsRevivalAllowance(scope(2), { ...facts, freeBlocked: true }).freeRate, 0);
|
||||
assert.equal(recruitsRevivalAllowance(scope(2), { ...facts, revivalBlocked: true }).freeRemaining, 0);
|
||||
assert.equal(recruitsRevivalAllowance({ turn: 3, recruits: { turn: 2, uses: 2 } }, facts).freeRate, 2);
|
||||
for (const uses of [0, -1, 1.5, Number.NaN, Number.MAX_SAFE_INTEGER + 1])
|
||||
assert.throws(() => recruitsRevivalAllowance(scope(uses), facts), /positive safe integer/);
|
||||
});
|
||||
|
||||
/** Genuine public Basic setup and normal auctions give the holder its real
|
||||
* Semuta and the owner the physical Recruits. The real next Storm sends the
|
||||
* owner's shipped group to the Tanks; no card or counter is injected. */
|
||||
void test('Semuta acquires and replays the same physical Recruits, retaining the first use and actual revival', () => {
|
||||
const f = fixture();
|
||||
let game = act(f.game, f.owner, f.play);
|
||||
let discard = game.pendingTreacheryDiscard;
|
||||
assert.ok(discard?.reaction && discard.reaction.stage === 'offer');
|
||||
const firstEvent = discard.batch.event;
|
||||
game = act(game, f.holder, { type: 'semutaCommit', event: firstEvent });
|
||||
if (game.pendingTreacheryDiscard?.reaction?.stage === 'select')
|
||||
game = act(game, f.holder, { type: 'semutaSelect', event: firstEvent, card: 'ecaz-recruits' });
|
||||
assert.equal(game.pendingTreacheryDiscard, null);
|
||||
assert.ok(player(game, f.holder).hand.some(card => card.id === 'ecaz-recruits'));
|
||||
assert.equal(viewGame(game, f.owner).revival.freeRemaining, 4);
|
||||
|
||||
const priorSpice = player(game, f.owner).spice;
|
||||
game = act(game, f.owner, { type: 'revive', amount: 2, elite: 0 });
|
||||
assert.equal(player(game, f.owner).freeForcesRevived, 2);
|
||||
assert.equal(player(game, f.owner).spice, priorSpice);
|
||||
const replay = recruitsPlayAction(viewGame(game, f.holder).recruitsPreview);
|
||||
assert.deepEqual(replay, f.play);
|
||||
const before = structuredClone(game);
|
||||
assert.throws(() => applyAction(game, f.owner, f.play), 'only the actual card holder may replay it');
|
||||
assert.deepEqual(game, before);
|
||||
game = act(game, f.holder, f.play);
|
||||
assert.equal(game.recruits?.uses, 2);
|
||||
assert.equal(game.recruits?.player, f.holder);
|
||||
discard = game.pendingTreacheryDiscard;
|
||||
if (discard?.reaction?.stage === 'offer') {
|
||||
const event = discard.batch.event;
|
||||
assert.notEqual(event, firstEvent);
|
||||
for (const seat of game.players) game = act(game, seat.id, { type: 'semutaPass', event });
|
||||
}
|
||||
assert.equal(game.pendingTreacheryDiscard, null);
|
||||
assert.equal(viewGame(game, f.owner).revival.limit, 7);
|
||||
assert.equal(viewGame(game, f.owner).revival.freeRemaining, 5);
|
||||
assert.equal(viewGame(game, f.owner).recruitsPreview?.plays, 2);
|
||||
assert.equal(player(game, f.owner).freeForcesRevived, 2);
|
||||
assert.equal(player(game, f.owner).spice, priorSpice);
|
||||
assert.equal(game.discard.filter(card => card.id === 'ecaz-recruits').length, 1);
|
||||
assert.equal(game.players.flatMap(seat => seat.hand).filter(card => card.id === 'ecaz-recruits').length, 0);
|
||||
assert.deepEqual(inventory(game), f.originalInventory);
|
||||
const restored = JSON.parse(JSON.stringify(game)) as Game;
|
||||
assert.equal(viewGame(restored, f.owner).revival.freeRemaining, 5);
|
||||
assert.equal(viewGame(restored, f.owner).recruitsPreview?.plays, 2);
|
||||
game = act(game, f.owner, { type: 'revive', amount: 1, elite: 0 });
|
||||
assert.equal(player(game, f.owner).freeForcesRevived, 3);
|
||||
assert.equal(player(game, f.owner).spice, priorSpice);
|
||||
});
|
||||
@@ -55,7 +55,7 @@ for (const claim of [false, true]) {
|
||||
assert.equal(resumed.discard.filter(card => card.id === SEMUTA_DRUG_ID).length, Number(claim));
|
||||
assert.deepEqual(inventory(resumed), f.originalInventory);
|
||||
rejected(resumed, f.holder, {type: 'semutaCommit', event});
|
||||
if (claim) rejected(resumed, f.holder, f.play);
|
||||
if (claim) assert.equal(viewGame(resumed, f.holder).recruitsPreview?.play?.blocked, null);
|
||||
const old = {reserves: player(resumed, f.owner).reserves, tanks: player(resumed, f.owner).tanks,
|
||||
spice: player(resumed, f.owner).spice};
|
||||
const revived = act(resumed, f.owner, {type: 'revive', amount: 3, elite: 0});
|
||||
|
||||
Reference in new issue
Block a user