@chrischall/warapp-mcp 0.1.0 → 0.3.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.
Files changed (86) hide show
  1. package/.claude-plugin/marketplace.json +3 -3
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +49 -20
  4. package/dist/analysis/accept-surrender.js +56 -0
  5. package/dist/analysis/calibrate.js +239 -0
  6. package/dist/analysis/finished-game.js +136 -0
  7. package/dist/analysis/game-lessons.js +217 -0
  8. package/dist/analysis/local-deploy.js +37 -17
  9. package/dist/analysis/opponent-profile.js +6 -5
  10. package/dist/analysis/opponents.js +10 -2
  11. package/dist/analysis/outlook.js +63 -1
  12. package/dist/analysis/plan/shared.js +194 -7
  13. package/dist/analysis/plan/threats.js +103 -29
  14. package/dist/analysis/planner.js +10 -5
  15. package/dist/analysis/stress.js +14 -7
  16. package/dist/analysis/whereabouts.js +3 -0
  17. package/dist/bundle.js +13214 -9759
  18. package/dist/calibration-source.js +75 -0
  19. package/dist/chat.js +73 -0
  20. package/dist/client.js +85 -7
  21. package/dist/direct/link.js +9 -5
  22. package/dist/direct/session.js +60 -6
  23. package/dist/direct/sign-in.js +296 -0
  24. package/dist/direct/transport.js +59 -24
  25. package/dist/finished-store.js +357 -0
  26. package/dist/hosted.js +6 -4
  27. package/dist/index.js +1 -1
  28. package/dist/lessons-store.js +356 -0
  29. package/dist/live.js +9 -0
  30. package/dist/map-details.js +127 -0
  31. package/dist/map-stats.js +14 -6
  32. package/dist/map-store.js +44 -6
  33. package/dist/my-games.js +44 -6
  34. package/dist/normalize.js +34 -2
  35. package/dist/notifications.js +143 -0
  36. package/dist/outlook-log.js +28 -1
  37. package/dist/player-record-store.js +2 -0
  38. package/dist/profile-store.js +61 -11
  39. package/dist/protocol/methods.js +86 -2
  40. package/dist/replay.js +16 -4
  41. package/dist/stats.js +26 -4
  42. package/dist/strategy/notes.js +64 -9
  43. package/dist/surrender-pending.js +126 -0
  44. package/dist/tools/accept-surrender.js +311 -0
  45. package/dist/tools/chat-inbox.js +17 -5
  46. package/dist/tools/chat-read-mark.js +179 -0
  47. package/dist/tools/chat.js +50 -8
  48. package/dist/tools/check-plan.js +1 -0
  49. package/dist/tools/commander-check.js +1 -0
  50. package/dist/tools/end-of-game.js +384 -0
  51. package/dist/tools/game.js +31 -6
  52. package/dist/tools/healthcheck.js +7 -1
  53. package/dist/tools/index.js +24 -8
  54. package/dist/tools/join-game.js +1 -1
  55. package/dist/tools/live-context.js +3 -1
  56. package/dist/tools/map-details.js +88 -0
  57. package/dist/tools/map-stats.js +15 -2
  58. package/dist/tools/map.js +10 -2
  59. package/dist/tools/my-games.js +78 -8
  60. package/dist/tools/notifications.js +484 -0
  61. package/dist/tools/open-games.js +5 -2
  62. package/dist/tools/opponents.js +14 -2
  63. package/dist/tools/past-games.js +94 -0
  64. package/dist/tools/picks.js +15 -2
  65. package/dist/tools/profile-opponents.js +1 -1
  66. package/dist/tools/profile-reads.js +3 -3
  67. package/dist/tools/push.js +72 -12
  68. package/dist/tools/session.js +50 -18
  69. package/dist/tools/sign-in.js +56 -0
  70. package/dist/tools/strategy.js +65 -8
  71. package/dist/tools/stress-opponents.js +1 -1
  72. package/dist/tools/surrender-pending.js +74 -0
  73. package/dist/tools/surrender.js +10 -3
  74. package/dist/tools/team-brief.js +1 -1
  75. package/dist/tools/team.js +2 -6
  76. package/dist/tools/turn.js +79 -15
  77. package/dist/tools/where.js +42 -17
  78. package/dist/tools/write-kit.js +16 -3
  79. package/dist/trend.js +145 -20
  80. package/dist/version.js +1 -1
  81. package/docs/examples/warapp-auth-flow.json +31 -0
  82. package/manifest.json +22 -2
  83. package/mint.yaml +44 -22
  84. package/package.json +3 -2
  85. package/server.json +2 -2
  86. package/skills/warapp-mcp/SKILL.md +141 -14
@@ -7,9 +7,9 @@ import { carriesTeam } from '../../teams.js';
7
7
  import { searchChains } from '../chains.js';
8
8
  import { guaranteedKills } from '../combat.js';
9
9
  import { bfsDistances, neighborsOf } from '../graph.js';
10
- import { enemyDeployReaching, heldBonusPools } from '../local-deploy.js';
10
+ import { couldHoldBonusPools, enemyDeployReaching, freeIncome } from '../local-deploy.js';
11
11
  import { incomeBasis, LOST_STACK_TURNS } from '../opponents.js';
12
- import { HIDDEN_POOL_INCOMES, MAX_NAMED_REVEALS, MIN_ENEMY_DEPLOY, openingArmies, ownerShown, visibleState, } from './shared.js';
12
+ import { HIDDEN_POOL_INCOMES, MAX_NAMED_REVEALS, coverageText, LOW_COVERAGE, MIN_ENEMY_DEPLOY, openingArmies, ownerShown, visibleState, } from './shared.js';
13
13
  import { territoryIncome } from '../player.js';
14
14
  import { simTerritories } from '../turn-sim.js';
15
15
  import { byNum } from './util.js';
@@ -126,29 +126,46 @@ export function threatSources(pc, ps, input) {
126
126
  if (carriesTeam(p.team) && foe(p.id))
127
127
  teamOf.set(p.id, p.team);
128
128
  /**
129
- * Local Deployment (#128): each opponent's bonuses it visibly holds in full, as deploy pools that
130
- * land only on their own territories. Empty without Local Deployment or under the override.
129
+ * Local Deployment (#128, #293): each opponent's bonuses it could hold (none of their territories
130
+ * shown with another owner), as deploy pools that land only on their own territories. Empty without
131
+ * Local Deployment or under the override.
131
132
  */
132
133
  const enemyPools = new Map();
133
134
  // #199: the one Local Deployment bound (local-deploy.ts), shared with check_plan's stress test.
134
135
  // A what-if `enemyDeploy` is taken as it stands: no pool bounds it.
135
- if (s.localDeployments && !custom)
136
- for (const [p, pools] of heldBonusPools(g, (t) => {
136
+ // #293 review: with per-territory income, income no pool carries (territories the fog hides) may land
137
+ // anywhere, so what an estimate holds beyond every bonus it could hold counts as free; without it, a
138
+ // border faces only the free income and the pools there.
139
+ const perTerritory = (s.bonusArmyPer ?? 0) > 0;
140
+ if (s.localDeployments && !custom) {
141
+ const foes = [...new Set([...state.values()].flatMap((t) => (t.owner.kind === 'player' && foe(t.owner.playerId) ? [t.owner.playerId] : [])))].sort(byNum);
142
+ for (const [p, pools] of couldHoldBonusPools(g, foes, (t) => {
137
143
  const o = ownerShown(state.get(t))?.owner;
138
- return o?.kind === 'player' ? o.playerId : undefined;
139
- }))
140
- if (foe(p))
141
- enemyPools.set(p, pools);
144
+ return o === undefined ? undefined : o.kind === 'player' ? o.playerId : null;
145
+ })) {
146
+ enemyPools.set(p, pools);
147
+ const e = estimates.get(p);
148
+ const free = freeIncome(e?.base ?? 0, MIN_ENEMY_DEPLOY, e?.card?.armies ?? 0);
149
+ const pooled = pools.reduce((n, q) => n + q.value, 0);
150
+ const figure = deployOf(p);
151
+ if (perTerritory && figure - pooled > free)
152
+ warnings.push(`Local Deployment with per-territory income: player ${p}'s estimate of ~${figure} is more than its free income +${free} and the +${pooled} of bonuses it could hold, so the ${figure - pooled - free} beyond them is taken as per-territory income the fog hides, which may be deployed anywhere: every border faces it.`);
153
+ }
154
+ }
142
155
  /**
143
- * What `player` may deploy on any of `on` (#128): its whole estimate, except under Local
144
- * Deployment, where a bonus it visibly holds pays only into that bonus's territories — the
145
- * estimate less the visible pools it counts (unseen income counts as deployable anywhere) plus
146
- * the pools that contain one of `on`, never above the estimate. The estimate may leave pools
147
- * out (the opening board's floor; a negative bonus lowering its bonus income), so only what
148
- * it holds above its free floor — max({@link MIN_ENEMY_DEPLOY}, base income) — is taken as
149
- * pooled: the free base always lands anywhere.
156
+ * What `player` may deploy on any of `on` (#128, #293): its whole estimate, except under Local
157
+ * Deployment, where a bonus it could hold pays only into that bonus's territories: its free income
158
+ * (base, never below {@link MIN_ENEMY_DEPLOY}, plus a Reinforcement card) plus the pools that contain
159
+ * one of `on`, never above the estimate ({@link enemyDeployReaching}). A tracked total or a prior above
160
+ * that never lands on one border. `figure` replaces the estimate (an untrusted opponent's, #275).
150
161
  */
151
- const deployReaching = (player, on) => enemyDeployReaching(deployOf(player), estimates.get(player)?.base ?? 0, MIN_ENEMY_DEPLOY, enemyPools.get(player) ?? [], on);
162
+ const deployReaching = (player, on, figure = deployOf(player)) => {
163
+ const pools = enemyPools.get(player);
164
+ if (!pools)
165
+ return figure;
166
+ const e = estimates.get(player);
167
+ return enemyDeployReaching(figure, freeIncome(e?.base ?? 0, MIN_ENEMY_DEPLOY, e?.card?.armies ?? 0), pools, on, perTerritory);
168
+ };
152
169
  /**
153
170
  * #120: what the owner of enemy territory `t` may add there before my attack lands — its deploy
154
171
  * estimate (under Local Deployment, what reaches `t`), or its growth there per turn when larger
@@ -331,6 +348,8 @@ export function threatForces(pc, ps, src) {
331
348
  * {@link nextTurnAt} (the frontier and a completion's defensibility) counts its stacks.
332
349
  */
333
350
  const returning = pc.truce.lookAheadFoes;
351
+ /** #293: under Local Deployment a next-turn judgement counts the visible stacks one step behind a front. */
352
+ const behindNext = s.localDeployments === true && !pc.custom;
334
353
  const foeNext = (p) => foe(p) || returning.has(p);
335
354
  const { growthOf, teamOf, deployReaching, holdArmies, bombSized, takesAlone, killsOf, hiddenFoe, hiddenMovable, lostAt, } = src;
336
355
  /**
@@ -399,7 +418,7 @@ export function threatForces(pc, ps, src) {
399
418
  * ({@link lostAt}), the pool's carrier keeping what they leave of it. With `trend`, its fastest
400
419
  * growth there. Shared by {@link forceAt} and the floor tier's armies already next to a border.
401
420
  */
402
- const stacksAt = (t, gone, trend, nextTurn = false) => {
421
+ const stacksAt = (t, gone, trend, nextTurn = false, behind = false) => {
403
422
  const isFoe = nextTurn ? foeNext : foe;
404
423
  const byPlayer = new Map();
405
424
  // #164: a player's unaccounted armies are one pool, in one place at most: its first hidden stack
@@ -457,6 +476,29 @@ export function threatForces(pc, ps, src) {
457
476
  const pool = hiddenMovable(player);
458
477
  c.movable = Math.max(viaCarrier, pool - lostElsewhere.reduce((n, l) => n + l.movable, 0));
459
478
  }
479
+ // #293: for a next-turn judgement under Local Deployment, its visible stacks one step behind its
480
+ // front (beside one of its stacks next to `t`, not next to `t` themselves) can walk up this turn
481
+ // and attack next turn: each joins the front stack it borders (the lowest id), once.
482
+ if (behind)
483
+ for (const [player, p] of byPlayer) {
484
+ const front = p.stacks.filter((x) => visibleState(state.get(x.id)) !== undefined).map((x) => x.id);
485
+ const seen = new Set([t, ...p.stacks.map((x) => x.id)]);
486
+ const ids = [];
487
+ for (const f of [...front].sort(byNum))
488
+ for (const m of [...neighborsOf(g, f)].sort(byNum)) {
489
+ const st = visibleState(state.get(m));
490
+ if (seen.has(m) || gone(m) || st?.owner.kind !== 'player' || st.owner.playerId !== player || neighborsOf(g, m).includes(t))
491
+ continue;
492
+ seen.add(m);
493
+ const walk = Math.max(0, st.armies - guard) + unitsAt(m);
494
+ if (walk <= 0)
495
+ continue;
496
+ p.stacks.find((x) => x.id === f).movable += walk;
497
+ ids.push(m);
498
+ }
499
+ if (ids.length)
500
+ p.behind = ids.sort(byNum);
501
+ }
460
502
  return byPlayer;
461
503
  };
462
504
  /**
@@ -472,7 +514,7 @@ export function threatForces(pc, ps, src) {
472
514
  chain,
473
515
  });
474
516
  const forceAt = (t, gone, o) => {
475
- const byPlayer = stacksAt(t, gone, o.trend, o.nextTurn === true);
517
+ const byPlayer = stacksAt(t, gone, o.trend, o.nextTurn === true, o.behind === true);
476
518
  // B2 (T2, plan/relations.ts): on a truce hold the partner attacks with its stacks alone — no
477
519
  // deploy, no trend, its Multi-Attack chains from the armies standing; `full` asks for the hold
478
520
  // the truce relaxed.
@@ -485,8 +527,11 @@ export function threatForces(pc, ps, src) {
485
527
  const each = [...byPlayer]
486
528
  .sort((a, b) => a[0] - b[0])
487
529
  .map(([player, p]) => {
488
- // #275 (b): a held bonus's border is sized for an untrusted estimate's figure, never below the estimate.
489
- const deploy = truced === player ? 0 : Math.max(deployReaching(player, p.stacks.map((x) => x.id)), untrustedAt(player, t));
530
+ // #275 (b): a held bonus's border is sized for an untrusted estimate's figure, never below the estimate
531
+ // (#293: under Local Deployment, what of that figure can reach these stacks).
532
+ const deploy = truced === player
533
+ ? 0
534
+ : deployReaching(player, [...p.stacks.map((x) => x.id), ...(p.behind ?? [])], Math.max(pc.deployOf(player), untrustedAt(player, t)));
490
535
  const growth = truced === player ? 0 : p.growth;
491
536
  const movable = p.stacks.reduce((n, x) => n + x.movable, 0);
492
537
  const add = Math.max(deploy, growth);
@@ -568,9 +613,9 @@ export function threatForces(pc, ps, src) {
568
613
  * from only this turn counted again ({@link foeNext}). The same as threatAt when there is none.
569
614
  */
570
615
  const nextTurnAt = (t, gone) => {
571
- if (!returning.size)
616
+ if (!returning.size && !behindNext)
572
617
  return threatAt(t, gone);
573
- const f = forceAt(t, gone, { trend: true, allPlayers: true, solo: ps.soloHeld.has(t), nextTurn: true });
618
+ const f = forceAt(t, gone, { trend: true, allPlayers: true, solo: ps.soloHeld.has(t), nextTurn: true, behind: behindNext });
574
619
  return f ? { player: f.player, threat: f.threat } : null;
575
620
  };
576
621
  /**
@@ -795,14 +840,38 @@ export function borderThreats(pc, ps, input, src, forces) {
795
840
  if (perTerritory && revealed > e.estimate - (e.card?.armies ?? 0))
796
841
  warnings.push(`Player ${p}: ${revealed} armies came into view on ${o.reveals.length} ${o.reveals.length === 1 ? 'territory' : 'territories'} (fog reveals, not income); with income per territory, stacks that size say it holds more territories than the ${e.held} in view, so its ~${e.estimate - (e.card?.armies ?? 0)} estimate may be far too low.`);
797
842
  rationale.push(`Observed deploy for player ${p}, ${turns}: +${e.observedRaw}/turn over ${o.counted.length} territories visible on both boards (${o.captured.length} captured${o.captured.length ? `, ${o.fromFog.length} from the fog` : ''}); ${o.reveals.length} skipped as fog reveals${o.reveals.length ? ` (${shown}${more}): not shown with an owner and armies last turn (fogged, armies hidden, or not yet picked), so what they hold is not income` : ''}.`);
843
+ // #294: each grown stack's growth split three ways, so the arithmetic can be checked on the board.
844
+ if (o.stacks.length) {
845
+ const grown = [...o.stacks].sort((a, b) => b.growth - a.growth || a.territoryId - b.territoryId);
846
+ const parts = grown.slice(0, MAX_NAMED_REVEALS).map((x) => {
847
+ const why = [
848
+ ...x.moved.map((m) => `${m.armies} could be a move from ${label(m.from)} in view`),
849
+ ...(x.fog ? [`${x.fog} could have come out of the fog`] : []),
850
+ ...(x.deploy ? [`${x.deploy} can only be deploy`] : []),
851
+ ];
852
+ return `${label(x.territoryId)} +${x.growth} (${why.join(', ')})`;
853
+ });
854
+ const rest = grown.length > MAX_NAMED_REVEALS ? ` and ${grown.length - MAX_NAMED_REVEALS} more` : '';
855
+ rationale.push(`Player ${p}'s growth by stack, ${turns}: ${parts.join('; ')}${rest}.`);
856
+ }
798
857
  // A stack that arrived from the fog by a capture is a threat, never income (#86).
799
858
  for (const id of o.fromFog) {
800
859
  const where = neighborsOf(g, id).some((n) => mineSet.has(n)) ? 'stack next to you' : 'stack';
801
860
  rationale.push(`Player ${p}'s ${where}: ${armiesOf(id)} on ${label(id)} (threat), arrived from the fog by a capture: a move, not income.`);
802
861
  }
803
- // #123: the ambiguous readings, each named with the other way it could read.
862
+ // #123: the ambiguous readings, each named with the other way it could read. #293: under Local
863
+ // Deployment growth outside every bonus it could hold is cut at its free income instead.
864
+ const fogReason = (x) => {
865
+ const twice = `beyond twice the ~${x.expected} it was expected to deploy`;
866
+ const cut = x.localCut;
867
+ if (!cut)
868
+ return twice;
869
+ const local = `in no bonus it could hold: under Local Deployment only its free income +${cut.free} could be deployed there`;
870
+ const all = x.grewFromFog.every((id) => cut.territories.includes(id));
871
+ return all ? local : `${cut.territories.map(label).join(', ')} ${local}; elsewhere ${twice}`;
872
+ };
804
873
  if (o.grewFromFog.length) {
805
- rationale.push(`Player ${p}: ${o.fogGrowth} of its growth on ${o.grewFromFog.map(label).join(', ')} (beyond twice the ~${o.expected} it was expected to deploy) is next to the fog: read as a move out of the fog, not income — though it may be income the fog hides (observed +${o.low}–${o.high} either way).`);
874
+ rationale.push(`Player ${p}: ${o.fogGrowth} of its growth on ${o.grewFromFog.map(label).join(', ')} (${fogReason(o)}) is next to the fog: read as a move out of the fog, not income — though it may be income the fog hides (observed +${o.low}–${o.high} either way).`);
806
875
  }
807
876
  if (o.reinforced.length)
808
877
  rationale.push(`Player ${p} took ${o.reinforced.map(label).join(', ')} with more than its visible stack next to ${o.reinforced.length === 1 ? 'it' : 'them'} sent: read as armies deployed on that stack before it attacked (deploy-then-capture), though a stack out of the fog may have joined (observed +${o.low}–${o.high} either way).`);
@@ -827,7 +896,12 @@ export function borderThreats(pc, ps, input, src, forces) {
827
896
  if (e.tracked !== null) {
828
897
  const track = input.tracks.find((t) => t.playerId === p);
829
898
  const used = track.turns.filter((x) => e.trackedTurns.includes(x.from));
830
- 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; at least its visible base + bonuses ${track.visibleIncome}; used in place of the single-turn observed figure (warapp_track_opponents has the details).`);
899
+ 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
+ }
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.`);
831
905
  }
832
906
  // #164: a Reinforcement card the clock says it may hold, on top of its income.
833
907
  if (e.card)
@@ -862,12 +936,12 @@ export function borderThreats(pc, ps, input, src, forces) {
862
936
  : `in ${incomePrior.format === 'ffa' ? 'a free-for-all that started even (no teams, every player still in)' : 'a 1v1 that started even'}, an opponent bordering the fog is assumed to earn at least my own income ${incomePrior.myIncome}`}, ${e.priorCap !== null
863
937
  ? `capped at an even share (1 of ${incomePrior.opponents} opponents) of what the board hides, ${e.priorCap} (all of it would be ${e.couldEarn})`
864
938
  : `capped at the most it could earn on this board, ${e.couldEarn}`}${e.priorBlend
865
- ? ` — 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 edge in view keep ${Math.round(e.priorBlend.weight * 100)}% of the gap from ${e.priorBlend.prior}`
939
+ ? ` — 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}`
866
940
  : ''}; ${visible}${e.tracked !== null ? `, tracked ~${e.tracked}` : e.observed !== null ? `, observed +${e.observed}/turn` : ''})${withCard}; observed deploys are lower bounds under fog, and it could deploy more.`);
867
941
  continue;
868
942
  }
869
943
  if (e.source === 'tracked') {
870
- warnings.push(`Enemy deploy estimate for player ${p}: ~${income} (tracked over ${e.trackedTurns.length} observed turns, more than ${visible})${withCard}; it holds income the fog hides, and could deploy more.`);
944
+ warnings.push(`Enemy deploy estimate for player ${p}: ~${income} (tracked over ${e.trackedTurns.length} observed turns, ${e.coverage ? `read from ${coverageText(e.coverage)}; ` : ''}more than ${visible})${withCard}; it holds income the fog hides, and could deploy more.`);
871
945
  continue;
872
946
  }
873
947
  if (e.source === 'observed') {
@@ -235,9 +235,11 @@
235
235
  // without that bonus — the judgement it gets with no bonus. A rationale line says so ("… as FFA players attack alone (#235)") when the plan
236
236
  // keeps it (live: a 23-stack that held against each neighbour alone, even at a 40 deploy, was
237
237
  // conceded on the two together and withdrawn as the first order). Teammates (the game's team list) are never a threat, an
238
- // estimate or a target. Under Local Deployment an opponent's visibly held bonus pays
239
- // only into its own territories: what reaches T is its estimate less its visible pools
240
- // plus the pools that contain one of its stacks next to T. An enemy commander counts in
238
+ // estimate or a target. Under Local Deployment a bonus an opponent could hold pays only
239
+ // into its own territories (#293, `enemyDeployReaching`): what reaches T is its free income
240
+ // plus the pools that contain one of its stacks next to T, never above its estimate (with
241
+ // per-territory income, plus what the estimate holds beyond every such pool, with a
242
+ // warning). An enemy commander counts in
241
243
  // the expected attack too (rule 1h's near miss, kept garrisons).
242
244
  // enemyDeploy is estimated per opponent (`enemyDeployEstimates`): base
243
245
  // income (the larger of MinimumArmyBonus and, with BonusArmyPer on, its
@@ -331,9 +333,12 @@
331
333
  // free-for-all with no teams that gets no prior says why (`game.unevenStart`, a player out — never
332
334
  // listed among the opponents beside the fog). The
333
335
  // prior shrinks with evidence: with a usable track it keeps PRIOR_EVIDENCE_TURNS / (PRIOR_EVIDENCE_TURNS
334
- // + its consecutive observed turns up to the newest board, none when the run stopped earlier, × the
335
- // share of its edge in view) of its lead over the larger of
336
+ // + the sum of each turn's frontier coverage (#294, `frontierCoverage`) over its consecutive observed
337
+ // turns up to the newest board, none when the run stopped earlier) of its lead over the larger of
336
338
  // its tracked income and its visible income (`priorBlend`), and the warning names both.
339
+ // #294: while the tracked figure, above its visible income, was read from under LOW_COVERAGE (0.5)
340
+ // of its frontier, the estimate is at least tracked × LOW_COVERAGE_FACTOR (1.5), at most what it
341
+ // could earn (`coverageFloor`); the warning says what it was read from. Both unmeasured.
337
342
  // In a 1v1 too, so it trades #119's prior back toward tracked figures #119 found 2-3x low:
338
343
  // PRIOR_EVIDENCE_TURNS (4) is unmeasured against a finished 1v1.
339
344
  // #164, exact income: under a fog setting that shows every owner (`OWNERS_SHOWN_FOG`: No, Light
@@ -46,8 +46,10 @@
46
46
  // is known; runs that end the same are reported once.
47
47
  //
48
48
  // Local Deployment (#180, `localDeployments`): every reply's deploy is bounded as the planner
49
- // bounds it (#128; local-deploy.ts `enemyDeployReaching`): the opponent's free income plus the
50
- // pools of the bonuses it holds that contain the territory deployed on.
49
+ // bounds it (#128, #293; local-deploy.ts `enemyDeployReaching`): the opponent's free income plus the
50
+ // pools of the bonuses it could hold (no member shown with another owner) that contain the territory
51
+ // deployed on; a deploy figure above that never lands on one territory, except with per-territory
52
+ // income (`perTerritoryIncome`), where what no bonus it could hold carries may land anywhere.
51
53
  //
52
54
  // One turn ahead (`exposedNextTurn`, computed by lookahead.ts, which the planner shares): a territory of mine that no enemy stack touches today can
53
55
  // be a border tomorrow. For each stack, each territory beside it that it can take this turn (mine
@@ -73,9 +75,10 @@ import { bonusTerritories } from './bonuses.js';
73
75
  import { breaksLuckFree, searchChains } from './chains.js';
74
76
  import { COMMANDER_STRENGTH, DEFAULT_DEFENSIVE_KILL_RATE, DEFAULT_OFFENSIVE_KILL_RATE, straightKills } from './combat.js';
75
77
  import { neighborsOf } from './graph.js';
76
- import { enemyDeployReaching, heldBonusPools } from './local-deploy.js';
78
+ import { couldHoldBonusPools, enemyDeployReaching, freeIncome } from './local-deploy.js';
77
79
  import { twoStepReaches } from './lookahead.js';
78
80
  import { DEFAULT_BASE_INCOME } from './player.js';
81
+ import { ownerShown } from './plan/shared.js';
79
82
  import { simTerritories, simulateTurn, } from './turn-sim.js';
80
83
  const DEFAULT_MAX_REPLIES = 8;
81
84
  /** The chain search's caps (#180), shared with the planner (chains.ts, #199). */
@@ -122,12 +125,16 @@ export function stressPlan(input) {
122
125
  const armiesOf = (r, test) => [...r.territories.values()].reduce((n, t) => n + (test(t.owner) ? t.armies : 0), 0);
123
126
  const holdsAny = (r, player) => [...r.territories.values()].some((t) => t.owner === player);
124
127
  const blindBorders = [...mineEither].filter((id) => neighborsOf(graph, id).some((n) => start.get(n)?.owner === 'unknown')).sort(byNum);
125
- // Local Deployment (#180): each opponent's held bonuses pay only into their own territories.
126
- const shownOwner = new Map(board.territories.flatMap((t) => (t.owner.kind === 'player' ? [[t.territoryId, t.owner.playerId]] : [])));
127
- const pools = input.localDeployments ? heldBonusPools(graph, (t) => shownOwner.get(t)) : undefined;
128
+ // Local Deployment (#180, #293): each opponent's bonuses it could hold pay only into their own territories.
129
+ const onBoard = new Map(board.territories.map((t) => [t.territoryId, t]));
130
+ const shownOwner = (t) => {
131
+ const o = ownerShown(onBoard.get(t))?.owner;
132
+ return o === undefined ? undefined : o.kind === 'player' ? o.playerId : null;
133
+ };
134
+ const pools = input.localDeployments ? couldHoldBonusPools(graph, input.opponents.map((o) => o.id), shownOwner) : undefined;
128
135
  const deployOn = (opp, on) => {
129
136
  const all = Math.max(0, Math.floor(opp.deploy));
130
- return pools ? enemyDeployReaching(all, opp.base ?? 0, DEFAULT_BASE_INCOME, pools.get(opp.id) ?? [], [on]) : all;
137
+ return pools ? enemyDeployReaching(all, freeIncome(opp.base ?? 0, DEFAULT_BASE_INCOME, opp.card ?? 0), pools.get(opp.id) ?? [], [on], input.perTerritoryIncome === true) : all;
131
138
  };
132
139
  /** Luck-free: `sent` armies (and a commander, when it goes along) take `t` as it stands. */
133
140
  const breaks = (sent, withCommander, t) => breaksLuckFree(sent, withCommander, t, { offensiveKillRate: off, defensiveKillRate: def });
@@ -1091,6 +1091,9 @@ function baseAssumptions(input, w) {
1091
1091
  out.push('No start candidates are known (no pickable territories were kept, and no statistics are in use), so no start is guessed: the rest works from what was seen.');
1092
1092
  else if (c.source === 'pickable')
1093
1093
  out.push(`Start candidates: the ${n} ${plural(n, 'territory', 'territories')} the live board showed as pickable during distribution.`);
1094
+ else if (c.source === 'distribution-mode')
1095
+ out.push(`Start candidates: the ${n} ${plural(n, 'territory', 'territories')} of the map's distribution mode${c.mode !== undefined ? ` ${c.mode}` : ''}, ` +
1096
+ "which dealt the starts automatically among them (read from war.app's map details); the ones nobody was dealt stay neutral.");
1094
1097
  else
1095
1098
  out.push(`Start candidates: the ${n} ${plural(n, 'territory', 'territories')} players started on in the finished games cached for this map; a start nobody used there is missed.`);
1096
1099
  if (c) {