55 lines
3.0 KiB
TypeScript
55 lines
3.0 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import { handLimit, viewGame } from '../game/engine';
|
|
import {
|
|
actDistransPrebid, advanceDistransPrebid, createDistransPrebidFixture,
|
|
distransPrebidClean, distransPrebidInventory, distransPrebidPlayer as player,
|
|
distransPrebidPosition, finishDistransPrebidLot,
|
|
} from './fixture-distrans-prebid';
|
|
|
|
for (const advanced of [false, true]) {
|
|
const mode = advanced ? 'Advanced' : 'Basic';
|
|
void test(`${mode} Distrans between ordinary bids preserves the standing purchase and resumes that lot`, () => {
|
|
const f = createDistransPrebidFixture({ advanced });
|
|
const bidder = f.game.auction!.active;
|
|
let game = actDistransPrebid(f.game, bidder, { type: 'bid', amount: 1, allyPayment: 0 });
|
|
assert.equal(game.auction!.bidder, bidder);
|
|
assert.equal(game.auction!.bid, 1);
|
|
const recipient = game.players.find(seat => seat.id !== f.holder && seat.id !== bidder &&
|
|
seat.hand.length < handLimit(seat));
|
|
assert.ok(recipient);
|
|
const action = { ...f.action, target: recipient.id };
|
|
const offered = viewGame(game, f.holder).distrans!;
|
|
assert.equal(offered.blocked, null);
|
|
assert.ok(offered.choices.find(choice => choice.recipient === recipient.id)!.cards.some(card => card.id === f.give));
|
|
const original = structuredClone(game), index = game.auction!.index, turn = game.turn;
|
|
const soldCard = game.auction!.cards[index].id;
|
|
const bidderSpice = player(game, bidder).spice;
|
|
game = actDistransPrebid(game, f.holder, action);
|
|
assert.deepEqual(distransPrebidPosition(game), distransPrebidPosition(original));
|
|
assert.ok(player(game, recipient.id).hand.some(card => card.id === f.give));
|
|
assert.equal(game.discard.filter(card => card.id === f.card).length, 1);
|
|
assert.deepEqual(distransPrebidInventory(game), f.originalInventory);
|
|
game = advanceDistransPrebid(game, distransPrebidClean);
|
|
assert.deepEqual(game.auction, original.auction);
|
|
game = finishDistransPrebidLot(game, turn, index);
|
|
assert.ok(player(game, bidder).hand.some(card => card.id === soldCard));
|
|
assert.equal(player(game, bidder).spice, bidderSpice - 1);
|
|
assert.deepEqual(distransPrebidInventory(game), f.originalInventory);
|
|
});
|
|
|
|
void test(`${mode} a standing bidder retains its last hand slot through a Distrans attempt`, () => {
|
|
const f = createDistransPrebidFixture({ advanced, capacity: 'recipientLastSlot' });
|
|
const bidder = f.game.auction!.active;
|
|
assert.equal(bidder, f.recipient);
|
|
assert.equal(player(f.game, bidder).hand.length, handLimit(player(f.game, bidder)) - 1);
|
|
const game = actDistransPrebid(f.game, bidder, { type: 'bid', amount: 1, allyPayment: 0 });
|
|
const before = structuredClone(game);
|
|
const option = viewGame(game, f.holder).distrans!.choices.find(choice => choice.recipient === bidder)!;
|
|
assert.ok(!option.cards.some(card => card.id === f.give));
|
|
assert.throws(() => actDistransPrebid(game, f.holder, f.action));
|
|
assert.deepEqual(game, before);
|
|
assert.deepEqual(distransPrebidInventory(game), f.originalInventory);
|
|
});
|
|
}
|