@chrischall/warapp-mcp 0.6.0 → 0.8.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 +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +100 -7
- package/dist/analysis/accept-surrender.js +20 -2
- package/dist/analysis/calibrate.js +1 -0
- package/dist/analysis/card-support.js +187 -20
- package/dist/analysis/card-threats.js +68 -3
- 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/coalition.js +55 -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 +12 -6
- package/dist/analysis/local-deploy.js +14 -0
- package/dist/analysis/opponent-profile.js +46 -3
- package/dist/analysis/opponents.js +246 -19
- package/dist/analysis/outlook.js +323 -17
- package/dist/analysis/picks.js +270 -37
- package/dist/analysis/plan/after-leftover.js +28 -3
- package/dist/analysis/plan/captures.js +80 -16
- package/dist/analysis/plan/completed.js +8 -1
- package/dist/analysis/plan/conceded-out.js +16 -11
- package/dist/analysis/plan/deploy-estimates.js +513 -0
- package/dist/analysis/plan/doomed-out.js +135 -0
- package/dist/analysis/plan/estimates.js +73 -7
- package/dist/analysis/plan/free-capture.js +34 -0
- package/dist/analysis/plan/guard-off.js +2 -1
- package/dist/analysis/plan/holds.js +85 -313
- package/dist/analysis/plan/horizon.js +42 -0
- package/dist/analysis/plan/leftover.js +188 -10
- package/dist/analysis/plan/observe.js +896 -0
- package/dist/analysis/plan/orders.js +35 -1
- package/dist/analysis/plan/relations.js +115 -2
- package/dist/analysis/plan/report.js +10 -4
- package/dist/analysis/plan/shared.js +7 -1189
- package/dist/analysis/plan/stand-still.js +7 -5
- package/dist/analysis/plan/state.js +12 -0
- package/dist/analysis/plan/stockpile.js +104 -0
- package/dist/analysis/plan/strike-stack.js +467 -0
- package/dist/analysis/plan/strike.js +8 -441
- package/dist/analysis/plan/targets.js +374 -72
- package/dist/analysis/plan/threats.js +120 -9
- package/dist/analysis/plan/transfers.js +35 -1
- package/dist/analysis/plan/two-move.js +70 -0
- package/dist/analysis/plan/vacated.js +124 -2
- package/dist/analysis/plan/withdraw.js +316 -0
- package/dist/analysis/planner.js +356 -53
- package/dist/analysis/player.js +4 -0
- package/dist/analysis/relations.js +8 -2
- package/dist/analysis/since-last.js +18 -5
- package/dist/analysis/stress.js +1 -1
- package/dist/board.js +36 -2
- package/dist/build-id.js +106 -0
- package/dist/bundle.js +15863 -10242
- package/dist/chat-automation.js +22 -0
- package/dist/client.js +14 -0
- package/dist/decision-log.js +1093 -0
- package/dist/finished-store.js +5 -1
- package/dist/lessons-store.js +322 -21
- package/dist/my-games.js +2 -0
- package/dist/open-games.js +122 -18
- package/dist/outlook-log.js +42 -1
- package/dist/protocol/methods.js +4 -2
- package/dist/review-export.js +198 -0
- package/dist/state-bundle.js +62 -3
- package/dist/state-cli.js +5 -3
- package/dist/strategy/notes.js +56 -0
- package/dist/tools/accept-surrender.js +23 -9
- package/dist/tools/award.js +5 -1
- package/dist/tools/card-advice.js +102 -33
- package/dist/tools/card-support-advice.js +53 -8
- package/dist/tools/chat-advice.js +330 -0
- package/dist/tools/chat-inbox.js +15 -4
- package/dist/tools/chat.js +41 -11
- package/dist/tools/check-plan.js +16 -3
- package/dist/tools/commander-check.js +2 -1
- package/dist/tools/decision-capture.js +461 -0
- package/dist/tools/end-of-game.js +146 -18
- package/dist/tools/game-kind.js +92 -0
- package/dist/tools/how-lost.js +7 -2
- package/dist/tools/index.js +3 -0
- package/dist/tools/join-game.js +51 -9
- package/dist/tools/live-context.js +6 -0
- package/dist/tools/live.js +43 -6
- package/dist/tools/map-curves.js +73 -0
- package/dist/tools/notifications.js +4 -3
- package/dist/tools/open-games.js +2 -2
- package/dist/tools/opponents.js +2 -0
- package/dist/tools/past-games.js +74 -8
- package/dist/tools/picks.js +169 -57
- package/dist/tools/profile-hook.js +62 -3
- package/dist/tools/profile-opponents.js +2 -0
- package/dist/tools/push.js +2 -2
- package/dist/tools/relations.js +2 -0
- package/dist/tools/scout.js +16 -2
- package/dist/tools/state.js +6 -1
- package/dist/tools/strategy.js +3 -3
- package/dist/tools/stress-opponents.js +2 -0
- package/dist/tools/surrender-pending.js +10 -1
- package/dist/tools/surrender.js +18 -3
- package/dist/tools/turn.js +353 -19
- package/dist/tools/where.js +3 -1
- package/dist/version.js +1 -1
- package/manifest.json +23 -2
- package/mint.yaml +23 -0
- package/package.json +1 -1
- package/server.json +20 -2
- package/skills/warapp-mcp/SKILL.md +42 -8
|
@@ -2,9 +2,10 @@ import { holdsSeat } from '../player-states.js';
|
|
|
2
2
|
import { carriesTeam, isTeamGame } from '../teams.js';
|
|
3
3
|
import { neutralizeSeats, staticSeats } from './static-seats.js';
|
|
4
4
|
import { bonusTerritories } from './bonuses.js';
|
|
5
|
-
import { DEFAULT_DEFENSIVE_KILL_RATE, DEFAULT_OFFENSIVE_KILL_RATE, straightKills } from './combat.js';
|
|
5
|
+
import { DEFAULT_DEFENSIVE_KILL_RATE, DEFAULT_OFFENSIVE_KILL_RATE, guaranteedKills, luckFraction, straightKills } from './combat.js';
|
|
6
6
|
import { bfsDistances, neighborsOf } from './graph.js';
|
|
7
|
-
import { bombPossibleOn, enemyDeployEstimates,
|
|
7
|
+
import { bombPossibleOn, enemyDeployEstimates, localFreeOn, LOW_COVERAGE, TRACKED_MIN_TURNS } from './planner.js';
|
|
8
|
+
import { captureFloor, failedAttackKills, frontierCoverage, holdLosses, observeSigned, ownerShown, repelledFloor, coverageText, trackCoverage, visibleState } from './plan/observe.js';
|
|
8
9
|
import { boardIncome, DEFAULT_BASE_INCOME } from './player.js';
|
|
9
10
|
/** #164: a stack is large when its armies are at least this many turns of its visible income. */
|
|
10
11
|
const LOST_STACK_INCOMES = 2;
|
|
@@ -35,8 +36,8 @@ const NEUTRAL_CAPTURE_LOSS = 1;
|
|
|
35
36
|
/**
|
|
36
37
|
* {@link TrackGame} from GameFeed's players and settings: each player's starting armies are
|
|
37
38
|
* TerritoryLimit × InitialPlayerArmiesPerTerritory, unless either is missing, the game uses full
|
|
38
|
-
* distribution (
|
|
39
|
-
*
|
|
39
|
+
* distribution ({@link fullDistribution}, #428: DistributionMode 0 with no TerritoryLimit — every
|
|
40
|
+
* territory is split among the players; -1 is a limited start) or a map distribution that is not `normal` (a
|
|
40
41
|
* scenario sets its own starts). A Sanctions card is an income caveat: it can cut income below
|
|
41
42
|
* the base the bound counts.
|
|
42
43
|
*/
|
|
@@ -57,7 +58,7 @@ endRules) {
|
|
|
57
58
|
const seats = [...staticSeats(list, endRules).keys()].sort(byNum);
|
|
58
59
|
const base = { players: list, ...(seats.length ? { staticSeats: seats } : {}), ...(caveats.length ? { incomeCaveats: caveats } : {}) };
|
|
59
60
|
const perTerritory = settings?.initialPlayerArmiesPerTerritory !== undefined ? { startArmiesPerTerritory: Math.max(0, settings.initialPlayerArmiesPerTerritory) } : {};
|
|
60
|
-
if (settings
|
|
61
|
+
if (fullDistribution(settings))
|
|
61
62
|
return {
|
|
62
63
|
...base,
|
|
63
64
|
startUnknown: 'the game uses full distribution, which splits every territory among the players whatever the territory limit',
|
|
@@ -87,8 +88,20 @@ export function staticSeatsFor(game, me) {
|
|
|
87
88
|
}
|
|
88
89
|
/** TerritoryLimit assumed when the settings do not say (war.app's usual default). */
|
|
89
90
|
export const DEFAULT_TERRITORY_LIMIT = 3;
|
|
90
|
-
/**
|
|
91
|
-
|
|
91
|
+
/**
|
|
92
|
+
* GameFeed's DistributionMode for full distribution: the client's id (docs/WARAPP-API.md, #235). #428:
|
|
93
|
+
* -1 is a limited start (the client's random warlords: TerritoryLimit territories each), verified on
|
|
94
|
+
* three finished games, where reading it as full distribution put an opponent's start at 189 for a real 9.
|
|
95
|
+
*/
|
|
96
|
+
const FULL_DISTRIBUTION = 0;
|
|
97
|
+
/**
|
|
98
|
+
* #428: the game deals every territory among the players — DistributionMode 0 with no TerritoryLimit
|
|
99
|
+
* (unset or 0: the client's "no cap"). Mode 0 with a TerritoryLimit stays a limited start (the client
|
|
100
|
+
* caps each player's share by the limit; that a full-distribution game never sends one is unverified).
|
|
101
|
+
*/
|
|
102
|
+
export function fullDistribution(settings) {
|
|
103
|
+
return settings?.distributionMode === FULL_DISTRIBUTION && !(settings.territoryLimit !== undefined && settings.territoryLimit > 0);
|
|
104
|
+
}
|
|
92
105
|
/** GameFeed's DistributionMode for a custom scenario (the client's id; unverified on GameFeed, docs/WARAPP-API.md). */
|
|
93
106
|
const CUSTOM_SCENARIO = -3;
|
|
94
107
|
/**
|
|
@@ -118,6 +131,15 @@ export function symmetricStart(settings) {
|
|
|
118
131
|
/** Player states still in the game (absent counts as playing), as the profile counts them. */
|
|
119
132
|
const playing = (p) => (p.state ?? 'Playing') === 'Playing';
|
|
120
133
|
const byNum = (a, b) => a - b;
|
|
134
|
+
/**
|
|
135
|
+
* #418: a rise no turn read in full confirmed ({@link confirmedBy}) is held to this many times the
|
|
136
|
+
* income carried before it, each turn: walk-ins beside the fog are read up to twice the carry (#123),
|
|
137
|
+
* so without it they compounded (10, 20, 40, …) while nothing backed them. Unmeasured beyond #418's
|
|
138
|
+
* calibration run.
|
|
139
|
+
*/
|
|
140
|
+
export const RISE_CAP = 1.3;
|
|
141
|
+
/** #418: my armies in view against its own, at or above which I lead it on the board ({@link ObservedTurn.leadIncome}). */
|
|
142
|
+
export const LEAD_ARMIES = 3;
|
|
121
143
|
/**
|
|
122
144
|
* Income over a window of observed turns (#99). Each observed deploy is a LOWER BOUND on that
|
|
123
145
|
* turn's income: deploys onto fogged territories are unseen, and so are armies moved into the
|
|
@@ -168,6 +190,16 @@ export function incomeBasis(t) {
|
|
|
168
190
|
: `carried from ${span}, ${range}: no bonus it visibly held has been visibly broken since`;
|
|
169
191
|
if (t.incomeMethod === 'max-observed')
|
|
170
192
|
return `max observed over ${span}, ${range}`;
|
|
193
|
+
if (t.incomeMethod === 'rise-capped')
|
|
194
|
+
return t.incomeRise
|
|
195
|
+
? t.incomeRise.proven !== undefined
|
|
196
|
+
? `max observed over ${span}, ${range}, held at the +${t.incomeRise.proven} a capture with every source in view proved (above ${RISE_CAP}× the ~${t.incomeRise.before} before it): no turn read in full reached ${t.incomeRise.read}`
|
|
197
|
+
: `max observed over ${span}, ${range}, held to ${RISE_CAP}× the ~${t.incomeRise.before} before it: no turn read in full reached ${t.incomeRise.read}`
|
|
198
|
+
: `max observed over ${span}, ${range}, a rise held to ${RISE_CAP}× a turn`;
|
|
199
|
+
if (t.incomeMethod === 'tripped')
|
|
200
|
+
return t.incomeTrip
|
|
201
|
+
? `stepped down from ~${t.incomeTrip.from} toward +${t.incomeTrip.proven}: every army it could deploy was in view on turn ${t.incomeTrip.turn}, which read +${t.incomeTrip.proven} (one ${RISE_CAP}× step a turn, never below that reading; ${span}, ${range})`
|
|
202
|
+
: `stepped down toward a turn read with every army it could deploy in view (${span}, ${range})`;
|
|
171
203
|
if (t.incomeMethod === 'stock-flow')
|
|
172
204
|
return `visible army growth plus losses (fog arrivals left out) over ${span}, ${range}`;
|
|
173
205
|
if (t.incomeMethod === 'fog-captures')
|
|
@@ -507,13 +539,96 @@ function fogCapturePattern(observed) {
|
|
|
507
539
|
const income = Math.min(last.cap, Math.ceil(armies / (last.from - hits[0].from + 1)));
|
|
508
540
|
return { turns: hits.map((x) => x.from), armies, income };
|
|
509
541
|
}
|
|
542
|
+
/**
|
|
543
|
+
* #418: {@link trackedIncome} with the tripwire's ceiling on the readings of the turns it covers: those
|
|
544
|
+
* count at most its value, the later ones whole; method `tripped` when that lowers the figure.
|
|
545
|
+
*/
|
|
546
|
+
function ceiledIncome(window, visibleIncome, ceiling) {
|
|
547
|
+
const est = trackedIncome(window, visibleIncome);
|
|
548
|
+
if (!ceiling || !window.some((x) => x.from <= ceiling.through))
|
|
549
|
+
return est;
|
|
550
|
+
const later = window.filter((x) => x.from > ceiling.through);
|
|
551
|
+
const income = Math.max(visibleIncome, Math.min(est.income, ceiling.value), later.length ? trackedIncome(later, visibleIncome).income : 0);
|
|
552
|
+
return income >= est.income ? est : { ...est, income, method: 'tripped' };
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* #418, the over-read tripwire (owner decision of 2026-11-20): proof may lower an estimate only when every
|
|
556
|
+
* army the opponent could have deployed that turn is accounted for in view. Its deploy lands only on its
|
|
557
|
+
* own territories, so the turn is read in full when every territory it held on either board shows its
|
|
558
|
+
* armies on both, nothing beside them hides its owner on either board (#294's whole frontier read: a
|
|
559
|
+
* territory of its cut off in deep fog, beside none of its land in view, is the one gap), and nothing
|
|
560
|
+
* beside it could hide a fight that cost it armies the board does not show: no third player beside it
|
|
561
|
+
* (another's attack, or a failed attack of its on another, is unseen), no neutral beside it that shrank or
|
|
562
|
+
* changed hands (a failed attack of its), no territory of its lost, and — beside my land — my orders known
|
|
563
|
+
* in full (`sent` and `cards`, so `measureOrders` counts what my attacks killed and what its failed attacks
|
|
564
|
+
* on me cost) with no card of mine on its land. A failed attack must always show: one army kills at least
|
|
565
|
+
* one defender ({@link guaranteedKills}); with a capture, luck is off under straight rounding (else its cost
|
|
566
|
+
* varies). Not in a commerce game with an army price (it may save gold rather than deploy).
|
|
567
|
+
*/
|
|
568
|
+
export function everyArmyInView(g, before, after, playerId, me, orders, settings = {}) {
|
|
569
|
+
if (settings.armyCostMultiplier)
|
|
570
|
+
return false;
|
|
571
|
+
const was = new Map(before.territories.map((t) => [t.territoryId, t]));
|
|
572
|
+
const now = new Map(after.territories.map((t) => [t.territoryId, t]));
|
|
573
|
+
const its = (t) => t?.owner.kind === 'player' && t.owner.playerId === playerId;
|
|
574
|
+
const land = new Set();
|
|
575
|
+
for (const id of g.territoryById.keys())
|
|
576
|
+
if (its(ownerShown(was.get(id))) || its(ownerShown(now.get(id))))
|
|
577
|
+
land.add(id);
|
|
578
|
+
if (!land.size)
|
|
579
|
+
return false;
|
|
580
|
+
let captured = false;
|
|
581
|
+
for (const id of land) {
|
|
582
|
+
const b = visibleState(was.get(id));
|
|
583
|
+
const a = visibleState(now.get(id));
|
|
584
|
+
if (!b || !a || !its(a))
|
|
585
|
+
return false;
|
|
586
|
+
if (!its(b))
|
|
587
|
+
captured = true;
|
|
588
|
+
}
|
|
589
|
+
let bordersMe = false;
|
|
590
|
+
for (const id of land)
|
|
591
|
+
for (const n of neighborsOf(g, id)) {
|
|
592
|
+
if (land.has(n))
|
|
593
|
+
continue;
|
|
594
|
+
const b = ownerShown(was.get(n));
|
|
595
|
+
const a = ownerShown(now.get(n));
|
|
596
|
+
if (!b || !a)
|
|
597
|
+
return false;
|
|
598
|
+
for (const o of [b.owner, a.owner]) {
|
|
599
|
+
if (o.kind !== 'player')
|
|
600
|
+
continue;
|
|
601
|
+
if (o.playerId !== me)
|
|
602
|
+
return false;
|
|
603
|
+
bordersMe = true;
|
|
604
|
+
}
|
|
605
|
+
if (b.owner.kind === 'neutral') {
|
|
606
|
+
const vb = visibleState(b);
|
|
607
|
+
const va = visibleState(a);
|
|
608
|
+
if (a.owner.kind !== 'neutral' || !vb || !va || va.armies < vb.armies)
|
|
609
|
+
return false;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
if (bordersMe) {
|
|
613
|
+
if (!orders?.sent || !orders.cards)
|
|
614
|
+
return false;
|
|
615
|
+
if (orders.cards.some((c) => [c.from, c.to, c.target].some((t) => t !== undefined && land.has(t))))
|
|
616
|
+
return false;
|
|
617
|
+
}
|
|
618
|
+
const luck = luckFraction(settings.luckModifier);
|
|
619
|
+
const straight = (settings.roundingMode ?? 'StraightRound') === 'StraightRound';
|
|
620
|
+
if (captured && (luck > 0 || !straight))
|
|
621
|
+
return false;
|
|
622
|
+
return guaranteedKills(1, settings.offensiveKillRate ?? DEFAULT_OFFENSIVE_KILL_RATE, settings.luckModifier, settings.roundingMode) >= 1;
|
|
623
|
+
}
|
|
510
624
|
/**
|
|
511
625
|
* #123 review: a turn read in full — no ambiguous army was read as a move out of the fog (the
|
|
512
|
-
* bound cut nothing) — whose observed deploy reaches `income` confirms it
|
|
626
|
+
* bound cut nothing) — whose observed deploy reaches `income` confirms it, and so does a pattern of
|
|
627
|
+
* fog captures (#271) or a capture floor (#418, {@link ObservedTurn.captureFloor}) that reaches it. A figure only bound-cut
|
|
513
628
|
* readings reached (each up to twice the income carried so far) is a guess, however often it
|
|
514
629
|
* compounded.
|
|
515
630
|
*/
|
|
516
|
-
const confirmedBy = (window, income) => window.some((x) => (x.fogArmies === 0 && x.observed >= income) || (x.fogCaptures?.income ?? 0) >= income);
|
|
631
|
+
const confirmedBy = (window, income) => window.some((x) => (x.fogArmies === 0 && x.observed >= income) || (x.fogCaptures?.income ?? 0) >= income || (x.captureFloor ?? 0) >= income);
|
|
517
632
|
/**
|
|
518
633
|
* #119: no decay. Walk the observed turns: each window's figure (as `trackedIncome` reads it)
|
|
519
634
|
* replaces the carried one only when larger; otherwise the carried figure stays, less the
|
|
@@ -526,9 +641,22 @@ const confirmedBy = (window, income) => window.some((x) => (x.fogArmies === 0 &&
|
|
|
526
641
|
* staying pinned). The trade-off: a hidden income beyond twice the visible one, learnt only from
|
|
527
642
|
* bound-cut readings (section 7's +20 read 10, 20, …), is dropped the first time it deploys into
|
|
528
643
|
* the fog and shows less in full — unless a turn read in full had already confirmed it.
|
|
644
|
+
*
|
|
645
|
+
* #418: while I lead it ({@link ObservedTurn.leadIncome} above the carry before the turn, or that
|
|
646
|
+
* turn's visible income when larger — not above the reading, which an over-read would pass), a window
|
|
647
|
+
* figure above the carry that no turn read in full confirmed rises at most to {@link RISE_CAP} × that
|
|
648
|
+
* figure, rounded up; on a turn read in full that observed less than the carry it does not rise at all.
|
|
649
|
+
* #418: never below a capture floor in the window (proof may always raise an estimate).
|
|
650
|
+
*
|
|
651
|
+
* #418, the over-read tripwire: on a turn with every army it could have deployed in view
|
|
652
|
+
* ({@link ObservedTurn.accounted}), a carry above that turn's reading steps down at most one step,
|
|
653
|
+
* to ⌈carry ÷ {@link RISE_CAP}⌉, never below the reading nor its visible income; the readings of the
|
|
654
|
+
* turns up to it then count at most the stepped figure in every later window ({@link ceiledIncome}),
|
|
655
|
+
* so the next turn does not read the over-read back.
|
|
529
656
|
*/
|
|
530
657
|
function carryIncome(observed) {
|
|
531
658
|
let carry = null;
|
|
659
|
+
let ceiling = null;
|
|
532
660
|
/**
|
|
533
661
|
* #271 (2): the latest pattern of captures that needed attackers out of sight, as a carry: it is
|
|
534
662
|
* evidence, not a bound-cut guess, so no later turn read in full disproves it; like any carry it
|
|
@@ -538,7 +666,7 @@ function carryIncome(observed) {
|
|
|
538
666
|
for (let i = 0; i < observed.length; i++) {
|
|
539
667
|
const x = observed[i];
|
|
540
668
|
const window = observed.slice(Math.max(0, i - INCOME_TURNS + 1), i + 1);
|
|
541
|
-
const est =
|
|
669
|
+
const est = ceiledIncome(window, 0, ceiling);
|
|
542
670
|
const fresh = { income: est.income, set: est.income, window, est, confirmed: confirmedBy(window, est.income) };
|
|
543
671
|
if (pattern)
|
|
544
672
|
pattern = { ...pattern, income: Math.min(x.cap, pattern.income - x.brokenValue) };
|
|
@@ -552,12 +680,37 @@ function carryIncome(observed) {
|
|
|
552
680
|
else {
|
|
553
681
|
const disproved = !prev.confirmed && x.fogArmies === 0 && x.observed < prev.income;
|
|
554
682
|
const kept = Math.min(x.cap, prev.income - x.brokenValue);
|
|
555
|
-
|
|
683
|
+
if (!(disproved || est.income >= kept))
|
|
684
|
+
carry = { ...prev, income: kept };
|
|
685
|
+
else {
|
|
686
|
+
const before = Math.max(prev.income, x.visibleIncome);
|
|
687
|
+
// #418: proof may always raise an estimate: the hold never goes below a capture floor in the window.
|
|
688
|
+
const proof = Math.max(0, ...window.map((w) => w.captureFloor ?? 0));
|
|
689
|
+
const limit = Math.max(disproved ? prev.income : Math.ceil(before * RISE_CAP - 1e-9), proof);
|
|
690
|
+
// #418 review: the lead is judged against the carry before the rise (or its visible income), never
|
|
691
|
+
// against the reading being judged: an over-read above my income must not switch its own cap off.
|
|
692
|
+
carry =
|
|
693
|
+
(x.leadIncome ?? 0) > before && !fresh.confirmed && fresh.income > limit
|
|
694
|
+
? { ...fresh, income: limit, set: limit, rise: { read: fresh.income, before, ...(proof >= limit ? { proven: proof } : {}) } }
|
|
695
|
+
: fresh;
|
|
696
|
+
}
|
|
556
697
|
}
|
|
557
698
|
if (pattern && pattern.income > carry.income)
|
|
558
699
|
carry = pattern;
|
|
700
|
+
// #418, the over-read tripwire: on a turn with every army it could deploy in view, the carry steps
|
|
701
|
+
// down at most one RISE_CAP step toward that turn's reading, never below it (nor its visible income).
|
|
702
|
+
// It steps `carry`, never `pattern`: a #271 fog-capture pattern above the stepped figure is restored by
|
|
703
|
+
// the line above on the next turn, so a pattern-set reading is lowered for that one turn only.
|
|
704
|
+
if (x.accounted && carry.income > x.observed) {
|
|
705
|
+
const step = Math.max(x.observed, x.visibleIncome, Math.ceil(carry.income / RISE_CAP - 1e-9));
|
|
706
|
+
if (step < carry.income) {
|
|
707
|
+
const trip = { from: carry.income, proven: x.observed, turn: x.from };
|
|
708
|
+
carry = { ...carry, income: step, set: step, trip };
|
|
709
|
+
ceiling = { value: step, through: x.from, trip };
|
|
710
|
+
}
|
|
711
|
+
}
|
|
559
712
|
}
|
|
560
|
-
return carry;
|
|
713
|
+
return carry && ceiling ? { ...carry, ceiling } : carry;
|
|
561
714
|
}
|
|
562
715
|
/** #250: a turn that reads more than this many times the most it was seen to earn before it is a jump. */
|
|
563
716
|
export const INCOME_JUMP_FACTOR = 2;
|
|
@@ -728,6 +881,29 @@ export function incomeJumpText(j, income, earlier) {
|
|
|
728
881
|
tail = `${j.verdict === 'reveal' ? `: more only counting the ${j.cameIntoView} armies that came into view` : ': no more'}.${k ? ` ${rate[0].toUpperCase()}${rate.slice(1)} it could have received up to ${k.received} by turn ${j.turn} ${from}, enough for the ${had}.` : ''}`;
|
|
729
882
|
return `${lead}${cut}${amb}${sum}${tail}`;
|
|
730
883
|
}
|
|
884
|
+
/**
|
|
885
|
+
* #420: the most armies one of `playerId`'s stacks beside my land grew over one turn (board `before` →
|
|
886
|
+
* `after`): each territory its own on both boards, shown with its armies on both (`visibleState`), and
|
|
887
|
+
* next to a territory of mine on `before`; a stack that shrank or stood still reads 0. `undefined` when
|
|
888
|
+
* there is no such stack. Growth counts deploys and armies moved in alike: what the stack facing me
|
|
889
|
+
* gained, the top-up a border must answer.
|
|
890
|
+
*/
|
|
891
|
+
export function borderTopUp(g, before, after, playerId, me) {
|
|
892
|
+
const was = new Map(before.territories.map((t) => [t.territoryId, t]));
|
|
893
|
+
const now = new Map(after.territories.map((t) => [t.territoryId, t]));
|
|
894
|
+
const owns = (t, p) => t?.owner.kind === 'player' && t.owner.playerId === p;
|
|
895
|
+
let most;
|
|
896
|
+
for (const id of [...g.territoryById.keys()].sort(byNum)) {
|
|
897
|
+
const b = visibleState(was.get(id));
|
|
898
|
+
const a = visibleState(now.get(id));
|
|
899
|
+
if (!owns(b, playerId) || !owns(a, playerId))
|
|
900
|
+
continue;
|
|
901
|
+
if (!neighborsOf(g, id).some((n) => owns(ownerShown(was.get(n)), me)))
|
|
902
|
+
continue;
|
|
903
|
+
most = Math.max(most ?? 0, a.armies - b.armies);
|
|
904
|
+
}
|
|
905
|
+
return most;
|
|
906
|
+
}
|
|
731
907
|
/**
|
|
732
908
|
* Per opponent: its observed deploys turn by turn, an income estimate, the armies that must be
|
|
733
909
|
* in the fog and the bonuses that could explain an income gap. Those visible on the newest
|
|
@@ -741,9 +917,15 @@ export function trackOpponents(g, boards, me, settings = {}, game) {
|
|
|
741
917
|
// One board per turn (the last given wins), oldest first.
|
|
742
918
|
const byTurn = new Map();
|
|
743
919
|
const ordersOn = new Map();
|
|
920
|
+
/** #420: the turns whose board came from GameFeed history (army counts unverified). */
|
|
921
|
+
const fromHistory = new Set();
|
|
744
922
|
for (const b of boards) {
|
|
745
923
|
byTurn.set(b.turn, neutralizeSeats(b.board, seats));
|
|
746
924
|
ordersOn.set(b.turn, b.orders);
|
|
925
|
+
if (b.source === 'history')
|
|
926
|
+
fromHistory.add(b.turn);
|
|
927
|
+
else
|
|
928
|
+
fromHistory.delete(b.turn);
|
|
747
929
|
}
|
|
748
930
|
const turns = [...byTurn.keys()].sort(byNum);
|
|
749
931
|
if (!turns.length)
|
|
@@ -859,13 +1041,18 @@ export function trackOpponents(g, boards, me, settings = {}, game) {
|
|
|
859
1041
|
...(expected !== null ? { expected: Math.max(expected, carriedSoFar) } : {}),
|
|
860
1042
|
// #293: the same Local Deployment reading the board-only observation used.
|
|
861
1043
|
...(settings.localDeployments ? { localFree: localFreeOn(e.base, DEFAULT_BASE_INCOME, settings.opponentReinforcement, from) } : {}),
|
|
1044
|
+
// #418: a Bomb it may have played halves a capture's defenders before the proof reads them.
|
|
1045
|
+
...(bombPossibleOn(settings, from) ? { bomb: true } : {}),
|
|
862
1046
|
};
|
|
863
1047
|
const { signed, ...o } = expected !== null && carriedSoFar > expected
|
|
864
1048
|
? observeSigned(g, after, before, playerId, settings, context)
|
|
865
1049
|
: { ...e.observation, signed: e.observedRaw };
|
|
866
1050
|
// #271 (1): a failed attack on a hold of mine bounds its deploy from below, fog or not.
|
|
867
1051
|
const repelled = orders ? repelledFloor(g, before, after, me, playerId, orders, settings, guard, bombPossibleOn(settings, from)) : null;
|
|
868
|
-
|
|
1052
|
+
// #418: a capture with every source army in view proves a minimum deploy (my orders known: one
|
|
1053
|
+
// beside my land reads too). Proof may always raise the reading.
|
|
1054
|
+
const proof = captureFloor(g, before, after, playerId, settings, guard, { me, orders, bomb: bombPossibleOn(settings, from) });
|
|
1055
|
+
const floor = Math.max(repelled?.floor ?? 0, proof.floor);
|
|
869
1056
|
const raw = Math.max(measured ? Math.max(0, observeSigned(g, after, before, playerId, settings, context).signed + measured) : Math.max(0, signed), floor);
|
|
870
1057
|
const losses = Math.max(0, change.losses + measured);
|
|
871
1058
|
// #123: with my orders known, what stood on an emptied capture is measured: no high reading.
|
|
@@ -873,10 +1060,28 @@ export function trackOpponents(g, boards, me, settings = {}, game) {
|
|
|
873
1060
|
const high = Math.max(raw, o.high + measured - (orders ? o.emptiedHigh : 0));
|
|
874
1061
|
const seenObserved = Math.min(raw, e.observedCap);
|
|
875
1062
|
const broken = visiblyBroken(g, before, after, playerId);
|
|
1063
|
+
// #418: did I lead it on the board read?
|
|
1064
|
+
const myLand = new Set();
|
|
1065
|
+
let myArmies = 0;
|
|
1066
|
+
let itsArmies = 0;
|
|
1067
|
+
for (const t of after.territories) {
|
|
1068
|
+
if (!g.territoryById.has(t.territoryId) || t.owner.kind !== 'player')
|
|
1069
|
+
continue;
|
|
1070
|
+
if (t.owner.playerId === me) {
|
|
1071
|
+
myLand.add(t.territoryId);
|
|
1072
|
+
myArmies += t.armies ?? 0;
|
|
1073
|
+
}
|
|
1074
|
+
else if (t.owner.playerId === playerId)
|
|
1075
|
+
itsArmies += t.armies ?? 0;
|
|
1076
|
+
}
|
|
1077
|
+
const leadIncome = myArmies >= LEAD_ARMIES * itsArmies ? boardIncome(g, myLand, rules).total : null;
|
|
1078
|
+
const topUp = fromHistory.has(from) || fromHistory.has(to) ? undefined : borderTopUp(g, before, after, playerId, me);
|
|
876
1079
|
observed.push({
|
|
877
1080
|
from,
|
|
878
1081
|
to,
|
|
879
1082
|
coverage: frontierCoverage(g, after, before, playerId),
|
|
1083
|
+
...(topUp !== undefined ? { topUp } : {}),
|
|
1084
|
+
...(leadIncome !== null ? { leadIncome } : {}),
|
|
880
1085
|
observed: seenObserved,
|
|
881
1086
|
raw,
|
|
882
1087
|
...(context.expected !== undefined ? { expected: context.expected } : {}),
|
|
@@ -898,7 +1103,9 @@ export function trackOpponents(g, boards, me, settings = {}, game) {
|
|
|
898
1103
|
unseenAttackers: o.unseenAttackers,
|
|
899
1104
|
unseenAttackerArmies: o.unseenAttackerArmies,
|
|
900
1105
|
repelled: repelled?.territories.length ? repelled : null,
|
|
901
|
-
repelledFloor: floor,
|
|
1106
|
+
repelledFloor: repelled?.floor ?? 0,
|
|
1107
|
+
...(proof.floor > 0 ? { proven: proof.territories, captureFloor: proof.floor } : {}),
|
|
1108
|
+
...(everyArmyInView(g, before, after, playerId, me, orders, settings) ? { accounted: true } : {}),
|
|
902
1109
|
combat: combatLosses(g, before, after, playerId, orders
|
|
903
1110
|
? {
|
|
904
1111
|
me,
|
|
@@ -929,15 +1136,26 @@ export function trackOpponents(g, boards, me, settings = {}, game) {
|
|
|
929
1136
|
const turnsUnseen = visible ? 0 : lastTurn - back;
|
|
930
1137
|
const turnsUnseenAtLeast = turnsUnseen > 0 && back >= 1 && !byTurn.has(back);
|
|
931
1138
|
const recent = observed.slice(-INCOME_TURNS);
|
|
932
|
-
const lastWindow = recent.length ? trackedIncome(recent, visibleIncome) : null;
|
|
933
1139
|
// #119: no decay ({@link carryIncome}). The last three turns alone read a real 31 as 12 once
|
|
934
1140
|
// it aged out.
|
|
935
1141
|
const carry = carryIncome(observed);
|
|
1142
|
+
// #418: the readings an over-read tripwire stepped down from count at most its ceiling.
|
|
1143
|
+
const lastWindow = recent.length ? ceiledIncome(recent, visibleIncome, carry?.ceiling) : null;
|
|
936
1144
|
const carried = carry !== null && lastWindow !== null && carry.income > lastWindow.income ? carry : null;
|
|
1145
|
+
// #418: an unconfirmed rise held below what the last window reads keeps the held figure.
|
|
1146
|
+
const held = !carried && carry?.rise && lastWindow !== null && carry.income < lastWindow.income ? carry : null;
|
|
937
1147
|
const estimate = carried
|
|
938
|
-
? { ...carried.est, income: carried.income, method: 'carried' }
|
|
939
|
-
:
|
|
940
|
-
|
|
1148
|
+
? { ...carried.est, income: carried.income, method: (carried.trip ? 'tripped' : 'carried') }
|
|
1149
|
+
: held
|
|
1150
|
+
? {
|
|
1151
|
+
...held.est,
|
|
1152
|
+
income: Math.max(visibleIncome, held.income),
|
|
1153
|
+
method: (visibleIncome >= held.income ? 'visible' : 'rise-capped'),
|
|
1154
|
+
}
|
|
1155
|
+
: lastWindow;
|
|
1156
|
+
const incomeRise = held && estimate.method === 'rise-capped' ? held.rise : null;
|
|
1157
|
+
const incomeTrip = estimate?.method === 'tripped' ? (carried?.trip ?? carry?.ceiling?.trip ?? null) : null;
|
|
1158
|
+
const incomeWindow = carried ? carried.window : held ? held.window : recent;
|
|
941
1159
|
const income = estimate?.income ?? null;
|
|
942
1160
|
// #250: an income set by one turn far above the turns before it, with the evidence for it. Its
|
|
943
1161
|
// starting armies, when known (under full distribution, an even share: an upper bound).
|
|
@@ -998,8 +1216,14 @@ export function trackOpponents(g, boards, me, settings = {}, game) {
|
|
|
998
1216
|
incomeTurns: incomeWindow.map((x) => x.from),
|
|
999
1217
|
observedRange: estimate.observedRange,
|
|
1000
1218
|
incomeLowered: carried ? carried.set - carried.income : 0,
|
|
1219
|
+
incomeRise,
|
|
1220
|
+
incomeTrip,
|
|
1001
1221
|
});
|
|
1002
|
-
if (
|
|
1222
|
+
if (incomeTrip)
|
|
1223
|
+
notes.push(`Income ~${income} (${basis}): proof lowers an estimate only on a turn with every army it could deploy in view, and then by one step a turn (#418). Each observed deploy is a lower bound under fog.`);
|
|
1224
|
+
else if (incomeRise)
|
|
1225
|
+
notes.push(`Income ~${income} (${basis}): a rise is held to ${RISE_CAP}× a turn until a turn read in full (no army read as a move out of the fog) confirms it, since armies walking in beside the fog are read up to twice the income carried (#418). Each observed deploy is a lower bound under fog.`);
|
|
1226
|
+
else if (carried)
|
|
1003
1227
|
notes.push(`Income ~${income} (${basis}): an income does not decay — it is kept until a bonus it visibly held is visibly broken (less its value) or it could no longer earn it; its last ${recent.length} observed turns alone give ~${lastWindow.income}. Each observed deploy is a lower bound under fog.`);
|
|
1004
1228
|
else
|
|
1005
1229
|
notes.push(`Income ~${income} (${basis}): the larger of the most it was observed to deploy (each observation is a lower bound under fog, so the largest is the tightest) and its visible army growth plus losses per turn, fog arrivals left out (${estimate.stockFlow}), capped at the most it could earn (${estimate.cap}), at least its visible income ${visibleIncome}.`);
|
|
@@ -1238,8 +1462,11 @@ export function trackOpponents(g, boards, me, settings = {}, game) {
|
|
|
1238
1462
|
observedRange: estimate?.observedRange ?? null,
|
|
1239
1463
|
incomeMethod: estimate?.method ?? null,
|
|
1240
1464
|
incomeLowered: carried ? carried.set - carried.income : 0,
|
|
1465
|
+
...(incomeRise ? { incomeRise } : {}),
|
|
1466
|
+
...(incomeTrip ? { incomeTrip } : {}),
|
|
1241
1467
|
unexplained,
|
|
1242
1468
|
inferred,
|
|
1469
|
+
topUp: observed.reduce((n, x) => (x.topUp === undefined ? n : Math.max(n ?? 0, x.topUp)), null),
|
|
1243
1470
|
visible,
|
|
1244
1471
|
turnsUnseen,
|
|
1245
1472
|
turnsUnseenAtLeast,
|