Support Truthtrance No-Field shipment promises
Verify and publish checkpoint container / container (push) Canceled after 0s
Verify and publish checkpoint container / container (push) Canceled after 0s
This commit is contained in:
1 parent
9ab9b9a613
commit
7fccd62814
16 files changed
+658
-32
No files matched your search
@@ -5,8 +5,11 @@ import { nativePromiseScopeSupported } from './native-promise-scope';
|
||||
|
||||
/** Every shipment leaf describes the same eventual reserve shipment, or its absence. */
|
||||
export type ShipmentLeaf = { territory: string; minimum: number; sector?: number };
|
||||
/** A public promise about use of a concealed marker, never its identity or value. */
|
||||
export type NoFieldShipmentLeaf = { kind: 'noField'; territory?: string; sector?: number };
|
||||
export type ShipmentExpression =
|
||||
| ShipmentLeaf
|
||||
| NoFieldShipmentLeaf
|
||||
| { constant: TruthAnswer }
|
||||
| { op: 'and' | 'or'; terms: ShipmentExpression[] };
|
||||
/** Old flat questions and saved promises remain valid without migration. */
|
||||
@@ -84,6 +87,25 @@ export function parseShipmentExpression(
|
||||
);
|
||||
return { constant: value.constant };
|
||||
}
|
||||
if (value.kind === 'noField') {
|
||||
const keys = Object.keys(value).sort().join(',');
|
||||
check(
|
||||
(keys === 'kind' || keys === 'kind,territory' || keys === 'kind,sector,territory') &&
|
||||
++leaves <= SHIPMENT_EXPRESSION_MAX_LEAVES,
|
||||
'Choose a No-Field shipment and optionally a printed destination and sector.',
|
||||
);
|
||||
if (keys === 'kind') return { kind: 'noField' };
|
||||
check(typeof value.territory === 'string' &&
|
||||
TERRITORIES.some(t => t.id === value.territory),
|
||||
'Choose a printed destination territory.');
|
||||
if (keys === 'kind,sector,territory') {
|
||||
check(typeof value.sector === 'number' && Number.isSafeInteger(value.sector) &&
|
||||
TERRITORIES.find(t => t.id === value.territory)!.sectors.includes(value.sector),
|
||||
'Choose a printed sector of the selected destination territory.');
|
||||
return { kind: 'noField', territory: value.territory, sector: value.sector };
|
||||
}
|
||||
return { kind: 'noField', territory: value.territory };
|
||||
}
|
||||
check(
|
||||
(Object.keys(value).sort().join(',') === 'minimum,territory' ||
|
||||
Object.keys(value).sort().join(',') === 'minimum,sector,territory') &&
|
||||
@@ -134,13 +156,22 @@ export function shipmentExpressionOf(claim: ShipmentClaim): ShipmentExpression {
|
||||
...(claim.sector === undefined ? {} : { sector: claim.sector }) }
|
||||
);
|
||||
}
|
||||
/** Public syntax check; it never reads a player's marker inventory. */
|
||||
export function shipmentClaimHasNoField(claim: ShipmentClaim): boolean {
|
||||
const contains = (expression: ShipmentExpression): boolean =>
|
||||
'op' in expression ? expression.terms.some(contains) :
|
||||
'kind' in expression && expression.kind === 'noField';
|
||||
return contains(shipmentExpressionOf(claim));
|
||||
}
|
||||
export function shipmentClaimDestinations(claim: ShipmentClaim): string[] {
|
||||
const collect = (expression: ShipmentExpression): string[] =>
|
||||
'op' in expression
|
||||
? expression.terms.flatMap(collect)
|
||||
: 'constant' in expression
|
||||
? []
|
||||
: [expression.territory];
|
||||
: 'kind' in expression && expression.territory === undefined
|
||||
? TERRITORIES.map(t => t.id)
|
||||
: [expression.territory!];
|
||||
return [...new Set(collect(shipmentExpressionOf(claim)))];
|
||||
}
|
||||
export function shipmentClaimText(
|
||||
@@ -152,9 +183,11 @@ export function shipmentClaimText(
|
||||
!('constant' in expression),
|
||||
'Format a compiled mixed claim using its original question, not its private answers.',
|
||||
);
|
||||
return 'op' in expression
|
||||
? `(${expression.terms.map(text).join(expression.op === 'and' ? ' AND ' : ' OR ')})`
|
||||
: `ship at least ${expression.minimum} physical forces from your reserves to ${territory(expression.territory).name}${expression.sector === undefined ? '' : `, sector ${expression.sector}`}`;
|
||||
if ('op' in expression)
|
||||
return `(${expression.terms.map(text).join(expression.op === 'and' ? ' AND ' : ' OR ')})`;
|
||||
if ('kind' in expression)
|
||||
return `ship your No-Field from your reserves${expression.territory === undefined ? '' : ` to ${territory(expression.territory).name}${expression.sector === undefined ? '' : `, sector ${expression.sector}`}`}`;
|
||||
return `ship at least ${expression.minimum} physical forces from your reserves to ${territory(expression.territory).name}${expression.sector === undefined ? '' : `, sector ${expression.sector}`}`;
|
||||
};
|
||||
return text(shipmentExpressionOf(claim));
|
||||
}
|
||||
@@ -221,9 +254,16 @@ export type ShipmentPromise = ShipmentClaim & {
|
||||
released?: boolean;
|
||||
fulfilled?: boolean;
|
||||
};
|
||||
/** A completed reserve shipment. Amount counts real physical counters only. */
|
||||
export type ShipmentReceipt = {
|
||||
territory: string;
|
||||
amount: number;
|
||||
sector?: number;
|
||||
noField?: true;
|
||||
};
|
||||
export function matchesShipment(
|
||||
claim: ShipmentClaim,
|
||||
shipment: { territory: string; amount: number; sector?: number } | null,
|
||||
shipment: ShipmentReceipt | null,
|
||||
): boolean | null {
|
||||
const matches = (expression: ShipmentExpression): boolean | null => {
|
||||
if ('constant' in expression)
|
||||
@@ -240,6 +280,10 @@ export function matchesShipment(
|
||||
}
|
||||
return unknown ? null : expression.op === 'and';
|
||||
}
|
||||
if ('kind' in expression)
|
||||
return !!shipment && shipment.noField === true &&
|
||||
(expression.territory === undefined || shipment.territory === expression.territory) &&
|
||||
(expression.sector === undefined || shipment.sector === expression.sector);
|
||||
return !!shipment &&
|
||||
shipment.territory === expression.territory &&
|
||||
(expression.sector === undefined || shipment.sector === expression.sector) &&
|
||||
|
||||
Reference in new issue
Block a user