@chrischall/warapp-mcp 0.14.0 → 0.16.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 +2 -0
- package/dist/analysis/income-calibration.js +280 -0
- package/dist/analysis/intel.js +1 -1
- package/dist/analysis/opponents.js +52 -3
- package/dist/analysis/plan/deploy-estimates.js +1 -1
- package/dist/analysis/plan/estimates.js +40 -6
- package/dist/analysis/plan/threats.js +1 -1
- package/dist/bundle.js +1716 -497
- package/dist/decision-log.js +44 -5
- package/dist/finished-store.js +41 -0
- package/dist/tools/calibration-harness.js +102 -0
- package/dist/tools/calibration.js +110 -0
- package/dist/tools/check-plan.js +23 -1
- package/dist/tools/common.js +14 -0
- package/dist/tools/decision-capture.js +14 -1
- package/dist/tools/end-of-game.js +86 -14
- package/dist/tools/index.js +6 -0
- package/dist/tools/opponents.js +2 -0
- package/dist/tools/state.js +30 -4
- package/dist/tools/stress-opponents.js +8 -4
- package/dist/tools/turn-history.js +214 -0
- package/dist/tools/turn.js +25 -7
- package/dist/turn-orders.js +64 -0
- package/dist/version.js +1 -1
- package/manifest.json +9 -1
- package/package.json +1 -1
- package/server.json +2 -2
- package/skills/warapp-mcp/SKILL.md +9 -1
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
},
|
|
8
8
|
"metadata": {
|
|
9
9
|
"description": "MCP server for war.app (Warzone) — your games, players, settings, map bonuses and chokepoints, board analysis and route planning through war.app's per-player GameFeed API, plus the live board, territory picks, cards, turn planning and submission, turn notifications and game chat through your signed-in war.app tab (joining, leaving or surrendering a game, closing out a finished game, accepting another player's surrender, Begin on a speed first turn, picks, turn orders, withdrawing them, chat sends, marking notifications and chat read, deleting notifications, importing local history and linking a session are confirm-gated).",
|
|
10
|
-
"version": "0.
|
|
10
|
+
"version": "0.16.0"
|
|
11
11
|
},
|
|
12
12
|
"plugins": [
|
|
13
13
|
{
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"displayName": "war.app (Warzone)",
|
|
16
16
|
"source": "./",
|
|
17
17
|
"description": "war.app (Warzone) game advisor for Claude — games, maps, bonuses, routes, live board, picks, turns, cards and chat",
|
|
18
|
-
"version": "0.
|
|
18
|
+
"version": "0.16.0",
|
|
19
19
|
"author": {
|
|
20
20
|
"name": "Chris Hall"
|
|
21
21
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "warapp-mcp",
|
|
3
3
|
"displayName": "war.app (Warzone)",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.16.0",
|
|
5
5
|
"description": "war.app (Warzone) game advisor for Claude — games, maps, bonuses, routes, live board, picks, turns, cards and chat",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Chris Hall",
|
package/README.md
CHANGED
|
@@ -155,6 +155,7 @@ Locally `WARAPP_AUTH_TOKEN` is ignored.
|
|
|
155
155
|
| `warapp_get_my_orders` | Your orders for the current turn read back from war.app (what the web client shows in "Modify orders"), read-only: `committed`, `orders` in exactly the shape `warapp_submit_turn` takes (card GUIDs and targets, players by GameFeed id, move options, Order Delay `before`) and `shown` (one line per order, with names). Resubmit them after `warapp_uncommit_turn` to change a committed turn without losing hand-made orders. `null` is unknown, never "none"; `unread` lists orders it could not read back. Committed orders verified live 2026-11-22; entered-but-uncommitted ones unverified. |
|
|
156
156
|
| `warapp_plan_turn` | A plan for your turn from the live board (defaults to the signed-in account): income, your cards and whether you must play one, deploys and moves by name and id, expected captures, bonuses and next income, the `frontier` budget (borders left, those facing an enemy, what they need to hold next turn, next income), warnings and reasoning, and an `orders` array (card plays included); `chat.unread` counts the chat messages not yet marked seen (counts only, from GameFeed, so every count is under `unknown`; its `note` says so); `surrenderPending` lists other players' surrenders still pending (from the game details, unverified live; `null` when unreadable), and when one waits on your acceptance the first warning says so. `goal`: balanced (default: best income per army across holds, bonuses and breaking enemy bonuses, with at least 30% on expansion) / expand / complete-bonus / defend / siege (one opponent, `siege_target` by GameFeed id, default the strongest one bordering you: its bonus breaks are funded cheapest per income lost first, its other territories are left alone and the spare deploys build one strike stack facing it until the assault trigger fires — its income at 0.6× its baseline — the most the tracker saw it deploy over its window, or its income when the siege began — yours at 1.8× its, or a stack of yours able to take a member of its held bonus against its whole deploy — then the stack strikes; `siege` reports `target`, `opponentIncome`, `baseline`, `ratio`, `fallenTo`, `breaks`, `brokenThisTurn`, `ready`, `trigger` and `memory` — the siege's first turn, its turns, the target's income trend and the bonuses broken and broken again, kept per game while the siege runs, a gap of more than 3 turns starting a new one) — omit it and the game profile (`profile`: the One Army Must Stand Guard case and what it means for interior defence, format, phase, standing) picks it: siege when it fits — in contact and not ahead, against one opponent (in an FFA the leader, earning 1.5× any other opponent beside you) with a bonus break in view costing at most twice its value and at most your income; the plan's reported `goal` is then `siege` (with no `goal` passed it may read `siege` where it read `balanced` or `defend` before: an additive value, so a caller should accept it) and `siege.auto` is set, a line saying why the profile chose the siege (the break that made it fit); `siege.auto` is absent when you passed `goal: 'siege'` yourself; once the assault trigger fires the profile hands back to its own goal (a rationale line says so, and there is no `siege` block) — else defend when behind on income outside a 1v1, else balanced tuned to the format (1v1 in contact: holds and breaks before expansion that completes nothing; behind on income in a 1v1: strike — break their bonuses, inferred ones too, sized to land; behind on armies: no trade below even; in a 1v1, spare deploys build one strike stack facing the opponent; FFA: no second front; ahead in a 1v1: more fog pressure); an explicit goal overrides it; `focus` bonuses; `reserve`; `enemy_deploy` (armies an enemy is assumed to deploy; default per opponent from its visible bonuses, or what it was observed to deploy when that is larger — its tracked income, carried across turns, once `warapp_track_opponents` has 2+ turns of it; growth beside the fog beyond twice what it was expected to deploy reads as a move out of the fog, not a deploy; in an even-start 1v1 or free-for-all an opponent bordering the fog is assumed to earn at least your income, a player out of a free-for-all having its share of the hidden board split among the rest; while its income was read from under half its frontier, an opponent is sized at the midpoint between its lower bound — its tracked figure, raised to its trend's next step when its tracked income rose two turns running — and its upper bound — that fog prior, else the most it could earn — moving toward what the evidence gives as more of its frontier is read; a rising track read from more of its frontier raises it to that lower bound); the `outlook` adds `leaning: behind` when it read even for 3 turns while a bonus of yours fell on each; `known_income` (per-player incomes you know, by GameFeed id — what a player said in chat, say: each replaces that opponent's estimate, a Reinforcement card the clock adds kept on top, said in its warning; `enemy_deploy` wins over it; the commander block keeps the submit's sizing); `min_win_chance` (0.5–1; default 1 = certain captures with no luck, 0.95 with luck on; below 1, each capture is sized for that exact win chance, and the captures a bonus still needs reach it together); `first_mover` (`me` or `opponent`, when you know who moves first this turn — Cycle move orders swap the first mover every turn; when you move first, Order Priority is not advised; the same argument as `warapp_check_plan`'s). Every attack carries `winChance` (its exact probability of capturing at the game's kill rates, luck and rounding); idle armies top an attack up to its next efficient size when the extra kill can matter. Reports the borders it gives up (`conceded`: not worth or not affordable to hold, never deployed to unless every territory you hold is conceded; it may still attack out with the armies already on it; an idle interior stack beside one that would make it hold transfers in, and it is then held), `cardAdvice` (`order-priority` when you hold one and it protects your first order: a commander strike while your commander is threatened, or a move out of a conceded border carrying enough armies to be worth a card — any size when the card must go anyway; never when `first_mover` is `me`; otherwise `order-delay` when you hold Order Delay and the schedule puts an attack last — the orders then carry the card with `before`, placed above the first non-urgent order, see `cards.advice.orderDelay`; an Order Delay that must leave the hand is played there rather than discarded), `cards.advice` for the cards `warapp_submit_turn` plays but the plan never does — `diplomacy` (the opponent tying down most of your border armies, only with two or more in contact, never a truce partner the truce already covers unless the card adds protection), `sanctions` (the leader, passing over a truce partner or a player a Diplomacy card keeps at peace with you, with the reason; yourself when the game's Sanctions percentage is negative — the card then raises the target's income — with `income`: your next income before and after the boost, by the client's rule (not under Local Deployment); never a negative card on an opponent nor a positive one on you), `airlift` (a border of yours or a teammate's that falls without it), `gift` (the members that complete a teammate's bonus), `spy` / `reconnaissance` / `surveillance` (only where the fog hides what the plan needs: an opponent out of view, a hidden territory on your border, a fogged member of a bonus you are completing; never with fog off) — each with an `order` to pass as is, never added to the orders save a completing `gift` (its play verified live 2026-11-23, #435: its card plays go into `orders` and the transfers out of or into the gifted members are dropped; never a territory with a special unit such as your commander, never one an attack leaves from) and a Reconnaissance (in a team game only cards read under you are played, discarded or advised; unverified live) and `trendSource` (where last turn's board came from — `history`, `cache` or null — for growing enemy stacks). Obeys the game's kill rates, Local Deployment and No-Split (`view: "full"` echoes the settings it assumed: `idleTransfers`, the planner's own switch for moving idle armies, beside the game's own `allowTransferOnly` and `allowAttackOnly`, `null` when GameFeed does not state them). Read-only; refuses outside a turn phase. In a Commanders game a commander counts as 7 armies, your commander's territory is never conceded (it gets the deploys it needs to hold against the worst case — the opponent's whole deploy, at least your own income, plus every enemy stack within two moves — or every army when that is not enough), and an adjacent enemy commander is attacked first, sized for its owner's full deploy. Within three moves of an enemy or the fog, with a safer territory of yours reachable, your commander walks one step a turn toward safety: a move in `orders` with `commander: true` (encoding not yet verified live), said in the first warning; the territory it leaves is held only for its own worth, plus what survives the attacks that may land before the walk (every enemy stack beside it, even when you move first: `warapp_submit_turn` checks both move orders; when that does not fit, each player's strongest attack, with the walk as your first order), no other order leaves it before the walk but a strike that ends a player, and Order Priority is advised for the walk only when even that falls short or the fog borders it; under No-Split a commander kill the walk displaces is named in a warning. Every turn of such a game `commander` reports your commander (#274): its territory, the armies there after the plan, `movesToEnemy` (to the nearest enemy or fog), `killedBy` (the smallest deploy, made by each opponent at once, at which a reply kills it: `player`, and `partner` when it is two opponents striking together; null when none reaches it this turn), and `safe` / `needs` at the larger of the estimate and your income; when it is not safe the first warning says so and whether `warapp_submit_turn` would refuse those orders (it does not without Commanders in the settings, nor when only an `enemy_deploy` what-if makes the commander unsafe). When the server kept your pick list, `award` says what the award of picks showed: the territories of your list that are another player's start for certain (in a two-player game planned as the opponent's while still fogged), whether you were awarded first or second and who moves first this turn under a `Cycle` move order, and with commanders the opponent's first award when the award pins it. `relations` reports each truce recorded with `warapp_record_agreement` as the plan treated it (honoured in a free-for-all; in a team or two-player game only its covered territories stay off-limits): while active or in notice no covered territory of the partner is attacked, a covered border facing only the partner is held against its stacks without a deploy (never your commander's, a border worth more than a quarter of your income, or any while trust is `watch`), and a border cap is kept: no move of yours fills that border past it, and the excess moves one step back (a warning when your own deploy for a hold is what exceeds it — deploy less, or give notice and ask before exceeding it — or when the cap leaves a border that also faces another opponent, or your commander's, short of its hold); `advice` says `give-notice` when the endgame or the partner outgrowing you made the trust `watch`; a truce the board shows broken is planned as an ordinary opponent, with the evidence (record it as `broken-by-them` before submitting: `warapp_submit_turn` reads only the ledger); each honoured truce reports `lossIfBroken` (what you would lose this turn if the partner landed its whole deploy beside your costliest covered territory, from any territory of its there, and attacked, carried out against the plan's orders: territories, armies, bonuses and income; logged per turn in the ledger beside the armies it freed); `tacit` lists quiet borders with no agreement (a report, never a truce). A Diplomacy card in effect between you and a player, read from the live board, is honoured in any format (that player is no threat and no target this turn), and Sanctions on you cut the plan's income (Sanctions on an opponent cut its estimate when that is read off the board, `sanctionsOnOthers`), when the decoder is sure of them (the card in play, its expiry within the game's duration); `cardsInEffect` lists them, marked `verified: false` (the active-card decoder is not yet checked live). Otherwise a warning says what was read and why it was not relied on. In a team game a bonus with a teammate's territory in it is never planned toward (a bonus pays one holder), and `team.sharedBonuses` lists each bonus you and a teammate both hold members of and who is `nearer` to holding it (advisory; team vision unverified). With your teammate's entered orders on the live board (unverified live): of two otherwise equal captures the one on the opponent they attack goes first (a "Team focus" rationale line); `team.support` lists a teammate's border that falls given their orders where your idle armies beside it would make it hold (each idle army offered to one border only, the border needing fewest first: the most borders held, not the most worth); `team.jointCaptures` a target neither of you takes alone but both together, resolved on the turn simulator in both orders (under a cyclic move order, `mustGoFirst`); and `cards.team` says who plays each card of the team hand — a card your teammate has entered is left to them and kept out of your plays. Support and joint captures are advice only (a move onto a teammate's territory is unverified live): never in `orders`. When one opponent touches two or more of your borders and no fixed split of the deploys there holds them all, `guess` offers a randomized split weighted by what each border is worth (each border's chance of being held, the best fixed split's worst case, the mix's expected loss, one draw seeded by the game, the turn and a local secret, so re-planning gives the same draw and the public code cannot reproduce it) and `guessOrders`, the plan's `orders` with that draw in place of its deploys on those borders — optional, a model of one opponent with one deploy, never taking armies off the territory your commander stands on or walks to, and dropped when its draw would be refused by the submit's commander check; the plan's `orders` are unchanged (`view: "full"` says why there is none). Holding an Airlift card, `airliftPlan` is an alternative beside the plan, its `orders` unchanged: the same planner on the board after the Airlifts (an interior stack flown onto a border the plan concedes, or a conceded border's armies flown to the border most pressed), the best compared by the plan's own measure — next income if its conceded borders fall, then next income, fewer concessions, more captures — with `airlifts`, `orders` (Airlift plays included), `expected`, `delta` (income, captures, borders saved, bonuses kept or completed), `cardsSpent` and `cardsLeft`; `keep_cards` holds cards in reserve; `null` with `airliftPlanNote` when none beats the plan. Airlifted armies cannot attack that turn, so a capture is staged for next turn instead (`staging`: an interior stack flown beside a target the plan does not take whose capture completes a bonus of yours or breaks an opponent's, with `nextTurnAttack` and the bonus value), scored on a two-turn objective — this turn's measure plus 0.8 × that bonus (`delta.twoTurn`) — and only when the staged stack holds against the plan's threat at that border; a plan the submit's commander check would refuse is not offered. Holding a Bomb card, `bombPlan` is the same kind of alternative: the planner on the board the Bomb leaves (its target keeps half its armies, rounded down, as the client bundle's Bomb result does) — an opponent's territory beside yours, a held bonus's member first, then the largest stacks, never a player at peace with you — with `bomb`, `orders` (the Bomb play included), `expected` and `delta`; `null` with `bombPlanNote` when none beats the plan. Holding an Emergency Blockade, `blockadePlan` walls off a border the plan concedes (neutral at its armies × the game's multiplier, before every move), worth the bonus its fall would hand an opponent when the wall holds this turn; holding a Blockade, the plain orders plus a Blockade on a territory of yours the stress-tested line keeps through the attacks (it walls it after them), worth the same denial less any bonus of yours it gives up — the better of the two is offered (owner-approved 2026-11-24). `reads` (opponent profiles, reported only — the plan never uses them): each opponent in contact with a habit at confidence 0.5 or a label, its `labels`, those habits with `n` and `basis`, and `gamesMet` (full adds the counter-play lines); absent with `WARAPP_PLAYER_PROFILE=off` or while a game's teams cannot be read. `headroom` (#275), weakest first: each border of yours with the smallest single deploy by a neighbouring opponent that takes it after the plan's orders, whether that is below your income, and what falls with it (bonuses, the territories behind it and their bonus income, and `breach`: the hollow territories within two moves behind it that only it shields, with their bonus income). The whole turn is carried out for it, so it may differ from the leftover spread's "~D" line (#268, reckoned on the deploys before any move); a player out of the game whose seat no AI plays gets no row. With the guard off the plan counts half of a border's breach income in its value. When one observation broke an opponent's estimate by 1.5× or more (a stack out of the fog, a capture, or an attack of yours it held), the first warning says so for 3 turns and the borders of your held bonuses facing it are sized for the larger of what it implied and your income (no `guess` is drawn against it then). Nothing is read once an opponent may hold an Airlift card or while the game's teams cannot be read (each `headroom` row then says `mayBeTeammate`); under Multi-Attack only a stack out of the fog is read. After turns 4 and 8 on a map you have finished games on, `pace` puts your income beside the median winner's there (reported only). `chat.messages` lists the newest unread messages other players sent (text delimited) with their `intent` and `advice` (compact: the stance and one reason; `messagesOmitted` counts the rest), from the plan's own standing: reported only, the orders never read chat. `chat.chatBlocks` lists the unread messages that would block the submit under `WARAPP_CHAT_BLOCKS_TURN` (report only). Once the outlook's surrender line (advice only) is crossed in a free-for-all with three or more still playing, `coalition` says whether a coalition against the leader is viable: the trailing players together out-earning it on the calibrated estimates, now or once a bonus of its that one of you borders breaks. While viable, for 2 turns from the crossing and as long as the leader's lead over you is not growing, "Try a coalition first" replaces the surrender warning; `coalition.partners` ranks every player who borders the leader, is not at war with you and has not broken a truce with you on the cross-game record (`leftOut` says why the others are not), and `coalition.drafts` holds a `propose` message for the top two naming the leader's bonus you could break together. Nothing is sent: send a draft yourself with `warapp_send_chat`, or with `WARAPP_CHAT_AUTOMATION=on` a draft carries `send`, still confirm-gated. |
|
|
157
157
|
| `warapp_check_plan` | A stress test of a list of orders before you submit it (`warapp_plan_turn`'s `orders`, or your own edit): the orders are carried out on the live board by the game's turn rules (deploys, then attacks and transfers in the zigzag move order, each an attack or a transfer by who holds its target when it runs) against the replies each opponent could make with one deploy — all of it on one stack and an attack on a territory you hold or are about to take, all of it on a territory you attack, or every stack attacking at once — with you moving first and with the opponent moving first unless `first_mover` says which. Returns `safe` (`null` when no reply could be tried), a one-line `summary`, the `worst` reply and the `otherReplies` that cost something (territories lost, captures that fail or are taken straight back, bonuses and income, your commander), everything `atRisk` to some single reply, `commander` (with your commander on the board: its territory, the armies there and `needs`, the armies that survive every reply tried — by `warapp_submit_turn`'s own check, each reply at the larger of the estimate and your income, `enemy_deploy` only raising it, both move orders, your Airlifts counted; when a reply kills it the `summary` starts with it), what the orders do unanswered, `blindBorders` (your territories next to the fog, where nothing could be tested) and `exposedNextTurn` (territories no stack touches today that one could take next turn by first taking the territory in between, each with the armies it would need to hold). Exact with no luck and straight rounding; otherwise `exact` is false. `known_income` (as `warapp_plan_turn`'s) tries a per-player income you know in place of that opponent's estimate (`enemyDeploy` source `known_income`; `enemy_deploy` wins over it; `commander` keeps the submit's sizing). Not tried: hidden stacks, a deploy above the estimate (`enemy_deploy` tests one), split deploys, opponents acting together, under Multi-Attack any chain but the one most damaging per stack, cards other than your own Order Priority, Airlifts, Bombs and Blockades: a Bomb is carried out after every deploy, its target keeping half its armies, rounded down; an Emergency Blockade (before the moves) and a Blockade (after them) turn their territory neutral at its armies × the game's multiplier, and the walled border is never counted lost (a wall with no multiplier in the settings is warned of as not simulated). An Airlift in the orders is carried out at its phase — after every deploy, before every move: its source loses the armies, its destination gains them, and they cannot move again that turn — so every reply is tried on the board it leaves. `award` (when the server kept your pick list) is the same reading `warapp_plan_turn` gives; its `firstMover` can be passed as `first_mover`. In a free-for-all with a recorded truce in force its partner is still tried (`safe` is safe against a break), a reply that attacks a territory the truce covers is marked `breaksTruce`, and `safeIfTruceHolds` is the verdict over the rest (`null` when every reply is a break); a Diplomacy card in effect that the decoder is sure of counts as such a truce in any format (`enforced`, `verified: false`). In a team game it warns, as `warapp_submit_turn` does, of a card play or discard your teammate has already entered. `headroom` (as `warapp_plan_turn`'s) gives each border the smallest single deploy that takes it after these orders; an opponent whose estimate an observation broke is tried at the larger of what it implied and your income (`enemyDeploy` source `untrusted`, said in the first warning). `belowPlan` (#275) compares the orders with the default plan made now on the same board, as `warapp_plan_turn` makes it with no options (or with its border guess when the deploys are the guess's: `belowPlanAgainst`): each border they leave below what that plan leaves standing there, with `planLeaves`, `left` and `short`, the largest shortfall first. `planLeaves` includes the plan's surplus, so a border named may still hold (see `headroom`). A Sanctions card in the orders is projected onto next turn in `sanctionsPlayed` (`nextIncome`: before, after and the change — yours from this turn's income when the game's percentage is negative and you play it on yourself, an opponent's estimate when positive); a card on the wrong side for its sign is a warning (`warapp_submit_turn` refuses it). Read-only. |
|
|
158
|
+
| `warapp_turn_history` | A game turn by turn as you saw it, beside what this server planned, sent and expected (read from the game's decision log; ids only): per turn the board in view (summary, or whole with `board: true`), `changedHands` since the turn before, every player's visible `orders` that turn (deploys, moves, card plays, discards — kept from the next turn's live board since #570), the `plan`, the orders `sent` and `differsFromPlan`, the `outcome` next turn, cards, events, and once finished the turn's `truth` and `accuracy`. `from_turn`/`to_turn` (default the newest 5, at most 20 per call, `next` pages on); `view: "full"` adds the plan's rationale and warnings, checks, times and first mover; `read_last_turn: true` reads the live board once to keep the turn just resolved. Read-only; attack results are not decoded. |
|
|
158
159
|
| `warapp_track_opponents` | Each opponent over your own board history (the boards `warapp_plan_turn` and this tool read, the last 10 turns, or the game history when war.app sends it), by name: its observed deploy each turn (territories visible both turns only — a stack that came out of the fog is not income), an income estimate (each observed deploy is a lower bound under fog, so the largest of its last three observed turns, or its visible army growth plus losses per turn (stacks out of the fog left out) when that is more; capped at what it could earn, at least its base plus the bonuses it visibly holds; `method` and `observedRange` say which term set it and how spread the observations were), `unexplainedArmies` (income earned since first seen minus its visible army change, its visible losses and its likely combat deaths: armies in the fog, spent there, or a misread) and `inferredBonuses` (the combinations of bonuses it could hold that best explain the gap, only those within 4 hops of its territories that it could have paid for, nearest first — candidates, never one asserted; none listed when more than 8 fit), with confidence notes. Every opponent still playing is listed, even with no territory in view (`visible` territories in view, `turnsUnseen` — a floor, `turnsUnseenAtLeast`, when your boards do not reach back to when it was last seen); one with nothing in view gets `earnedAtLeast` — its starting armies plus the base income for every turn so far, a lower bound on armies received (not held: its expansion cost some) — and a warning, also in `warapp_plan_turn`, when that beats your largest stack or your total visible armies. Once an opponent has 2+ observed turns, `warapp_plan_turn` uses this income in place of the single-turn observed figure. `view`: compact / full. Read-only on war.app (it caches the board it read); refuses outside a turn phase. `full` adds `pastGames`: the lessons of your finished games — how they were lost, when your income went flat, and this tracker's estimate ÷ the true income by format and coverage band (reported only). |
|
|
159
160
|
| `warapp_locate_opponents` | Where each opponent probably is and what it may be doing, by name. `seen` is the only fact: its territories in view, and those your earlier boards last showed as its own. Everything else is a simple model's guess with its `basis`, and every `likelihood` is that model's estimate, not a measured probability: `starts` (proven by the award of your picks, then the likely ones among the territories the live board showed as pickable — kept by `warapp_plan_picks` and the `warapp_submit_picks` preview — or, in a game dealt automatically from a map distribution mode, that mode's territories — read once from war.app's map details and kept with the map, with a `warnings` line when unknown — less those a board showed as a neutral or as yours), `presence` (hidden territories it may hold: last seen, start, the corridor between a likely start and a sighting, what it could have grown into from that start, bonuses that explain its tracked income), `bonuses` it probably holds, its tracked `income` and `hiddenArmies` (`warapp_track_opponents`' `unexplainedArmies`), `approaches` (the earliest turn it could attack each of your border territories, from a stack in view with the armies that could arrive, or `guessed`) and `doing`; then `prepare` (`hold`, `contested`, `scout`). The start prior is uniform, or — locally with `WARAPP_STATS=1`, never hosted — weighted by the starts in the finished games `warapp_map_stats` already cached for the map. No war.app request beyond the live board and the game feed, and the map details once per map for a mode's territories. `view`: compact / full (adds the assumptions). Read-only on war.app (it caches the board it read); refuses outside a turn phase. `warapp_plan_turn` does not use it yet. `startCandidates` says where the start candidates came from (and, for a distribution mode, its id and name). |
|
|
160
161
|
| `warapp_profile_opponents` | What each opponent tends to do, by name, counted from your boards and the orders this server sent: per opponent `seen.turnsObserved` (the only fact) and `habits` — `reinforce` (your attack on its territory met more armies than the board showed; measured only at 0% luck with straight rounding), `attack` (turns in contact it attacked you), `firstStrike`, `stacking` (share of its visible growth on one territory), `retaliate` and `retake` (within two turns) — each this game's counts pooled with the player's faded counts from your earlier finished games (`seen.gamesMet`) and shrunk toward a prior (all players in this format, then all players, once that pool has 10 opportunities; the AI pool for an AI seat; else a neutral default) — a `value`, its `n`, `confidence` and `basis` (`this-game`, `past-games`, `population` or `default`), then `labels` and `counter` lines at confidence 0.5 or more. Known teammates are never profiled; while a game's teams cannot be read, nothing is kept and every other player carries `mayBeTeammate: true`. The turns are kept per game (`<dataDir>/profiles/games/`, ids and counts only) by this tool, `warapp_plan_turn` (not a what-if plan), `warapp_track_opponents`, `warapp_locate_opponents` and `warapp_get_relations`, unless `WARAPP_PLAYER_PROFILE=off`. `profile` says whether the turns are `kept`, `not-kept` (no data dir, or the teams unknown) or `off`. `detail`: compact / full (adds the counts and each observed turn). `lastAttackTurn` beside the labels is the last turn it attacked you (null: none seen); `turtle` is never given within two turns of one. Given a finished game it folds it into the cross-game counts instead (`fold`: once, from the turns kept while it was played, else a backfill from the boards cached then — no other request, nothing while its teams are unknown — or "counts start with games played on this build"); `warapp_get_game` does the same on a finished game (`profileFold`). Read-only on war.app (it caches the board it read); refuses any other state outside a turn phase. `warapp_plan_turn` reports a compact read as `reads` (with `lastAttackTurn`) but does not use it. A habit whose past weighs most and was mostly read from finished games' histories reads `basis: history`. |
|
|
@@ -175,6 +176,7 @@ Locally `WARAPP_AUTH_TOKEN` is ignored.
|
|
|
175
176
|
| `warapp_get_mod_alliances` | The Diplomacy 2 mod's (mod 191) alliances in a game that runs it, read from the game details (UNVERIFIED live): each pair `allied`, `breaking` (your own break order entered: it still holds this turn, either side can attack from `endsTurn`) or `pending` (a proposal to you), who proposed it and the mod's `id` (its order; the mod keeps no turn), your `allies` and the mod's `alerts`. Proposals you sent and an ally's break before it applies are not visible. Proposing, accepting and breaking are manual only (the mod's menu in the web client). Read-only. |
|
|
176
177
|
| `warapp_record_agreement` | **Writes (locally).** Record a truce you made, proposed or received in a free-for-all, or a change to it (agreed, notice, ended, broken by them or by you), with structured terms: what it covers (all, territories or bonuses), turns of notice (0–3), an optional border cap, an end (a turn, or a player out). `caps` (`[{territory, max, note?}]`, up to 20) amends a proposed, agreed or in-notice truce without rewriting its terms: at most `max` of your armies on that territory, dated, the planner keeping it like the border cap and `warapp_check_plan` warning when orders exceed it; `caps_remove` lifts one. `coordination` (`[{target, mine?, theirs?, turn?, note?}]`) records a joint attack agreed with the partner (`with` or the agreement's; no agreement needed), and `coordination_done: [id]` closes one: report only — `warapp_get_relations` lists them and `warapp_plan_turn` tells one on its turn, never changing the orders. Refused for yourself, an AI, a player out, a teammate, in a 1v1 and once two players remain. Refused too when no third player or team stands outside you, your team and the partner's, and for an `until_turn` already past. Writes only the server's ledger (`<dataDir>/relations/`, name-free) and, unless `WARAPP_PLAYER_RECORD=off` (on locally and hosted: owner decision D5), the cross-game player record: per partner, keyed by a salted hash with no id, game, name or message, one entry per agreement (format, turns, terms shape, outcome, a break's turn, flag and context, retaliation, proposing again) and tallies; nothing goes to war.app, so it is not confirm-gated. |
|
|
177
178
|
| `warapp_record_intel` | **Writes (locally).** Keep what diplomacy told you for a game in its agreement ledger (#386): `avoid_territories` (with an optional `promised_to`), `avoid_players` (each with a reason code: promised, asked-by-them, joint-enemy, kingmaker, other) and `known_income` (a player's stated income and the turn it was stated, `stated_turn`, default this turn); `forget` removes entries. `warapp_plan_turn` and `warapp_check_plan` then apply them by default and report `intel` (what was applied, the kinds an explicit argument overrode, and stale incomes); an explicit `avoid_territories`, `avoid_players` or `known_income` replaces the stored list of its kind for that call, and a stored income more than 3 turns old is not applied (the estimate stands, with a warning). Ids, turns and reason codes only; nothing goes to war.app, so it is not confirm-gated. |
|
|
179
|
+
| `warapp_calibration` | The opponent income estimates this server planned with, scored against the truth its finished games kept (the decision log's end-of-game truth): estimate ÷ truth and the signed error in armies, overall and by format, seats, phase, coverage band, estimate source, thin evidence, the tracker's income method (rise-capped or not, logged since #569) and leader vs trailer; the catch-up lag after a true income jump; a consequences proxy; the largest misses. `samples: true` returns the scored rows name-free; `harness: true` also runs the #318 harness (tracker, fog prior and plan estimate over the cached boards, and the opening benchmark). Games are numbered by their place in the report, never by id. No war.app request; read-only. |
|
|
178
180
|
| `warapp_backfill_history` | **Writes (locally).** Give the end-of-game pass to up to `limit` (default 10, max 25) of your finished games not yet processed, newest first, among your newest `window` (default 250, max 500) finished games: each history read once from GameFeed, never again, and kept name-free for the profiles, map records and lessons (what `warapp_my_games` does two games per call). Reports `processed`, `processedCount`, `remaining` and `outsideWindow`; safe to call again until `remaining` is 0. Writes only this server's state, never war.app, so it is not confirm-gated. |
|
|
179
181
|
| `warapp_upload_slots` | **Hosted only** (needs mcp-host's blob store). A signed upload URL and `curl` for a state bundle; changes nothing. See [Moving local history to the hosted server](#moving-local-history-to-the-hosted-server). |
|
|
180
182
|
| `warapp_import_state` | **Hosted only. Writes (this server's state), confirm-gated.** Import a bundle from `warapp-mcp export-state` by its `blob_key`. The preview shows the files per store, the bundle's account against the signed-in one (another account is refused), and the salt here against the bundle's: a different one is refused unless `replace: true`, which moves this server's hashed stores (profiles, relations, finished, lessons, maps-record) into `state-backups/<time>/` (never deleted). Every file's sha256 is checked first; files are written atomically, `0600`. Never shows the salt or any file's contents; the upload is deleted once imported. |
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { CALIBRATION_HIGH, CALIBRATION_LOW, COVERAGE_BUCKETS, coverageBucket } from './game-lessons.js';
|
|
2
|
+
/** A true income jump at least this many times the turn before starts a catch-up count. */
|
|
3
|
+
export const JUMP_FACTOR = 1.5;
|
|
4
|
+
/** The estimate has caught up once it reaches this share of the truth. */
|
|
5
|
+
export const CATCH_UP_SHARE = 2 / 3;
|
|
6
|
+
/** The largest misses listed. */
|
|
7
|
+
export const WORST_LISTED = 10;
|
|
8
|
+
/** The phases a turn falls in. */
|
|
9
|
+
export const PHASES = ['turns-1-4', 'turns-5-10', 'turns-11-up'];
|
|
10
|
+
/** Seat-count bands. */
|
|
11
|
+
export const SEAT_BANDS = ['2', '3-6', '7-16', '17-up'];
|
|
12
|
+
export function phaseOf(turn) {
|
|
13
|
+
return turn <= 4 ? 'turns-1-4' : turn <= 10 ? 'turns-5-10' : 'turns-11-up';
|
|
14
|
+
}
|
|
15
|
+
export function seatBand(seats) {
|
|
16
|
+
if (seats === null || seats < 2)
|
|
17
|
+
return 'unknown';
|
|
18
|
+
return seats === 2 ? '2' : seats <= 6 ? '3-6' : seats <= 16 ? '7-16' : '17-up';
|
|
19
|
+
}
|
|
20
|
+
const r3 = (x) => Math.round(x * 1000) / 1000;
|
|
21
|
+
export function errorView(samples) {
|
|
22
|
+
const n = samples.length;
|
|
23
|
+
if (!n)
|
|
24
|
+
return null;
|
|
25
|
+
const ratios = samples.map((s) => s.ratio).sort((a, b) => a - b);
|
|
26
|
+
const mid = n >> 1;
|
|
27
|
+
const median = n % 2 ? ratios[mid] : (ratios[mid - 1] + ratios[mid]) / 2;
|
|
28
|
+
return {
|
|
29
|
+
n,
|
|
30
|
+
mean: r3(ratios.reduce((s, r) => s + r, 0) / n),
|
|
31
|
+
median: r3(median),
|
|
32
|
+
geoMean: r3(Math.exp(ratios.reduce((s, r) => s + Math.log(Math.max(r, 1e-6)), 0) / n)),
|
|
33
|
+
under: r3(ratios.filter((r) => r < CALIBRATION_LOW).length / n),
|
|
34
|
+
over: r3(ratios.filter((r) => r > CALIBRATION_HIGH).length / n),
|
|
35
|
+
meanError: r3(samples.reduce((s, x) => s + x.error, 0) / n),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const turnKeys = (turns) => Object.keys(turns)
|
|
39
|
+
.filter((k) => /^\d+$/.test(k))
|
|
40
|
+
.map(Number)
|
|
41
|
+
.sort((a, b) => a - b);
|
|
42
|
+
/** Every scored estimate of every game, in game then turn then opponent order. Pure. */
|
|
43
|
+
export function incomeSamples(games) {
|
|
44
|
+
const out = [];
|
|
45
|
+
games.forEach((g, i) => {
|
|
46
|
+
for (const turn of turnKeys(g.turns)) {
|
|
47
|
+
const e = g.turns[String(turn)];
|
|
48
|
+
const acc = e.accuracy?.estimates;
|
|
49
|
+
if (!acc?.length)
|
|
50
|
+
continue;
|
|
51
|
+
const truths = e.truth?.opponents ?? [];
|
|
52
|
+
const top = truths.length ? Math.max(...truths.map((o) => o.income)) : null;
|
|
53
|
+
const logged = new Map((e.decision?.estimates ?? []).map((x) => [x.player, x]));
|
|
54
|
+
for (const a of [...acc].sort((x, y) => x.player - y.player)) {
|
|
55
|
+
if (a.truth <= 0)
|
|
56
|
+
continue;
|
|
57
|
+
const ratio = a.estimate / a.truth;
|
|
58
|
+
out.push({
|
|
59
|
+
game: i + 1,
|
|
60
|
+
turn,
|
|
61
|
+
format: g.format,
|
|
62
|
+
seats: g.seats,
|
|
63
|
+
phase: phaseOf(turn),
|
|
64
|
+
estimate: a.estimate,
|
|
65
|
+
truth: a.truth,
|
|
66
|
+
ratio: r3(ratio),
|
|
67
|
+
error: a.estimate - a.truth,
|
|
68
|
+
source: a.source ?? 'unknown',
|
|
69
|
+
coverage: a.coverage,
|
|
70
|
+
band: coverageBucket(a.coverage),
|
|
71
|
+
thin: a.thin,
|
|
72
|
+
method: logged.get(a.player)?.method ?? null,
|
|
73
|
+
leader: top !== null && a.truth >= top,
|
|
74
|
+
stages: logged.get(a.player)?.stages ?? null,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Per game and opponent, a turn whose true income is at least {@link JUMP_FACTOR} × the turn before (both
|
|
83
|
+
* read, the earlier above 0) is a jump; its lag is the turns from it to the first logged estimate of that
|
|
84
|
+
* opponent at or after it that reaches {@link CATCH_UP_SHARE} of that turn's truth. Pure.
|
|
85
|
+
*/
|
|
86
|
+
export function catchUp(games) {
|
|
87
|
+
const lagsList = [];
|
|
88
|
+
let censored = 0;
|
|
89
|
+
for (const g of games) {
|
|
90
|
+
const turns = turnKeys(g.turns);
|
|
91
|
+
const truth = new Map(); // player → turn → income
|
|
92
|
+
const est = new Map(); // player → turn → estimate
|
|
93
|
+
for (const t of turns) {
|
|
94
|
+
const e = g.turns[String(t)];
|
|
95
|
+
for (const o of e.truth?.opponents ?? [])
|
|
96
|
+
(truth.get(o.player) ?? truth.set(o.player, new Map()).get(o.player)).set(t, o.income);
|
|
97
|
+
for (const a of e.accuracy?.estimates ?? [])
|
|
98
|
+
(est.get(a.player) ?? est.set(a.player, new Map()).get(a.player)).set(t, a.estimate);
|
|
99
|
+
}
|
|
100
|
+
for (const [player, series] of [...truth].sort((a, b) => a[0] - b[0])) {
|
|
101
|
+
const estimates = est.get(player);
|
|
102
|
+
if (!estimates?.size)
|
|
103
|
+
continue;
|
|
104
|
+
const last = Math.max(...estimates.keys());
|
|
105
|
+
for (const [t, income] of [...series].sort((a, b) => a[0] - b[0])) {
|
|
106
|
+
const before = series.get(t - 1);
|
|
107
|
+
if (before === undefined || before <= 0 || income < JUMP_FACTOR * before || t > last)
|
|
108
|
+
continue;
|
|
109
|
+
let lag = null;
|
|
110
|
+
for (const u of [...estimates.keys()].filter((u) => u >= t).sort((a, b) => a - b)) {
|
|
111
|
+
const truthU = series.get(u) ?? income;
|
|
112
|
+
if (estimates.get(u) >= CATCH_UP_SHARE * truthU) {
|
|
113
|
+
lag = u - t;
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (lag === null)
|
|
118
|
+
censored++;
|
|
119
|
+
else
|
|
120
|
+
lagsList.push(lag);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const sorted = [...lagsList].sort((a, b) => a - b);
|
|
125
|
+
const n = sorted.length;
|
|
126
|
+
const lags = {};
|
|
127
|
+
for (const l of sorted)
|
|
128
|
+
lags[String(l)] = (lags[String(l)] ?? 0) + 1;
|
|
129
|
+
return {
|
|
130
|
+
jumps: n + censored,
|
|
131
|
+
caught: n,
|
|
132
|
+
meanLag: n ? r3(sorted.reduce((s, x) => s + x, 0) / n) : null,
|
|
133
|
+
medianLag: n ? (n % 2 ? sorted[n >> 1] : (sorted[(n >> 1) - 1] + sorted[n >> 1]) / 2) : null,
|
|
134
|
+
lags,
|
|
135
|
+
censored,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
export function consequences(games) {
|
|
139
|
+
const c = { turns: 0, underTurns: 0, underWithLoss: 0, otherTurns: 0, otherWithLoss: 0 };
|
|
140
|
+
for (const g of games)
|
|
141
|
+
for (const t of turnKeys(g.turns)) {
|
|
142
|
+
const e = g.turns[String(t)];
|
|
143
|
+
const acc = e.accuracy?.estimates;
|
|
144
|
+
if (!acc?.length || !e.next || !e.decision)
|
|
145
|
+
continue;
|
|
146
|
+
const conceded = new Set(e.decision.conceded ?? []);
|
|
147
|
+
const loss = e.next.lost.some((id) => !conceded.has(id));
|
|
148
|
+
const under = acc.some((a) => a.ratio !== null && a.ratio < CALIBRATION_LOW);
|
|
149
|
+
c.turns++;
|
|
150
|
+
if (under) {
|
|
151
|
+
c.underTurns++;
|
|
152
|
+
if (loss)
|
|
153
|
+
c.underWithLoss++;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
c.otherTurns++;
|
|
157
|
+
if (loss)
|
|
158
|
+
c.otherWithLoss++;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return c;
|
|
162
|
+
}
|
|
163
|
+
/** #568: the stages scored, in pipeline order (`card` is armies on top of an income, not scored alone). */
|
|
164
|
+
export const STAGES = ['visible', 'observed', 'tracked', 'prior', 'stated', 'blend', 'thin', 'known'];
|
|
165
|
+
/**
|
|
166
|
+
* #568: each stage's figure ÷ the truth, over the samples that logged it and where the stage applied (a figure
|
|
167
|
+
* above 0; the truth is the income, card armies apart, so the card is left out). Pure.
|
|
168
|
+
*/
|
|
169
|
+
export function stageErrors(samples) {
|
|
170
|
+
const out = {};
|
|
171
|
+
for (const stage of STAGES) {
|
|
172
|
+
const rows = samples.flatMap((s) => {
|
|
173
|
+
const v = s.stages?.[stage];
|
|
174
|
+
return typeof v === 'number' && v > 0 ? [{ ratio: r3(v / s.truth), error: v - s.truth }] : [];
|
|
175
|
+
});
|
|
176
|
+
const view = errorView(rows);
|
|
177
|
+
if (view)
|
|
178
|
+
out[stage] = view;
|
|
179
|
+
}
|
|
180
|
+
return out;
|
|
181
|
+
}
|
|
182
|
+
/** #568: the dampings the what-if tries (0: no correction; 1: the full band factor). */
|
|
183
|
+
export const WHAT_IF_DAMPINGS = [0, 0.25, 0.5, 0.75, 1];
|
|
184
|
+
/** #568: a band's factor counts only from this many samples of the other games. */
|
|
185
|
+
export const WHAT_IF_MIN_SAMPLES = 5;
|
|
186
|
+
/**
|
|
187
|
+
* #568: what dividing the tracked figure by its coverage band's geometric mean of tracked ÷ truth, to each
|
|
188
|
+
* damping in {@link WHAT_IF_DAMPINGS}, would have read. Leave one game out: a game's samples are corrected by
|
|
189
|
+
* the bands of the other games only (at least {@link WHAT_IF_MIN_SAMPLES} samples, a band under 1×), so a game
|
|
190
|
+
* never calibrates itself. Only ever raises, as the draft rule does. The tracked stage alone, not the whole
|
|
191
|
+
* pipeline (the prior, its blend and thin evidence would move with it). Pure.
|
|
192
|
+
*/
|
|
193
|
+
export function trackedWhatIf(samples) {
|
|
194
|
+
const rows = samples.flatMap((s) => (typeof s.stages?.tracked === 'number' && s.stages.tracked > 0 ? [{ s, tracked: s.stages.tracked }] : []));
|
|
195
|
+
const sums = new Map();
|
|
196
|
+
const key = (game, band) => `${game}|${band}`;
|
|
197
|
+
for (const { s, tracked } of rows) {
|
|
198
|
+
const k = key(s.game, s.band);
|
|
199
|
+
const v = sums.get(k) ?? { n: 0, log: 0 };
|
|
200
|
+
v.n++;
|
|
201
|
+
v.log += Math.log(tracked / s.truth);
|
|
202
|
+
sums.set(k, v);
|
|
203
|
+
}
|
|
204
|
+
const bandTotals = new Map();
|
|
205
|
+
for (const [k, v] of sums) {
|
|
206
|
+
const band = k.slice(k.indexOf('|') + 1);
|
|
207
|
+
const t = bandTotals.get(band) ?? { n: 0, log: 0 };
|
|
208
|
+
bandTotals.set(band, { n: t.n + v.n, log: t.log + v.log });
|
|
209
|
+
}
|
|
210
|
+
const factorFor = (game, band) => {
|
|
211
|
+
const all = bandTotals.get(band);
|
|
212
|
+
const own = sums.get(key(game, band)) ?? { n: 0, log: 0 };
|
|
213
|
+
const n = (all?.n ?? 0) - own.n;
|
|
214
|
+
if (n < WHAT_IF_MIN_SAMPLES)
|
|
215
|
+
return undefined;
|
|
216
|
+
const g = Math.exp(((all?.log ?? 0) - own.log) / n);
|
|
217
|
+
return g < 1 ? g : undefined;
|
|
218
|
+
};
|
|
219
|
+
return WHAT_IF_DAMPINGS.map((damping) => {
|
|
220
|
+
let raised = 0;
|
|
221
|
+
const scored = rows.map(({ s, tracked }) => {
|
|
222
|
+
const g = factorFor(s.game, s.band);
|
|
223
|
+
const v = g === undefined ? tracked : Math.max(tracked, Math.round(tracked / g ** damping));
|
|
224
|
+
if (v > tracked)
|
|
225
|
+
raised++;
|
|
226
|
+
return { band: s.band, ratio: r3(v / s.truth), error: v - s.truth };
|
|
227
|
+
});
|
|
228
|
+
const byBand = {};
|
|
229
|
+
for (const band of COVERAGE_BUCKETS) {
|
|
230
|
+
const view = errorView(scored.filter((x) => x.band === band));
|
|
231
|
+
if (view)
|
|
232
|
+
byBand[band] = view;
|
|
233
|
+
}
|
|
234
|
+
return { damping, error: errorView(scored), raised, byBand };
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
function groupBy(samples, key, order) {
|
|
238
|
+
const groups = new Map();
|
|
239
|
+
for (const s of samples) {
|
|
240
|
+
const k = key(s);
|
|
241
|
+
(groups.get(k) ?? groups.set(k, []).get(k)).push(s);
|
|
242
|
+
}
|
|
243
|
+
const keys = order ? order.filter((k) => groups.has(k)) : [...groups.keys()].sort();
|
|
244
|
+
const out = {};
|
|
245
|
+
for (const k of keys)
|
|
246
|
+
out[k] = errorView(groups.get(k));
|
|
247
|
+
return out;
|
|
248
|
+
}
|
|
249
|
+
/** The report over `games` (each finished game's log, in a stable order). Pure. */
|
|
250
|
+
export function incomeCalibration(games) {
|
|
251
|
+
const samples = incomeSamples(games);
|
|
252
|
+
const byPhaseAndCoverage = {};
|
|
253
|
+
for (const p of PHASES) {
|
|
254
|
+
const of = samples.filter((s) => s.phase === p);
|
|
255
|
+
if (of.length)
|
|
256
|
+
byPhaseAndCoverage[p] = groupBy(of, (s) => s.band, COVERAGE_BUCKETS);
|
|
257
|
+
}
|
|
258
|
+
const worst = [...samples]
|
|
259
|
+
.sort((a, b) => Math.abs(Math.log(Math.max(b.ratio, 1e-6))) - Math.abs(Math.log(Math.max(a.ratio, 1e-6))) || a.game - b.game || a.turn - b.turn)
|
|
260
|
+
.slice(0, WORST_LISTED);
|
|
261
|
+
return {
|
|
262
|
+
games: games.filter((g) => turnKeys(g.turns).some((t) => g.turns[String(t)].accuracy?.estimates.length)).length,
|
|
263
|
+
samples: samples.length,
|
|
264
|
+
all: errorView(samples),
|
|
265
|
+
byFormat: groupBy(samples, (s) => s.format),
|
|
266
|
+
bySeats: groupBy(samples, (s) => seatBand(s.seats), [...SEAT_BANDS, 'unknown']),
|
|
267
|
+
byPhase: groupBy(samples, (s) => s.phase, PHASES),
|
|
268
|
+
byCoverage: groupBy(samples, (s) => s.band, COVERAGE_BUCKETS),
|
|
269
|
+
bySource: groupBy(samples, (s) => s.source),
|
|
270
|
+
byThin: groupBy(samples, (s) => (s.thin ? 'thin' : 'solid')),
|
|
271
|
+
byMethod: groupBy(samples, (s) => s.method ?? 'unlogged'),
|
|
272
|
+
byLeader: groupBy(samples, (s) => (s.leader ? 'leader' : 'trailer')),
|
|
273
|
+
byPhaseAndCoverage,
|
|
274
|
+
catchUp: catchUp(games),
|
|
275
|
+
consequences: consequences(games),
|
|
276
|
+
worst,
|
|
277
|
+
byStage: stageErrors(samples),
|
|
278
|
+
trackedWhatIf: trackedWhatIf(samples),
|
|
279
|
+
};
|
|
280
|
+
}
|
package/dist/analysis/intel.js
CHANGED
|
@@ -56,7 +56,7 @@ export function resolveIntel(stored, turn, args) {
|
|
|
56
56
|
}
|
|
57
57
|
report.applied.knownIncome = fresh.map((i) => ({ player: i.player, income: i.income, statedTurn: i.turn }));
|
|
58
58
|
if (fresh.length)
|
|
59
|
-
out.knownIncome = fresh.map((i) => ({ player: i.player, income: i.income }));
|
|
59
|
+
out.knownIncome = fresh.map((i) => ({ player: i.player, income: i.income, source: 'chat' }));
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
for (const st of report.stale)
|
|
@@ -138,6 +138,13 @@ const byNum = (a, b) => a - b;
|
|
|
138
138
|
* calibration run.
|
|
139
139
|
*/
|
|
140
140
|
export const RISE_CAP = 1.3;
|
|
141
|
+
/**
|
|
142
|
+
* #567 (owner decision 2026-11-25): a turn read from at least this share of its frontier
|
|
143
|
+
* ({@link ObservedTurn.coverage}) is evidence enough that its low end (every ambiguous army read as a move,
|
|
144
|
+
* at most its could-earn cap) was deployed: the {@link RISE_CAP} hold never stays below it. Offline, on the
|
|
145
|
+
* calibration records, no turn read at 60% or more had a low end above the truth.
|
|
146
|
+
*/
|
|
147
|
+
export const RISE_LOW_COVERAGE = 0.6;
|
|
141
148
|
/** #418: my armies in view against its own, at or above which I lead it on the board ({@link ObservedTurn.leadIncome}). */
|
|
142
149
|
export const LEAD_ARMIES = 3;
|
|
143
150
|
/**
|
|
@@ -194,7 +201,9 @@ export function incomeBasis(t) {
|
|
|
194
201
|
return t.incomeRise
|
|
195
202
|
? t.incomeRise.proven !== undefined
|
|
196
203
|
? `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
|
-
:
|
|
204
|
+
: t.incomeRise.low !== undefined
|
|
205
|
+
? `max observed over ${span}, ${range}, held at the +${t.incomeRise.low} a turn read from ${Math.round(RISE_LOW_COVERAGE * 100)}% or more of its frontier surely deployed (above ${RISE_CAP}× the ~${t.incomeRise.before} before it): no turn read in full reached ${t.incomeRise.read}`
|
|
206
|
+
: `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
207
|
: `max observed over ${span}, ${range}, a rise held to ${RISE_CAP}× a turn`;
|
|
199
208
|
if (t.incomeMethod === 'tripped')
|
|
200
209
|
return t.incomeTrip
|
|
@@ -539,6 +548,32 @@ function fogCapturePattern(observed) {
|
|
|
539
548
|
const income = Math.min(last.cap, Math.ceil(armies / (last.from - hits[0].from + 1)));
|
|
540
549
|
return { turns: hits.map((x) => x.from), armies, income };
|
|
541
550
|
}
|
|
551
|
+
/**
|
|
552
|
+
* #567: the turn of `window` whose low end (at most its could-earn cap) is highest, the newest on a tie,
|
|
553
|
+
* when that low end is above `income`; else `null`. Pure.
|
|
554
|
+
*/
|
|
555
|
+
export function observedLowOf(window, income) {
|
|
556
|
+
if (income === null)
|
|
557
|
+
return null;
|
|
558
|
+
let top = null;
|
|
559
|
+
for (const x of window)
|
|
560
|
+
if (!top || Math.min(x.low, x.cap) >= Math.min(top.low, top.cap))
|
|
561
|
+
top = x;
|
|
562
|
+
if (!top || Math.min(top.low, top.cap) <= income)
|
|
563
|
+
return null;
|
|
564
|
+
return { low: Math.min(top.low, top.cap), high: Math.min(top.high, top.cap), turn: top.from, coverage: top.coverage?.share ?? null };
|
|
565
|
+
}
|
|
566
|
+
/** #567: the warning that a tracked income is held below what a turn of its window surely read. */
|
|
567
|
+
export function observedLowWarning(player, income, o, method) {
|
|
568
|
+
const read = o.coverage !== null ? `, from ${Math.round(o.coverage * 100)}% of its frontier` : '';
|
|
569
|
+
const range = o.high > o.low ? `, up to +${o.high}` : '';
|
|
570
|
+
const why = method === 'tripped'
|
|
571
|
+
? 'the over-read tripwire keeps the readings before its step at most the stepped figure (#418)'
|
|
572
|
+
: `a rise no turn read in full confirmed is held to ${RISE_CAP}× a turn (#418)`;
|
|
573
|
+
return (`Player ${player}'s income is held at ~${income}, but turn ${o.turn} read it deploying at least +${o.low}${range}${read} (#567): ` +
|
|
574
|
+
`${why}, so the plan sizes its borders for ~${income}. To test the low end, pass known_income ${o.low} for it to ` +
|
|
575
|
+
'warapp_check_plan (a board figure: it moves no other opponent, #567).');
|
|
576
|
+
}
|
|
542
577
|
/**
|
|
543
578
|
* #418: {@link trackedIncome} with the tripwire's ceiling on the readings of the turns it covers: those
|
|
544
579
|
* count at most its value, the later ones whole; method `tripped` when that lowers the figure.
|
|
@@ -686,12 +721,21 @@ function carryIncome(observed) {
|
|
|
686
721
|
const before = Math.max(prev.income, x.visibleIncome);
|
|
687
722
|
// #418: proof may always raise an estimate: the hold never goes below a capture floor in the window.
|
|
688
723
|
const proof = Math.max(0, ...window.map((w) => w.captureFloor ?? 0));
|
|
689
|
-
|
|
724
|
+
// #567: nor below the low end of a turn read from RISE_LOW_COVERAGE or more of its frontier.
|
|
725
|
+
const low = disproved
|
|
726
|
+
? 0
|
|
727
|
+
: Math.max(0, ...window.filter((w) => (w.coverage?.share ?? 0) >= RISE_LOW_COVERAGE).map((w) => Math.min(w.low, w.cap)));
|
|
728
|
+
const limit = Math.max(disproved ? prev.income : Math.ceil(before * RISE_CAP - 1e-9), proof, low);
|
|
690
729
|
// #418 review: the lead is judged against the carry before the rise (or its visible income), never
|
|
691
730
|
// against the reading being judged: an over-read above my income must not switch its own cap off.
|
|
692
731
|
carry =
|
|
693
732
|
(x.leadIncome ?? 0) > before && !fresh.confirmed && fresh.income > limit
|
|
694
|
-
? {
|
|
733
|
+
? {
|
|
734
|
+
...fresh,
|
|
735
|
+
income: limit,
|
|
736
|
+
set: limit,
|
|
737
|
+
rise: { read: fresh.income, before, ...(proof >= limit ? { proven: proof } : low >= limit ? { low } : {}) },
|
|
738
|
+
}
|
|
695
739
|
: fresh;
|
|
696
740
|
}
|
|
697
741
|
}
|
|
@@ -1203,6 +1247,10 @@ export function trackOpponents(g, boards, me, settings = {}, game) {
|
|
|
1203
1247
|
if (earnedAtLeast.exceedsTotal)
|
|
1204
1248
|
warnings.push(`${head}; it could be banking more than your total visible armies (${visibleArmies}).`);
|
|
1205
1249
|
}
|
|
1250
|
+
// #567: a turn of the window surely read more than the income held: said, never applied.
|
|
1251
|
+
const observedLow = observed.length >= TRACKED_MIN_TURNS ? observedLowOf(incomeWindow, income) : null;
|
|
1252
|
+
if (observedLow)
|
|
1253
|
+
warnings.push(observedLowWarning(nameOf(playerId), income, observedLow, estimate.method));
|
|
1206
1254
|
if (jump)
|
|
1207
1255
|
warnings.push(`Player ${nameOf(playerId)}'s ${incomeJumpText(jump, income, observed.filter((x) => x.from >= jump.since && x.from < jump.turn))}`);
|
|
1208
1256
|
if (firstSeen === null) {
|
|
@@ -1464,6 +1512,7 @@ export function trackOpponents(g, boards, me, settings = {}, game) {
|
|
|
1464
1512
|
incomeLowered: carried ? carried.set - carried.income : 0,
|
|
1465
1513
|
...(incomeRise ? { incomeRise } : {}),
|
|
1466
1514
|
...(incomeTrip ? { incomeTrip } : {}),
|
|
1515
|
+
...(observedLow ? { observedLow } : {}),
|
|
1467
1516
|
unexplained,
|
|
1468
1517
|
inferred,
|
|
1469
1518
|
topUp: observed.reduce((n, x) => (x.topUp === undefined ? n : Math.max(n ?? 0, x.topUp)), null),
|
|
@@ -199,7 +199,7 @@ export function enemyDeployEstimates(g, board, me, settings = {}, previous, trac
|
|
|
199
199
|
: null;
|
|
200
200
|
const priorFull = prior && fogBeside ? Math.min(Math.max(0, Math.floor(priorBase)), priorCap ?? couldEarn) : null;
|
|
201
201
|
// #444: incomes other players stated scale this one's prior down by their ratio to mine (never up).
|
|
202
|
-
const statedRatio = prior?.stated && !prior.stated.players.some((x) => x.id === playerId) ? prior.stated.
|
|
202
|
+
const statedRatio = prior?.stated && !prior.stated.players.some((x) => x.id === playerId) ? prior.stated.scale : null;
|
|
203
203
|
const priorFigure = priorFull !== null && statedRatio !== null ? Math.min(priorFull, Math.ceil(priorFull * statedRatio - 1e-9)) : priorFull;
|
|
204
204
|
// #419: the past winners' pace, as the prior is figured (capped, scaled, only beside the fog), when above it.
|
|
205
205
|
const paceIncome = prior?.winnerPace ? fogPaceIncome(prior.winnerPace, prior.myIncome) : null;
|
|
@@ -102,21 +102,32 @@ export function planEnemyEstimates(input) {
|
|
|
102
102
|
const priced = applyKnown(applyArmyPrice(applySanctions(estimates, input.sanctions ?? [], turn), input.settings?.armyCostMultiplier ?? 0), input.known ?? []);
|
|
103
103
|
return { estimates: priced, prior, ...(skipped ? { priorSkipped: skipped } : {}) };
|
|
104
104
|
}
|
|
105
|
+
/** #567: the fewest players in view with an income stated in chat before #444's scale applies. */
|
|
106
|
+
export const MIN_STATED_PLAYERS = 2;
|
|
105
107
|
/**
|
|
106
|
-
* #
|
|
107
|
-
*
|
|
108
|
+
* #567: the scale is (mean stated ÷ my income) to this power: the square root, so a stated mean half mine
|
|
109
|
+
* scales the others' prior to ~0.71 of it, not 0.5. Offline evidence (13 finished FFAs, true incomes): the
|
|
110
|
+
* full ratio set the others' prior far below their truth.
|
|
111
|
+
*/
|
|
112
|
+
export const STATED_DAMPING = 0.5;
|
|
113
|
+
/**
|
|
114
|
+
* #444: the incomes stated in chat (`known` with `source: 'chat'`, #567) for players in view (not me) scale
|
|
115
|
+
* the prior of every other opponent when their mean is below my income: `EnemyIncomePrior.stated`. #567: only
|
|
116
|
+
* from {@link MIN_STATED_PLAYERS} such players, and by the mean's ratio to mine to the {@link STATED_DAMPING}
|
|
117
|
+
* power (`scale`; `ratio` keeps the ratio itself). A `board` income (the default) never scales anyone. The prior
|
|
118
|
+
* unchanged otherwise.
|
|
108
119
|
*/
|
|
109
120
|
function statedScale(prior, board, me, known) {
|
|
110
121
|
if (!prior || !known.length || prior.myIncome <= 0)
|
|
111
122
|
return prior;
|
|
112
123
|
const inView = new Set(board.territories.flatMap((t) => (t.owner.kind === 'player' ? [t.owner.playerId] : [])));
|
|
113
124
|
const players = known
|
|
114
|
-
.filter((k) => k.player !== me && inView.has(k.player))
|
|
125
|
+
.filter((k) => k.source === 'chat' && k.player !== me && inView.has(k.player))
|
|
115
126
|
.map((k) => ({ id: k.player, income: Math.max(0, Math.floor(k.income)) }));
|
|
116
|
-
if (
|
|
127
|
+
if (players.length < MIN_STATED_PLAYERS)
|
|
117
128
|
return prior;
|
|
118
|
-
const
|
|
119
|
-
return
|
|
129
|
+
const raw = players.reduce((n, x) => n + x.income, 0) / players.length / prior.myIncome;
|
|
130
|
+
return raw < 1 ? { ...prior, stated: { players, mine: prior.myIncome, ratio: raw, scale: raw ** STATED_DAMPING } } : prior;
|
|
120
131
|
}
|
|
121
132
|
/**
|
|
122
133
|
* #368: each estimate whose player the user gave a known income for (what it said in chat, say): that
|
|
@@ -135,6 +146,29 @@ export function applyKnown(estimates, known) {
|
|
|
135
146
|
return { ...e, estimate: income + card, known: { income, was: e.estimate - card } };
|
|
136
147
|
});
|
|
137
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* #567: the opponents whose estimate the #444 scale moved: each in `scaled` (estimates made with the known
|
|
151
|
+
* incomes) whose fog prior was scaled (`stated`) and whose estimate differs from `plain` (made without them).
|
|
152
|
+
* A player whose own income was given (`known`) is left out: its figure is the one supplied. Ascending ids. Pure.
|
|
153
|
+
*/
|
|
154
|
+
export function statedShifts(plain, scaled, prior) {
|
|
155
|
+
if (!prior?.stated)
|
|
156
|
+
return [];
|
|
157
|
+
const before = new Map(plain.map((e) => [e.playerId, e.estimate]));
|
|
158
|
+
return scaled
|
|
159
|
+
.filter((e) => e.stated && !e.known && before.has(e.playerId) && before.get(e.playerId) !== e.estimate)
|
|
160
|
+
.map((e) => ({ player: e.playerId, was: before.get(e.playerId), now: e.estimate, by: prior.stated.players }))
|
|
161
|
+
.sort((a, b) => a.player - b.player);
|
|
162
|
+
}
|
|
163
|
+
/** #567: the warning naming each opponent a known income moved (#444), and by how much; `null` with none. */
|
|
164
|
+
export function statedShiftWarning(shifts, name = String) {
|
|
165
|
+
if (!shifts.length)
|
|
166
|
+
return null;
|
|
167
|
+
const by = shifts[0].by.map((x) => `player ${name(x.id)}'s ${x.income}`).join(', ');
|
|
168
|
+
const moved = shifts.map((x) => `player ${name(x.player)} ~${x.was} → ~${x.now}`).join(', ');
|
|
169
|
+
return (`The known income${shifts[0].by.length === 1 ? '' : 's'} given (${by}) moved ${shifts.length === 1 ? 'another opponent\'s estimate' : 'other opponents\' estimates'}: ${moved} (#444: ` +
|
|
170
|
+
'incomes stated in chat scale the fog prior of every opponent who stated none). To size them without it, give those incomes source "board" or leave them out.');
|
|
171
|
+
}
|
|
138
172
|
/**
|
|
139
173
|
* #332: in a commerce game with a rising army price (multiplier m > 0), what each estimate read off the board
|
|
140
174
|
* (`visible`, `exact`: its base and bonuses, in gold) buys in armies, its Reinforcement card's armies kept on top.
|
|
@@ -1105,7 +1105,7 @@ export function borderThreats(pc, ps, input, src, forces) {
|
|
|
1105
1105
|
const st = incomePrior.stated;
|
|
1106
1106
|
const said = st.players.map((x) => `player ${x.id} states ${x.income}`).join(', ');
|
|
1107
1107
|
const mid = e.stated.midpoint;
|
|
1108
|
-
warnings.push(`Player ${p}'s fog prior is scaled by the incomes stated in chat (known_income: ${said}), ${Math.round(st.
|
|
1108
|
+
warnings.push(`Player ${p}'s fog prior is scaled by the incomes stated in chat (known_income: ${said}), ${Math.round(st.scale * 100) / 100}× my ${st.mine} (the square root of their mean's ${Math.round(st.ratio * 100) / 100}× mine, #567): ~${e.stated.scaled} in place of ~${e.stated.full}, never below what is in view or tracked${mid !== null ? `; with no track it is sized at the midpoint ~${mid} between ~${e.stated.lower} and ~${e.stated.scaled} (#368)` : ''}.`);
|
|
1109
1109
|
}
|
|
1110
1110
|
// #368: an income the user supplied replaces the estimate.
|
|
1111
1111
|
if (e.known) {
|