Disallow Offshore bids on empty reward lots
This commit is contained in:
parent
1e12a2c314
commit
2509441ec8
5 changed files with 158 additions and 3 deletions
|
|
@ -19,6 +19,8 @@ Score breakdown remains same length: ship line includes bankHolding at $3 each.
|
|||
|
||||
## Interpretations / unresolved physical-rule detail
|
||||
|
||||
The PDF says any lot may be chosen, so empty lots are legal (positive opening bid still required). For two auctions pending at game end, p18 says to resolve each, but does not specify a simultaneous-payment snapshot or which resolves first. This implementation resolves the persisted `auctions` array in order, with each payment before collection/cleanup as p14 directs. Only currently active tokens freeze lots; a cleaned-up lot can receive later payments. This is deterministic but end-resolution ordering is an explicit rules ambiguity requiring publisher clarification, not a claimed mandated tie-break. Normal turn-start resolution follows the same pay/collect/clean sequence.
|
||||
By user-selected rule, empty container reward lots and $0 cash reward lots cannot receive opening bids or raises; replenished lots become eligible again, subject to normal auction restrictions. This resolves the PDF’s “any lot” ambiguity for this implementation, not as a publisher-confirmed ruling. Existing saved auctions on empty lots still settle normally (positive opening bids remain required).
|
||||
|
||||
For two auctions pending at game end, p18 says to resolve each, but does not specify a simultaneous-payment snapshot or which resolves first. This implementation resolves the persisted `auctions` array in order, with each payment before collection/cleanup as p14 directs. Only currently active tokens freeze lots; a cleaned-up lot can receive later payments. This is deterministic but end-resolution ordering is an explicit rules ambiguity requiring publisher clarification, not a claimed mandated tie-break. Normal turn-start resolution follows the same pay/collect/clean sequence.
|
||||
|
||||
`initialContainerLots` is an additional public immutable setup snapshot used to reconstruct observed cash from a stripped state with an unrelated analysis seed. It contains only the publicly seeded bank pieces, never secret cash or scoring cards.
|
||||
|
|
|
|||
|
|
@ -5,7 +5,14 @@ import { availableMoves } from './available-moves';
|
|||
import { move, setup, stripSecret } from './engine';
|
||||
import { GameState, Phase, ShipPosition } from './gamestate';
|
||||
import { Move, MoveName } from './move';
|
||||
import { bankProductionAllowed, payBankCash, reserved } from './offshore';
|
||||
import {
|
||||
applyBankMove,
|
||||
bankProductionAllowed,
|
||||
normalizeBankDistribution,
|
||||
payBankCash,
|
||||
reserved,
|
||||
settleBank,
|
||||
} from './offshore';
|
||||
|
||||
function game(n = 3) {
|
||||
const g = setup(n, { offshoreIsland: true }, 'bank-tests');
|
||||
|
|
@ -48,6 +55,81 @@ describe('optional Off-Shore Bank', () => {
|
|||
expect(g.containersLeft.length).equal(base.containersLeft.length - 3);
|
||||
expect(game()).deep.equal(g);
|
||||
});
|
||||
for (const type of ['cash', 'containers'] as const) {
|
||||
it(`rejects empty ${type} rewards without mutation and enables replenished lots`, () => {
|
||||
const g = game();
|
||||
const p = g.players[g.currentPlayers[0]];
|
||||
const b = g.offshoreBank!;
|
||||
b.cashLots[2] = 0;
|
||||
const bid: Move = {
|
||||
name: MoveName.CallBank,
|
||||
data: { type, lot: 2 },
|
||||
extraData: type === 'cash' ? { containers: [p.containersOnFactoryStore[0].piece.id] } : { cash: 1 },
|
||||
};
|
||||
refresh(g);
|
||||
expect(p.availableMoves!.callBank).not.to.deep.include(bid.data);
|
||||
const before = cloneDeep(g);
|
||||
expect(() => act(g, bid)).throw();
|
||||
expect(g).deep.equal(before);
|
||||
expect(() => applyBankMove(g, bid, p)).throw('Bank reward lot is empty or invalid');
|
||||
expect(g).deep.equal(before);
|
||||
for (const lot of [-1, 3, 0.5, NaN]) {
|
||||
expect(() => applyBankMove(g, { ...bid, data: { type, lot } }, p)).throw(
|
||||
'Bank reward lot is empty or invalid'
|
||||
);
|
||||
expect(g).deep.equal(before);
|
||||
}
|
||||
if (type === 'cash') payBankCash(g, 3);
|
||||
else b.containerLots[2].push(g.containersLeft.pop()!);
|
||||
refresh(g);
|
||||
expect(p.availableMoves!.callBank).to.deep.include(bid.data);
|
||||
act(g, bid);
|
||||
expect(b.auctions[0].lot).equal(2);
|
||||
expect(p.actions).equal(1);
|
||||
});
|
||||
it(`blocks raises on legacy empty ${type} rewards but still settles them`, () => {
|
||||
const g = game();
|
||||
const b = g.offshoreBank!;
|
||||
const owner = g.players[g.currentPlayers[0]];
|
||||
b.cashLots[2] = 0;
|
||||
const payment = type === 'cash' ? owner.containersOnFactoryStore.splice(0, 1) : [];
|
||||
if (type === 'containers') owner.money--;
|
||||
b.auctions.push({
|
||||
type,
|
||||
lot: 2,
|
||||
bidder: owner.id,
|
||||
cash: type === 'containers' ? 1 : 0,
|
||||
containers: payment.map((container) => ({ container, district: 'factory' as const })),
|
||||
});
|
||||
const challenger = g.players[(owner.id + 1) % g.players.length];
|
||||
challenger.containersOnFactoryStore.push({ piece: g.containersLeft.pop()!, price: 2, moved: false });
|
||||
g.currentPlayers = [challenger.id];
|
||||
refresh(g);
|
||||
expect(challenger.availableMoves!.callBank).equal(undefined);
|
||||
const before = cloneDeep(g);
|
||||
expect(() =>
|
||||
applyBankMove(
|
||||
g,
|
||||
{
|
||||
name: MoveName.CallBank,
|
||||
data: { type, lot: 2 },
|
||||
extraData:
|
||||
type === 'cash'
|
||||
? { containers: challenger.containersOnFactoryStore.map((c) => c.piece.id) }
|
||||
: { cash: 2 },
|
||||
},
|
||||
challenger
|
||||
)
|
||||
).throw();
|
||||
expect(g).deep.equal(before);
|
||||
g.currentPlayers = [owner.id];
|
||||
settleBank(g);
|
||||
normalizeBankDistribution(g);
|
||||
expect(b.auctions).deep.equal([]);
|
||||
expect(b.decision).equal(undefined);
|
||||
expect(owner.offshoreStats![type === 'cash' ? 'cashAuctionsWon' : 'containerAuctionsWon']).equal(1);
|
||||
});
|
||||
}
|
||||
it('enables via expansion ID and persists the option', async () => {
|
||||
expect((await wrapper.init(3, ['offshore-island'], {}, 'seed')).options.offshoreIsland).equal(true);
|
||||
expect((await wrapper.init(3, [], {}, 'seed')).offshoreBank).equal(undefined);
|
||||
|
|
|
|||
|
|
@ -28,6 +28,11 @@ export function seizureChoices(G: GameState, player: Player): ContainerPiece[] {
|
|||
].find((a) => a.length > 0) || []
|
||||
);
|
||||
}
|
||||
function hasBankPrize(G: GameState, type: 'cash' | 'containers', lot: number): boolean {
|
||||
if (!Number.isInteger(lot) || lot < 0 || lot >= 3) return false;
|
||||
const b = G.offshoreBank!;
|
||||
return type === 'cash' ? b.cashLots[lot] > 0 : type === 'containers' && b.containerLots[lot].length > 0;
|
||||
}
|
||||
export function bankMoves(G: GameState, player: Player): AvailableMoves {
|
||||
const b = G.offshoreBank!;
|
||||
const d = b.decision;
|
||||
|
|
@ -59,7 +64,7 @@ export function bankMoves(G: GameState, player: Player): AvailableMoves {
|
|||
(active?.containers.length || 0);
|
||||
if (!canBid) continue;
|
||||
for (let lot = 0; lot < 3; lot++) {
|
||||
if (!active || active.lot === lot) offers.push({ type, lot });
|
||||
if ((!active || active.lot === lot) && hasBankPrize(G, type, lot)) offers.push({ type, lot });
|
||||
}
|
||||
}
|
||||
if (offers.length) moves[MoveName.CallBank] = offers;
|
||||
|
|
@ -153,6 +158,7 @@ export function applyBankMove(G: GameState, move: Move, p: Player): { handled: b
|
|||
const b = G.offshoreBank;
|
||||
if (!b) return { handled: false };
|
||||
if (move.name === MoveName.CallBank) {
|
||||
assert(move.data && hasBankPrize(G, move.data.type, move.data.lot), 'Bank reward lot is empty or invalid');
|
||||
assert(
|
||||
move.extraData &&
|
||||
typeof move.extraData === 'object' &&
|
||||
|
|
|
|||
|
|
@ -49,7 +49,9 @@ try {
|
|||
});
|
||||
await page.goto(`http://127.0.0.1:${server.address().port}/`);
|
||||
let state = engine.setup(3, { offshoreIsland: true }, 'offshore-browser');
|
||||
state.offshoreBank.containerLots[2].push(state.containersLeft.pop());
|
||||
const player = state.currentPlayers[0];
|
||||
state.players[player].availableMoves = engine.availableMoves(state, state.players[player]);
|
||||
state.players.forEach((p, i) => (p.name = ['Ada', 'Benoît', 'Cleo'][i]));
|
||||
state.newTurn = true;
|
||||
await page.evaluate(
|
||||
|
|
@ -73,6 +75,35 @@ try {
|
|||
await page.waitForSelector('.offshore-bank .offshore-lot', { state: 'attached' });
|
||||
assert.equal(await page.locator('.offshore-bank .offshore-lot').count(), 6);
|
||||
assert.equal(await page.locator('text=OPTIONAL EXPANSION').count(), 0);
|
||||
// Empty rewards remain visible, but cannot open a draft or emit a move.
|
||||
const reward = state.offshoreBank.containerLots[2].pop();
|
||||
state.containersLeft.push(reward);
|
||||
state.offshoreBank.cashLots[1] = 0;
|
||||
await push();
|
||||
for (const [type, lot] of [
|
||||
['containers', 2],
|
||||
['cash', 1],
|
||||
]) {
|
||||
const node = page.locator(`.offshore-lot[data-type="${type}"][data-lot="${lot}"]`);
|
||||
assert.equal(await node.getAttribute('role'), null);
|
||||
assert.ok(!(await node.getAttribute('class')).split(/\s+/).includes('legal'));
|
||||
assert.ok((await node.textContent()).includes('Bid'));
|
||||
await node.click();
|
||||
assert.equal(await page.locator('.bank-draft').count(), 0);
|
||||
assert.equal(await page.evaluate(() => moves.length), 0);
|
||||
}
|
||||
state.offshoreBank.containerLots[2].push(state.containersLeft.pop());
|
||||
state.offshoreBank.cashLots[1] = 2;
|
||||
await push();
|
||||
for (const [type, lot] of [
|
||||
['containers', 2],
|
||||
['cash', 1],
|
||||
]) {
|
||||
assert.equal(
|
||||
await page.locator(`.offshore-lot[data-type="${type}"][data-lot="${lot}"]`).getAttribute('role'),
|
||||
'button'
|
||||
);
|
||||
}
|
||||
const lotBounds = await page.locator('.offshore-lot[data-type="containers"][data-lot="2"]').boundingBox();
|
||||
const pierBounds = await page.locator('.bank-piers').boundingBox();
|
||||
assert.ok(pierBounds.x >= lotBounds.x + lotBounds.width, 'harbor is beside the bank lots');
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import { describe, expect, it } from 'vitest';
|
|||
|
||||
function fixture() {
|
||||
const state = setup(3, { offshoreIsland: true }, 'offshore-viewer');
|
||||
state.offshoreBank!.containerLots[2].push(state.containersLeft.pop()!);
|
||||
const player = state.currentPlayers[0];
|
||||
state.players.forEach((p, i) => (p.name = `Trader ${i + 1}`));
|
||||
const own = state.players[player];
|
||||
|
|
@ -150,6 +151,39 @@ describe('Offshore bank viewer', () => {
|
|||
wrapper.destroy();
|
||||
});
|
||||
|
||||
it('keeps empty lot bid labels but disables selection until replenished', async () => {
|
||||
const { state, refresh, render, own } = fixture();
|
||||
state.containersLeft.push(...state.offshoreBank!.containerLots[2].splice(0));
|
||||
state.offshoreBank!.cashLots[1] = 0;
|
||||
refresh();
|
||||
const wrapper = render();
|
||||
for (const [type, lot] of [
|
||||
['containers', 2],
|
||||
['cash', 1],
|
||||
]) {
|
||||
const node = wrapper.find(`[data-type="${type}"][data-lot="${lot}"]`);
|
||||
expect(node.classes()).not.toContain('legal');
|
||||
expect(node.attributes('role')).toBeUndefined();
|
||||
expect(node.text()).toContain('Bid');
|
||||
await node.trigger('click');
|
||||
}
|
||||
expect(wrapper.emitted('choose-offer')).toBeUndefined();
|
||||
state.offshoreBank!.containerLots[2].push(state.containersLeft.pop()!);
|
||||
state.offshoreBank!.cashLots[1] = 1;
|
||||
refresh();
|
||||
await wrapper.setProps({ availableMoves: own.availableMoves });
|
||||
for (const [type, lot] of [
|
||||
['containers', 2],
|
||||
['cash', 1],
|
||||
]) {
|
||||
const node = wrapper.find(`[data-type="${type}"][data-lot="${lot}"]`);
|
||||
expect(node.classes()).toContain('legal');
|
||||
await node.trigger('click');
|
||||
expect(wrapper.emitted('choose-offer')!.slice(-1)[0][0]).toEqual({ type, lot });
|
||||
}
|
||||
wrapper.destroy();
|
||||
});
|
||||
|
||||
function gameFixture() {
|
||||
const f = fixture();
|
||||
const emitter = new EventEmitter();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue