@chrischall/warapp-mcp 0.0.0 → 0.2.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 +4 -4
- package/.claude-plugin/plugin.json +2 -2
- package/README.md +211 -9
- package/dist/analysis/accept-surrender.js +56 -0
- package/dist/analysis/award.js +159 -0
- package/dist/analysis/bonuses.js +98 -0
- package/dist/analysis/breach.js +62 -0
- package/dist/analysis/calibrate.js +239 -0
- package/dist/analysis/card-support.js +329 -0
- package/dist/analysis/card-threats.js +234 -0
- package/dist/analysis/cards-in-effect.js +130 -0
- package/dist/analysis/chains.js +59 -0
- package/dist/analysis/chokepoints.js +140 -0
- package/dist/analysis/combat.js +231 -0
- package/dist/analysis/commander-safety.js +149 -0
- package/dist/analysis/commitments.js +338 -0
- package/dist/analysis/exchange.js +155 -0
- package/dist/analysis/finished-game.js +136 -0
- package/dist/analysis/game-lessons.js +217 -0
- package/dist/analysis/graph.js +82 -0
- package/dist/analysis/guard-off.js +54 -0
- package/dist/analysis/guess.js +351 -0
- package/dist/analysis/headroom.js +241 -0
- package/dist/analysis/hold-diff.js +64 -0
- package/dist/analysis/how-lost.js +130 -0
- package/dist/analysis/index.js +14 -0
- package/dist/analysis/local-deploy.js +179 -0
- package/dist/analysis/lookahead.js +108 -0
- package/dist/analysis/opponent-profile.js +552 -0
- package/dist/analysis/opponents.js +1253 -0
- package/dist/analysis/outlook.js +695 -0
- package/dist/analysis/overrides.js +60 -0
- package/dist/analysis/picks.js +1879 -0
- package/dist/analysis/plan/after-leftover.js +140 -0
- package/dist/analysis/plan/cap-spend.js +242 -0
- package/dist/analysis/plan/captures.js +1195 -0
- package/dist/analysis/plan/commander.js +236 -0
- package/dist/analysis/plan/completed.js +29 -0
- package/dist/analysis/plan/conceded-out.js +131 -0
- package/dist/analysis/plan/estimates.js +715 -0
- package/dist/analysis/plan/guard-off.js +232 -0
- package/dist/analysis/plan/holds.js +1631 -0
- package/dist/analysis/plan/leftover.js +760 -0
- package/dist/analysis/plan/move-order.js +319 -0
- package/dist/analysis/plan/orders.js +317 -0
- package/dist/analysis/plan/relations.js +702 -0
- package/dist/analysis/plan/report.js +672 -0
- package/dist/analysis/plan/shared.js +1405 -0
- package/dist/analysis/plan/stand-still.js +823 -0
- package/dist/analysis/plan/state.js +44 -0
- package/dist/analysis/plan/strike.js +1416 -0
- package/dist/analysis/plan/targets.js +651 -0
- package/dist/analysis/plan/team.js +299 -0
- package/dist/analysis/plan/threats.js +1001 -0
- package/dist/analysis/plan/transfers.js +328 -0
- package/dist/analysis/plan/util.js +5 -0
- package/dist/analysis/plan/vacated.js +285 -0
- package/dist/analysis/planner.js +2927 -0
- package/dist/analysis/player-record.js +144 -0
- package/dist/analysis/player.js +268 -0
- package/dist/analysis/profile.js +347 -0
- package/dist/analysis/relations.js +1030 -0
- package/dist/analysis/schedule.js +88 -0
- package/dist/analysis/since-last.js +50 -0
- package/dist/analysis/static-seats.js +71 -0
- package/dist/analysis/stress.js +584 -0
- package/dist/analysis/team-brief.js +151 -0
- package/dist/analysis/tripwire.js +644 -0
- package/dist/analysis/turn-sim.js +259 -0
- package/dist/analysis/whereabouts.js +1112 -0
- package/dist/board.js +105 -0
- package/dist/bundle.js +121082 -36148
- package/dist/calibration-source.js +75 -0
- package/dist/cards.js +435 -0
- package/dist/chat-cursor.js +135 -0
- package/dist/chat.js +265 -0
- package/dist/client.js +439 -0
- package/dist/config.js +62 -0
- package/dist/direct/link.js +102 -0
- package/dist/direct/session.js +267 -0
- package/dist/direct/transport.js +424 -0
- package/dist/finished-store.js +357 -0
- package/dist/guess-salt.js +65 -0
- package/dist/hosted.js +24 -0
- package/dist/index.js +33 -0
- package/dist/join-color.js +140 -0
- package/dist/lessons-store.js +356 -0
- package/dist/live.js +287 -0
- package/dist/map-details.js +127 -0
- package/dist/map-stats.js +160 -0
- package/dist/map-store.js +242 -0
- package/dist/move-order.js +141 -0
- package/dist/my-games.js +218 -0
- package/dist/normalize.js +443 -0
- package/dist/notifications.js +143 -0
- package/dist/open-games.js +537 -0
- package/dist/outlook-log.js +165 -0
- package/dist/path-lock.js +22 -0
- package/dist/pick-list.js +193 -0
- package/dist/player-record-store.js +231 -0
- package/dist/player-states.js +31 -0
- package/dist/profile-store.js +727 -0
- package/dist/protocol/bundle.js +375 -0
- package/dist/protocol/codec.js +556 -0
- package/dist/protocol/decoded.js +12 -0
- package/dist/protocol/interp.js +1904 -0
- package/dist/protocol/methods.js +615 -0
- package/dist/protocol/rpc.js +202 -0
- package/dist/push/listener.js +393 -0
- package/dist/push/packets.js +66 -0
- package/dist/push/socketio.js +333 -0
- package/dist/push/websocket.js +179 -0
- package/dist/redact.js +62 -0
- package/dist/relations-store.js +242 -0
- package/dist/replay.js +227 -0
- package/dist/scalars.js +28 -0
- package/dist/scout.js +346 -0
- package/dist/stats.js +291 -0
- package/dist/strategy/card-clock.js +185 -0
- package/dist/strategy/map-notes.js +128 -0
- package/dist/strategy/notes.js +2223 -0
- package/dist/surrender-pending.js +126 -0
- package/dist/team-cards.js +84 -0
- package/dist/team-orders.js +150 -0
- package/dist/teams.js +19 -0
- package/dist/tools/accept-surrender.js +311 -0
- package/dist/tools/award.js +206 -0
- package/dist/tools/begin-turn.js +162 -0
- package/dist/tools/board.js +77 -0
- package/dist/tools/card-advice.js +256 -0
- package/dist/tools/card-effects.js +49 -0
- package/dist/tools/card-plays.js +434 -0
- package/dist/tools/card-support-advice.js +140 -0
- package/dist/tools/chat-inbox.js +158 -0
- package/dist/tools/chat-read-mark.js +179 -0
- package/dist/tools/chat.js +525 -0
- package/dist/tools/check-plan.js +689 -0
- package/dist/tools/commander-check.js +103 -0
- package/dist/tools/commitments.js +216 -0
- package/dist/tools/common.js +143 -0
- package/dist/tools/diplomacy.js +342 -0
- package/dist/tools/end-of-game.js +384 -0
- package/dist/tools/game.js +151 -0
- package/dist/tools/guess-view.js +56 -0
- package/dist/tools/healthcheck.js +90 -0
- package/dist/tools/hints.js +34 -0
- package/dist/tools/how-lost.js +154 -0
- package/dist/tools/index.js +152 -0
- package/dist/tools/join-game.js +327 -0
- package/dist/tools/leave-game.js +181 -0
- package/dist/tools/live-context.js +339 -0
- package/dist/tools/live.js +404 -0
- package/dist/tools/map-details.js +88 -0
- package/dist/tools/map-stats.js +130 -0
- package/dist/tools/map.js +141 -0
- package/dist/tools/my-games.js +193 -0
- package/dist/tools/notifications.js +484 -0
- package/dist/tools/open-games.js +104 -0
- package/dist/tools/opponents.js +163 -0
- package/dist/tools/order-options.js +135 -0
- package/dist/tools/past-games.js +94 -0
- package/dist/tools/picks.js +305 -0
- package/dist/tools/profile-hook.js +156 -0
- package/dist/tools/profile-opponents.js +121 -0
- package/dist/tools/profile-reads.js +99 -0
- package/dist/tools/push.js +445 -0
- package/dist/tools/relations.js +611 -0
- package/dist/tools/resolve.js +45 -0
- package/dist/tools/route.js +36 -0
- package/dist/tools/scout.js +87 -0
- package/dist/tools/session.js +163 -0
- package/dist/tools/strategy.js +257 -0
- package/dist/tools/stress-opponents.js +83 -0
- package/dist/tools/surrender-pending.js +74 -0
- package/dist/tools/surrender.js +247 -0
- package/dist/tools/survival.js +189 -0
- package/dist/tools/team-brief.js +266 -0
- package/dist/tools/team-source.js +222 -0
- package/dist/tools/team.js +178 -0
- package/dist/tools/turn.js +2825 -0
- package/dist/tools/uncommit.js +160 -0
- package/dist/tools/where.js +300 -0
- package/dist/tools/write-kit.js +164 -0
- package/dist/transport-bridge.js +33 -0
- package/dist/trend.js +577 -0
- package/dist/version.js +4 -0
- package/manifest.json +194 -4
- package/mint.yaml +106 -14
- package/package.json +11 -6
- package/server.json +40 -3
- package/skills/warapp-api/SKILL.md +95 -4
- package/skills/warapp-api/references/scout.mjs +348 -0
- package/skills/warapp-api/scripts/warapp.sh +69 -8
- package/skills/warapp-mcp/SKILL.md +1096 -21
|
@@ -0,0 +1,695 @@
|
|
|
1
|
+
// The outlook (#178): whether a game is being won, lost, is even or is stuck, from my boards over
|
|
2
|
+
// the last turns. Pure and deterministic; no I/O.
|
|
3
|
+
//
|
|
4
|
+
// Strength is armies + STRENGTH_INCOME_TURNS × income (the #167 FFA ranking's measure): what a
|
|
5
|
+
// player can field over the next few turns. Mine is exact. An opponent's is a range under fog:
|
|
6
|
+
// - low: its visible armies + k × the income it visibly earns (both lower bounds);
|
|
7
|
+
// - high: what it could have, at most — every army it can have received and k × the most it
|
|
8
|
+
// could earn now. Received: its start (given, or #205 with the starts unknown under an even
|
|
9
|
+
// split, ⌈territories ÷ players⌉ × the armies each starting territory had) plus, each turn
|
|
10
|
+
// paid, the most it could earn that turn — on a turn I have a board of (#205), the territory
|
|
11
|
+
// income of every territory nobody else visibly holds plus every bonus none of whose
|
|
12
|
+
// territories someone else visibly holds; on any other turn the whole map's territory income
|
|
13
|
+
// plus every bonus, since a bonus held by someone else now may have paid it before — plus,
|
|
14
|
+
// with cards on (#205), the Reinforcement armies the card clock lets it have played by now and
|
|
15
|
+
// over the next k turns (`cardArmies`, capturing every turn).
|
|
16
|
+
// In a team game a teammate can transfer armies to it, so its high is not a ceiling there.
|
|
17
|
+
// Unbounded (`null`) when its start is unknown (a scenario's, or no armies per territory) or
|
|
18
|
+
// cards are on without that bound (a Gift card, a progressive or unknown Reinforcement card).
|
|
19
|
+
// With every territory in view, high = low.
|
|
20
|
+
// The ratio is mine ÷ the strongest opponent's, as a range: `low` against the highest `high`,
|
|
21
|
+
// `high` against the highest `low` (`null`: no upper limit). PLAN-TEAMS C3: in a team game it is by
|
|
22
|
+
// team — mine is my team's (me and each teammate still playing, `minePlayers`), and each enemy team
|
|
23
|
+
// is one side whose low, high and likely high are its players' summed (`strongest.team`, `players`);
|
|
24
|
+
// summed, a teammate's transfers stay inside its team's high. A player with no team is its own side.
|
|
25
|
+
//
|
|
26
|
+
// #208: the high is a bound, and under fog it stays far too loose to call a win until late: the
|
|
27
|
+
// most it could earn each turn is what the whole fog could pay, though most of the fog is
|
|
28
|
+
// neutral. So each opponent also gets a LIKELY high — an estimate, not a bound: the same sum, with
|
|
29
|
+
// every turn's income at most LIKELY_INCOME_MARGIN × the income the tracker reads off my boards
|
|
30
|
+
// (`trackOpponents`: the most it was seen to deploy, its visible income at least), never above
|
|
31
|
+
// that turn's cap, clamped between its low and its high (`source: 'tracked'`). #214: that needs
|
|
32
|
+
// territory in view NOW and an observed income (a turn pair that measured its deploy); one with
|
|
33
|
+
// nothing in view on this board, or never measured, gets a modest labelled prior instead
|
|
34
|
+
// (`source: 'prior'`), PEER-PACED (`peerPace`, owner's decision on #214): each turn's income is
|
|
35
|
+
// LIKELY_INCOME_MARGIN × the higher of my income that turn (on a turn without my board, my latest
|
|
36
|
+
// board before it; before my first board, unknown — the cache keeps ten turns — so a linear ramp
|
|
37
|
+
// from the symmetric opening's income below up to my first board's) and the most any opponent was
|
|
38
|
+
// tracked earning by then
|
|
39
|
+
// (observed deploys up to that turn; on the judged turn its tracked or visible income), the base
|
|
40
|
+
// income at least — at most an even share of the map's income (an even share of the territories at
|
|
41
|
+
// the base income, plus the map's bonuses ÷ the seated players; base income alone when no one is
|
|
42
|
+
// seated) and that turn's cap: a CEILING only, since as a floor it read thousands on a
|
|
43
|
+
// 1,200-territory map whatever anyone earned. It never falls below what the opponent's own evidence
|
|
44
|
+
// says: LIKELY_INCOME_MARGIN × its visible income, and × the income tracked on earlier boards when
|
|
45
|
+
// one was measured before it went out of view; one out of view now also keeps at least the armies
|
|
46
|
+
// and income it held on the latest board it was in view on. So less evidence never reads more
|
|
47
|
+
// hopeful than a measure would — and never its loose high, which used to stand in for it and then
|
|
48
|
+
// outranked every real estimate. Every likely high (tracked or prior) starts symmetric, never on my
|
|
49
|
+
// fortunes since (#214 review: shrinking would read every opponent weaker): the given start; under
|
|
50
|
+
// full distribution the even share, which is then every player's real start; else (TerritoryLimit
|
|
51
|
+
// unknown, so the share is only a bound) my armies on my opening board (turn 1), else war.app's
|
|
52
|
+
// default territory limit (DEFAULT_TERRITORY_LIMIT) at the armies each starting territory had —
|
|
53
|
+
// either at most the bound's start. None is
|
|
54
|
+
// made while any opponent is unbounded. When an estimate exists but does not show a win, the
|
|
55
|
+
// basis names the opponent that blocks it and why.
|
|
56
|
+
// Each turn gets a state: `winning` when even the low ratio is at least OUTLOOK_RATIO (or every
|
|
57
|
+
// opponent is bounded at no strength at all while I have some, or — `estimated` — my strength is
|
|
58
|
+
// at least OUTLOOK_RATIO × the highest likely high), `losing`
|
|
59
|
+
// when even the high ratio is at most 1 / OUTLOOK_RATIO — or (#228, `estimated`) when mine is at most
|
|
60
|
+
// LIKELY_LOSING_RATIO × the highest likely high (1 / OUTLOOK_RATIO once its LIKELY_INCOME_MARGIN is
|
|
61
|
+
// taken back out: it counts every army received and none lost, so alone it read 0.05× in a game I
|
|
62
|
+
// led) AND that is corroborated, by the main front grinding me down or by my income at most
|
|
63
|
+
// BEHIND_RATIO × the most an opponent is tracked earning (the profile's "behind"); such a turn carries
|
|
64
|
+
// `lowLikely`, and so does an uncorroborated one, whose basis says why it is no loss. The front that
|
|
65
|
+
// corroborates it is always forecast on the incomes read off my boards (below), never the plan's
|
|
66
|
+
// (#228 review): warapp_plan_turn plans on an outlook read without the plan's front and then reports
|
|
67
|
+
// one read with it, so a losing state that followed the plan's incomes could differ between the two
|
|
68
|
+
// and the plan would act on a state it never showed — `stalemate` when neither and no territory
|
|
69
|
+
// in view on both boards changed owner since the turn before while I face an enemy and (#201) the
|
|
70
|
+
// main front's multi-turn forecast is a stand-off, else `even`. The main front (#218: `mainFront`,
|
|
71
|
+
// exchange.ts, the planner's definition) is the biggest enemy stack next to me against my biggest
|
|
72
|
+
// stack beside it, both owners deploying their whole income there every turn (`forecastBorder`):
|
|
73
|
+
// mine off my board, theirs the tracked income (its visible income at least) — and on the turn
|
|
74
|
+
// being played, when the plan's `front` is that pair (`front` input), the plan's incomes, so the
|
|
75
|
+
// plan's front outlook and this forecast agree. A front that breaks or grinds me down within the
|
|
76
|
+
// horizon is not stuck, however quiet the last turns were; the basis says what the front assumed.
|
|
77
|
+
// The outlook reports a state only once it has held for OUTLOOK_TURNS consecutive turns; until
|
|
78
|
+
// then `state` is null and the basis says what each turn read. #228: given the plan's profile
|
|
79
|
+
// `standing`, an `even` or `stalemate` latest turn beside `ahead` / `behind` says why the two differ
|
|
80
|
+
// (the standing compares incomes; this outlook needs a decided ratio). The state never reads it.
|
|
81
|
+
// #304: beside the state, each turn reports what it rests on (`evidence`): the two incomes compared
|
|
82
|
+
// and how much of each opponent's frontier its income was read from (#294's coverage); a share under
|
|
83
|
+
// LOW_COVERAGE, or none measured, under fog is thin evidence, and the basis says "even" is then not safe.
|
|
84
|
+
// Reporting only: the state never reads it.
|
|
85
|
+
//
|
|
86
|
+
// OUTLOOK_RATIO (2.4×) is borrowed from a published bot's "lost" rule and has never been measured
|
|
87
|
+
// for war.app: the outlook is a basis for a decision, not a verdict. The planner acts on it in one
|
|
88
|
+
// way only (#201): once winning or losing, its payback tests count the turns the game has left.
|
|
89
|
+
import { holdsSeat } from '../player-states.js';
|
|
90
|
+
import { carriesTeam, isTeamGame } from '../teams.js';
|
|
91
|
+
import { neighborsOf } from './graph.js';
|
|
92
|
+
import { DEFAULT_TERRITORY_LIMIT, staticSeatsFor, trackOpponents } from './opponents.js';
|
|
93
|
+
import { neutralizeSeats } from './static-seats.js';
|
|
94
|
+
import { ownerShown } from './planner.js';
|
|
95
|
+
import { bonusTerritories } from './bonuses.js';
|
|
96
|
+
import { cardArmiesBy } from '../strategy/card-clock.js';
|
|
97
|
+
import { boardIncome, DEFAULT_BASE_INCOME, territoryIncome } from './player.js';
|
|
98
|
+
import { BEHIND_RATIO, STRENGTH_INCOME_TURNS } from './profile.js';
|
|
99
|
+
import { FORECAST_TURNS, forecastBorder, mainFront } from './exchange.js';
|
|
100
|
+
import { specialUnitStrength } from './combat.js';
|
|
101
|
+
import { coverageText, LOW_COVERAGE } from './plan/shared.js';
|
|
102
|
+
/** Turns a state must hold before it is reported. */
|
|
103
|
+
export const OUTLOOK_TURNS = 3;
|
|
104
|
+
/** Winning at this strength ratio or more, losing at its inverse or less (borrowed, unmeasured). */
|
|
105
|
+
export const OUTLOOK_RATIO = 2.4;
|
|
106
|
+
/** #208: the likely high lets an opponent earn up to this many times its tracked income every turn (unmeasured). */
|
|
107
|
+
export const LIKELY_INCOME_MARGIN = 2;
|
|
108
|
+
/**
|
|
109
|
+
* #228: losing on the estimate needs mine at most this share of the likely high — 1/OUTLOOK_RATIO
|
|
110
|
+
* of it once its LIKELY_INCOME_MARGIN is taken back out, since the likely high is generous to the
|
|
111
|
+
* opponent (it counts every army received, at the margin, and none lost) — and corroboration.
|
|
112
|
+
*/
|
|
113
|
+
export const LIKELY_LOSING_RATIO = 1 / (OUTLOOK_RATIO * LIKELY_INCOME_MARGIN);
|
|
114
|
+
/**
|
|
115
|
+
* #214: the peer-paced prior — what an opponent I cannot measure likely earns in a turn:
|
|
116
|
+
* LIKELY_INCOME_MARGIN × the higher of my income that turn and the most any opponent was tracked
|
|
117
|
+
* earning by then, the base income at least; at most `ceiling` (an even share of the map's income:
|
|
118
|
+
* a ceiling only, never a floor); and never below `floor` (what its own evidence says: its visible
|
|
119
|
+
* income, the margin on what it was seen or tracked earning). Pure: the planner reuses it.
|
|
120
|
+
*/
|
|
121
|
+
export function peerPace(p) {
|
|
122
|
+
return Math.max(p.floor ?? 0, Math.min(p.ceiling, Math.max(p.base, LIKELY_INCOME_MARGIN * Math.max(p.mine, p.peers))));
|
|
123
|
+
}
|
|
124
|
+
const round2 = (n) => Math.round(n * 100) / 100;
|
|
125
|
+
/** The armies the special units on a territory fight as (commanders), as the planner counts them. */
|
|
126
|
+
const unitsOn = (b, id) => specialUnitStrength(b.territories.find((t) => t.territoryId === id)?.specialUnits);
|
|
127
|
+
const fullyVisible = (g, b) => {
|
|
128
|
+
const seen = new Set();
|
|
129
|
+
for (const t of b.territories)
|
|
130
|
+
if (t.owner.kind !== 'unknown' && t.armies !== null)
|
|
131
|
+
seen.add(t.territoryId);
|
|
132
|
+
return [...g.territoryById.keys()].every((t) => seen.has(t));
|
|
133
|
+
};
|
|
134
|
+
function ownersOf(g, b) {
|
|
135
|
+
const m = new Map();
|
|
136
|
+
for (const t of b.territories) {
|
|
137
|
+
if (!g.territoryById.has(t.territoryId) || t.owner.kind === 'unknown')
|
|
138
|
+
continue;
|
|
139
|
+
m.set(t.territoryId, t.owner.kind === 'player' ? `p${t.owner.playerId}` : 'n');
|
|
140
|
+
}
|
|
141
|
+
return m;
|
|
142
|
+
}
|
|
143
|
+
export function gameOutlook(input) {
|
|
144
|
+
const { graph: g, me } = input;
|
|
145
|
+
const settings = input.settings ?? {};
|
|
146
|
+
const k = STRENGTH_INCOME_TURNS;
|
|
147
|
+
const byTurn = new Map();
|
|
148
|
+
// #270: a static seat (out, no AI on it) is no opponent: its territories read as neutrals.
|
|
149
|
+
const seats = staticSeatsFor(input.game, me);
|
|
150
|
+
for (const b of input.boards)
|
|
151
|
+
byTurn.set(b.turn, seats.size ? { ...b, board: neutralizeSeats(b.board, seats) } : b);
|
|
152
|
+
const all = [...byTurn.keys()].sort((a, b) => a - b);
|
|
153
|
+
// The latest run of consecutive turns, at most OUTLOOK_TURNS long.
|
|
154
|
+
const run = [];
|
|
155
|
+
for (let i = all.length - 1; i >= 0 && run.length < OUTLOOK_TURNS; i--) {
|
|
156
|
+
if (run.length && all[i] !== run[0] - 1)
|
|
157
|
+
break;
|
|
158
|
+
run.unshift(all[i]);
|
|
159
|
+
}
|
|
160
|
+
const players = input.game?.players ?? [];
|
|
161
|
+
const myTeam = players.find((p) => p.id === me)?.team;
|
|
162
|
+
const ally = (id) => id === me || (carriesTeam(myTeam) && players.find((p) => p.id === id)?.team === myTeam);
|
|
163
|
+
const teamGame = isTeamGame(players);
|
|
164
|
+
const stillPlaying = (id) => (players.find((p) => p.id === id)?.state ?? 'Playing') === 'Playing';
|
|
165
|
+
const rules = { base: Math.max(0, Math.floor(settings.baseIncome ?? DEFAULT_BASE_INCOME)), per: settings.bonusArmyPer ?? 0 };
|
|
166
|
+
const allBonuses = [...g.bonusById.values()].reduce((s, b) => s + Math.max(0, b.value), 0);
|
|
167
|
+
// The most any player can earn in a turn: the whole map's territory income (BonusArmyPer) plus
|
|
168
|
+
// every bonus. An observed turn's cap counts only the territories in view, so under BonusArmyPer
|
|
169
|
+
// it is raised by what the rest of the map could add to the base, never past this ceiling.
|
|
170
|
+
const mapTerritories = territoryIncome(g.territoryById.size, rules.base, rules.per);
|
|
171
|
+
const ceiling = mapTerritories + allBonuses;
|
|
172
|
+
// #205: on a turn I have a board of, a player earned at most the territory income of every
|
|
173
|
+
// territory nobody else visibly holds plus every bonus none of whose territories someone else
|
|
174
|
+
// (a player or neutral) visibly holds: income is paid from the board the turn starts on.
|
|
175
|
+
const boardCap = (b, playerId) => {
|
|
176
|
+
const other = new Set();
|
|
177
|
+
for (const t of b.territories) {
|
|
178
|
+
if (!g.territoryById.has(t.territoryId))
|
|
179
|
+
continue;
|
|
180
|
+
const shown = ownerShown(t);
|
|
181
|
+
if (shown && !(shown.owner.kind === 'player' && shown.owner.playerId === playerId))
|
|
182
|
+
other.add(t.territoryId);
|
|
183
|
+
}
|
|
184
|
+
let bonuses = 0;
|
|
185
|
+
for (const bonus of g.bonusById.values()) {
|
|
186
|
+
if (bonus.value <= 0)
|
|
187
|
+
continue;
|
|
188
|
+
const ts = bonusTerritories(g, bonus.id);
|
|
189
|
+
if (ts.length && !ts.some((t) => other.has(t)))
|
|
190
|
+
bonuses += bonus.value;
|
|
191
|
+
}
|
|
192
|
+
return Math.min(ceiling, territoryIncome(g.territoryById.size - other.size, rules.base, rules.per) + bonuses);
|
|
193
|
+
};
|
|
194
|
+
const turnCap = (t, playerId) => {
|
|
195
|
+
const b = byTurn.get(t)?.board;
|
|
196
|
+
return b ? boardCap(b, playerId) : ceiling;
|
|
197
|
+
};
|
|
198
|
+
// Its starting armies: given, or (#205) at most an even share of the map at the armies each
|
|
199
|
+
// starting territory had. Only seated players split the map: GameFeed also lists players who
|
|
200
|
+
// never took a seat (Invited, Declined, RemovedByHost), and counting them would shrink the share.
|
|
201
|
+
const game = input.game;
|
|
202
|
+
const seated = game ? game.players.filter((p) => holdsSeat(p.state)).length : 0;
|
|
203
|
+
const share = seated > 0 ? Math.ceil(g.territoryById.size / seated) : null;
|
|
204
|
+
const start = game?.start
|
|
205
|
+
? game.start.territories * game.start.armiesPerTerritory
|
|
206
|
+
: game?.startArmiesPerTerritory !== undefined && share !== null
|
|
207
|
+
? share * game.startArmiesPerTerritory
|
|
208
|
+
: null;
|
|
209
|
+
// #214: an even share of the map's income — the prior's CEILING only (a floor there read
|
|
210
|
+
// thousands on a big map whatever anyone earned).
|
|
211
|
+
const evenShare = seated > 0 ? territoryIncome(share ?? 0, rules.base, rules.per) + Math.floor(allBonuses / seated) : rules.base;
|
|
212
|
+
// #214: the likely high's start — symmetric, never my fortunes since. The given start; under full
|
|
213
|
+
// distribution the even share, which is then every player's real start; else (TerritoryLimit
|
|
214
|
+
// unknown, so the share is only a bound) my opening board (turn 1) when I have it, else war.app's
|
|
215
|
+
// default territory limit at the starting armies — each at most the bound's start. Never the
|
|
216
|
+
// territories I held on a later board: shrinking would read every opponent weaker.
|
|
217
|
+
const mineOn = (t) => byTurn.get(t).board.territories.filter((x) => g.territoryById.has(x.territoryId) && x.owner.kind === 'player' && x.owner.playerId === me);
|
|
218
|
+
const opening = (() => {
|
|
219
|
+
if (start === null)
|
|
220
|
+
return null;
|
|
221
|
+
if (game?.start)
|
|
222
|
+
return { armies: start, territories: game.start.territories };
|
|
223
|
+
if (game?.fullDistribution)
|
|
224
|
+
return { armies: start, territories: share ?? 0 };
|
|
225
|
+
const first = all.find((t) => t <= 1);
|
|
226
|
+
if (first !== undefined) {
|
|
227
|
+
const ts = mineOn(first);
|
|
228
|
+
return { armies: Math.min(start, ts.reduce((s, x) => s + (x.armies ?? 0), 0)), territories: ts.length };
|
|
229
|
+
}
|
|
230
|
+
const n = Math.min(share ?? 0, DEFAULT_TERRITORY_LIMIT);
|
|
231
|
+
return { armies: Math.min(start, n * (game?.startArmiesPerTerritory ?? 0)), territories: n };
|
|
232
|
+
})();
|
|
233
|
+
const likelyStart = opening?.armies ?? null;
|
|
234
|
+
// My income on each of my boards; on a turn between them, the latest board before it. Before my
|
|
235
|
+
// first board it is unknown (the board cache keeps ten turns), so it ramps linearly from that
|
|
236
|
+
// symmetric opening's income (its territories at the base, no bonus) up to my first board's.
|
|
237
|
+
const myIncome = new Map();
|
|
238
|
+
for (const t of all) {
|
|
239
|
+
const ts = new Set();
|
|
240
|
+
for (const x of mineOn(t))
|
|
241
|
+
ts.add(x.territoryId);
|
|
242
|
+
myIncome.set(t, boardIncome(g, ts, rules).total);
|
|
243
|
+
}
|
|
244
|
+
const openingIncome = territoryIncome(opening?.territories ?? 0, rules.base, rules.per);
|
|
245
|
+
const myIncomeAt = (t) => {
|
|
246
|
+
const first = all[0];
|
|
247
|
+
if (first === undefined)
|
|
248
|
+
return rules.base;
|
|
249
|
+
if (t < first) {
|
|
250
|
+
const to = myIncome.get(first);
|
|
251
|
+
return first <= 1 ? to : Math.round(openingIncome + ((to - openingIncome) * Math.max(0, t - 1)) / (first - 1));
|
|
252
|
+
}
|
|
253
|
+
let at = first;
|
|
254
|
+
for (const x of all)
|
|
255
|
+
if (x <= t)
|
|
256
|
+
at = x;
|
|
257
|
+
return myIncome.get(at);
|
|
258
|
+
};
|
|
259
|
+
// Cards: unbounded unless the card clock bounds what they add.
|
|
260
|
+
const cardsBound = !input.cards ? null : (input.cardArmies ?? undefined);
|
|
261
|
+
// The armies and income a player held on the latest of my boards up to `turn` where it had any
|
|
262
|
+
// territory in view, and that board's turn (none when it never had).
|
|
263
|
+
const lastSeen = (playerId, turn) => {
|
|
264
|
+
for (let i = all.length - 1; i >= 0; i--) {
|
|
265
|
+
if (all[i] > turn)
|
|
266
|
+
continue;
|
|
267
|
+
const held = new Set();
|
|
268
|
+
let armies = 0;
|
|
269
|
+
for (const t of byTurn.get(all[i]).board.territories) {
|
|
270
|
+
if (!g.territoryById.has(t.territoryId) || t.owner.kind !== 'player' || t.owner.playerId !== playerId || t.armies === null)
|
|
271
|
+
continue;
|
|
272
|
+
held.add(t.territoryId);
|
|
273
|
+
armies += t.armies;
|
|
274
|
+
}
|
|
275
|
+
if (held.size)
|
|
276
|
+
return { turn: all[i], armies, income: boardIncome(g, held, rules).total };
|
|
277
|
+
}
|
|
278
|
+
return undefined;
|
|
279
|
+
};
|
|
280
|
+
const turns = run.map((turn) => {
|
|
281
|
+
const board = byTurn.get(turn).board;
|
|
282
|
+
// #208: what the tracker reads of each opponent's income off my boards up to this turn.
|
|
283
|
+
let tracked;
|
|
284
|
+
const trackedAll = () => (tracked ??= new Map(trackOpponents(g, all.filter((t) => t <= turn).map((t) => byTurn.get(t)), me, settings, input.game).map((tr) => [
|
|
285
|
+
tr.playerId,
|
|
286
|
+
{
|
|
287
|
+
visible: tr.visible,
|
|
288
|
+
income: tr.income === null ? null : Math.max(tr.visibleIncome, tr.income),
|
|
289
|
+
visibleIncome: tr.visibleIncome,
|
|
290
|
+
observed: tr.turns.map((o) => ({ to: o.to, observed: o.observed })),
|
|
291
|
+
coverage: tr.coverage ?? null,
|
|
292
|
+
},
|
|
293
|
+
])));
|
|
294
|
+
const trackedOf = (playerId) => trackedAll().get(playerId);
|
|
295
|
+
// #214: the most any opponent was tracked earning by turn `t`: its observed deploys up to then,
|
|
296
|
+
// and on this turn its tracked (or visible) income.
|
|
297
|
+
const peersAt = (t) => {
|
|
298
|
+
let most = 0;
|
|
299
|
+
for (const [p, tr] of trackedAll()) {
|
|
300
|
+
if (ally(p))
|
|
301
|
+
continue;
|
|
302
|
+
for (const o of tr.observed)
|
|
303
|
+
if (o.to <= t)
|
|
304
|
+
most = Math.max(most, o.observed);
|
|
305
|
+
if (t >= turn)
|
|
306
|
+
most = Math.max(most, tr.visibleIncome, tr.income ?? 0);
|
|
307
|
+
}
|
|
308
|
+
return most;
|
|
309
|
+
};
|
|
310
|
+
const held = new Map();
|
|
311
|
+
const armies = new Map();
|
|
312
|
+
for (const t of board.territories) {
|
|
313
|
+
if (!g.territoryById.has(t.territoryId) || t.owner.kind !== 'player' || t.armies === null)
|
|
314
|
+
continue;
|
|
315
|
+
const p = t.owner.playerId;
|
|
316
|
+
if (!held.has(p))
|
|
317
|
+
held.set(p, new Set());
|
|
318
|
+
held.get(p).add(t.territoryId);
|
|
319
|
+
armies.set(p, (armies.get(p) ?? 0) + t.armies);
|
|
320
|
+
}
|
|
321
|
+
// PLAN-TEAMS C3: in a team game my side is my team: me and each teammate still playing.
|
|
322
|
+
const mates = teamGame
|
|
323
|
+
? [...new Set([...held.keys(), ...players.map((p) => p.id)])].filter((p) => p !== me && ally(p) && stillPlaying(p)).sort((a, b) => a - b)
|
|
324
|
+
: [];
|
|
325
|
+
const strengthOf = (p) => (armies.get(p) ?? 0) + k * boardIncome(g, held.get(p) ?? new Set(), rules).total;
|
|
326
|
+
const mine = mates.reduce((n, p) => n + strengthOf(p), strengthOf(me));
|
|
327
|
+
// #283: what `mine` is made of.
|
|
328
|
+
const mineFigures = [me, ...mates].reduce((f, p) => ({ armies: f.armies + (armies.get(p) ?? 0), income: f.income + boardIncome(g, held.get(p) ?? new Set(), rules).total }), { armies: 0, income: 0 });
|
|
329
|
+
const open = fullyVisible(g, board);
|
|
330
|
+
const ids = new Set([...held.keys()].filter((p) => !ally(p)));
|
|
331
|
+
for (const p of players)
|
|
332
|
+
if (!ally(p.id) && stillPlaying(p.id))
|
|
333
|
+
ids.add(p.id);
|
|
334
|
+
const rows = [...ids]
|
|
335
|
+
.filter((p) => stillPlaying(p))
|
|
336
|
+
.sort((a, b) => a - b)
|
|
337
|
+
.map((playerId) => {
|
|
338
|
+
const a = armies.get(playerId) ?? 0;
|
|
339
|
+
const income = boardIncome(g, held.get(playerId) ?? new Set(), rules).total;
|
|
340
|
+
const low = a + k * income;
|
|
341
|
+
const seen = { armies: a, income };
|
|
342
|
+
const none = { likely: undefined, source: undefined, why: undefined };
|
|
343
|
+
if (open)
|
|
344
|
+
return { playerId, low, high: low, seen, ...none };
|
|
345
|
+
if (start === null || likelyStart === null || cardsBound === undefined)
|
|
346
|
+
return { playerId, low, high: null, seen, ...none };
|
|
347
|
+
// Each turn's could-earn cap: from that turn's board when I have it, else the ceiling.
|
|
348
|
+
let received = start;
|
|
349
|
+
for (let t = 1; t <= turn; t++)
|
|
350
|
+
received += turnCap(t, playerId);
|
|
351
|
+
const cap = Math.max(income, turnCap(turn, playerId));
|
|
352
|
+
// Cards: what the clock lets it have played by now, and over the next k turns.
|
|
353
|
+
const now = cardsBound ? cardArmiesBy(cardsBound, turn) : 0;
|
|
354
|
+
const ahead = cardsBound ? cardArmiesBy(cardsBound, turn + k) - now : 0;
|
|
355
|
+
const high = Math.max(a, received + now) + k * cap + ahead;
|
|
356
|
+
// #208: the likely high — the same sum at LIKELY_INCOME_MARGIN × its tracked income a turn;
|
|
357
|
+
// #214: only with territory in view now and an observed income, else at the peer-paced
|
|
358
|
+
// prior (`peerPace`). An unmeasured one keeps the margin on its visible income too, and an
|
|
359
|
+
// unseen one measured on earlier boards keeps it on that tracked income: less evidence never
|
|
360
|
+
// reads lower. Both start symmetric (`likelyStart`).
|
|
361
|
+
const tr = trackedOf(playerId);
|
|
362
|
+
const why = !tr || tr.visible === 0 ? 'unseen' : tr.income === null ? 'unmeasured' : undefined;
|
|
363
|
+
const source = why ? 'prior' : 'tracked';
|
|
364
|
+
const own = Math.max(income, LIKELY_INCOME_MARGIN * Math.max(tr?.visibleIncome ?? 0, tr?.income ?? 0));
|
|
365
|
+
const paceAt = (t) => why
|
|
366
|
+
? peerPace({ base: rules.base, mine: myIncomeAt(t), peers: peersAt(t), ceiling: evenShare, floor: own })
|
|
367
|
+
: LIKELY_INCOME_MARGIN * tr.income;
|
|
368
|
+
const pace = paceAt(turn);
|
|
369
|
+
let likelyReceived = likelyStart;
|
|
370
|
+
for (let t = 1; t <= turn; t++)
|
|
371
|
+
likelyReceived += Math.min(turnCap(t, playerId), paceAt(t));
|
|
372
|
+
// An unseen one keeps at least the armies it was last seen with, plus what the same pace
|
|
373
|
+
// paid it on each turn since, and the income it then held: losing sight of a stack bigger
|
|
374
|
+
// than its pace could have paid never reads more hopeful than seeing it.
|
|
375
|
+
const last = why === 'unseen' ? lastSeen(playerId, turn) : undefined;
|
|
376
|
+
let since = last?.armies ?? 0;
|
|
377
|
+
if (last)
|
|
378
|
+
for (let t = last.turn + 1; t <= turn; t++)
|
|
379
|
+
since += Math.min(turnCap(t, playerId), paceAt(t));
|
|
380
|
+
const likely = Math.max(a, likelyReceived + now, since) + k * Math.max(income, last?.income ?? 0, Math.min(cap, pace)) + ahead;
|
|
381
|
+
return { playerId, low, high, seen, likely: Math.min(high, Math.max(low, likely)), source, why };
|
|
382
|
+
});
|
|
383
|
+
// PLAN-TEAMS C3: an enemy team is one side, its figures summed; elsewhere a side is a player.
|
|
384
|
+
const teamOf = (p) => {
|
|
385
|
+
const t = players.find((x) => x.id === p)?.team;
|
|
386
|
+
return teamGame && carriesTeam(t) ? t : undefined;
|
|
387
|
+
};
|
|
388
|
+
const sides = [];
|
|
389
|
+
for (const r of rows) {
|
|
390
|
+
const t = teamOf(r.playerId);
|
|
391
|
+
const side = t === undefined ? undefined : sides.find((x) => x.team === t);
|
|
392
|
+
if (t === undefined)
|
|
393
|
+
sides.push(r);
|
|
394
|
+
else if (!side)
|
|
395
|
+
sides.push({ ...r, seen: { ...r.seen }, team: t, players: [r.playerId] });
|
|
396
|
+
else {
|
|
397
|
+
side.low += r.low;
|
|
398
|
+
side.seen.armies += r.seen.armies;
|
|
399
|
+
side.seen.income += r.seen.income;
|
|
400
|
+
side.high = side.high === null || r.high === null ? null : side.high + r.high;
|
|
401
|
+
side.likely = side.likely === undefined || r.likely === undefined ? undefined : side.likely + r.likely;
|
|
402
|
+
if (r.source === 'prior' && side.source !== 'prior') {
|
|
403
|
+
side.source = 'prior';
|
|
404
|
+
side.why = r.why;
|
|
405
|
+
}
|
|
406
|
+
side.players.push(r.playerId);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
const sideOf = (x) => (x.team !== undefined ? { team: x.team, players: x.players } : {});
|
|
410
|
+
const maxLow = sides.reduce((m, r) => Math.max(m, r.low), 0);
|
|
411
|
+
const unbounded = sides.some((r) => r.high === null);
|
|
412
|
+
const maxHigh = sides.reduce((m, r) => Math.max(m, r.high ?? 0), 0);
|
|
413
|
+
const top = [...sides].sort((a, b) => (a.high === null ? 0 : 1) - (b.high === null ? 0 : 1) || (b.high ?? 0) - (a.high ?? 0) || b.low - a.low || a.playerId - b.playerId)[0];
|
|
414
|
+
const strongest = top ? { playerId: top.playerId, low: top.low, high: top.high, ...sideOf(top) } : null;
|
|
415
|
+
const ratio = {
|
|
416
|
+
low: !unbounded && maxHigh > 0 ? round2(mine / maxHigh) : 0,
|
|
417
|
+
high: maxLow > 0 ? round2(mine / maxLow) : null,
|
|
418
|
+
};
|
|
419
|
+
// #208: the highest likely high, when every opponent is bounded and one is not in full view.
|
|
420
|
+
let likely;
|
|
421
|
+
if (!unbounded && !open && sides.length) {
|
|
422
|
+
const top = [...sides].sort((a, b) => (b.likely ?? 0) - (a.likely ?? 0) || a.playerId - b.playerId)[0];
|
|
423
|
+
const high = top.likely ?? 0;
|
|
424
|
+
likely = {
|
|
425
|
+
playerId: top.playerId,
|
|
426
|
+
...sideOf(top),
|
|
427
|
+
high,
|
|
428
|
+
ratio: high > 0 ? round2(mine / high) : 0,
|
|
429
|
+
source: top.source ?? 'tracked',
|
|
430
|
+
...(top.why ? { why: top.why } : {}),
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
// Every opponent bounded at no strength at all while I have some: dominated.
|
|
434
|
+
const dominated = sides.length > 0 && !unbounded && maxHigh === 0 && mine > 0;
|
|
435
|
+
const prev = byTurn.get(turn - 1)?.board;
|
|
436
|
+
let changed = null;
|
|
437
|
+
if (prev) {
|
|
438
|
+
const before = ownersOf(g, prev);
|
|
439
|
+
const after = ownersOf(g, board);
|
|
440
|
+
changed = [...after].filter(([t, o]) => before.has(t) && before.get(t) !== o).length;
|
|
441
|
+
}
|
|
442
|
+
// The first entry per territory, as a linear find would read it.
|
|
443
|
+
const ownerById = new Map();
|
|
444
|
+
for (const x of board.territories)
|
|
445
|
+
if (!ownerById.has(x.territoryId))
|
|
446
|
+
ownerById.set(x.territoryId, x.owner);
|
|
447
|
+
const front = [...(held.get(me) ?? [])].some((t) => neighborsOf(g, t).some((n) => {
|
|
448
|
+
const o = ownerById.get(n);
|
|
449
|
+
return o?.kind === 'player' && !ally(o.playerId);
|
|
450
|
+
}));
|
|
451
|
+
// #201: the main front, forecast forward. #218: the planner's definition (`mainFront`), and on
|
|
452
|
+
// the turn being played the planner's incomes (`input.front`, the plan's `front`), so the plan's
|
|
453
|
+
// front outlook and this forecast are one computation.
|
|
454
|
+
const enemies = [];
|
|
455
|
+
for (const t of board.territories) {
|
|
456
|
+
if (!g.territoryById.has(t.territoryId) || t.armies == null || ownerById.get(t.territoryId) !== t.owner)
|
|
457
|
+
continue;
|
|
458
|
+
if (t.owner.kind !== 'player' || ally(t.owner.playerId))
|
|
459
|
+
continue;
|
|
460
|
+
enemies.push({ id: t.territoryId, armies: t.armies + unitsOn(board, t.territoryId), player: t.owner.playerId });
|
|
461
|
+
}
|
|
462
|
+
const armiesById = new Map();
|
|
463
|
+
for (const t of board.territories)
|
|
464
|
+
if (!armiesById.has(t.territoryId))
|
|
465
|
+
armiesById.set(t.territoryId, t.armies ?? 0);
|
|
466
|
+
const mineNow = held.get(me) ?? new Set();
|
|
467
|
+
const main = mainFront(g, (x) => mineNow.has(x), enemies, (x) => (armiesById.get(x) ?? 0) + unitsOn(board, x));
|
|
468
|
+
let forecast;
|
|
469
|
+
// #228 review: the front on my boards' incomes, for losing on the estimate (equal to `forecast`
|
|
470
|
+
// unless the plan's incomes are given), so the plan's read and the reported one share the state.
|
|
471
|
+
let ownOutcome;
|
|
472
|
+
if (main) {
|
|
473
|
+
const given = input.front && input.front.turn === turn && input.front.from === main.from && input.front.at === main.at ? input.front : undefined;
|
|
474
|
+
// Their income: the plan's estimate on the turn being played; else what the tracker reads
|
|
475
|
+
// off my boards (its tracked income, its visible income at least).
|
|
476
|
+
const tr = given ? undefined : trackedAll().get(main.player);
|
|
477
|
+
const myIncome = given?.myIncome ?? boardIncome(g, mineNow, rules).total;
|
|
478
|
+
const theirIncome = given?.theirIncome ?? Math.max(boardIncome(g, held.get(main.player) ?? new Set(), rules).total, tr?.income ?? 0);
|
|
479
|
+
const forecastAt = (mineIncome, foeIncome) => forecastBorder({
|
|
480
|
+
mine: main.mine,
|
|
481
|
+
theirs: main.theirs,
|
|
482
|
+
myIncome: mineIncome,
|
|
483
|
+
theirIncome: foeIncome,
|
|
484
|
+
outcomeOnly: true,
|
|
485
|
+
settings: {
|
|
486
|
+
...(settings.offensiveKillRate !== undefined ? { offensiveKillRate: settings.offensiveKillRate } : {}),
|
|
487
|
+
...(settings.defensiveKillRate !== undefined ? { defensiveKillRate: settings.defensiveKillRate } : {}),
|
|
488
|
+
...(settings.oneArmyStandsGuard !== undefined ? { oneArmyStandsGuard: settings.oneArmyStandsGuard } : {}),
|
|
489
|
+
},
|
|
490
|
+
});
|
|
491
|
+
const f = forecastAt(myIncome, theirIncome);
|
|
492
|
+
if (!given)
|
|
493
|
+
ownOutcome = f.outcome;
|
|
494
|
+
else {
|
|
495
|
+
const own = trackedAll().get(main.player);
|
|
496
|
+
ownOutcome = forecastAt(boardIncome(g, mineNow, rules).total, Math.max(boardIncome(g, held.get(main.player) ?? new Set(), rules).total, own?.income ?? 0)).outcome;
|
|
497
|
+
}
|
|
498
|
+
forecast = {
|
|
499
|
+
mine: main.mine,
|
|
500
|
+
theirs: main.theirs,
|
|
501
|
+
player: main.player,
|
|
502
|
+
from: main.from,
|
|
503
|
+
at: main.at,
|
|
504
|
+
myIncome,
|
|
505
|
+
theirIncome,
|
|
506
|
+
incomeSource: given ? 'plan' : tr?.income != null && tr.income > boardIncome(g, held.get(main.player) ?? new Set(), rules).total ? 'tracked' : 'visible',
|
|
507
|
+
outcome: f.outcome,
|
|
508
|
+
turn: f.turn,
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
const bound = dominated || (sides.length > 0 && ratio.low >= OUTLOOK_RATIO);
|
|
512
|
+
const estimated = !bound && likely !== undefined && likely.high > 0 && likely.ratio >= OUTLOOK_RATIO;
|
|
513
|
+
const lostOnBound = !bound && !estimated && ratio.high !== null && ratio.high <= 1 / OUTLOOK_RATIO;
|
|
514
|
+
// #228: losing on the likely high — far below it (LIKELY_LOSING_RATIO, its margin taken back
|
|
515
|
+
// out), and corroborated: the likely high alone reads every fogged opponent strong (it counts
|
|
516
|
+
// every army received and none lost, so a game I lead can read 0.05×). Corroborated by the
|
|
517
|
+
// main front grinding me down, or by my income at most BEHIND_RATIO × the most an opponent is
|
|
518
|
+
// tracked earning (the profile's "behind").
|
|
519
|
+
// PLAN-TEAMS C3: in a team game my team's income, against the most an enemy team is tracked earning.
|
|
520
|
+
const myNow = mates.reduce((n, p) => n + boardIncome(g, held.get(p) ?? new Set(), rules).total, boardIncome(g, mineNow, rules).total);
|
|
521
|
+
const mostTracked = () => {
|
|
522
|
+
const by = new Map();
|
|
523
|
+
for (const [p, tr] of trackedAll()) {
|
|
524
|
+
if (ally(p) || tr.income === null)
|
|
525
|
+
continue;
|
|
526
|
+
const t = teamOf(p);
|
|
527
|
+
const key = t === undefined ? `p${p}` : `t${t}`;
|
|
528
|
+
by.set(key, (by.get(key) ?? 0) + tr.income);
|
|
529
|
+
}
|
|
530
|
+
let most = 0;
|
|
531
|
+
for (const v of by.values())
|
|
532
|
+
most = Math.max(most, v);
|
|
533
|
+
return most;
|
|
534
|
+
};
|
|
535
|
+
const lowLikely = !bound && !estimated && !lostOnBound && likely !== undefined && likely.high > 0 && likely.ratio <= LIKELY_LOSING_RATIO;
|
|
536
|
+
// #228 review: on my boards' incomes, whatever the plan gave the reported front.
|
|
537
|
+
const groundDown = ownOutcome === 'ground-down';
|
|
538
|
+
const incomeBehind = lowLikely && mostTracked() > 0 && myNow <= BEHIND_RATIO * mostTracked();
|
|
539
|
+
const lostOnEstimate = lowLikely && (groundDown || incomeBehind);
|
|
540
|
+
// #304: what the state rests on — the two incomes compared and each opponent's frontier read.
|
|
541
|
+
// Reporting only: nothing above reads it.
|
|
542
|
+
const evidenceRows = rows.map((r) => {
|
|
543
|
+
const tr = trackedOf(r.playerId);
|
|
544
|
+
const tracked = tr?.income ?? null;
|
|
545
|
+
const cov = tr?.coverage ?? null;
|
|
546
|
+
return {
|
|
547
|
+
playerId: r.playerId,
|
|
548
|
+
income: tracked ?? r.seen.income,
|
|
549
|
+
source: tracked !== null ? 'tracked' : 'visible',
|
|
550
|
+
coverage: cov ? round2(cov.share) : null,
|
|
551
|
+
thin: !open && (cov === null || cov.share < LOW_COVERAGE),
|
|
552
|
+
...(cov ? { read: coverageText(cov) } : {}),
|
|
553
|
+
};
|
|
554
|
+
});
|
|
555
|
+
const compared = likely ? sides.find((x) => x.playerId === likely.playerId) : top;
|
|
556
|
+
const comparedRows = compared ? evidenceRows.filter((r) => (compared.players ?? [compared.playerId]).includes(r.playerId)) : [];
|
|
557
|
+
const evidence = {
|
|
558
|
+
incomes: compared
|
|
559
|
+
? {
|
|
560
|
+
mine: myNow,
|
|
561
|
+
theirs: comparedRows.reduce((n, r) => n + r.income, 0),
|
|
562
|
+
playerId: compared.playerId,
|
|
563
|
+
...sideOf(compared),
|
|
564
|
+
source: comparedRows.some((r) => r.source === 'tracked') ? 'tracked' : 'visible',
|
|
565
|
+
}
|
|
566
|
+
: null,
|
|
567
|
+
opponents: evidenceRows,
|
|
568
|
+
thin: evidenceRows.some((r) => r.thin),
|
|
569
|
+
};
|
|
570
|
+
const state = bound || estimated
|
|
571
|
+
? 'winning'
|
|
572
|
+
: lostOnBound || lostOnEstimate
|
|
573
|
+
? 'losing'
|
|
574
|
+
: changed === 0 && front && (!forecast || forecast.outcome === 'stand-off')
|
|
575
|
+
? 'stalemate'
|
|
576
|
+
: 'even';
|
|
577
|
+
return {
|
|
578
|
+
turn,
|
|
579
|
+
mine,
|
|
580
|
+
...(teamGame ? { minePlayers: [me, ...mates] } : {}),
|
|
581
|
+
strongest,
|
|
582
|
+
ratio,
|
|
583
|
+
...(likely ? { likely } : {}),
|
|
584
|
+
figures: { mine: mineFigures, strongest: top ? { ...top.seen } : null },
|
|
585
|
+
changed,
|
|
586
|
+
...(forecast ? { front: forecast } : {}),
|
|
587
|
+
state,
|
|
588
|
+
...(estimated || lostOnEstimate ? { estimated: true } : {}),
|
|
589
|
+
...(lowLikely ? { lowLikely: { myIncome: myNow, mostTracked: mostTracked(), groundDown, losing: lostOnEstimate } } : {}),
|
|
590
|
+
evidence,
|
|
591
|
+
};
|
|
592
|
+
});
|
|
593
|
+
const last = turns.at(-1);
|
|
594
|
+
let heldTurns = 0;
|
|
595
|
+
for (let i = turns.length - 1; i >= 0 && turns[i].state === last?.state; i--)
|
|
596
|
+
heldTurns++;
|
|
597
|
+
const state = last && heldTurns >= OUTLOOK_TURNS ? last.state : null;
|
|
598
|
+
const measure = teamGame
|
|
599
|
+
? `Strength = armies + ${k} × income; an opponent's is a range under fog (low: what is in view; high: the most it could have received and earn). By team: my team's strength (mine and my teammates' still playing) against the strongest enemy team's, each the sum of its players'; summed, a teammate's transfers stay inside its team's high.`
|
|
600
|
+
: `Strength = armies + ${k} × income; an opponent's is a range under fog (low: what is in view; high: the most it could have received and earn). Per player: my strength alone against the single strongest opponent, teams not summed.`;
|
|
601
|
+
/** PLAN-TEAMS C3: how a side is named — an enemy team with its players, else the player. */
|
|
602
|
+
const sideName = (x) => x.team !== undefined ? `team ${x.team} (players ${x.players.join(', ')})` : `player ${x.playerId}`;
|
|
603
|
+
const cap = (t) => `${t[0].toUpperCase()}${t.slice(1)}`;
|
|
604
|
+
const thresholds = `Winning at ${OUTLOOK_RATIO}× the strongest opponent or more even at its high, losing at 1/${OUTLOOK_RATIO} (${round2(1 / OUTLOOK_RATIO)}×) or less even at its low (or, on an estimate under fog, at ${round2(LIKELY_LOSING_RATIO)}× or less of its likely strength while the main front grinds me down or my income is at most ${BEHIND_RATIO}× the most an opponent is tracked earning), stalemate when nothing in view changed hands for ${OUTLOOK_TURNS} turns along a front whose forecast is a stand-off. The ${OUTLOOK_RATIO}× is borrowed from a bot and was never measured for war.app: a basis for a decision, not a verdict.`;
|
|
605
|
+
// PLAN-TEAMS C3: in a team game the thresholds are against the strongest enemy team.
|
|
606
|
+
const thresholdsText = teamGame
|
|
607
|
+
? thresholds.replace(/the strongest opponent/g, 'the strongest enemy team').replace('my income is at most', "my team's income is at most").replace('the most an opponent is tracked earning', 'the most an enemy team is tracked earning')
|
|
608
|
+
: thresholds;
|
|
609
|
+
let reading;
|
|
610
|
+
if (!last)
|
|
611
|
+
reading = 'No board to judge.';
|
|
612
|
+
else {
|
|
613
|
+
const s = last.strongest;
|
|
614
|
+
const figures = s
|
|
615
|
+
? `turn ${last.turn}: ${teamGame ? `my team's ${last.mine}, the strongest enemy ${s.team !== undefined ? `team, ${sideName(s)}` : sideName(s)}` : `mine ${last.mine}, the strongest opponent player ${s.playerId}`} at ${s.high === s.low ? s.low : `${s.low}–${s.high ?? 'unbounded'}`}, ratio ${last.ratio.high === last.ratio.low ? last.ratio.low : `${last.ratio.low}–${last.ratio.high ?? 'unbounded'}`}×`
|
|
616
|
+
: `turn ${last.turn}: mine ${last.mine}, no opponent to compare`;
|
|
617
|
+
// #208: the likely high, said as what it is; #214: a prior says so and why, and an estimate
|
|
618
|
+
// that does not show a win names the opponent that blocks it.
|
|
619
|
+
const l = last.likely;
|
|
620
|
+
const rests = l?.source === 'prior'
|
|
621
|
+
? `for ${sideName(l)} a prior (${l.why === 'unmeasured' ? 'no observed income: no pair of my boards measured its deploy' : 'no territory in view now'}), paced by its peers: it starts as a symmetric opening, and each turn earns ${LIKELY_INCOME_MARGIN === 2 ? 'twice' : `${LIKELY_INCOME_MARGIN}×`} the higher of my income that turn (ramped up from the opening's before my first board) and the most any opponent was tracked earning by then (the base income at least), at most an even share of the map's income (${evenShare}) and that turn's cap, and at least ${LIKELY_INCOME_MARGIN}× its visible income (and any income tracked earlier)${l.why === 'unmeasured' ? '' : ', and at least the armies and income it held when last in view'}`
|
|
622
|
+
: `each turn at most ${LIKELY_INCOME_MARGIN}× the income the tracker reads off my boards`;
|
|
623
|
+
let est = '';
|
|
624
|
+
if (l && (l.high !== s?.high || l.source === 'prior'))
|
|
625
|
+
est = ` The likely high — an estimate, not a bound: ${rests} — is ${sideName(l)} at ${l.high}, ratio ${l.ratio}×${last.estimated ? `; ${last.state} rests on it` : ''}.`;
|
|
626
|
+
if (l && l.high > 0 && last.state !== 'winning')
|
|
627
|
+
est += ` ${cap(sideName(l))} blocks a win on the estimate: winning needs mine at ${OUTLOOK_RATIO}× its likely high (${round2(OUTLOOK_RATIO * l.high)}), and mine is ${last.mine}.`;
|
|
628
|
+
reading =
|
|
629
|
+
turns.length < OUTLOOK_TURNS
|
|
630
|
+
? `Only ${turns.length} turn${turns.length === 1 ? '' : 's'} of boards in a row (${OUTLOOK_TURNS} needed), so no state yet; ${figures}.`
|
|
631
|
+
: state
|
|
632
|
+
? `${state[0].toUpperCase()}${state.slice(1)} for ${OUTLOOK_TURNS} turns running; ${figures}.`
|
|
633
|
+
: `${last.state[0].toUpperCase()}${last.state.slice(1)} for ${heldTurns} of the ${OUTLOOK_TURNS} turns (${turns.map((t) => t.state).join(', ')}), so no state yet; ${figures}.`;
|
|
634
|
+
// #304: the incomes compared and each opponent's frontier read, said beside the state, and thin
|
|
635
|
+
// evidence named so that "even" does not read as safe.
|
|
636
|
+
const ev = last.evidence;
|
|
637
|
+
if (ev?.incomes) {
|
|
638
|
+
const i = ev.incomes;
|
|
639
|
+
reading += ` Incomes compared: ${teamGame ? "my team's" : 'mine'} ${i.mine}, ${sideName(i)}'s ${i.theirs} (${i.source === 'tracked' ? 'tracked off my boards' : 'in view, a lower bound under fog'}).`;
|
|
640
|
+
}
|
|
641
|
+
if (ev && !fullyVisible(g, byTurn.get(last.turn).board) && ev.opponents.length)
|
|
642
|
+
reading += ` Frontier read: ${ev.opponents.map((r) => `player ${r.playerId} ${r.read ?? 'not measured'}`).join('; ')}.`;
|
|
643
|
+
if (ev?.thin) {
|
|
644
|
+
const pct = Math.round(LOW_COVERAGE * 100);
|
|
645
|
+
const which = ev.opponents
|
|
646
|
+
.filter((r) => r.thin)
|
|
647
|
+
.map((r) => `player ${r.playerId} (${r.coverage === null ? 'not measured' : `${Math.round(r.coverage * 100)}%`})`)
|
|
648
|
+
.join(', ');
|
|
649
|
+
reading += ` Thin evidence: the income of ${which} was read from under ${pct}% of its frontier, so "${last.state}" is not a safe reading: an opponent may be stronger than the fog shows.`;
|
|
650
|
+
}
|
|
651
|
+
reading += est;
|
|
652
|
+
// #228: a likely ratio far below parity, said with what it took (or lacked) to read losing.
|
|
653
|
+
const low = last.lowLikely;
|
|
654
|
+
if (low) {
|
|
655
|
+
const share = `mine is at most 1/${round2(1 / LIKELY_LOSING_RATIO)} (${round2(LIKELY_LOSING_RATIO)}×) of the likely high`;
|
|
656
|
+
const incomeText = low.mostTracked > 0
|
|
657
|
+
? teamGame
|
|
658
|
+
? `my team's income (${low.myIncome}) at most ${BEHIND_RATIO}× the most an enemy team is tracked earning (${low.mostTracked})`
|
|
659
|
+
: `my income (${low.myIncome}) at most ${BEHIND_RATIO}× the most an opponent is tracked earning (${low.mostTracked})`
|
|
660
|
+
: '';
|
|
661
|
+
const behind = low.mostTracked > 0 && low.myIncome <= BEHIND_RATIO * low.mostTracked;
|
|
662
|
+
reading += low.losing
|
|
663
|
+
? ` Losing on the estimate: ${share}, corroborated by ${[low.groundDown ? 'the main front grinding me down on the incomes read off my boards' : '', behind ? incomeText : ''].filter(Boolean).join(' and ')}.`
|
|
664
|
+
: ` ${share[0].toUpperCase()}${share.slice(1)}, but that alone is no loss: the likely high counts every army an opponent could have received at ${LIKELY_INCOME_MARGIN}× its pace and none it lost, so it reads every fogged opponent strong. Losing on it needs the main front grinding me down on the incomes read off my boards (not the plan's, so the plan acts on the state shown) or my income at most ${BEHIND_RATIO}× the most an opponent is tracked earning${low.mostTracked > 0 ? ` (mine ${low.myIncome}, the most tracked ${low.mostTracked})` : ' (none is tracked)'}.`;
|
|
665
|
+
}
|
|
666
|
+
// #228: the plan's profile standing is a different measure (incomes, then the armies in view).
|
|
667
|
+
const standing = input.standing;
|
|
668
|
+
if ((last.state === 'even' || last.state === 'stalemate') && (standing === 'ahead' || standing === 'behind'))
|
|
669
|
+
reading += ` The profile's standing reads ${standing} (my income against the strongest opponent's estimate, overruled by the armies in view); this outlook reads ${last.state} because neither the winning nor the losing threshold was met on strength (armies + ${k} × income, and the likely high), a stricter test for a decided game.`;
|
|
670
|
+
// #218: the main front, said with what it assumes, so it reads with the plan's front outlook.
|
|
671
|
+
const fr = last.front;
|
|
672
|
+
if (fr) {
|
|
673
|
+
const theirs = fr.incomeSource === 'plan'
|
|
674
|
+
? "the plan's estimate"
|
|
675
|
+
: fr.incomeSource === 'tracked'
|
|
676
|
+
? 'tracked off my boards'
|
|
677
|
+
: 'its visible income, a lower bound under fog';
|
|
678
|
+
const outcome = fr.outcome === 'ground-down'
|
|
679
|
+
? `I am ground down on turn ${fr.turn}`
|
|
680
|
+
: fr.outcome === 'breaks'
|
|
681
|
+
? `my stack breaks it on turn ${fr.turn}`
|
|
682
|
+
: `a stand-off over ${FORECAST_TURNS} turns`;
|
|
683
|
+
reading += ` The main front (the biggest enemy stack next to me against my biggest beside it), each side deploying its whole income there every turn (mine ${fr.myIncome}, player ${fr.player}'s ${fr.theirIncome}: ${theirs}): my ${fr.mine} on #${fr.from} against its ${fr.theirs} on #${fr.at}, ${outcome}.`;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
return {
|
|
687
|
+
state,
|
|
688
|
+
heldTurns,
|
|
689
|
+
turns,
|
|
690
|
+
k,
|
|
691
|
+
threshold: OUTLOOK_RATIO,
|
|
692
|
+
basis: `${reading} ${measure} ${thresholdsText}`,
|
|
693
|
+
...(last?.evidence ? { evidence: last.evidence } : {}),
|
|
694
|
+
};
|
|
695
|
+
}
|