Connect real Basic/Advanced base-faction audit setup to all seven Discovery Spice Cards and eight physical tokens. Add Great Maker's ordered majority vote and Fremen reserve ride, destructive Discovery blows, private faction peeks and Collection inspection/reveal, stash rewards and mandatory saved card overflow, and revealed nested board locations. Share private legal choices with human controls and all four AI profiles. Preserve normal gates. Independent review repairs orphaned worm/vote/ride controls, retargeted reserve arrivals, actor bindings and incomplete overflow discard receipts. Harden room-aware admission against unrevealed nested locations. Extend the backed-up local prototype starter with a Discovery profile; preserve seats. Still missing: next-turn free entry, five special location benefits and Ornithopter movement spending. Current prototype playthroughs do not certify those effects or complete module/expansion compliance. Verification: npm run check passed 4264 offline tests plus types/lint; npm run build passed; npm run test:integration passed 40 tests. The single source-bound broad run took 129358ms / 6782ms / 23918ms respectively. Report: /home/quintine/.local/share/dune/checkpoints/20260913-discovery-prototype/verification/report.json Source fingerprint: 4ea7b5209a58c369b0b1f8dc239b5dd2f3302bb759d83c32ba5406e80d8ae154 Two seeded Basic/Advanced games complete with component custody intact. SQLite races pay stashes once and resume committed discards without replay. Browser 3RJBH26Y verifies genuine human Fremen setup, a Discovery blow from one reordered physical card, native private Hiereg visibility, enlarged card/rules reading and refresh. Room remains paused at spice acceptance. All 125 opening saved rooms unchanged; 31 added, 156 total. No server restart. Efficiency: three reused bounded helpers; aggregate counter 60591430 to 61812513 after verification, 1221083 tokens before final Git/push overhead. 47 added offline tests. One stable broad run after focused review fixes; no calibration or exhaustive optional-module interaction matrix.
148 lines
4.8 KiB
TypeScript
148 lines
4.8 KiB
TypeScript
import type { Game, Player, ResponseWindow } from './engine';
|
|
import { MOBILE_STRONGHOLD, validGameLocation } from './board';
|
|
import { validateRicheseNoField } from './richese-no-field';
|
|
|
|
export class NoFieldCancellationError extends Error {}
|
|
export type NoFieldCancellationContext = Pick<
|
|
Game,
|
|
| 'status'
|
|
| 'phase'
|
|
| 'turn'
|
|
| 'active'
|
|
| 'pendingShipment'
|
|
| 'richeseAllyOffer'
|
|
| 'richeseAllyOpportunity'
|
|
| 'richeseAllyBlocked'
|
|
| 'discoveries'
|
|
> & {
|
|
players: readonly Pick<
|
|
Player,
|
|
| 'id'
|
|
| 'faction'
|
|
| 'ally'
|
|
| 'shipped'
|
|
| 'noField'
|
|
| 'noFieldEvent'
|
|
| 'noFieldBlockedTurn'
|
|
>[];
|
|
};
|
|
export type NoFieldCancellation =
|
|
| { kind: 'own'; player: string; blockedTurn: number; pendingShipment: null }
|
|
| {
|
|
kind: 'allied';
|
|
owner: string;
|
|
player: string;
|
|
blocked: { turn: number; recipient: string };
|
|
pendingShipment: null;
|
|
};
|
|
function requireDeclaration(
|
|
condition: unknown,
|
|
message: string,
|
|
): asserts condition {
|
|
if (!condition) throw new NoFieldCancellationError(message);
|
|
}
|
|
const identity = (value: unknown): value is string =>
|
|
typeof value === 'string' && value.trim().length > 0;
|
|
const whole = (value: unknown): value is number =>
|
|
Number.isSafeInteger(value) && (value as number) >= 0;
|
|
|
|
/** Quote only the denied declaration. Cancellation neither ships nor reveals:
|
|
* no rate, balance, reserves, route, capacity or repeat-token availability is read.
|
|
* The token's private identity is consumed as evidence, never returned. */
|
|
export function quoteNoFieldCancellation(
|
|
g: NoFieldCancellationContext,
|
|
response: ResponseWindow,
|
|
): NoFieldCancellation {
|
|
const shipment = g.pendingShipment;
|
|
const owner = g.players.find((p) => p.id === response.owner);
|
|
const controller = g.players.find((p) => p.id === shipment?.player);
|
|
requireDeclaration(
|
|
response.kind === 'richeseNoField' &&
|
|
g.status === 'playing' &&
|
|
g.phase === 5 &&
|
|
whole(g.turn) &&
|
|
g.turn > 0 &&
|
|
owner?.faction === 'richese' &&
|
|
controller &&
|
|
g.active === controller.id &&
|
|
!controller.shipped &&
|
|
shipment &&
|
|
(shipment.turn === undefined || shipment.turn === g.turn),
|
|
'The canceled No-Field needs its original unused shipment opportunity.',
|
|
);
|
|
requireDeclaration(
|
|
!!shipment.noField !== !!shipment.alliedNoField,
|
|
'The canceled No-Field needs exactly one own or allied declaration.',
|
|
);
|
|
requireDeclaration(
|
|
shipment.territory !== MOBILE_STRONGHOLD &&
|
|
validGameLocation(g, shipment.territory, shipment.sector) &&
|
|
whole(shipment.amount) &&
|
|
shipment.amount <= 5 &&
|
|
whole(shipment.elite) &&
|
|
shipment.elite <= shipment.amount &&
|
|
typeof shipment.advisors === 'boolean',
|
|
'The canceled No-Field needs a valid declared destination and force type.',
|
|
);
|
|
requireDeclaration(
|
|
owner.noField && identity(owner.noFieldEvent),
|
|
'The canceled No-Field needs its physical token inventory and selection event.',
|
|
);
|
|
try {
|
|
validateRicheseNoField(owner.noField);
|
|
} catch (error) {
|
|
throw new NoFieldCancellationError(
|
|
error instanceof Error ? error.message : 'Invalid No-Field inventory.',
|
|
);
|
|
}
|
|
const own = shipment.noField;
|
|
if (own) {
|
|
requireDeclaration(
|
|
controller.id === owner.id &&
|
|
shipment.amount === 1 &&
|
|
shipment.elite === 0 &&
|
|
identity(own.tokenId) &&
|
|
own.event === owner.noFieldEvent &&
|
|
owner.noField.tokens.some((token) => token.id === own.tokenId) &&
|
|
owner.noFieldBlockedTurn !== g.turn,
|
|
'The canceled own No-Field declaration is stale or already blocked.',
|
|
);
|
|
return {
|
|
kind: 'own',
|
|
player: owner.id,
|
|
blockedTurn: g.turn,
|
|
pendingShipment: null,
|
|
};
|
|
}
|
|
const offer = shipment.alliedNoField!;
|
|
requireDeclaration(
|
|
controller.id !== owner.id &&
|
|
offer.owner === owner.id &&
|
|
offer.recipient === controller.id &&
|
|
owner.ally === controller.id &&
|
|
controller.ally === owner.id &&
|
|
identity(offer.event) &&
|
|
identity(offer.tokenId) &&
|
|
offer.tokenEvent === owner.noFieldEvent &&
|
|
owner.noField.tokens.some((token) => token.id === offer.tokenId) &&
|
|
offer.territory === shipment.territory &&
|
|
offer.sector === shipment.sector &&
|
|
[owner.id, controller.id, 'both'].includes(offer.payer) &&
|
|
g.richeseAllyOpportunity?.turn === g.turn &&
|
|
g.richeseAllyOpportunity.recipient === controller.id &&
|
|
!g.richeseAllyOffer &&
|
|
!(
|
|
g.richeseAllyBlocked?.turn === g.turn &&
|
|
g.richeseAllyBlocked.recipient === controller.id
|
|
),
|
|
'The canceled allied No-Field needs its accepted token offer and recipient.',
|
|
);
|
|
return {
|
|
kind: 'allied',
|
|
owner: owner.id,
|
|
player: controller.id,
|
|
blocked: { turn: g.turn, recipient: controller.id },
|
|
pendingShipment: null,
|
|
};
|
|
}
|