Allow clean active Basic ground-movement questions before or after shipment. Enumerate ordinary reserve amounts, native physical allocations, destinations and pledged payment splits through the actual declaration and shared physical commit. Detached projection stops before income/arrival effects and never counts shipment as ground fulfillment. Joint movement No and shipment Yes retain a legal next action rather than invalid End guidance. Preserve exact pending ordinary reserve and native Guild permission/rate declarations when checking the remaining route. Voluntary wrong destination, force splitting or fee loss cannot release Yes through an opponent response. Guard unsupported sources before full speculative continuation. Existing live payment, cancellation, income and entry paths remain. Persistent busy-safe controls display reinforcement and both obligations; all four existing profiles use the same legal witness without strategy refinement. Verify 19 files165/165, types/lint/build, six original-action gameplay/control/table-rendering programmes and four profiles with16 accepted actions. Genuine sources19/37/24/19 retain classic Arrakeen10 reinforced to11, native zero-board Emperor/CHOAM starts and original Guild5/15/5 reserve/cross transport. Second-card/counter cases explicitly transfer conserved originals. Bounded review repaired source guarding, funding completeness and exact pending-frame behavior. Stop an observed expensive search, reorder complete candidates by useful proximity and conservatively prune dead-end final moves; twelve new engine cases pass in3.2s. Correct a display-template lint issue. Earlier phases/waiting turns, native transport/relocation preparation, No-Field/module sources, broader interactions, full modes, comprehensive assurance and deployed acceptance remain open. No strategic tuning or saved-room/reset/restart/deployment operation.
40 lines
2.5 KiB
TypeScript
40 lines
2.5 KiB
TypeScript
import { gameDistance, gameTerritories, splitLocation, territory } from './board';
|
|
import type { Action, Game } from './engine';
|
|
import { liveMovementPromises } from './movement-promises';
|
|
|
|
/** Ordinary physical reserve shipments, not an AI shortlist. The authoritative
|
|
* dispatcher supplies cost, funding, route and arrival legality. */
|
|
export function* movementShipmentPreparations(game: Game, actor: string,
|
|
project: (game: Game, actor: string, action: Action) => Game | null,
|
|
): Generator<{ game: Game; actions: Action[] }> {
|
|
const player = game.players.find(player => player.id === actor);
|
|
if (!player || player.shipped || game.pendingNullentropy) return;
|
|
const present = (territory: string) => Object.entries(player.forces)
|
|
.filter(([key]) => splitLocation(key).territory === territory)
|
|
.reduce((sum, [, amount]) => sum + amount, 0);
|
|
const wanted = liveMovementPromises(game.movementPromises ?? [], actor, game.turn)
|
|
.filter(promise => promise.answer).map(promise => territory(promise.territory));
|
|
const destinations = [...gameTerritories(game)];
|
|
const proximity = new Map(destinations.map(destination => [destination.id, wanted.length
|
|
? Math.min(...wanted.flatMap(target => destination.id === target.id ? [Number.MAX_SAFE_INTEGER]
|
|
: destination.sectors.flatMap(from => target.sectors.map(to =>
|
|
gameDistance(game, `${destination.id}:${from}`, `${target.id}:${to}`))))) : 0]));
|
|
destinations.sort((a, b) => present(b.id) - present(a.id) ||
|
|
Number(b.type === 'stronghold') - Number(a.type === 'stronghold') || proximity.get(a.id)! - proximity.get(b.id)!);
|
|
for (const destination of destinations) for (const sector of destination.sectors)
|
|
for (let amount = 1; amount <= player.reserves; amount++) {
|
|
const special = player.elites?.reserves ?? 0;
|
|
for (let elite = Math.max(0, amount - (player.reserves - special)); elite <= Math.min(amount, special); elite++) {
|
|
// The bare ordinary desert tariff is at most two per force. Enumerate
|
|
// funding splits as well: retaining owned spice can preserve a later
|
|
// Box fee. The dispatcher rejects stale/ineligible/over-price pledges.
|
|
const maximum = Math.min(2 * amount, game.aid[player.ally ?? '']?.amount ?? 0);
|
|
for (let allyPayment = maximum; allyPayment >= 0; allyPayment--) {
|
|
const action: Action = { type: 'ship', territory: destination.id, sector, amount, elite, allyPayment };
|
|
const next = project(game, actor, action);
|
|
if (next) yield { game: next, actions: [action] };
|
|
}
|
|
}
|
|
}
|
|
}
|