Connect revealed Harass force allocation and exact casualties
Harass & Withdraw now admits legal Basic/Advanced mixed ordinary/elite commitments and multi-sector returns. A shared physical quote validates every returned counter against one exact legal dial/support complement. After both plans are revealed, the owner selects an ambiguous allocation; unique returns remain automatic. Selected counters become public before Traitor declarations, while physical transfer waits for atomic settlement and opposing-Traitor cancellation. This information is never added to a sealed Battle Plan or complete-plan inspection. Existing optional-module and Richese/Ecaz-allied gates remain. The player panel, four AI profiles and saved event use the same quote. A versioned receipt binds the revealed plans, current typed location pools, battle and owner. Missing or altered receipts fail before reads, normalization and writes; concurrent choices select once. Previously valid legacy unique plans continue without reopening. Winner casualties now equal the selected dialed group, preventing a second smaller physical commitment after its undialed complement has returned. Independent source and implementation review passed. Pure, engine, control and SQLite regressions cover typed/sector legality, exact complement, private pre-reveal views, public selected views, stale/malformed state, cross-owner actions, raced allocations, selected restoration, automatic exact casualties, opposing-Traitor cancellation and mandatory disposal. Types, lint and 4850 offline tests, production build and 43 HTTP/session tests pass. The first broad check caught the exhaustive decision registry and test union-narrowing omissions; those were fixed before the final stable checks. Browser testing corrected the incomplete-allocation selector label before verification. Eight genuine card-variant Basic/Advanced games across all four homogeneous AI profiles completed with 9956 accepted actions, 266 periodic JSON restores and zero rejected candidates. Three Harass plans/returns and two Recruits plays occurred; no ambiguous allocation arose in these seeds. The new choice is exercised by targeted engine, authenticated recovery and browser cases, not inferred from those full-game samples. Full variant and combined-expansion acceptance remains incomplete. A fresh isolated browser room used genuine Advanced card-variant setup followed by a conserved two-sector battle fixture. Actual controls rejected a partial return, selected two ordinary counters from sector nine, and preserved the selected state after refresh. Following actual owner and engine-driven opponent Traitor declines, two counters returned, the exact remaining ordinary/elite pair went to the Tanks, support cost one, and Harass discarded once. Final refresh restored 18 reserves, two Tanks, 29 spice and the same private Traitor. This is targeted browser evidence, not a complete human game. All 1038 opening games and original seat/recovery/entry/handover records are unchanged; 1072 rooms remain including new QA. SQLite integrity and foreign keys pass. The healthy development server was reused without restart or reset. No mode/publication gate was opened. Verified source tree: 61ee78f6e2bce47cb322b04f896db27fef28c56ba2097571a1d85bad5c121156
This commit is contained in:
1 parent
640342527a
commit
62e87d2b96
18 files changed
+1654
-71
No files matched your search
@@ -28,7 +28,7 @@ import {
|
||||
type StoneBurnerComparison,
|
||||
} from './stone-burner';
|
||||
import { matchingTraitor } from './traitors';
|
||||
import { HARASS_WITHDRAW_CARD, isHarassWithdraw, quoteHarassWithdraw, type HarassWithdrawContext, type HarassWithdrawQuote } from './harass-withdraw';
|
||||
import { HARASS_WITHDRAW_CARD, isHarassWithdraw, quoteHarassWithdraw, type HarassWithdrawContext, type HarassWithdrawQuote, type HarassWithdrawSelection } from './harass-withdraw';
|
||||
import { auditCount } from './choam-auditor';
|
||||
import { sukGraduateSkill, type SukGraduateSkill } from './suk-graduate';
|
||||
import { validateSpiceBankerSpend } from './spice-banker';
|
||||
@@ -75,6 +75,7 @@ export type ResolutionParticipant = {
|
||||
};
|
||||
export type ResolutionCombatant = ResolutionParticipant & {
|
||||
harassWithdraw?: HarassWithdrawContext;
|
||||
harassSelection?: HarassWithdrawSelection;
|
||||
diplomatDefense?: Pick<DiplomatDefenseQuote, 'leader' | 'source' | 'kind'> & { card: string };
|
||||
spice: number;
|
||||
hand: readonly Card[];
|
||||
@@ -371,7 +372,7 @@ function calculate(input: BattleResolutionInput): BattleResolutionQuote {
|
||||
requireQuote(!slots.some(c => c?.id === 'ecaz-reinforcements'),
|
||||
'Reinforcements battle effects are still being implemented.');
|
||||
const harass = slots.some(isHarassWithdraw);
|
||||
requireQuote(!side.harassWithdraw || harass, 'The withdrawal context requires the physical Harass & Withdraw card.');
|
||||
requireQuote((!side.harassWithdraw && side.harassSelection === undefined) || harass, 'The withdrawal context requires the physical Harass & Withdraw card.');
|
||||
if (harass) {
|
||||
requireQuote(validBattleSlotPair(slots[0], slots[1]),
|
||||
'The Harass & Withdraw plan has an invalid weapon and defense pair.');
|
||||
@@ -379,7 +380,7 @@ function calculate(input: BattleResolutionInput): BattleResolutionQuote {
|
||||
'Harass & Withdraw needs its supported physical context; Homeworld and Stone Burner combinations remain unfinished.');
|
||||
requireQuote(JSON.stringify(side.harassWithdraw.forces) === JSON.stringify(side.forces),
|
||||
'The withdrawal context must match the current battle force roles.');
|
||||
withdrawals.set(side.id, quoteHarassWithdraw(side.harassWithdraw, side.plan.dial, side.plan.support));
|
||||
withdrawals.set(side.id, quoteHarassWithdraw(side.harassWithdraw, side.plan.dial, side.plan.support, side.harassSelection));
|
||||
}
|
||||
}
|
||||
const tie =
|
||||
@@ -662,11 +663,15 @@ function calculate(input: BattleResolutionInput): BattleResolutionQuote {
|
||||
homeworld ||
|
||||
winner.faction === 'ixians'
|
||||
) {
|
||||
const withdrawal = harassWithdraw.find(entry => entry.player === winner.id);
|
||||
// Withdrawal already identifies every undialed counter. Do not choose a
|
||||
// smaller physical commitment a second time after returning its complement.
|
||||
const options = casualtyOptions(
|
||||
harassWithdraw.find(entry => entry.player === winner.id)?.remaining ?? winner.forces,
|
||||
withdrawal?.remaining ?? winner.forces,
|
||||
winner.plan.dial,
|
||||
winner.plan.support,
|
||||
);
|
||||
).filter(option => !withdrawal ||
|
||||
option.normal === withdrawal.remaining.normal && option.elite === withdrawal.remaining.elite);
|
||||
requireQuote(
|
||||
options.length > 0,
|
||||
'No valid casualty choice remains for this battle.',
|
||||
|
||||
+11
-2
@@ -3,7 +3,7 @@ import { recruitsPlayAction } from './recruits';
|
||||
import type { Card } from './cards';
|
||||
import { bureaucratBattlePenalty, canUsePlanetologistBattleSpecial, leaderSkillBattleBonus } from './leader-skill-combat';
|
||||
import { battleCardSlotEligible, battleCategoryInspectionValue, fixedBattleInspectionMatches, validBattleSlotPair, type BattlePlanInspectionField } from './battle-card-slots';
|
||||
import { quoteHarassWithdraw } from './harass-withdraw';
|
||||
import { defaultHarassWithdrawAllocation, quoteHarassWithdraw } from './harass-withdraw';
|
||||
import { leaderSkillStrongholdCount } from './leader-skill-battle-board';
|
||||
import { discoveryFlightBotActions } from './discovery-flight-options';
|
||||
import { discoveryEntryBotActions } from './discovery-entry-options';
|
||||
@@ -936,7 +936,10 @@ function plans(g: GameView): Action[] {
|
||||
if (harass) {
|
||||
if (!b.harassWithdraw) continue;
|
||||
try {
|
||||
const quote = quoteHarassWithdraw(b.harassWithdraw, Number(action.dial), Number(action.support ?? 0));
|
||||
const allocation = b.harassWithdraw.allowAllocation
|
||||
? defaultHarassWithdrawAllocation(b.harassWithdraw, Number(action.dial), Number(action.support ?? 0))
|
||||
: undefined;
|
||||
const quote = quoteHarassWithdraw(b.harassWithdraw, Number(action.dial), Number(action.support ?? 0), allocation);
|
||||
withdrawn = quote.returned.normal + quote.returned.elite;
|
||||
} catch { continue; }
|
||||
}
|
||||
@@ -1465,6 +1468,12 @@ function policyActions(g: GameView): Action[] {
|
||||
if (g.decision.player !== me.id) return [];
|
||||
const d = g.decision;
|
||||
if (d.kind === 'leaderSkillVisibility' || d.kind === 'leaderSkillRevival' || d.kind === 'mentatQuestion' || d.kind === 'bureaucratPayment') return [];
|
||||
if (d.kind === 'harassWithdraw') {
|
||||
const offer = g.battle?.harassAllocation;
|
||||
if (!offer || offer.event !== d.event) return [];
|
||||
return [{ type: 'decision', event: d.event,
|
||||
returns: offer.selection ?? defaultHarassWithdrawAllocation(offer.context, offer.dial, offer.support) }];
|
||||
}
|
||||
if (d.kind === 'choamAudit')
|
||||
return [{ type: 'decision', event: d.event, audit: true }];
|
||||
if (d.kind === 'choamAuditPayment') {
|
||||
|
||||
+109
-4
@@ -17,7 +17,7 @@ import { spiceBankerModeSupported, validateSpiceBankerSpend } from './spice-bank
|
||||
import { quoteDiplomatDefense, diplomatDefenseModeSupported, type DiplomatDefenseQuote } from './diplomat-defense';
|
||||
import { ECAZ_START_FORCES, quoteEcazStartingForces } from './ecaz-setup';
|
||||
import { battleCardSlotEligible, battleCategoryInspectionValue, fixedBattleInspectionMatches, validBattleSlotPair } from './battle-card-slots';
|
||||
import { HARASS_WITHDRAW_CARD, HarassWithdrawError, isHarassWithdraw, quoteHarassWithdraw, type HarassWithdrawContext, type HarassWithdrawPreview } from './harass-withdraw';
|
||||
import { HARASS_WITHDRAW_CARD, HarassWithdrawError, isHarassWithdraw, quoteHarassWithdraw, defaultHarassWithdrawAllocation, harassWithdrawNeedsAllocation, type HarassWithdrawSelection, type HarassWithdrawContext, type HarassWithdrawPreview } from './harass-withdraw';
|
||||
import { discoveryChoices, discoveryStashSignature, type DiscoveryStash } from './discovery-actions';
|
||||
import { createStormSource, validateStormSource, discoveryStormOffer, createDiscoveryStorm, chooseDiscoveryStorm, validateDiscoveryStorm, finishDiscoveryStorm, type StormMovementSource, type DiscoveryStorm } from './discovery-storm';
|
||||
import { completeDiscoveryFlight, discoveryFlightOffer, quoteDiscoveryFlight, validateDiscoveryFlight, type DiscoveryFlightReceipt } from './discovery-flight';
|
||||
@@ -606,7 +606,15 @@ export type DiplomatDefenseReceipt = DiplomatDefenseQuote & {
|
||||
card: string | null;
|
||||
signature: string;
|
||||
};
|
||||
export type HarassAllocationReceipt = {
|
||||
player: string; event: string; battle: string; turn: number; frame: string;
|
||||
stage: 'offered' | 'selected'; selection: HarassWithdrawSelection | null; signature: string;
|
||||
};
|
||||
export type Battle = {
|
||||
/** New battles allow physical withdrawal choice after reveal, never in the sealed plan. */
|
||||
harassAllocationVersion?: 1;
|
||||
harassAllocationEvent?: string;
|
||||
harassAllocation?: HarassAllocationReceipt;
|
||||
/** Scheduling owner; physical combat slots and aggressor remain independent. */
|
||||
chooser?: string;
|
||||
chooserEvent?: string;
|
||||
@@ -678,6 +686,7 @@ export type Auction = {
|
||||
allyPayment?: number;
|
||||
};
|
||||
export type Decision =
|
||||
| { kind: 'harassWithdraw'; player: string; event: string }
|
||||
| { kind: 'diplomatDefense'; player: string; event: string; cards: string[]; source: string }
|
||||
| { kind: 'leaderSkillVisibility'; player: string; event: string; resumePowers?: boolean }
|
||||
| { kind: 'leaderSkillRevival'; player: string; event: string }
|
||||
@@ -5250,6 +5259,7 @@ function leaderSkillsIntegrity(g: Game) {
|
||||
bureaucratPaymentIntegrity(g);
|
||||
mentatQuestionIntegrity(g);
|
||||
diplomatDefenseIntegrity(g);
|
||||
harassAllocationIntegrity(g);
|
||||
const noFieldShipment = leaderSkillNoFieldIntegrity(g);
|
||||
sandmasterIntegrity(g);
|
||||
sukRescueIntegrity(g);
|
||||
@@ -13550,7 +13560,11 @@ function harassWithdrawContext(g: Game, p: Player): HarassWithdrawContext {
|
||||
}
|
||||
function currentHarassWithdrawQuote(g: Game, p: Player, plan: Pick<Plan, 'dial' | 'support'>) {
|
||||
try {
|
||||
const quote = quoteHarassWithdraw(harassWithdrawContext(g, p), plan.dial, plan.support);
|
||||
const context = harassWithdrawContext(g, p);
|
||||
const receipt = g.battle?.harassAllocation;
|
||||
const selection = receipt?.player === p.id && receipt.stage === 'selected' ? receipt.selection! :
|
||||
g.battle?.harassAllocationVersion === 1 ? defaultHarassWithdrawAllocation(context, plan.dial, plan.support) : undefined;
|
||||
const quote = quoteHarassWithdraw(context, plan.dial, plan.support, selection);
|
||||
validateHarassReturnCounters(p, quote.returned);
|
||||
return quote;
|
||||
}
|
||||
@@ -13567,7 +13581,7 @@ function harassWithdrawPreview(g: Game, p: Player): HarassWithdrawPreview | null
|
||||
const b = g.battle;
|
||||
if (!b || ![b.attacker, b.defender].includes(p.id) || !p.hand.some(isHarassWithdraw)) return null;
|
||||
const context = harassWithdrawContext(g, p);
|
||||
return { ...context, card: HARASS_WITHDRAW_CARD,
|
||||
return { ...context, card: HARASS_WITHDRAW_CARD, allowAllocation: b.harassAllocationVersion === 1,
|
||||
blocked: context.blocked ?? (b.revealed || b.plans[p.id] ? 'Your Battle Plan is already sealed.' : null) };
|
||||
}
|
||||
function validateResidualPoison(
|
||||
@@ -15267,8 +15281,76 @@ function offerDiplomatDefense(g: Game): boolean {
|
||||
{ faction: getPlayer(g, offer.player).faction, name: 'Diplomat defense' });
|
||||
return true;
|
||||
}
|
||||
function harassAllocationOffer(g: Game) {
|
||||
const b = g.battle;
|
||||
if (!b?.revealed || b.harassAllocationVersion !== 1) return null;
|
||||
for (const id of [b.attacker, b.defender]) {
|
||||
const p = getPlayer(g, id), plan = b.plans[id];
|
||||
if (![plan.weapon, plan.defense].includes(HARASS_WITHDRAW_CARD)) continue;
|
||||
const context = harassWithdrawContext(g, p);
|
||||
try {
|
||||
if (harassWithdrawNeedsAllocation(context, plan.dial, plan.support))
|
||||
return { player: id, context, dial: plan.dial, support: plan.support };
|
||||
} catch (error) { if (error instanceof HarassWithdrawError) throw new RuleError(error.message); throw error; }
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function harassAllocationFrame(g: Game): string {
|
||||
const b = g.battle!;
|
||||
return JSON.stringify({ battle: b.event, turn: g.turn, territory: b.territory,
|
||||
attacker: b.attacker, defender: b.defender, plans: b.plans, offer: harassAllocationOffer(g) });
|
||||
}
|
||||
function harassAllocationSignature(receipt: HarassAllocationReceipt): string {
|
||||
return JSON.stringify({ ...receipt, signature: undefined });
|
||||
}
|
||||
function harassAllocationIntegrity(g: Game) {
|
||||
const b = g.battle, decisions = homeworldSavedDecisions(g).filter(d => d.kind === 'harassWithdraw');
|
||||
if (b?.harassAllocationVersion === undefined && b?.harassAllocation === undefined &&
|
||||
b?.harassAllocationEvent === undefined && !decisions.length) return;
|
||||
requireRule(b && b.harassAllocationVersion === 1, 'The saved withdrawal choice lost its original battle version.');
|
||||
const receipt = b.harassAllocation, offer = harassAllocationOffer(g);
|
||||
if (!receipt) {
|
||||
requireRule(receipt === undefined && b.harassAllocationEvent === undefined && !decisions.length && !offer,
|
||||
'The revealed Harass & Withdraw plan lost its physical allocation choice.');
|
||||
return;
|
||||
}
|
||||
requireRule(g.status === 'playing' && g.phase === 6 && b.revealed && offer &&
|
||||
receipt.player === offer.player && receipt.battle === b.event && receipt.turn === g.turn &&
|
||||
typeof receipt.event === 'string' && receipt.event.length > 0 && receipt.event === b.harassAllocationEvent &&
|
||||
receipt.frame === harassAllocationFrame(g) && receipt.signature === harassAllocationSignature(receipt) &&
|
||||
['offered', 'selected'].includes(receipt.stage),
|
||||
'The saved withdrawal choice changed its revealed plan, force locations or event.');
|
||||
requireRule(decisions.length === (receipt.stage === 'offered' ? 1 : 0),
|
||||
'The saved withdrawal choice lost or reopened its unique decision.');
|
||||
if (receipt.stage === 'offered') requireRule(receipt.selection === null && !Object.keys(b.traitorCalls).length,
|
||||
'Choose undialed forces before any traitor declarations.');
|
||||
else {
|
||||
requireRule(receipt.selection !== null, 'The saved withdrawal choice lost its selected counters.');
|
||||
try { quoteHarassWithdraw(offer.context, offer.dial, offer.support, receipt.selection); }
|
||||
catch (error) { if (error instanceof HarassWithdrawError) throw new RuleError(error.message); throw error; }
|
||||
}
|
||||
for (const decision of decisions) requireRule(decision.player === receipt.player && decision.event === receipt.event &&
|
||||
Object.keys(decision).every(key => ['kind', 'player', 'event'].includes(key)),
|
||||
'The withdrawal decision no longer matches its original owner and event.');
|
||||
}
|
||||
function offerHarassAllocation(g: Game): boolean {
|
||||
const b = g.battle!;
|
||||
if (b.harassAllocation || b.harassAllocationVersion !== 1) return false;
|
||||
const offer = harassAllocationOffer(g);
|
||||
if (!offer) return false;
|
||||
requireRule(b.event && !Object.keys(b.traitorCalls).length, 'Choose withdrawal counters immediately after reveal.');
|
||||
const event = crypto.randomUUID();
|
||||
const receipt: HarassAllocationReceipt = { player: offer.player, event, battle: b.event, turn: g.turn,
|
||||
frame: harassAllocationFrame(g), stage: 'offered', selection: null, signature: '' };
|
||||
receipt.signature = harassAllocationSignature(receipt);
|
||||
b.harassAllocation = receipt; b.harassAllocationEvent = event;
|
||||
g.decision = { kind: 'harassWithdraw', player: offer.player, event };
|
||||
log(g, `${getPlayer(g, offer.player).name} must identify all undialed forces returned by Harass & Withdraw before traitor declarations.`);
|
||||
return true;
|
||||
}
|
||||
function nextRevealedDecision(g: Game) {
|
||||
const b = g.battle!;
|
||||
if (offerHarassAllocation(g)) return;
|
||||
if (offerDiplomatDefense(g)) return;
|
||||
const stoneOwner = [b.attacker, b.defender].find(
|
||||
(id) =>
|
||||
@@ -15345,7 +15427,9 @@ function currentBattleResolutionQuote(g: Game, canceledVoter?: string) {
|
||||
occupiedStrongholds: leaderSkillStrongholdCount(g, p),
|
||||
forces: combatForces(g, p, b.territory, opponent),
|
||||
...([cardOf(p, plan.weapon), cardOf(p, plan.defense)].some(isHarassWithdraw)
|
||||
? { harassWithdraw: harassWithdrawContext(g, p) } : {}),
|
||||
? { harassWithdraw: harassWithdrawContext(g, p),
|
||||
...(b.harassAllocation?.player === p.id && b.harassAllocation.stage === 'selected'
|
||||
? { harassSelection: b.harassAllocation.selection! } : {}) } : {}),
|
||||
stronghold: strongholdEffect(g, p.id),
|
||||
lateDefense: b.lateDefense?.[p.id],
|
||||
...(b.diplomatDefense?.stage === 'copied' && b.diplomatDefense.player === p.id
|
||||
@@ -21643,6 +21727,20 @@ function applyActionInner(
|
||||
if (harkonnen) returnCaptives(g, harkonnen);
|
||||
settleAdvisors(g);
|
||||
finishBattle(g);
|
||||
} else if (decision.kind === 'harassWithdraw') {
|
||||
const receipt = g.battle?.harassAllocation, offer = harassAllocationOffer(g);
|
||||
requireRule(Object.keys(action).every(key => ['type', 'event', 'returns'].includes(key)) &&
|
||||
action.event === decision.event && receipt?.event === decision.event && receipt.player === id &&
|
||||
receipt.stage === 'offered' && offer && action.returns !== undefined,
|
||||
'Choose all undialed forces for this exact revealed Harass & Withdraw plan.');
|
||||
let quote;
|
||||
try { quote = quoteHarassWithdraw(offer.context, offer.dial, offer.support, action.returns as HarassWithdrawSelection); }
|
||||
catch (error) { if (error instanceof HarassWithdrawError) throw new RuleError(error.message); throw error; }
|
||||
validateHarassReturnCounters(p, quote.returned);
|
||||
receipt.selection = structuredClone(quote.locations); receipt.stage = 'selected';
|
||||
receipt.signature = harassAllocationSignature(receipt);
|
||||
log(g, `${p.name} selected ${quote.returned.normal} ordinary and ${quote.returned.elite} elite undialed forces for Harass & Withdraw: ${Object.entries(quote.locations).map(([key, group]) => `${key} (${group.normal} ordinary, ${group.elite} elite)`).join('; ')}. The return waits for traitor declarations; an opposing successful call cancels it.`);
|
||||
nextRevealedDecision(g);
|
||||
} else if (decision.kind === 'diplomatDefense') {
|
||||
const receipt = g.battle?.diplomatDefense;
|
||||
requireRule(Object.keys(action).every(key => ['type', 'event', 'card'].includes(key)) &&
|
||||
@@ -23690,6 +23788,7 @@ function applyActionInner(
|
||||
event: battleEvent,
|
||||
...(g.mentatQuestionPreview === true && g.leaderSkills && mentatQuestionModeSupported(g) ? { mentatQuestionVersion: 1 as const } : {}),
|
||||
...(g.leaderSkills && diplomatDefenseModeSupported(g) ? { diplomatDefenseVersion: 1 as const } : {}),
|
||||
...(g.ecazTreachery ? { harassAllocationVersion: 1 as const } : {}),
|
||||
...(byFaction(g, 'richese')
|
||||
? { preLeader: { event: battleEvent, ready: [], closed: false } }
|
||||
: {}),
|
||||
@@ -25000,6 +25099,12 @@ export function viewGame(state: Game, id: string) {
|
||||
source: b.diplomatDefense.source, kind: b.diplomatDefense.kind,
|
||||
stage: b.diplomatDefense.stage, card: b.diplomatDefense.card }
|
||||
: null,
|
||||
harassAllocation: b.revealed && b.harassAllocation &&
|
||||
(b.harassAllocation.player === id || b.harassAllocation.stage === 'selected')
|
||||
? { event: b.harassAllocation.event, context: harassWithdrawContext(g, getPlayer(g, b.harassAllocation.player)),
|
||||
dial: b.plans[b.harassAllocation.player].dial, support: b.plans[b.harassAllocation.player].support,
|
||||
selection: b.harassAllocation.selection ? structuredClone(b.harassAllocation.selection) : null }
|
||||
: null,
|
||||
fullPlan: b.fullPlan ?? null,
|
||||
fullPlanInsight:
|
||||
b.fullPlan?.owner === id &&
|
||||
|
||||
+175
-21
@@ -8,6 +8,9 @@ import { ecazTreacheryDefinition } from './ecaz-cards';
|
||||
|
||||
export const HARASS_WITHDRAW_CARD = 'ecaz-harass-withdraw' as const;
|
||||
export type HarassWithdrawForces = Readonly<{ normal: number; elite: number }>;
|
||||
export type HarassWithdrawSelection = Readonly<
|
||||
Record<string, HarassWithdrawForces>
|
||||
>;
|
||||
export type HarassWithdrawContext = Readonly<{
|
||||
blocked: string | null;
|
||||
forces: CombatForces;
|
||||
@@ -16,6 +19,8 @@ export type HarassWithdrawContext = Readonly<{
|
||||
export type HarassWithdrawPreview = HarassWithdrawContext &
|
||||
Readonly<{
|
||||
card: typeof HARASS_WITHDRAW_CARD;
|
||||
/** New battle protocol allows the physical return to be chosen after reveal. */
|
||||
allowAllocation?: boolean;
|
||||
}>;
|
||||
export type HarassWithdrawQuote = {
|
||||
returned: { normal: number; elite: number };
|
||||
@@ -39,12 +44,29 @@ export function isHarassWithdraw(card: Card | undefined): boolean {
|
||||
function requireHarass(condition: unknown, message: string): asserts condition {
|
||||
if (!condition) throw new HarassWithdrawError(message);
|
||||
}
|
||||
/** Resolve only the user's physical counters. Neither opposing plans nor outcomes are inputs. */
|
||||
export function quoteHarassWithdraw(
|
||||
context: HarassWithdrawContext,
|
||||
dial: number,
|
||||
support: number,
|
||||
): HarassWithdrawQuote {
|
||||
function record(value: unknown): value is Record<string, unknown> {
|
||||
return (
|
||||
!!value &&
|
||||
typeof value === 'object' &&
|
||||
!Array.isArray(value) &&
|
||||
[Object.prototype, null].includes(Object.getPrototypeOf(value))
|
||||
);
|
||||
}
|
||||
function physicalGroup(value: unknown): value is HarassWithdrawForces {
|
||||
return (
|
||||
record(value) &&
|
||||
Object.keys(value).sort().join(',') === 'elite,normal' &&
|
||||
[value.normal, value.elite].every(
|
||||
(n) => typeof n === 'number' && Number.isSafeInteger(n) && n >= 0,
|
||||
)
|
||||
);
|
||||
}
|
||||
function validateContext(context: HarassWithdrawContext) {
|
||||
requireHarass(
|
||||
record(context) &&
|
||||
(context.blocked === null || typeof context.blocked === 'string'),
|
||||
'Harass & Withdraw needs a valid physical battle context.',
|
||||
);
|
||||
requireHarass(
|
||||
!context.blocked,
|
||||
context.blocked ?? 'Harass & Withdraw is unavailable.',
|
||||
@@ -54,32 +76,158 @@ export function quoteHarassWithdraw(
|
||||
validCombatForces(forces) && !forces.temporaryElite,
|
||||
'Harass & Withdraw needs ordinary physical force roles.',
|
||||
);
|
||||
requireHarass(
|
||||
record(context.locations),
|
||||
'Harass & Withdraw needs named physical force locations.',
|
||||
);
|
||||
const locations = Object.entries(context.locations);
|
||||
requireHarass(
|
||||
locations.every(
|
||||
([key, group]) =>
|
||||
key.length > 0 &&
|
||||
group &&
|
||||
Object.keys(group).sort().join(',') === 'elite,normal' &&
|
||||
[group.normal, group.elite].every(
|
||||
(n) => Number.isSafeInteger(n) && n >= 0,
|
||||
),
|
||||
) &&
|
||||
locations.every(([key, group]) => key.length > 0 && physicalGroup(group)) &&
|
||||
locations.reduce((n, [, group]) => n + group.normal, 0) ===
|
||||
forces.normal &&
|
||||
locations.reduce((n, [, group]) => n + group.elite, 0) === forces.elite,
|
||||
'Harass & Withdraw must match the user’s physical forces in this battle.',
|
||||
);
|
||||
const choices = casualtyOptions(forces, dial, support);
|
||||
return locations;
|
||||
}
|
||||
/** Distinct physical dial commitments; equivalent support allocations are not extra choices. */
|
||||
export function harassWithdrawCommitments(
|
||||
context: HarassWithdrawContext,
|
||||
dial: number,
|
||||
support: number,
|
||||
): { normal: number; elite: number }[] {
|
||||
validateContext(context);
|
||||
const choices = casualtyOptions(context.forces, dial, support);
|
||||
requireHarass(
|
||||
choices.length > 0,
|
||||
'Dial and spice must match a legal physical force commitment.',
|
||||
);
|
||||
const physical = [
|
||||
return [
|
||||
...new Map(
|
||||
choices.map((choice) => [`${choice.normal}:${choice.elite}`, choice]),
|
||||
choices.map(({ normal, elite }) => [
|
||||
`${normal}:${elite}`,
|
||||
{ normal, elite },
|
||||
]),
|
||||
).values(),
|
||||
];
|
||||
}
|
||||
function ambiguousAllocation(
|
||||
context: HarassWithdrawContext,
|
||||
physical: readonly HarassWithdrawForces[],
|
||||
) {
|
||||
if (physical.length !== 1) return true;
|
||||
return (['normal', 'elite'] as const).some((type) => {
|
||||
const returned = context.forces[type] - physical[0][type];
|
||||
return (
|
||||
returned !== 0 &&
|
||||
returned !== context.forces[type] &&
|
||||
Object.values(context.locations).filter((group) => group[type] > 0)
|
||||
.length > 1
|
||||
);
|
||||
});
|
||||
}
|
||||
/** Invalid plans still throw; true means only a legal physical/sector choice remains. */
|
||||
export function harassWithdrawNeedsAllocation(
|
||||
context: HarassWithdrawContext,
|
||||
dial: number,
|
||||
support: number,
|
||||
): boolean {
|
||||
return ambiguousAllocation(
|
||||
context,
|
||||
harassWithdrawCommitments(context, dial, support),
|
||||
);
|
||||
}
|
||||
/** Stable fallback policy only: the selected (or first legal) commitment, then sorted locations. */
|
||||
export function defaultHarassWithdrawAllocation(
|
||||
context: HarassWithdrawContext,
|
||||
dial: number,
|
||||
support: number,
|
||||
selected?: HarassWithdrawForces,
|
||||
): Record<string, { normal: number; elite: number }> {
|
||||
const choices = harassWithdrawCommitments(context, dial, support);
|
||||
requireHarass(
|
||||
selected === undefined ||
|
||||
(physicalGroup(selected) &&
|
||||
choices.some(
|
||||
(choice) =>
|
||||
choice.normal === selected.normal &&
|
||||
choice.elite === selected.elite,
|
||||
)),
|
||||
'Choose one legal physical dial commitment before allocating its return.',
|
||||
);
|
||||
const commitment = selected ?? choices[0];
|
||||
const remaining = {
|
||||
normal: context.forces.normal - commitment.normal,
|
||||
elite: context.forces.elite - commitment.elite,
|
||||
};
|
||||
return Object.fromEntries(
|
||||
Object.entries(context.locations)
|
||||
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
|
||||
.flatMap(([key, group]) => {
|
||||
const returned = {
|
||||
normal: Math.min(remaining.normal, group.normal),
|
||||
elite: Math.min(remaining.elite, group.elite),
|
||||
};
|
||||
remaining.normal -= returned.normal;
|
||||
remaining.elite -= returned.elite;
|
||||
return returned.normal || returned.elite ? [[key, returned]] : [];
|
||||
}),
|
||||
);
|
||||
}
|
||||
/** Resolve only the user's physical counters. Neither opposing plans nor outcomes are inputs. */
|
||||
export function quoteHarassWithdraw(
|
||||
context: HarassWithdrawContext,
|
||||
dial: number,
|
||||
support: number,
|
||||
selection?: HarassWithdrawSelection,
|
||||
): HarassWithdrawQuote {
|
||||
const physical = harassWithdrawCommitments(context, dial, support);
|
||||
const forces = context.forces;
|
||||
if (selection !== undefined) {
|
||||
requireHarass(
|
||||
record(selection),
|
||||
'Choose the returned physical forces by location.',
|
||||
);
|
||||
const entries = Object.entries(selection);
|
||||
requireHarass(
|
||||
entries.every(
|
||||
([key, group]) =>
|
||||
Object.hasOwn(context.locations, key) &&
|
||||
physicalGroup(group) &&
|
||||
group.normal <= context.locations[key].normal &&
|
||||
group.elite <= context.locations[key].elite,
|
||||
),
|
||||
'Returned forces must be whole available normal and elite counters at known battle locations.',
|
||||
);
|
||||
const returned = entries.reduce(
|
||||
(sum, [, group]) => ({
|
||||
normal: sum.normal + group.normal,
|
||||
elite: sum.elite + group.elite,
|
||||
}),
|
||||
{ normal: 0, elite: 0 },
|
||||
);
|
||||
const committed = physical.find(
|
||||
(choice) =>
|
||||
choice.normal === forces.normal - returned.normal &&
|
||||
choice.elite === forces.elite - returned.elite,
|
||||
);
|
||||
requireHarass(
|
||||
committed,
|
||||
'The returned counters must be the exact undialed complement of a legal physical commitment.',
|
||||
);
|
||||
return {
|
||||
returned,
|
||||
remaining: { ...forces, ...committed },
|
||||
locations: Object.fromEntries(
|
||||
entries
|
||||
.filter(([, group]) => group.normal || group.elite)
|
||||
.map(([key, group]) => [
|
||||
key,
|
||||
{ normal: group.normal, elite: group.elite },
|
||||
]),
|
||||
),
|
||||
};
|
||||
}
|
||||
requireHarass(
|
||||
physical.length === 1,
|
||||
'Harass & Withdraw with an ambiguous regular/elite commitment is still being implemented. Choose a uniquely determined physical commitment.',
|
||||
@@ -89,7 +237,8 @@ export function quoteHarassWithdraw(
|
||||
normal: forces.normal - committed.normal,
|
||||
elite: forces.elite - committed.elite,
|
||||
};
|
||||
const allocation: HarassWithdrawQuote['locations'] = {};
|
||||
const locations = Object.entries(context.locations);
|
||||
const allocation = new Map<string, { normal: number; elite: number }>();
|
||||
for (const type of ['normal', 'elite'] as const) {
|
||||
const amount = returned[type],
|
||||
occupied = locations.filter(([, group]) => group[type] > 0);
|
||||
@@ -97,6 +246,7 @@ export function quoteHarassWithdraw(
|
||||
amount === 0 || amount === forces[type] || occupied.length === 1,
|
||||
'Harass & Withdraw with an ambiguous allocation among sectors is still being implemented. Choose a uniquely determined physical commitment.',
|
||||
);
|
||||
// Preserve legacy insertion order as well as the uniquely determined counts.
|
||||
for (const [key, group] of occupied) {
|
||||
const count =
|
||||
amount === forces[type]
|
||||
@@ -104,12 +254,16 @@ export function quoteHarassWithdraw(
|
||||
: occupied.length === 1
|
||||
? amount
|
||||
: 0;
|
||||
if (count) (allocation[key] ??= { normal: 0, elite: 0 })[type] = count;
|
||||
if (count) {
|
||||
const selected = allocation.get(key) ?? { normal: 0, elite: 0 };
|
||||
selected[type] = count;
|
||||
allocation.set(key, selected);
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
returned,
|
||||
remaining: { ...forces, normal: committed.normal, elite: committed.elite },
|
||||
locations: allocation,
|
||||
locations: Object.fromEntries(allocation),
|
||||
};
|
||||
}
|
||||
+4
-4
@@ -3713,16 +3713,16 @@ export const RULE_TOPICS: RuleTopic[] = [
|
||||
'When Atreides asks for that weapon or defense category, answer None without exposing Harass & Withdraw. The category is fixed, while the special card may occupy its physical slot. A literal Truthtrance promise that a slot is empty still means no physical card.',
|
||||
'Return your undialed ordinary and elite forces to reserves. Your leader can still be killed. An opponent’s successful Traitor call cancels withdrawal, including mutual calls. A Face Dancer cannot replace the forces already returned.',
|
||||
'Discard Harass after use, including a win by your own Traitor call. Reveal-before-explosion return and card-specific discard precedence are explicit implementation inferences; neither is a dedicated combined FAQ ruling.',
|
||||
'The battle controls show the exact return. Basic and Advanced commitments need a unique physical allocation. Ambiguous regular/elite or sector choices, Richese card combinations and additional optional modules are still being integrated. The printed card forbids use on your own Homeworld.',
|
||||
'For multiple legal physical allocations, choose all undialed ordinary and elite counters by sector after both plans reveal and before traitor declarations. Unique returns are automatic. The selected return is public; it is not an extra sealed plan element. Richese card combinations and additional optional modules remain guarded. The printed card forbids use on your own Homeworld.',
|
||||
'With Ecaz and an ally together, only the card user’s undialed forces return. Combined army attribution remains unfinished. Public variant starts and complete rules acceptance remain gated.',
|
||||
],
|
||||
related: ['battle-cards', 'battle', 'card-recruits', 'ecaz-modules', 'implementation-checklist'],
|
||||
checklist: [
|
||||
{ area: 'Implementation', status: 'Partial', detail: 'Physical slot commitment, category inspection, unique typed return before losses, opponent-Traitor cancellation, mandatory disposal and saved continuation are connected. Richese and optional-module combinations remain gated.', evidence: ['game/harass-withdraw.ts', 'game/battle-card-slots.ts', 'game/battle-resolution-quote.ts', 'game/engine.ts'] },
|
||||
{ area: 'Player controls', status: 'Partial', detail: 'Either slot, compatible pair selection, category-null commitment, exact private return guide and card inspection are usable. Ambiguous allocation controls remain unfinished.', evidence: ['components/battle-preparation.tsx', 'components/harass-withdraw.tsx', 'components/game-table.tsx'] },
|
||||
{ area: 'Implementation', status: 'Partial', detail: 'Physical slot commitment, category inspection, revealed typed/sector return selection, exact committed losses, opponent-Traitor cancellation, mandatory disposal and saved continuation are connected. Richese and optional-module combinations remain gated.', evidence: ['game/harass-withdraw.ts', 'game/battle-card-slots.ts', 'game/battle-resolution-quote.ts', 'game/engine.ts'] },
|
||||
{ area: 'Player controls', status: 'Partial', detail: 'Either slot, compatible pair selection, category-null commitment and card inspection are usable. Multiple legal typed or sector returns have an owner choice after plans reveal and before traitor declarations; unique returns are automatic.', evidence: ['components/battle-preparation.tsx', 'components/harass-withdraw.tsx', 'components/game-table.tsx'] },
|
||||
{ area: 'AI', status: 'Partial', detail: 'All four profiles have a legal shared-quote path and preserve inspection secrecy. Retreat strategy and combined-game strength remain uncalibrated.', evidence: ['game/bots.ts', 'tests/ecaz-battle-bots.test.ts'] },
|
||||
{ area: 'Documentation', status: 'Implemented', detail: 'The card guide distinguishes printed effects, explicit inference and unfinished physical allocation/Stone Burner combinations.', evidence: ['docs/HARASS_WITHDRAW_RUNTIME.md', 'docs/ECAZ_TREACHERY_RULES.md'] },
|
||||
{ area: 'Verification', status: 'Partial', detail: 'Focused rules, controls, AI and authenticated recovery checks cover the prototype; final sample and browser evidence remains bounded, with full combination acceptance open.', evidence: ['tests/harass-withdraw.test.ts', 'tests/ecaz-battle-controls.test.tsx', 'tests/ecaz-battle-bots.test.ts', 'tests/ecaz-battle-recovery.test.ts'] },
|
||||
{ area: 'Verification', status: 'Partial', detail: 'Focused rules, controls, AI and authenticated recovery checks cover the prototype; final sample and browser evidence remains bounded, with full combination acceptance open.', evidence: ['tests/harass-allocation-engine.test.ts', 'tests/harass-allocation-recovery.test.ts', 'tests/harass-withdraw-choice-controls.test.tsx', 'tests/harass-withdraw.test.ts', 'tests/ecaz-battle-controls.test.tsx', 'tests/ecaz-battle-bots.test.ts', 'tests/ecaz-battle-recovery.test.ts'] },
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -12,6 +12,7 @@ const DECISIONS = {
|
||||
sukRescue: true,
|
||||
rihani: true,
|
||||
diplomatDefense: true,
|
||||
harassWithdraw: true,
|
||||
choamAudit: true,
|
||||
choamAuditPayment: true,
|
||||
strongholdCopy: true,
|
||||
|
||||
Reference in new issue
Block a user