@chrischall/warapp-mcp 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +3 -3
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +133 -8
- package/dist/analysis/accept-surrender.js +20 -2
- package/dist/analysis/calibrate.js +1 -0
- package/dist/analysis/card-support.js +177 -17
- package/dist/analysis/card-threats.js +126 -14
- package/dist/analysis/chat-advice.js +182 -0
- package/dist/analysis/chat-blocks.js +106 -0
- package/dist/analysis/chat-intent.js +559 -0
- package/dist/analysis/chat-read.js +159 -0
- package/dist/analysis/decision-replay.js +279 -0
- package/dist/analysis/decision-truth.js +146 -0
- package/dist/analysis/finished-game.js +62 -3
- package/dist/analysis/game-lessons.js +15 -10
- package/dist/analysis/hold-diff.js +3 -1
- package/dist/analysis/income-trend.js +38 -0
- package/dist/analysis/intel.js +75 -0
- package/dist/analysis/opens.js +64 -0
- package/dist/analysis/opponent-profile.js +121 -10
- package/dist/analysis/opponents.js +246 -20
- package/dist/analysis/outlook.js +360 -15
- package/dist/analysis/picks.js +91 -12
- package/dist/analysis/plan/after-leftover.js +4 -1
- package/dist/analysis/plan/bonus-attempts.js +105 -0
- package/dist/analysis/plan/capture-instead.js +116 -0
- package/dist/analysis/plan/captures.js +49 -7
- package/dist/analysis/plan/conceded-out.js +13 -2
- package/dist/analysis/plan/estimates.js +203 -30
- package/dist/analysis/plan/guard-off.js +2 -1
- package/dist/analysis/plan/holds.js +110 -9
- package/dist/analysis/plan/jabs.js +113 -0
- package/dist/analysis/plan/leftover.js +393 -8
- package/dist/analysis/plan/orders.js +76 -4
- package/dist/analysis/plan/relations.js +135 -2
- package/dist/analysis/plan/report.js +69 -3
- package/dist/analysis/plan/second-sizing.js +133 -0
- package/dist/analysis/plan/shared.js +279 -27
- package/dist/analysis/plan/siege.js +303 -0
- package/dist/analysis/plan/stand-still.js +9 -5
- package/dist/analysis/plan/state.js +8 -0
- package/dist/analysis/plan/stockpile.js +104 -0
- package/dist/analysis/plan/strike.js +39 -7
- package/dist/analysis/plan/targets.js +256 -110
- package/dist/analysis/plan/threats.js +148 -10
- package/dist/analysis/plan/transfers.js +57 -6
- package/dist/analysis/plan/two-move.js +70 -0
- package/dist/analysis/plan/vacated.js +124 -2
- package/dist/analysis/planner.js +527 -49
- package/dist/analysis/profile.js +13 -2
- package/dist/analysis/since-last.js +18 -5
- package/dist/analysis/stress.js +8 -2
- package/dist/board.js +36 -2
- package/dist/bonus-attempt-store.js +55 -0
- package/dist/build-id.js +106 -0
- package/dist/bundle.js +54138 -41059
- package/dist/cards.js +7 -5
- package/dist/chat-automation.js +22 -0
- package/dist/chat.js +35 -1
- package/dist/client.js +14 -0
- package/dist/commerce.js +111 -0
- package/dist/decision-log.js +1093 -0
- package/dist/finished-store.js +5 -1
- package/dist/index.js +9 -1
- package/dist/lessons-store.js +322 -21
- package/dist/live.js +43 -0
- package/dist/move-order.js +64 -3
- package/dist/normalize.js +17 -0
- package/dist/open-games.js +36 -16
- package/dist/outlook-log.js +42 -1
- package/dist/profile-store.js +12 -2
- package/dist/protocol/methods.js +62 -5
- package/dist/protocol/rpc.js +8 -0
- package/dist/relations-store.js +38 -4
- package/dist/review-export.js +198 -0
- package/dist/siege-store.js +49 -0
- package/dist/state-bundle.js +584 -0
- package/dist/state-cli.js +71 -0
- package/dist/strategy/notes.js +56 -0
- package/dist/team-cards.js +25 -0
- package/dist/tools/accept-surrender.js +23 -9
- package/dist/tools/award.js +20 -2
- package/dist/tools/card-advice.js +93 -28
- package/dist/tools/card-plays.js +2 -2
- package/dist/tools/card-support-advice.js +37 -7
- package/dist/tools/chat-advice.js +330 -0
- package/dist/tools/chat-inbox.js +19 -4
- package/dist/tools/chat.js +106 -17
- package/dist/tools/check-plan.js +68 -12
- package/dist/tools/commerce-deploy.js +33 -0
- package/dist/tools/common.js +31 -0
- package/dist/tools/decision-capture.js +459 -0
- package/dist/tools/end-of-game.js +151 -21
- package/dist/tools/game-kind.js +92 -0
- package/dist/tools/how-lost.js +7 -2
- package/dist/tools/index.js +10 -0
- package/dist/tools/join-game.js +10 -4
- package/dist/tools/live-context.js +6 -0
- package/dist/tools/live.js +10 -1
- package/dist/tools/map-curves.js +73 -0
- package/dist/tools/notifications.js +4 -3
- package/dist/tools/opponents.js +2 -0
- package/dist/tools/past-games.js +74 -8
- package/dist/tools/picks.js +61 -10
- package/dist/tools/profile-hook.js +62 -3
- package/dist/tools/profile-opponents.js +4 -0
- package/dist/tools/push.js +2 -2
- package/dist/tools/relations.js +139 -0
- package/dist/tools/scout.js +16 -2
- package/dist/tools/state.js +232 -0
- package/dist/tools/strategy.js +3 -3
- package/dist/tools/stress-opponents.js +7 -2
- package/dist/tools/surrender-pending.js +10 -1
- package/dist/tools/surrender.js +18 -3
- package/dist/tools/survival.js +11 -3
- package/dist/tools/team-brief.js +2 -2
- package/dist/tools/team.js +12 -3
- package/dist/tools/turn.js +643 -76
- package/dist/tools/where.js +3 -1
- package/dist/version.js +1 -1
- package/manifest.json +32 -3
- package/mint.yaml +37 -4
- package/package.json +4 -4
- package/server.json +20 -2
- package/skills/warapp-mcp/SKILL.md +73 -17
|
@@ -14,9 +14,9 @@ import { territoryIncome } from '../player.js';
|
|
|
14
14
|
import { simTerritories } from '../turn-sim.js';
|
|
15
15
|
import { byNum } from './util.js';
|
|
16
16
|
/** Read the threats against my territories, and state them. */
|
|
17
|
-
export function threatsPhase(pc, ps, input) {
|
|
17
|
+
export function threatsPhase(pc, ps, input, valueOf) {
|
|
18
18
|
const src = threatSources(pc, ps, input);
|
|
19
|
-
const forces = threatForces(pc, ps, src);
|
|
19
|
+
const forces = threatForces(pc, ps, src, valueOf);
|
|
20
20
|
const { borders, facing, borderAt, safeAtStart } = borderThreats(pc, ps, input, src, forces);
|
|
21
21
|
const { growthOf, deployReaching, reinforcementAt, holdArmies, bombSized, hiddenFoe, hiddenMovable, hiddenPool, } = src;
|
|
22
22
|
const { chainAt, stacksAt, forceAt, threatAt, nextTurnAt, expectedAt, exposure } = forces;
|
|
@@ -32,6 +32,10 @@ export function threatsPhase(pc, ps, input) {
|
|
|
32
32
|
return {
|
|
33
33
|
...seen,
|
|
34
34
|
growthOf,
|
|
35
|
+
/** #420: each opponent's full-deploy border and the borders its top-up sizes (the leftover's revival reads it). */
|
|
36
|
+
oneBorder: forces.oneBorder,
|
|
37
|
+
/** #290: the previous board as given (the leftover reads which enemy stacks grew since). */
|
|
38
|
+
previousBoard: input.previousBoard,
|
|
35
39
|
deployReaching,
|
|
36
40
|
reinforcementAt,
|
|
37
41
|
holdArmies,
|
|
@@ -324,6 +328,20 @@ export function threatSources(pc, ps, input) {
|
|
|
324
328
|
warnings.push(`Player ${l.player}'s stack of ${l.armies} armies last seen on ${label(l.seenOn)} on turn ${l.turn} is out of view and can stand on ${at.slice(0, MAX_NAMED_REVEALS).join('; ')}${more}, by next turn, and attack the turn after with up to ${l.movable} plus its deploy: not counted in this turn's holds${multiNote}.`);
|
|
325
329
|
}
|
|
326
330
|
}
|
|
331
|
+
/**
|
|
332
|
+
* #420: each opponent's largest top-up seen (its track's `topUp`: the most one of its stacks beside my
|
|
333
|
+
* land grew in one turn). None under an explicit `enemyDeploy` (the caller's figure stands as given).
|
|
334
|
+
*/
|
|
335
|
+
const topUpOf = new Map();
|
|
336
|
+
if (!custom)
|
|
337
|
+
for (const tr of input.tracks ?? [])
|
|
338
|
+
if (foe(tr.playerId) && typeof tr.topUp === 'number')
|
|
339
|
+
topUpOf.set(tr.playerId, tr.topUp);
|
|
340
|
+
/** #420 (P1 amended): the quiet neighbours with a top-up seen, by player. */
|
|
341
|
+
const quietOf = new Map();
|
|
342
|
+
for (const q of input.quiet ?? [])
|
|
343
|
+
if (topUpOf.has(q.player))
|
|
344
|
+
quietOf.set(q.player, { contactTurns: q.contactTurns, attacks: q.attacks });
|
|
327
345
|
return {
|
|
328
346
|
growthOf,
|
|
329
347
|
teamOf,
|
|
@@ -337,10 +355,12 @@ export function threatSources(pc, ps, input) {
|
|
|
337
355
|
hiddenMovable,
|
|
338
356
|
hiddenPool,
|
|
339
357
|
lostAt,
|
|
358
|
+
topUpOf,
|
|
359
|
+
quietOf,
|
|
340
360
|
};
|
|
341
361
|
}
|
|
342
362
|
/** What each opponent can bring against one territory: its stacks, its deploy, its Multi-Attack chains (#199). */
|
|
343
|
-
export function threatForces(pc, ps, src) {
|
|
363
|
+
export function threatForces(pc, ps, src, valueOf) {
|
|
344
364
|
const { g, board, s, foe, territories: state, mineSet, unitsAt, guard, rates, toTake, ffaLeader, untrustedAt } = pc;
|
|
345
365
|
const { captured } = ps;
|
|
346
366
|
/**
|
|
@@ -501,6 +521,49 @@ export function threatForces(pc, ps, src) {
|
|
|
501
521
|
}
|
|
502
522
|
return byPlayer;
|
|
503
523
|
};
|
|
524
|
+
/**
|
|
525
|
+
* #420 (owner decision of 2026-11-20, "One opponent's deploy"): an opponent deploys its income in one
|
|
526
|
+
* place, so its full deploy sizes only its single most valuable border of mine (by protected value —
|
|
527
|
+
* `valueOf` —, then its movable armies beside it, then id); each other border of mine its stacks face is
|
|
528
|
+
* sized at those stacks plus its largest top-up seen (`topUpOf`), never above the full deploy. `capAt`:
|
|
529
|
+
* by my territory, the players capped there and the figure; `primary`: each such player's full border.
|
|
530
|
+
* Not on my commander's territory (rule 1k's worst case), nor for an untrusted estimate (#275) at that
|
|
531
|
+
* border, a player with no top-up seen, or one facing a single border of mine. A quiet neighbour
|
|
532
|
+
* (`quietOf`, #420's P1 amendment) has every border capped so, its most valuable one included, and no
|
|
533
|
+
* `primary`. Judged on the board as it stands (no territory gone) and built once.
|
|
534
|
+
*/
|
|
535
|
+
let oneBorderMemo;
|
|
536
|
+
const oneBorder = () => {
|
|
537
|
+
if (oneBorderMemo)
|
|
538
|
+
return oneBorderMemo;
|
|
539
|
+
oneBorderMemo = { capAt: new Map(), primary: new Map() };
|
|
540
|
+
if (!src.topUpOf.size)
|
|
541
|
+
return oneBorderMemo;
|
|
542
|
+
const facing = new Map();
|
|
543
|
+
for (const t of [...pc.mine].sort(byNum))
|
|
544
|
+
for (const [player, p] of stacksAt(t, () => false, false)) {
|
|
545
|
+
if (!src.topUpOf.has(player))
|
|
546
|
+
continue;
|
|
547
|
+
facing.set(player, [...(facing.get(player) ?? []), { t, movable: p.stacks.reduce((n, x) => n + x.movable, 0) }]);
|
|
548
|
+
}
|
|
549
|
+
for (const [player, list] of [...facing].sort((a, b) => a[0] - b[0])) {
|
|
550
|
+
// #420 (P1 amended): a quiet neighbour's every border, its most valuable one included.
|
|
551
|
+
const quiet = src.quietOf.has(player);
|
|
552
|
+
if (list.length < 2 && !quiet)
|
|
553
|
+
continue;
|
|
554
|
+
const ranked = [...list].sort((a, b) => valueOf(b.t) - valueOf(a.t) || b.movable - a.movable || a.t - b.t);
|
|
555
|
+
if (!quiet)
|
|
556
|
+
oneBorderMemo.primary.set(player, ranked[0].t);
|
|
557
|
+
for (const { t } of quiet ? ranked : ranked.slice(1)) {
|
|
558
|
+
if (pc.myCommanders.has(t) || untrustedAt(player, t) > 0)
|
|
559
|
+
continue;
|
|
560
|
+
const m = oneBorderMemo.capAt.get(t) ?? new Map();
|
|
561
|
+
m.set(player, src.topUpOf.get(player));
|
|
562
|
+
oneBorderMemo.capAt.set(t, m);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
return oneBorderMemo;
|
|
566
|
+
};
|
|
504
567
|
/**
|
|
505
568
|
* #199: the force of a Multi-Attack chain onto my `t`: its player's, its armies all of it (the
|
|
506
569
|
* deploy that reaches its stack is already inside them), no growth or separate deploy.
|
|
@@ -529,9 +592,12 @@ export function threatForces(pc, ps, src) {
|
|
|
529
592
|
.map(([player, p]) => {
|
|
530
593
|
// #275 (b): a held bonus's border is sized for an untrusted estimate's figure, never below the estimate
|
|
531
594
|
// (#293: under Local Deployment, what of that figure can reach these stacks).
|
|
532
|
-
const
|
|
595
|
+
const full = truced === player
|
|
533
596
|
? 0
|
|
534
597
|
: deployReaching(player, [...p.stacks.map((x) => x.id), ...(p.behind ?? [])], Math.max(pc.deployOf(player), untrustedAt(player, t)));
|
|
598
|
+
// #420: off its most valuable border, the stack plus its largest top-up seen.
|
|
599
|
+
const cap = oneBorder().capAt.get(t)?.get(player);
|
|
600
|
+
const deploy = cap !== undefined ? Math.min(full, cap) : full;
|
|
535
601
|
const growth = truced === player ? 0 : p.growth;
|
|
536
602
|
const movable = p.stacks.reduce((n, x) => n + x.movable, 0);
|
|
537
603
|
const add = Math.max(deploy, growth);
|
|
@@ -641,6 +707,7 @@ export function threatForces(pc, ps, src) {
|
|
|
641
707
|
return out;
|
|
642
708
|
};
|
|
643
709
|
return {
|
|
710
|
+
oneBorder,
|
|
644
711
|
chainAt,
|
|
645
712
|
stacksAt,
|
|
646
713
|
forceAt,
|
|
@@ -773,6 +840,29 @@ export function borderThreats(pc, ps, input, src, forces) {
|
|
|
773
840
|
rationale.push(`My commander's territory ${label(t)} is held against the worst case (#274), ~${b.threat}: ${w.players.length > 1 ? `players ${w.players.join(' and ')}` : `player ${w.players[0]}`}'s whole deploy, ~${w.deploy} (never below my own income), plus the ${w.stacks} movable armies ${w.players.length > 1 ? 'they have' : 'it has'} within two moves of it.`);
|
|
774
841
|
}
|
|
775
842
|
}
|
|
843
|
+
// #420: say where one opponent's full deploy is sized, and which borders take its top-up instead.
|
|
844
|
+
{
|
|
845
|
+
const { capAt, primary } = forces.oneBorder();
|
|
846
|
+
for (const [player, q] of [...src.quietOf].sort((a, b) => a[0] - b[0])) {
|
|
847
|
+
const sized = [...capAt].filter(([t, m]) => borders.has(t) && m.has(player)).map(([t]) => t).sort(byNum);
|
|
848
|
+
if (!sized.length)
|
|
849
|
+
continue;
|
|
850
|
+
rationale.push(`Player ${player} ${q.attacks ? `has attacked me on ${q.attacks} of ${q.contactTurns} contact turns, and not since it was read quiet` : `has not attacked me in ${q.contactTurns} contact turns`} (#420, P1 amended: a quiet neighbour): ${sized.map(label).join(', ')} ${sized.length === 1 ? 'is' : 'are'} sized at its stack beside ${sized.length === 1 ? 'it' : 'them'} plus its largest top-up seen, +${src.topUpOf.get(player)}, not its ~${pc.deployOf(player)} deploy, until its first attack on me.`);
|
|
851
|
+
}
|
|
852
|
+
for (const [player, top] of [...primary].sort((a, b) => a[0] - b[0])) {
|
|
853
|
+
// The deploy its most valuable border is sized for (under Local Deployment, what reaches it).
|
|
854
|
+
const at = borders.get(top);
|
|
855
|
+
const full = at && at.player === player && !at.chain && !at.commanderWorst ? at.deploy : pc.deployOf(player);
|
|
856
|
+
const rest = [...capAt]
|
|
857
|
+
.filter(([t, m]) => borders.has(t) && m.has(player) && m.get(player) < full)
|
|
858
|
+
.map(([t]) => t)
|
|
859
|
+
.sort(byNum);
|
|
860
|
+
if (!rest.length)
|
|
861
|
+
continue;
|
|
862
|
+
const one = rest.length === 1;
|
|
863
|
+
rationale.push(`Player ${player} deploys its ~${full} in one place (#420): its full deploy is sized only on its most valuable border, ${label(top)}; ${rest.map(label).join(', ')} ${one ? 'is' : 'are'} sized at its stack beside ${one ? 'it' : 'them'} plus its largest top-up seen, +${capAt.get(rest[0]).get(player)} (the most one of its stacks beside my land grew in a turn).`);
|
|
864
|
+
}
|
|
865
|
+
}
|
|
776
866
|
// #199: say where a Multi-Attack chain sets a border's threat.
|
|
777
867
|
for (const b of [...borders.values()].filter((x) => x.chain).sort((x, y) => y.chain.armies - x.chain.armies || x.id - y.id).slice(0, MAX_NAMED_REVEALS)) {
|
|
778
868
|
const c = b.chain;
|
|
@@ -824,6 +914,10 @@ export function borderThreats(pc, ps, input, src, forces) {
|
|
|
824
914
|
const fogged = [...estimates.values()].filter((e) => foe(e.playerId) && e.fogBeside && !out.has(e.playerId)).map((e) => e.playerId).sort(byNum);
|
|
825
915
|
if (incomePriorSkipped && fogged.length)
|
|
826
916
|
warnings.push(`No fog prior for the opponents beside the fog (${fogged.length === 1 ? 'player' : 'players'} ${fogged.join(', ')}) in this free-for-all: ${incomePriorSkipped}; their estimates rest on what the board shows, each a lower bound under fog.`);
|
|
917
|
+
// #368: a known income given for a player with no estimate (none of its territories in view).
|
|
918
|
+
for (const k of input.knownIncome ?? [])
|
|
919
|
+
if (!estimates.has(k.player) && foe(k.player))
|
|
920
|
+
warnings.push(`known_income for player ${k.player} is not used: none of its territories is in view, so the plan has no border it threatens.`);
|
|
827
921
|
for (const p of [...estimated].sort(byNum)) {
|
|
828
922
|
const e = estimates.get(p);
|
|
829
923
|
const visible = `base ${e.base} + visible bonuses +${e.bonusIncome} = ${e.base + e.bonusIncome}`;
|
|
@@ -898,11 +992,6 @@ export function borderThreats(pc, ps, input, src, forces) {
|
|
|
898
992
|
const used = track.turns.filter((x) => e.trackedTurns.includes(x.from));
|
|
899
993
|
rationale.push(`Tracked income for player ${p}: ~${e.tracked}/turn (${incomeBasis(track)}): ${used.map((x) => `turn ${x.from} +${x.observed}`).join(', ')}, each observed deploy a lower bound under fog${e.coverage ? `, read from ${coverageText(e.coverage)}` : ''}; at least its visible base + bonuses ${track.visibleIncome}; used in place of the single-turn observed figure (warapp_track_opponents has the details).`);
|
|
900
994
|
}
|
|
901
|
-
// #294: a tracked figure read from little of its frontier keeps a floor above it.
|
|
902
|
-
if (e.coverageFloor) {
|
|
903
|
-
const f = e.coverageFloor;
|
|
904
|
-
warnings.push(`Player ${p}'s tracked ~${f.tracked} was read from ${coverageText({ ...e.coverage, hiddenBonuses: 0 }).replace(/\)$/, `, under ${Math.round(LOW_COVERAGE * 100)}%)`)}: the estimate is at least ~${f.tracked} × ${f.factor} = ${f.figure} (the factor is unmeasured), since the fog hid most of where it deploys.`);
|
|
905
|
-
}
|
|
906
995
|
// #164: a Reinforcement card the clock says it may hold, on top of its income.
|
|
907
996
|
if (e.card)
|
|
908
997
|
warnings.push(`Player ${p} may hold a Reinforcement card from turn ${e.card.due} (the card clock${e.cardPlayed !== null ? `; it last played one on turn ${e.cardPlayed}` : ''}): +${e.card.armies} added to its deploy, ~${e.estimate} in all, until a deployment above its income is seen; one card at most is counted, though more may be in hand after a long time due.`);
|
|
@@ -920,12 +1009,57 @@ export function borderThreats(pc, ps, input, src, forces) {
|
|
|
920
1009
|
? `Player ${p} is under Sanctions (${pct}, until turn ${z.untilTurn}, read from the board by an unverified decoder): its estimate is cut from ~${z.before} to ~${income} by the client's rule.`
|
|
921
1010
|
: `Player ${p} is under Sanctions (${pct}, until turn ${z.untilTurn}, read from the board by an unverified decoder), but its estimate ~${income} is not cut: ${e.source === 'prior' ? 'it is a prior, a floor guessed from what it could earn, not its income' : `it is ${e.source} from its deploys, which may already carry the cut`}.`);
|
|
922
1011
|
}
|
|
1012
|
+
// #332: a commerce game's rising army price, applied to a figure read off the board.
|
|
1013
|
+
if (e.armyPrice)
|
|
1014
|
+
warnings.push(`Player ${p} earns ~${e.armyPrice.gold} gold, which buys ~${income} armies at the army cost multiplier ${e.armyPrice.multiplier} (commerce).`);
|
|
923
1015
|
const withCard = e.card ? `, plus +${e.card.armies} from its Reinforcement card (~${e.estimate} in all)` : '';
|
|
924
1016
|
// #235 1c: the track's newest turn read more with the armies beside the fog as deploys: a label,
|
|
925
1017
|
// never income (#123 lesson 5); the higher figure is the caller's to test.
|
|
926
1018
|
const cut = e.newestCut;
|
|
927
1019
|
if (cut && e.source !== 'exact' && cut.reading > income)
|
|
928
1020
|
warnings.push(`Player ${p}'s newest turn (turn ${cut.from} → turn ${cut.to}) reads up to +${cut.reading} if the armies that arrived beside the fog were deploys (+${cut.observed} with those beyond twice the ~${cut.expected ?? '?'} it was expected to deploy read as moves); the estimate keeps ~${income} (${e.source === 'tracked' ? 'tracked' : e.source === 'prior' ? 'the fog prior' : 'its visible base + bonuses'}) because a stack walking in is not income (#123). To test the higher figure, pass enemy_deploy ${cut.reading} to warapp_check_plan.`);
|
|
1021
|
+
// #444: incomes other players stated scaled its fog prior down.
|
|
1022
|
+
if (e.stated && incomePrior?.stated) {
|
|
1023
|
+
const st = incomePrior.stated;
|
|
1024
|
+
const said = st.players.map((x) => `player ${x.id} states ${x.income}`).join(', ');
|
|
1025
|
+
const mid = e.stated.midpoint;
|
|
1026
|
+
warnings.push(`Player ${p}'s fog prior is scaled by the incomes stated in chat (known_income: ${said}), ${Math.round(st.ratio * 100) / 100}× my ${st.mine}: ~${e.stated.scaled} in place of ~${e.stated.full}, never below what is in view or tracked${mid !== null ? `; with no track it is sized at the midpoint ~${mid} between ~${e.stated.lower} and ~${e.stated.scaled} (#368)` : ''}.`);
|
|
1027
|
+
}
|
|
1028
|
+
// #368: an income the user supplied replaces the estimate.
|
|
1029
|
+
if (e.known) {
|
|
1030
|
+
warnings.push(`Enemy deploy estimate for player ${p}: ~${income} (the known income you supplied (known_income), in place of the estimate ~${e.known.was})${withCard}; a figure supplied is taken as it is, not checked against the board.`);
|
|
1031
|
+
continue;
|
|
1032
|
+
}
|
|
1033
|
+
// #368: thin evidence sizes it between its lower bound and its upper (owner decision of
|
|
1034
|
+
// 2026-11-19: the middle until we learn otherwise).
|
|
1035
|
+
if (e.thinEvidence) {
|
|
1036
|
+
const t = e.thinEvidence;
|
|
1037
|
+
const thin = t.coverage !== null && t.coverage < LOW_COVERAGE;
|
|
1038
|
+
const why = [
|
|
1039
|
+
...(thin
|
|
1040
|
+
? [`its tracked income was read from ${e.coverage ? coverageText(e.coverage) : `${Math.round(t.coverage * 100)}% of its frontier`}, under ${Math.round(LOW_COVERAGE * 100)}%`]
|
|
1041
|
+
: []),
|
|
1042
|
+
...(t.rising ? [`its tracked income rose two turns running (${t.rising.join(', ')})`] : []),
|
|
1043
|
+
];
|
|
1044
|
+
const lowerIs = t.trend !== null && t.lower === t.trend && t.trend > t.tracked
|
|
1045
|
+
? `the trend's next step ~${t.lower} (the tracked ~${t.tracked})`
|
|
1046
|
+
: t.lower === t.tracked
|
|
1047
|
+
? `~${t.lower} (the tracked figure)`
|
|
1048
|
+
: `~${t.lower} (its visible income; the tracked ~${t.tracked})`;
|
|
1049
|
+
// #419: the upper bound's basis: the past winners' pace (map or format), the prior, or what it could earn.
|
|
1050
|
+
const upperIs = t.pace && t.upper === t.pace.figure
|
|
1051
|
+
? t.pace.basis === 'map'
|
|
1052
|
+
? `the median past winner's income after turn ${t.pace.afterTurn} on this map, ${t.pace.games} games of this format and settings (#419)`
|
|
1053
|
+
: `my income × ${t.pace.ratio}, the median past winner's pace against mine after turn ${t.pace.afterTurn} in this format, ${t.pace.games} games (fewer than 3 on this map) (#419)`
|
|
1054
|
+
: t.prior !== null && t.upper === Math.min(e.couldEarn, t.prior)
|
|
1055
|
+
? 'the fog prior, not shrunk toward the track'
|
|
1056
|
+
: 'the most it could earn';
|
|
1057
|
+
const sized = thin
|
|
1058
|
+
? `it is sized between the lower bound ${lowerIs} and the upper bound ~${t.upper} (${upperIs}): the midpoint ~${t.midpoint}, moved toward what the evidence gives, ~${t.toward}, as more of its frontier is read (${Math.round(t.weight * 100)}% of the way from that to the midpoint)`
|
|
1059
|
+
: `its lower bound is ${lowerIs.startsWith('~') ? lowerIs.slice(1) : lowerIs}, read from enough of its frontier to plan on it`;
|
|
1060
|
+
warnings.push(`Enemy deploy estimate for player ${p}: ~${income} (thin evidence: ${why.join(' and ')}, so ${sized})${withCard}; it could deploy more.`);
|
|
1061
|
+
continue;
|
|
1062
|
+
}
|
|
929
1063
|
if (e.source === 'exact') {
|
|
930
1064
|
warnings.push(`Enemy deploy estimate for player ${p}: ~${income} (exact: under ${ctx.fog} every territory's owner shows, so its income is ${visible}${e.observed !== null && e.observed > income ? `; the +${e.observed} observed above it is a card or armies the board misread, not income` : ''}); only the army cap, Sanctions and a Reinforcement card are unknown.`);
|
|
931
1065
|
continue;
|
|
@@ -933,7 +1067,11 @@ export function borderThreats(pc, ps, input, src, forces) {
|
|
|
933
1067
|
if (e.source === 'prior') {
|
|
934
1068
|
warnings.push(`Enemy deploy estimate for player ${p}: ~${income} (a prior, not an observation: ${(incomePrior.opening?.get(p) ?? -1) > incomePrior.myIncome
|
|
935
1069
|
? `its opening simulated from the starts the award of picks proved earns ${incomePrior.opening.get(p)} this turn`
|
|
936
|
-
: `in ${incomePrior.format === 'ffa'
|
|
1070
|
+
: `in ${incomePrior.format === 'ffa'
|
|
1071
|
+
? incomePrior.out?.length
|
|
1072
|
+
? `a free-for-all that started even (no teams; ${incomePrior.out.map((o) => `player ${o.id} is out (${o.state})`).join(', ')}, ${incomePrior.out.length === 1 ? 'its' : 'their'} share of what the board hides split among the ${incomePrior.opponents} ${incomePrior.opponents === 1 ? 'opponent' : 'opponents'} still playing)`
|
|
1073
|
+
: 'a free-for-all that started even (no teams, every player still in)'
|
|
1074
|
+
: 'a 1v1 that started even'}, an opponent bordering the fog is assumed to earn at least my own income ${incomePrior.myIncome}`}, ${e.priorCap !== null
|
|
937
1075
|
? `capped at an even share (1 of ${incomePrior.opponents} opponents) of what the board hides, ${e.priorCap} (all of it would be ${e.couldEarn})`
|
|
938
1076
|
: `capped at the most it could earn on this board, ${e.couldEarn}`}${e.priorBlend
|
|
939
1077
|
? ` — shrunk toward its ${e.priorBlend.toward === e.tracked ? `tracked ~${e.tracked}` : `visible ${e.priorBlend.toward}`} by the evidence: ${e.priorBlend.turns} observed ${e.priorBlend.turns === 1 ? 'turn' : 'turns'} with ${Math.round(e.priorBlend.share * 100)}% of its ${e.coverage ? 'frontier read' : 'edge in view'} keep ${Math.round(e.priorBlend.weight * 100)}% of the gap from ${e.priorBlend.prior}`
|
|
@@ -14,9 +14,12 @@
|
|
|
14
14
|
// and never from a stack beside a visible enemy at the start of the turn (interior only once a
|
|
15
15
|
// strike lands).
|
|
16
16
|
// When those steps together make the border hold, it is held after all, never left reported conceded.
|
|
17
|
+
// #367: heading for an enemy front, a step must also bring the stack strictly nearer it measured through
|
|
18
|
+
// the conceded borders, so a stack behind one waits where the front will be instead of walking away and back.
|
|
17
19
|
import { bfsDistances, neighborsOf } from '../graph.js';
|
|
18
20
|
import { teammateAt } from './state.js';
|
|
19
21
|
import { capStepRoom, truceKeep } from './relations.js';
|
|
22
|
+
import { breachLine, breachOf } from './vacated.js';
|
|
20
23
|
/** The transfers (rule 6), with staging toward `staging` (#125) when the leftover saved toward a step. */
|
|
21
24
|
export function transfers(pc, ps, book, threats, hd, caps, staging) {
|
|
22
25
|
const { g, me, s, foe, territories: state, label, bonusName, mine, mineSet, unitsAt, toTake, noSplit, myCommanders } = pc;
|
|
@@ -41,7 +44,11 @@ export function transfers(pc, ps, book, threats, hd, caps, staging) {
|
|
|
41
44
|
* it may fail, #172's two-step hold, an exit's cover (#179), the leftover kept central (#218) and a
|
|
42
45
|
* truce's hold (B2).
|
|
43
46
|
*/
|
|
44
|
-
|
|
47
|
+
/**
|
|
48
|
+
* `t`'s keeps. `through`: a conceded border `t` is about to make hold (#257) — a two-step reach through it is cut
|
|
49
|
+
* by that very move (#291: else the gate behind a conceded border would keep its armies from the border itself).
|
|
50
|
+
*/
|
|
51
|
+
const keepOf = (t, through) => {
|
|
45
52
|
// #128: interior only if this turn's attacks on players beside it land. Until they do, it
|
|
46
53
|
// keeps what holds against the threat there as if they failed (its neighbours' owners'
|
|
47
54
|
// stacks and deploy as they stand): a +12 bonus was left on 1 beside a capture.
|
|
@@ -50,7 +57,7 @@ export function transfers(pc, ps, book, threats, hd, caps, staging) {
|
|
|
50
57
|
const keep128 = ifFail ? Math.max(0, holdArmies(ifFail.threat) - unitsAt(t)) : 0;
|
|
51
58
|
// #172: or it is interior now, but a stack two steps away can take the territory in between
|
|
52
59
|
// this turn and attack it next. The larger hold binds (never the two added together).
|
|
53
|
-
const far = twoStepHold(t);
|
|
60
|
+
const far = twoStepHold(t, through !== undefined ? (n) => n === through : undefined);
|
|
54
61
|
const twoStep = far !== null && far.stay > keep128 ? far : null;
|
|
55
62
|
const truceHold = truceKeep(pc, threats, t);
|
|
56
63
|
const keep = Math.max(keep128, twoStep?.stay ?? 0, coverKeep.has(t) ? coverKeep.get(t) + guardAt(t) : 0,
|
|
@@ -101,7 +108,7 @@ export function transfers(pc, ps, book, threats, hd, caps, staging) {
|
|
|
101
108
|
.filter((t) => !neighborsOf(g, t).some((x) => isEnemy(x)))
|
|
102
109
|
.map((t) => {
|
|
103
110
|
const n = avail.get(t);
|
|
104
|
-
const part = Math.min(n, Math.max(0, stayAt(t) - keepOf(t).keep), capStepRoom(pc, ps, t, id));
|
|
111
|
+
const part = Math.min(n, Math.max(0, stayAt(t) - keepOf(t, id).keep), capStepRoom(pc, ps, t, id));
|
|
105
112
|
return { t, n, part: noSplit && part < n ? 0 : part };
|
|
106
113
|
})
|
|
107
114
|
.filter((x) => x.part >= c.k)
|
|
@@ -161,6 +168,26 @@ export function transfers(pc, ps, book, threats, hd, caps, staging) {
|
|
|
161
168
|
const withdrawn = new Set(moves.filter((m) => m.kind === 'transfer' && conceded.has(m.from)).map((m) => m.from));
|
|
162
169
|
const viaOk = (id) => !conceded.has(id) || (!withdrawn.has(id) && attacksFrom(id).length > 0);
|
|
163
170
|
const distEnemyVia = bfsDistances(g, enemyFront, { passable: (id) => held.has(id) && viaOk(id) });
|
|
171
|
+
// #367: the enemy front measured through every territory held, conceded borders included. A border the
|
|
172
|
+
// plan concedes falls to the stack beside it, and the front is then right where it stood; measured only
|
|
173
|
+
// around it (distEnemy), the front jumped to a farther one and an idle stack behind it walked away, to
|
|
174
|
+
// walk straight back the next turn once the border had fallen (live: 649 armies, twice). So a step toward
|
|
175
|
+
// an enemy front must also bring the stack strictly nearer it measured this way: one board, no memory.
|
|
176
|
+
const distEnemyThrough = bfsDistances(g, enemyFront, { passable: (id) => held.has(id) });
|
|
177
|
+
/** The conceded border on the way from `t` to the enemy front nearest it through conceded borders, and that front. */
|
|
178
|
+
const pastConceded = (t) => {
|
|
179
|
+
let at = t;
|
|
180
|
+
let border;
|
|
181
|
+
while ((distEnemyThrough.get(at) ?? 0) > 0) {
|
|
182
|
+
const d = distEnemyThrough.get(at);
|
|
183
|
+
at = neighborsOf(g, at)
|
|
184
|
+
.filter((x) => distEnemyThrough.get(x) === d - 1)
|
|
185
|
+
.sort((a, b) => Number(conceded.has(b)) - Number(conceded.has(a)) || a - b)[0];
|
|
186
|
+
if (border === undefined && conceded.has(at))
|
|
187
|
+
border = at;
|
|
188
|
+
}
|
|
189
|
+
return border === undefined ? undefined : { border, front: at };
|
|
190
|
+
};
|
|
164
191
|
// #125: staging. Idle armies on a territory facing no visible enemy — a border beside neutrals
|
|
165
192
|
// included — walk one step toward the source of the capture the leftover saved toward, when
|
|
166
193
|
// it is no farther than the enemy front; once there they help take it.
|
|
@@ -171,6 +198,9 @@ export function transfers(pc, ps, book, threats, hd, caps, staging) {
|
|
|
171
198
|
const n = avail.get(t);
|
|
172
199
|
if (n <= 0 || locked.has(t) || t === st.from || conceded.has(t) || myCommanders.has(t))
|
|
173
200
|
continue;
|
|
201
|
+
// #417: the breach force stays beside the land a static seat left (said by rule 6 below).
|
|
202
|
+
if (breachOf(pc, captured, t).length)
|
|
203
|
+
continue;
|
|
174
204
|
if (neighborsOf(g, t).some((x) => isEnemy(x) || x === st.t))
|
|
175
205
|
continue;
|
|
176
206
|
if (moves.some((m) => m.from === t && m.kind === 'attack'))
|
|
@@ -228,6 +258,13 @@ export function transfers(pc, ps, book, threats, hd, caps, staging) {
|
|
|
228
258
|
const n = avail.get(t);
|
|
229
259
|
if (n <= 0 || locked.has(t))
|
|
230
260
|
continue;
|
|
261
|
+
// #417, the breach force: beside land a static seat left, still untaken and cheap at the
|
|
262
|
+
// 2-defender price, the stack stays until it is taken (it attacks into it when a pass funds it).
|
|
263
|
+
const land = breachOf(pc, captured, t);
|
|
264
|
+
if (land.length) {
|
|
265
|
+
rationale.push(breachLine(pc, t, n, land));
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
231
268
|
// My commander's territory next to an enemy at the start of the turn keeps its armies,
|
|
232
269
|
// even when this turn's captures make it interior: a capture can still fail. So does one
|
|
233
270
|
// next to a border the plan concedes (#121): the enemy takes it next, and then faces it.
|
|
@@ -240,14 +277,28 @@ export function transfers(pc, ps, book, threats, hd, caps, staging) {
|
|
|
240
277
|
// Only into a territory held at the start of the turn: a planned capture is
|
|
241
278
|
// not mine yet, and a "transfer" into it would execute as an attack.
|
|
242
279
|
// B2 (T5): never onto a truce's capped border past its cap, nor back along a transfer.
|
|
243
|
-
const
|
|
280
|
+
const steps = neighborsOf(g, t)
|
|
244
281
|
.filter((x) => mineSet.has(x) &&
|
|
245
282
|
(via ? viaOk(x) : !conceded.has(x)) &&
|
|
246
283
|
(dist.get(x) ?? Infinity) < d &&
|
|
247
284
|
capStepRoom(pc, ps, t, x) > 0)
|
|
248
|
-
.sort((a, b) => dist.get(a) - dist.get(b) || a - b)
|
|
249
|
-
|
|
285
|
+
.sort((a, b) => dist.get(a) - dist.get(b) || a - b);
|
|
286
|
+
// #367: heading for an enemy front, never a step that does not bring the stack strictly nearer it
|
|
287
|
+
// through the conceded borders (a #260 via step already goes through one, and a neutral edge is
|
|
288
|
+
// another target: both as before).
|
|
289
|
+
const through = !via && dist === distEnemy ? distEnemyThrough.get(t) : undefined;
|
|
290
|
+
const step = steps.find((x) => through === undefined || (distEnemyThrough.get(x) ?? Infinity) < through);
|
|
291
|
+
if (step === undefined) {
|
|
292
|
+
const past = steps.length ? pastConceded(t) : undefined;
|
|
293
|
+
if (past) {
|
|
294
|
+
rationale.push(`Keep the ${n} idle armies on ${label(t)}: the enemy front nearest them, ${label(past.front)}, lies past ${label(past.border)}, a border the plan concedes (#367); once it falls the front is here, so they do not walk away toward a farther front only to walk back.`);
|
|
295
|
+
// #291: what a stack two steps away needs them to hold here, said as when the keep alone stops them.
|
|
296
|
+
const { twoStep } = keepOf(t);
|
|
297
|
+
if (twoStep)
|
|
298
|
+
rationale.push(twoStepCite(t, twoStep, (c) => `Keep the ${n} idle armies on ${label(t)}: ${c}.`, `Keep the ${n} idle armies on ${label(t)}.`));
|
|
299
|
+
}
|
|
250
300
|
continue;
|
|
301
|
+
}
|
|
251
302
|
const { pending, ifFail, twoStep, truceHold, keep } = keepOf(t);
|
|
252
303
|
// No-Split (#124): a transfer sends the whole stack, so one that must keep some sends none.
|
|
253
304
|
const room = capStepRoom(pc, ps, t, step);
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// #439: a high-value single-territory bonus two moves away through a visible neutral is a two-turn
|
|
2
|
+
// completion. The planner plans one turn ahead, so such a bonus (a city, a capital) was never a bonus
|
|
3
|
+
// plan — its one member is not next to mine, so no capture reaches it — and the neutral in between
|
|
4
|
+
// lost to captures that complete nothing: live, two cities came a turn late (about 17 armies of income).
|
|
5
|
+
import { bonusTerritories } from '../bonuses.js';
|
|
6
|
+
import { neighborsOf } from '../graph.js';
|
|
7
|
+
import { teammateAt } from './state.js';
|
|
8
|
+
/** #439: the least value of a single-territory bonus worth staging toward two moves ahead. */
|
|
9
|
+
export const TWO_MOVE_MIN_VALUE = 5;
|
|
10
|
+
/**
|
|
11
|
+
* The single-territory bonuses of at least {@link TWO_MOVE_MIN_VALUE} two moves from mine through a
|
|
12
|
+
* visible neutral target, each with its cheapest neutral in between, best income per army first (then
|
|
13
|
+
* bonus id). The bonus territory is a visible neutral, or a fogged one the picking board showed as a
|
|
14
|
+
* neutral (`rememberedNeutrals`, costed at that size); never a player's, a teammate's, a truce's or one
|
|
15
|
+
* whose bonus was dropped. Kept only when the two captures repay their armies within the payback turns.
|
|
16
|
+
*/
|
|
17
|
+
export function twoMoveStages(pc, tgt) {
|
|
18
|
+
const { g, territories: state, mineSet, costAt, completedOver, paybackTurns, opts } = pc;
|
|
19
|
+
const out = [];
|
|
20
|
+
for (const b of [...g.map.bonuses].sort((x, y) => x.id - y.id)) {
|
|
21
|
+
if (b.value < TWO_MOVE_MIN_VALUE || tgt.bonusDropped.has(b.id))
|
|
22
|
+
continue;
|
|
23
|
+
const ts = bonusTerritories(g, b.id);
|
|
24
|
+
if (ts.length !== 1)
|
|
25
|
+
continue;
|
|
26
|
+
const member = ts[0];
|
|
27
|
+
if (mineSet.has(member) || tgt.fromMine.get(member) !== 2 || pc.truce.noTarget(member) || teammateAt(pc, member))
|
|
28
|
+
continue;
|
|
29
|
+
const st = state.get(member);
|
|
30
|
+
let memberCost = null;
|
|
31
|
+
if (st?.owner.kind === 'neutral' && st.armies !== null)
|
|
32
|
+
memberCost = costAt(member);
|
|
33
|
+
else if (!st || st.owner.kind === 'unknown' || st.armies === null) {
|
|
34
|
+
const was = opts.rememberedNeutrals?.get(member);
|
|
35
|
+
if (was !== undefined && st?.owner.kind !== 'player')
|
|
36
|
+
memberCost = costAt(member, was);
|
|
37
|
+
}
|
|
38
|
+
if (memberCost === null)
|
|
39
|
+
continue;
|
|
40
|
+
let best;
|
|
41
|
+
for (const via of [...neighborsOf(g, member)].sort((x, y) => x - y)) {
|
|
42
|
+
const tg = tgt.targets.get(via);
|
|
43
|
+
if (!tg || tg.enemy || state.get(via)?.owner.kind !== 'neutral')
|
|
44
|
+
continue;
|
|
45
|
+
const cost = tg.cost + memberCost;
|
|
46
|
+
const net = completedOver((x) => mineSet.has(x) || x === via || x === member, [via, member]).reduce((n, id) => n + g.bonusById.get(id).value, 0);
|
|
47
|
+
if (net <= 0 || cost > paybackTurns * net)
|
|
48
|
+
continue;
|
|
49
|
+
if (!best || cost < best.cost)
|
|
50
|
+
best = { bonusId: b.id, member, via, cost, net };
|
|
51
|
+
}
|
|
52
|
+
if (best)
|
|
53
|
+
out.push(best);
|
|
54
|
+
}
|
|
55
|
+
return out.sort((a, b) => b.net / b.cost - a.net / a.cost || a.bonusId - b.bonusId);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* #439: take `s.via` toward its bonus (pass 3's capture: R3, rule 4d and the usual sizing), unless this
|
|
59
|
+
* turn's captures already took it or stand next to the bonus territory, or it lowers income. Says so.
|
|
60
|
+
*/
|
|
61
|
+
export function stageTwoMove(pc, ps, s, gainWith, tryExpand) {
|
|
62
|
+
const { g, label, bonusName } = pc;
|
|
63
|
+
if (ps.captured.has(s.via) || neighborsOf(g, s.member).some((n) => ps.captured.has(n)) || gainWith([s.via]) < 0)
|
|
64
|
+
return;
|
|
65
|
+
const value = g.bonusById.get(s.bonusId).value;
|
|
66
|
+
const worth = s.net === value ? `+${value}` : `+${value}, net +${s.net}`;
|
|
67
|
+
if (!tryExpand(s.via, `stages bonus ${bonusName(s.bonusId)} (${worth}) two moves away (#439)`))
|
|
68
|
+
return;
|
|
69
|
+
ps.rationale.push(`Stage toward ${bonusName(s.bonusId)} (${worth}), two moves away: ${label(s.via)} now, ${label(s.member)} next turn — ${s.cost} armies over two turns (#439).`);
|
|
70
|
+
}
|
|
@@ -22,10 +22,132 @@
|
|
|
22
22
|
// judged by rule 4d as before. Never a truce's covered territory, one my attacks failed on (#240) or
|
|
23
23
|
// one lowering income; the capture spends what stands above its source's hold, as any.
|
|
24
24
|
import { neighborsOf } from '../graph.js';
|
|
25
|
+
import { visibleState } from './shared.js';
|
|
25
26
|
/** The end of every empty enemy capture's reason (#281, the owner's extension): tests and sweeps match on it. */
|
|
26
27
|
export const CHEAP_EXPANSION = 'cheap expansion (#281)';
|
|
27
|
-
/**
|
|
28
|
-
|
|
28
|
+
/**
|
|
29
|
+
* #417 / #428: for each territory fogged on `board`, its sighting on the newest earlier board that showed
|
|
30
|
+
* its owner (`boards` in any order; boards that fog it too are skipped): the owner, and the armies that
|
|
31
|
+
* board showed (`null` when only its owner was shown). The one source of both {@link foggedLastSeen}
|
|
32
|
+
* (#417, who held it) and the planner's last-seen price (#428, `PlanOptions.lastSeen`), so they never
|
|
33
|
+
* read different boards. A GameFeed history board (`source: 'history'`) gives its owner only: no army count.
|
|
34
|
+
*/
|
|
35
|
+
export function fogSightings(board, boards) {
|
|
36
|
+
const fogged = new Set(board.territories.filter((t) => t.owner.kind === 'unknown').map((t) => t.territoryId));
|
|
37
|
+
const out = new Map();
|
|
38
|
+
for (const b of [...boards].sort((x, y) => y.turn - x.turn))
|
|
39
|
+
for (const t of b.board.territories) {
|
|
40
|
+
if (!fogged.has(t.territoryId) || out.has(t.territoryId) || t.owner.kind === 'unknown')
|
|
41
|
+
continue;
|
|
42
|
+
// A GameFeed history board (unverified while the game is played) gives the owner, never a count.
|
|
43
|
+
const armies = b.source === 'history' ? null : (visibleState(t)?.armies ?? null);
|
|
44
|
+
out.set(t.territoryId, { owner: t.owner.kind === 'player' ? t.owner.playerId : null, armies });
|
|
45
|
+
}
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* #417: for each territory fogged on `board`, the player who held it on the newest earlier board that
|
|
50
|
+
* showed it (`boards` in any order; boards that fog it too are skipped). None when that sighting was
|
|
51
|
+
* neutral, or no earlier board showed it. A static seat's land stays costed as vacated however many
|
|
52
|
+
* turns it has been out of view, not only on the turn after vision was lost. The owners of {@link fogSightings}.
|
|
53
|
+
*/
|
|
54
|
+
export function foggedLastSeen(board, boards) {
|
|
55
|
+
return ownersOf(fogSightings(board, boards));
|
|
56
|
+
}
|
|
57
|
+
/** #417: the players of a {@link fogSightings} map (its neutral sightings left out). */
|
|
58
|
+
export function ownersOf(sightings) {
|
|
59
|
+
const out = new Map();
|
|
60
|
+
for (const [t, s] of sightings)
|
|
61
|
+
if (s.owner !== null)
|
|
62
|
+
out.set(t, s.owner);
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
/** #428: the counts of a {@link fogSightings} map (a sighting that showed only the owner left out). */
|
|
66
|
+
export function countsOf(sightings) {
|
|
67
|
+
const out = new Map();
|
|
68
|
+
for (const [t, s] of sightings)
|
|
69
|
+
if (s.armies !== null)
|
|
70
|
+
out.set(t, { armies: s.armies, owner: s.owner });
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* A vacated territory costing at most this many armies to take is cheap enough to deny (#281). #417:
|
|
75
|
+
* raised from 2 to 3, what {@link VACATED_FOG_ARMIES} defenders cost at the default settings.
|
|
76
|
+
*/
|
|
77
|
+
export const VACATED_MAX_COST = 3;
|
|
78
|
+
/**
|
|
79
|
+
* #417: the defenders a static seat's fogged territory is costed at. A seat deploys on its borders, so
|
|
80
|
+
* its interior stands on 0-2: its border stack in view says nothing about the land behind it.
|
|
81
|
+
*/
|
|
82
|
+
export const VACATED_FOG_ARMIES = 2;
|
|
83
|
+
/**
|
|
84
|
+
* #417 (the breach force): `id` is land a static seat left (`vacated`) whose armies the fog hides now —
|
|
85
|
+
* owner hidden, or shown neutral (a seat's own, planned as a neutral) without its armies. It is priced at
|
|
86
|
+
* {@link VACATED_FOG_ARMIES} defenders. Never one the fog shows another player holding: that player got there first.
|
|
87
|
+
*/
|
|
88
|
+
export function fogVacated(vacated, st, id) {
|
|
89
|
+
if (!vacated?.has(id))
|
|
90
|
+
return false;
|
|
91
|
+
if (!st || st.owner.kind === 'unknown')
|
|
92
|
+
return true;
|
|
93
|
+
return st.owner.kind === 'neutral' && st.armies === null;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* #417 (the breach force): the land a static seat left beside `t` that is still untaken — not captured
|
|
97
|
+
* this turn, still neutral or hidden (never a live player's in view), in no negative bonus
|
|
98
|
+
* — and cheap at the 2-defender price: fogged ({@link fogVacated}), or costing at most {@link VACATED_MAX_COST}. By id.
|
|
99
|
+
*/
|
|
100
|
+
export function breachOf(pc, captured, t) {
|
|
101
|
+
if (!pc.vacated.size)
|
|
102
|
+
return [];
|
|
103
|
+
return neighborsOf(pc.g, t)
|
|
104
|
+
.filter((x) => {
|
|
105
|
+
if (!pc.vacated.has(x) || pc.mineSet.has(x) || captured.has(x))
|
|
106
|
+
return false;
|
|
107
|
+
// Never a negative bonus's member (pass 3 never takes one): nothing to race for.
|
|
108
|
+
if ((pc.bonusesWith.get(x) ?? []).some((id) => (pc.g.bonusById.get(id)?.value ?? 0) < 0))
|
|
109
|
+
return false;
|
|
110
|
+
const st = pc.territories.get(x);
|
|
111
|
+
if (fogVacated(pc.vacated, st, x))
|
|
112
|
+
return true;
|
|
113
|
+
if (st?.owner.kind !== 'neutral')
|
|
114
|
+
return false;
|
|
115
|
+
const c = pc.costAt(x);
|
|
116
|
+
return c !== null && c <= VACATED_MAX_COST;
|
|
117
|
+
})
|
|
118
|
+
.sort((a, b) => a - b);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* #417, the 1v1 race (owner decision of 2026-11-20): the land a static seat left that this turn's greedy
|
|
122
|
+
* step races for ahead of rule 0p.1's "expansion last" — a capture target next to mine, still untaken
|
|
123
|
+
* (neutral, or hidden: {@link fogVacated}), costing at most {@link VACATED_MAX_COST} (the 2-defender price
|
|
124
|
+
* included), never a negative bonus's member. Cheapest first, then by id. Pure.
|
|
125
|
+
*/
|
|
126
|
+
export function raceTargets(pc, targets, captured) {
|
|
127
|
+
const out = [];
|
|
128
|
+
for (const t of [...pc.vacated.keys()].sort((a, b) => a - b)) {
|
|
129
|
+
const tg = targets.get(t);
|
|
130
|
+
if (!tg || tg.enemy || pc.mineSet.has(t) || captured.has(t) || tg.cost > VACATED_MAX_COST)
|
|
131
|
+
continue;
|
|
132
|
+
const st = pc.territories.get(t);
|
|
133
|
+
if (st?.owner.kind !== 'neutral' && !fogVacated(pc.vacated, st, t))
|
|
134
|
+
continue;
|
|
135
|
+
if ((pc.bonusesWith.get(t) ?? []).some((id) => (pc.g.bonusById.get(id)?.value ?? 0) < 0))
|
|
136
|
+
continue;
|
|
137
|
+
out.push({ t, cost: tg.cost });
|
|
138
|
+
}
|
|
139
|
+
return out.sort((a, b) => a.cost - b.cost || a.t - b.t);
|
|
140
|
+
}
|
|
141
|
+
/** #417: the 1v1 race's rationale line, said once when the greedy step has races. */
|
|
142
|
+
export function raceLine(pc, races) {
|
|
143
|
+
const left = [...new Set(races.map((r) => pc.vacated.get(r.t)))].sort((a, b) => a - b).map((p) => `player ${p}`).join(' and ');
|
|
144
|
+
return `1v1 race for vacated land (#417): ${races.map((r) => `${pc.label(r.t)} (${r.cost})`).join(', ')}, land ${left} left (out, no AI), ${races.length === 1 ? 'goes' : 'go'} ahead of the "expansion last" rule while it is up for taking — the opponent takes it otherwise; holds of my held bonuses and my commander still come first.`;
|
|
145
|
+
}
|
|
146
|
+
/** #417: the rationale line for a stack the breach force keeps beside land a static seat left. */
|
|
147
|
+
export function breachLine(pc, t, n, land) {
|
|
148
|
+
const left = [...new Set(land.map((x) => pc.vacated.get(x)))].sort((a, b) => a - b).map((p) => `player ${p}`).join(' and ');
|
|
149
|
+
return `Keep the ${n} idle armies on ${pc.label(t)}: the breach force beside ${land.map(pc.label).join(', ')}, land ${left} left (out, no AI), until it is taken (#417).`;
|
|
150
|
+
}
|
|
29
151
|
/** The vacated territories that are denials (#281), by territory: {@link denialOf} over them, computed once. */
|
|
30
152
|
export function denialsOf(pc) {
|
|
31
153
|
const out = new Map();
|