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);
|
||||
});
|
||||
Reference in new issue
Block a user