Combine Basic bidding and movement commitments
Verify and publish checkpoint container / container (push) Successful in 10m49s
Verify and publish checkpoint container / container (push) Successful in 10m49s
This commit is contained in:
1 parent
b03efd2371
commit
235696263a
9 files changed
+404
-17
No files matched your search
@@ -0,0 +1,62 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { type Game } from '../game/engine';
|
||||
import {
|
||||
actMentatBribe as act, createMentatBribeFixture as fixture,
|
||||
mentatBribeInventory as inventory, mentatBribePlayer as player,
|
||||
} from './fixture-mentat-bribes';
|
||||
|
||||
/** Real Basic setup and Mentat; both separate four-spice debts are accepted
|
||||
* through public offers and votes before the controlled external loss. */
|
||||
function withTwoDebts() {
|
||||
const f = fixture();
|
||||
let game: Game = f.game;
|
||||
const debts: string[] = [];
|
||||
for (let n = 0; n < 2; n++) {
|
||||
game = act(game, f.asker, {type:'dealOffer', target:f.target, terms:'Pay four spice.',
|
||||
payment:{kind:'deferredBribe', payer:f.target, recipient:f.asker, amount:4, dueTurn:game.turn}});
|
||||
const id = game.deals?.at(-1)?.id; assert.ok(id); debts.push(id);
|
||||
game = act(game, f.target, {type:'dealRespond', deal:id, accept:true});
|
||||
}
|
||||
return {f, game, debts};
|
||||
}
|
||||
|
||||
void test('an unrelated insolvency does not block a funded multi-payment deal', () => {
|
||||
const {f, game:accepted, debts} = withTwoDebts();
|
||||
const staged = structuredClone(accepted);
|
||||
const beforeTotal = staged.players.reduce((sum, seat) => sum + seat.spice + seat.bribes, 0);
|
||||
// Transfer five existing spice to represent a settled external loss. Each
|
||||
// debt remains individually payable, while their sum no longer fits.
|
||||
player(staged,f.target).spice -= 5;
|
||||
player(staged,f.asker).spice += 5;
|
||||
let game = act(staged, f.opponent, {type:'ready'});
|
||||
assert.deepEqual(debts.map(id => game.deals!.find(deal => deal.id === id)!.paymentStatus), ['pending','pending']);
|
||||
const payerBefore = player(game,f.asker).spice, recipientBefore = player(game,f.opponent).bribes;
|
||||
game = act(game,f.asker,{type:'dealOffer',target:f.opponent,terms:'Two immediate payments.',
|
||||
payment:{kind:'immediateBribe',payer:f.asker,recipient:f.opponent,amount:1},
|
||||
additionalImmediatePayments:[{kind:'immediateBribe',payer:f.asker,recipient:f.opponent,amount:1}]});
|
||||
const id = game.deals?.at(-1)?.id; assert.ok(id);
|
||||
game = act(game,f.opponent,{type:'dealRespond',deal:id,accept:true});
|
||||
assert.equal(game.deals!.find(deal => deal.id === id)!.status,'active');
|
||||
assert.equal(player(game,f.asker).spice,payerBefore-2);
|
||||
assert.equal(player(game,f.opponent).bribes,recipientBefore+2);
|
||||
assert.equal(player(game,f.target).spice,5);
|
||||
assert.deepEqual(debts.map(debt => game.deals!.find(deal => deal.id === debt)!.paymentStatus), ['pending','pending']);
|
||||
assert.equal(game.players.reduce((sum, seat) => sum + seat.spice + seat.bribes, 0),beforeTotal);
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
});
|
||||
|
||||
void test('a payer cannot use the same spice for due debts and immediate payments', () => {
|
||||
const {f, game:accepted, debts} = withTwoDebts();
|
||||
const offered = act(accepted,f.asker,{type:'dealOffer',target:f.target,terms:'Two immediate payments.',
|
||||
payment:{kind:'immediateBribe',payer:f.target,recipient:f.asker,amount:1},
|
||||
additionalImmediatePayments:[{kind:'immediateBribe',payer:f.target,recipient:f.asker,amount:2}]});
|
||||
const id = offered.deals?.at(-1)?.id; assert.ok(id);
|
||||
const before = structuredClone(offered);
|
||||
assert.throws(() => act(offered,f.target,{type:'dealRespond',deal:id,accept:true}));
|
||||
assert.deepEqual(offered,before);
|
||||
assert.equal(offered.deals!.find(deal => deal.id === id)!.status,'offered');
|
||||
assert.deepEqual(debts.map(debt => offered.deals!.find(deal => deal.id === debt)!.paymentStatus), ['pending','pending']);
|
||||
assert.equal(player(offered,f.target).spice,10);
|
||||
assert.deepEqual(inventory(offered),f.originalCards);
|
||||
});
|
||||
Reference in new issue
Block a user