@chrischall/warapp-mcp 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/.claude-plugin/marketplace.json +3 -3
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +41 -5
  4. package/dist/analysis/card-support.js +2 -1
  5. package/dist/analysis/card-threats.js +59 -12
  6. package/dist/analysis/game-lessons.js +3 -4
  7. package/dist/analysis/hold-diff.js +3 -1
  8. package/dist/analysis/income-trend.js +38 -0
  9. package/dist/analysis/intel.js +75 -0
  10. package/dist/analysis/opens.js +64 -0
  11. package/dist/analysis/opponent-profile.js +75 -7
  12. package/dist/analysis/opponents.js +2 -2
  13. package/dist/analysis/outlook.js +39 -0
  14. package/dist/analysis/picks.js +91 -12
  15. package/dist/analysis/plan/bonus-attempts.js +105 -0
  16. package/dist/analysis/plan/capture-instead.js +116 -0
  17. package/dist/analysis/plan/captures.js +45 -4
  18. package/dist/analysis/plan/conceded-out.js +13 -2
  19. package/dist/analysis/plan/estimates.js +135 -26
  20. package/dist/analysis/plan/holds.js +31 -3
  21. package/dist/analysis/plan/jabs.js +113 -0
  22. package/dist/analysis/plan/leftover.js +249 -4
  23. package/dist/analysis/plan/orders.js +76 -4
  24. package/dist/analysis/plan/relations.js +21 -1
  25. package/dist/analysis/plan/report.js +69 -3
  26. package/dist/analysis/plan/second-sizing.js +133 -0
  27. package/dist/analysis/plan/shared.js +82 -20
  28. package/dist/analysis/plan/siege.js +303 -0
  29. package/dist/analysis/plan/stand-still.js +7 -3
  30. package/dist/analysis/plan/state.js +8 -0
  31. package/dist/analysis/plan/strike.js +10 -5
  32. package/dist/analysis/plan/targets.js +91 -60
  33. package/dist/analysis/plan/threats.js +41 -6
  34. package/dist/analysis/plan/transfers.js +46 -6
  35. package/dist/analysis/planner.js +234 -16
  36. package/dist/analysis/profile.js +13 -2
  37. package/dist/analysis/stress.js +8 -2
  38. package/dist/bonus-attempt-store.js +55 -0
  39. package/dist/bundle.js +48009 -39350
  40. package/dist/cards.js +7 -5
  41. package/dist/chat.js +46 -4
  42. package/dist/commerce.js +111 -0
  43. package/dist/index.js +9 -1
  44. package/dist/live.js +43 -0
  45. package/dist/move-order.js +64 -3
  46. package/dist/my-games.js +1 -1
  47. package/dist/normalize.js +17 -0
  48. package/dist/profile-store.js +12 -2
  49. package/dist/protocol/bundle.js +28 -10
  50. package/dist/protocol/codec.js +1 -1
  51. package/dist/protocol/dialect.js +371 -0
  52. package/dist/protocol/interp.js +143 -66
  53. package/dist/protocol/methods.js +95 -34
  54. package/dist/protocol/rpc.js +35 -3
  55. package/dist/push/socketio.js +2 -2
  56. package/dist/relations-store.js +38 -4
  57. package/dist/siege-store.js +49 -0
  58. package/dist/state-bundle.js +525 -0
  59. package/dist/state-cli.js +69 -0
  60. package/dist/surrender-pending.js +4 -4
  61. package/dist/team-cards.js +25 -0
  62. package/dist/tools/award.js +15 -1
  63. package/dist/tools/card-advice.js +16 -5
  64. package/dist/tools/card-plays.js +2 -2
  65. package/dist/tools/card-support-advice.js +2 -1
  66. package/dist/tools/chat-inbox.js +36 -3
  67. package/dist/tools/chat-read-mark.js +3 -1
  68. package/dist/tools/chat.js +65 -6
  69. package/dist/tools/check-plan.js +54 -10
  70. package/dist/tools/commerce-deploy.js +33 -0
  71. package/dist/tools/common.js +31 -0
  72. package/dist/tools/end-of-game.js +5 -3
  73. package/dist/tools/index.js +7 -0
  74. package/dist/tools/my-games.js +10 -3
  75. package/dist/tools/notifications.js +2 -2
  76. package/dist/tools/picks.js +12 -0
  77. package/dist/tools/profile-opponents.js +2 -0
  78. package/dist/tools/push.js +2 -1
  79. package/dist/tools/relations.js +137 -0
  80. package/dist/tools/state.js +227 -0
  81. package/dist/tools/stress-opponents.js +5 -2
  82. package/dist/tools/surrender-pending.js +11 -6
  83. package/dist/tools/survival.js +11 -3
  84. package/dist/tools/team-brief.js +2 -2
  85. package/dist/tools/team.js +12 -3
  86. package/dist/tools/turn.js +332 -60
  87. package/dist/version.js +1 -1
  88. package/manifest.json +10 -2
  89. package/mint.yaml +14 -4
  90. package/package.json +4 -4
  91. package/server.json +2 -2
  92. package/skills/warapp-mcp/SKILL.md +31 -9
@@ -6,8 +6,8 @@
6
6
  "email": "chris.c.hall@gmail.com"
7
7
  },
8
8
  "metadata": {
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, 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 and linking a session are confirm-gated).",
10
- "version": "0.4.0"
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, 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.6.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.4.0",
18
+ "version": "0.6.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.0",
4
+ "version": "0.6.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
@@ -147,14 +147,14 @@ Locally `WARAPP_AUTH_TOKEN` is ignored.
147
147
  | `warapp_plan_route` | Shortest path between two territories, given by name or id. |
148
148
  | `warapp_get_live_board` | The live board through your war.app tab: every territory with its owner (player, `neutral`, or `pickable` during picks), armies and fog, and in a Commanders game whose `commander` stands there. Works in the pick phase and mid-game. `view`: compact / full (every special unit — commanders, bosses — with its owner). Narrow it with `owner` (`me`, `neutral`, `pickable` or a player), `territories`, and `limit`/`offset` paging. Fog levels use war.app's own names: `You` (yours), `Visible`, `OwnerOnly` (owner shown, armies hidden: `armies` is null) and `Fogged` (owner and armies hidden). |
149
149
  | `warapp_get_my_picks` | Your submitted territory picks in priority order, and how many the game allows. |
150
- | `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 — 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: 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 an opponent bordering the fog is assumed to earn at least your income); `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), `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 (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). `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). |
151
- | `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. 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 (a Bomb or Emergency Blockade in the orders is warned of as not simulated). `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`). Read-only. |
150
+ | `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), `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 (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). `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). |
151
+ | `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 (a Bomb or Emergency Blockade in the orders is warned of as not simulated). `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`). Read-only. |
152
152
  | `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). |
153
153
  | `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). |
154
154
  | `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`. |
155
155
  | `warapp_plan_picks` | A pick list for a manual-distribution game in the picking stage, from the map, the settings and the live board's pickable territories: priority order by name and id, a compact primary group (the territory limit) and a disjoint fallback group (as long as war.app's client allows), each pick's score and reasons (bonus, value, turns to complete, first-turn bonus, entry points, contested), the award (the sets the award order can grant, and the worst), the primary's `coverage` (the reasonable bonuses its picks can stand next to within 2 moves) and, in a 1v1 when it covers more, a coverage-first `alternative` list with its own `submitPicks` (compact is the default; the alternative suits a small board), warnings for assumed settings, and `submitPicks` — the ids in order, ready for `warapp_submit_picks`. In a team game only the players off your team are threats, `team` names your teammates, and the list is judged by both award orders that fit (`award.orders`; a team game's is unverified); `warapp_submit_picks` warns when a team game's list is shorter than starts × all players. When a teammate's pick list can be read (their entered orders, else `GetTerritoryPicks`; unverified live), each teammate carries `picks` and `team.coordination` reports the overlap with your list, the bonuses their top picks into (a bonus pays one holder, so your picks there are not credited) and a `mirrored` alternative — the same top picks in both lists, laid on the positions a reversing award gives one player, with the bonuses a repeating order would split and its own `submitPicks` — beside the split list in `submitPicks`, which leaves their top picks to them and is shortened only when disjoint from their list and theirs is full length; every `submitPicks` fits war.app's client limit. With no list read the plan is unchanged. The heuristics are in [docs/STRATEGY.md](docs/STRATEGY.md). `view`: compact / full. Read-only; refuses outside the picking stage. With finished games on the map, `mapRecord` reports them beside the list (reported only): your results by start bonus, where winners started, and the median income after turns 4 and 8. |
156
156
  | `warapp_submit_picks` | **Writes.** Replace your territory picks (priority order, pickable territories only; a list longer than war.app's client allows — players × territories per player — or shorter than each player's share is warned about in the preview). Confirm-gated; reads the picks back and reports `verified` only on an exact match. |
157
- | `warapp_submit_turn` | **Writes.** Commit your turn's orders (e.g. `warapp_plan_turn`'s `orders`) as the signed-in account: card plays (Reinforcement, Order Priority, Order Delay, Blockade, Airlift — the Blockade and Airlift plays verified live 2026-11-16; and, encoded as the client does but not yet verified live, Spy, Reconnaissance, Surveillance, Gift, Diplomacy, Sanctions, Bomb and Emergency Blockade with their targets — refused where war.app would refuse them, e.g. a commander gifted or airlifted to a teammate, a Spy or Sanctions on your own side, a Spy on the neutral (player `0`) unless the game's Spy card allows it, Diplomacy between teammates or naming a player who is out, a Bomb on your own side or not next to you, an Emergency Blockade on a territory not yours or on your commander; in a team game the preview warns when the orders play or discard a card your teammate has already entered (a card named by type is one nobody entered when there is one; their orders are read from the live board, unverified); an Airlift may send `armies: 0` with `commander` to move the commander alone, and a Gift to an opponent is named as one in the preview), discards, deploys and moves. Confirm-gated; validated on the live board (cards in your hand, your territories, adjacent moves, armies available, deploys = income + played Reinforcement armies; bonus armies inside their bonus under Local Deployment; one attack/transfer per territory under No-Split, with a warning when one sends less than the whole stack; enough card plays or discards when you hold more cards than the limit); confirmed from game state (`resolved` / `committed` / `unknown`). An order that attacks (or a Bomb that hits) a territory an active or in-notice truce covers (`warapp_record_agreement`) is refused unless `break_agreement: true`: the preview then names the agreement, and once the orders are committed the ledger records it broken by you (and the partner's player record says so). In a Commanders game, orders that leave your commander takeable by one opponent's single deploy, or two striking together when you lead a free-for-all (each reply sized at the larger of its estimate and your income, on the live board; your Airlifts are counted, after the deploys and before the moves, the commander with one that takes it), are refused with the armies that would hold (under Local Deployment the hint says a deploy there must come from a pool that reaches it), and so is a Blockade or Gift of a territory your commander stands on before or after the orders (not simulated), unless `accept_commander_risk: true` (ask first: losing the commander loses the game); the preview then warns first and the result records `commanderRiskAccepted`. The preview also warns when the orders break a promise a chat message declared (`warapp_send_chat`'s `commitments`): an attack you said you would not make, or an attack you said you would make and left out. It warns too (never refuses) when the orders leave a border of a bonus you hold falling to a single deploy below your own income (#275 headroom), and when they leave any border below what the default plan made now (as `warapp_plan_turn` makes it with no options, or its border guess when the deploys are the guess's) leaves standing there, naming each with the difference (#275). Other players see the results. |
157
+ | `warapp_submit_turn` | **Writes.** Commit your turn's orders (e.g. `warapp_plan_turn`'s `orders`) as the signed-in account: card plays (Reinforcement, Order Priority, Order Delay, Blockade, Airlift, Diplomacy — the Blockade and Airlift plays verified live 2026-11-16, Diplomacy 2026-11-18; and, encoded as the client does but not yet verified live, Spy, Reconnaissance, Surveillance, Gift, Sanctions, Bomb and Emergency Blockade with their targets — refused where war.app would refuse them, e.g. a commander gifted or airlifted to a teammate, a Spy or Sanctions on your own side, a Spy on the neutral (player `0`) unless the game's Spy card allows it, Diplomacy between teammates or naming a player who is out, a Bomb on your own side or not next to you, an Emergency Blockade on a territory not yours or on your commander; in a team game the preview warns when the orders play or discard a card your teammate has already entered (a card named by type is one nobody entered when there is one; their orders are read from the live board, unverified); an Airlift may send `armies: 0` with `commander` to move the commander alone, and a Gift to an opponent is named as one in the preview), discards, deploys and moves. Confirm-gated; validated on the live board (cards in your hand, your territories, adjacent moves, armies available, deploys = income + played Reinforcement armies; bonus armies inside their bonus under Local Deployment; one attack/transfer per territory under No-Split, with a warning when one sends less than the whole stack; enough card plays or discards when you hold more cards than the limit); confirmed from game state (`resolved` / `committed` / `unknown`). An order that attacks (or a Bomb that hits) a territory an active or in-notice truce covers (`warapp_record_agreement`) is refused unless `break_agreement: true`: the preview then names the agreement, and once the orders are committed the ledger records it broken by you (and the partner's player record says so). In a Commanders game, orders that leave your commander takeable by one opponent's single deploy, or two striking together when you lead a free-for-all (each reply sized at the larger of its estimate and your income, on the live board; your Airlifts are counted, after the deploys and before the moves, the commander with one that takes it), are refused with the armies that would hold (under Local Deployment the hint says a deploy there must come from a pool that reaches it), and so is a Blockade or Gift of a territory your commander stands on before or after the orders (not simulated), unless `accept_commander_risk: true` (ask first: losing the commander loses the game); the preview then warns first and the result records `commanderRiskAccepted`. The preview also warns when the orders break a promise a chat message declared (`warapp_send_chat`'s `commitments`): an attack you said you would not make, or an attack you said you would make and left out. It warns too (never refuses) when the orders leave a border of a bonus you hold falling to a single deploy below your own income (#275 headroom), and when they leave any border below what the default plan made now (as `warapp_plan_turn` makes it with no options, or its border guess when the deploys are the guess's) leaves standing there, naming each with the difference (#275). Other players see the results. |
158
158
  | `warapp_uncommit_turn` | **Writes.** Withdraw your committed orders for the current turn (war.app's UnCommit, the game's "Modify orders") so you can submit corrected ones with `warapp_submit_turn`. Confirm-gated; refuses outside a turn phase and when your orders are not committed; reads the outcome from GameFeed (`uncommitted` / `unconfirmed`, or `unknown` when war.app did not answer — never resent). The game waits on you again, so recommit before the boot timer. A truce recorded broken by you on that turn (`break_agreement`) stays recorded: `agreementsStillBroken` names it. |
159
159
  | `warapp_chat_inbox` | The chat you have not marked seen, across all your games in one call (your lobbies and games being picked or played, from your games list, and a finished game when war.app flags its chat unread, or when those flags do not read (`finishedUnflagged` counts these) — or exactly the games in `game_ids`; `gamesFrom` says which, and from the list `listed`/`complete` whether it was whole): per game with something new, `unread` per channel and only the new messages (the newest `limit`, delimited, as `warapp_get_chat` shows them); games with nothing new in `quiet`, a game whose read failed in `failed` (never an error for the call). At most `max_games` (default and max 10) games per call, read one at a time: pass `next` back as `cursor` for the rest. Reading marks nothing; `mark_seen: true` marks every channel of each game read as seen, on this machine only (war.app still shows them unread until `warapp_mark_chat_read` marks them read there). Read-only. |
160
160
  | `warapp_get_notifications` | Your war.app in-app notifications (the game's notifications screen), 30 per page and by id only: each with `id`, `kind` (`game-ended` when the title is war.app's `Game "…" has ended.` line, else `other`), `gameId` (the game its link names, or null), `time` and `unread`; never the title or body, which carry other players' names. `total`, `next` (pass back as `start`) and `unread_only`. A game-ended notification runs the end-of-game pass on that game once, as `warapp_get_game` does (`endOfGame`: `processed`, each with `profileFold`, and `pending`; at most two games a call, one history read each, none for a game already processed), and folds the opponent profile kept for it (`profilesFolded`: one game read, only when such a profile is still kept unfolded). Read from war.app's client code, unverified live. Read-only. |
@@ -167,6 +167,10 @@ Locally `WARAPP_AUTH_TOKEN` is ignored.
167
167
  | `warapp_send_chat` | **Writes.** Post a chat message to the whole game, to your team (`channel: "team"`, refused outside a team game or when your team is unknown; unverified live), or privately to one player (`to`; refused when the game turns private messaging off). Confirm-gated; the preview names the channel. The game is read from GameFeed first, so it needs the GameFeed credentials as well as the bridge (an unknown game, or a private message to yourself, is refused); a message reaches other players and cannot be unsent. `outcome`: `confirmed` when war.app's reply shows it as your newest message there, `accepted` when the reply cannot be read, `unconfirmed` otherwise. Whatever a message promises is declared in `commitments` (the text is never read): `no-attack` (a player, optionally some territories or bonuses, for 1–10 turns), `will-attack` (a player or a territory, this turn only), `notice` (on an agreed truce, optionally the turn the message says it ends, which must be the one the agreed notice gives; with 0 turns of notice the truce ends with the message), `propose` / `accept` (a truce on structured terms; an accept compares only the terms it restates, and a truce whose last turn is past is refused; a proposal, acceptance or notice goes to the partner — privately or to the whole game — and is refused privately to anyone else or on the team channel). Each is checked against this turn's plan (made in the call, or the orders this server already submitted) and the agreement ledger, and one they do not carry refuses the send. Once the message is confirmed or accepted they are recorded in the ledger as yours (a proposal, an acceptance or a notice also creates or moves the agreement), and `warapp_submit_turn` (and `warapp_plan_turn`, for its plan) warns when later orders break one — an attack into the fog under a promise over all of a player's territories is warned on as unchecked. |
168
168
  | `warapp_get_relations` | The truces you recorded for a game (`warapp_record_agreement`), each with its state this turn (proposed, active, in notice and the turn it ends, or over and why), and for a live one watch `flags` from your own board history — `broken` (the partner took or attacked a covered territory), `cap-exceeded`, `massing` (its visible armies near the covered border grew two turns running, or an event the fog leaves open), `outgrowing`, `kept` — and `trust` (`clear`, or `watch` on any flag but kept, their notice, or the endgame). Also `tacit`: neighbours with no agreement whose shared border stayed quiet three turns or more (reported, never relied on), and per partner the cross-game `record` of how it kept earlier agreements (tallies, kept rate, notices honoured, breaks in the endgame or while leading, retaliation, turns to a break; `view: "full"` adds the name-free entries). Chat never moves a flag; only the board does. Caches the board it read. |
169
169
  | `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). 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. |
170
+ | `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. |
171
+ | `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. |
172
+ | `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). |
173
+ | `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. |
170
174
  | `warapp_advise_diplomacy` | Truce advice in a free-for-all (refused in a 1v1 or a team game), read-only: whether the game allows private messages and the host's description when the feed carries one (untrusted text — read it for house rules such as "no alliances"); per neighbour the shared border (territories each side, chokepoints, stacks), a truce priced on suggested terms (the border territories, one turn of notice, a cap at the largest stack there, an end five turns on) — or on the recorded terms of an open agreement, keeping the board's reading of it (`relation`: a break or a watch flag is `no`) — by planning the turn with and without it: armies freed, captures, bonuses and next income gained, borders no longer conceded, planned attacks given up, `lossIfBroken`, an estimated reading of the partner's side and its cross-game record, with its `retaliate` and `attack` habits beside it (`habits`, as `warapp_profile_opponents` reads them; shown only, never priced) — and a verdict (`propose`, `accept-if-offered`, `no`) with reasons. `offer` (structured terms someone proposed, never parsed from chat) adds the three checks (I gain only if they keep it; I lose if I comply and they do not; they gain from my compliance — all three: `stressTestFirst`). `facts`: true statements about third players you may cite, each with whether the recipient can see it under the fog. Sends and records nothing. |
171
175
  | `warapp_wait_for_turn` | Wait until one of the given games (`game_ids`, 1–20; omitted, every game of yours being played or picked) is waiting on you, woken by war.app's push notifications through your war.app tab; returns at once if one already is, else at `timeout_seconds` (default 300, max 1800). A game whose push said chat arrived carries `chatActivity: true` (no text; unverified live). Also returns `surrender_pending` when another player's surrender waits on your acceptance (each game's `surrenderPending`, from the game details, unverified live; `surrenders` lists those games), unless `ignore_surrenders`; after one failed details read it stops asking for the rest of the wait (`surrenderUnread` says why). Reports progress; honours cancellation. |
172
176
  | `warapp_recent_events` | The game-update pushes this server process has received (newest first), and whether the push socket is connected. |
@@ -174,12 +178,40 @@ Locally `WARAPP_AUTH_TOKEN` is ignored.
174
178
  | `warapp_sign_in` | **Hosted only, for mcp-host's sign-in flow.** Signs in to war.app once with your email and password and returns the session cookie to the host, which keeps it as this connection's secret. The password is never stored; a refusal is never retried. Not offered on a local install. |
175
179
  | `warapp_link_session` | **Writes (locally).** Capture your signed-in war.app session cookie once and store it on this machine for the direct transport. Confirm-gated; stores a full-account credential locally (file mode `0600`) and never shows or sends it anywhere but war.app. |
176
180
 
177
- Everything except `warapp_submit_picks`, `warapp_submit_turn`, `warapp_send_chat`, `warapp_join_game`, `warapp_leave_game`, `warapp_surrender`, `warapp_accept_surrender`, `warapp_begin_turn`, `warapp_uncommit_turn`, `warapp_dismiss_notification`, `warapp_delete_notification`, `warapp_mark_chat_read`, `warapp_link_session`, `warapp_sign_in` (hosted only: starts a war.app session for the host's sign-in flow, not confirm-gated) and `warapp_record_agreement` (this machine's agreement ledger only, not confirm-gated) only reads. Player, game, map
181
+ Everything except `warapp_submit_picks`, `warapp_submit_turn`, `warapp_send_chat`, `warapp_join_game`, `warapp_leave_game`, `warapp_surrender`, `warapp_accept_surrender`, `warapp_begin_turn`, `warapp_uncommit_turn`, `warapp_dismiss_notification`, `warapp_delete_notification`, `warapp_mark_chat_read`, `warapp_link_session`, `warapp_import_state` (hosted only: this server's own state), `warapp_backfill_history` (this server's state only, not confirm-gated), `warapp_sign_in` (hosted only: starts a war.app session for the host's sign-in flow, not confirm-gated), `warapp_record_agreement` and `warapp_record_intel` (this machine's agreement ledger only, not confirm-gated) only reads. Player, game, map
178
182
  and chat text comes back marked as untrusted third-party content.
179
183
 
184
+ ## Moving local history to the hosted server
185
+
186
+ A local install keeps history war.app cannot give back: the salt behind every hashed key (the keys
187
+ also carry your account id), the deal record and per-game ledgers, the opponent profiles, lessons,
188
+ map records and end-of-game records. To carry it into the hosted server:
189
+
190
+ 1. **Export** on the machine with the local install:
191
+ `npx -y @chrischall/warapp-mcp export-state --out ~/Downloads/warapp-state.json.gz`
192
+ (`--data-dir` to read another dir, `--account <id>` when more than one account has files there,
193
+ `--force` to overwrite). It writes one gzipped bundle with a manifest (format version, account
194
+ id, created time, each file's sha256), file mode `0600`, and prints only counts and sizes. It
195
+ carries the stores above plus, for games still in play only (read from the local game records
196
+ and end-of-game marks), the boards, game records, outlook, picks, move order, teams, per-game
197
+ profile turns and siege memory. It never reads or includes credentials (`.env`,
198
+ `session.json`), and leaves out the bundle cache, guess salt, chat cursors, maps and stats
199
+ (all rebuilt) and the per-game files of finished games.
200
+ 2. **Upload**: ask the hosted server for `warapp_upload_slots`, then run the `curl` it returns with
201
+ the bundle's path (the URL is short-lived; share it with no one).
202
+ 3. **Import**: `warapp_import_state` with that `blob_key` previews first; confirm to write. If the
203
+ hosted server already made its own salt, the preview refuses until you pass `replace: true`,
204
+ which backs its hashed stores up into `state-backups/<time>/` rather than mixing two salts.
205
+ 4. **Backfill**: `warapp_backfill_history` processes your finished games not yet processed, up to
206
+ 25 a call, until `remaining` is 0.
207
+
208
+ **Privacy.** The salt travels only inside the bundle, which is why the bundle is `0600` and the
209
+ upload is deleted once imported: delete the local bundle too. Credentials never travel; the hosted
210
+ server keeps its own sign-in. Neither tool ever returns the salt or a file's contents.
211
+
180
212
  ## Confirming writes
181
213
 
182
- `warapp_submit_picks`, `warapp_submit_turn`, `warapp_send_chat`, `warapp_leave_game`, `warapp_surrender`, `warapp_accept_surrender`, `warapp_begin_turn`, `warapp_uncommit_turn`, `warapp_dismiss_notification`, `warapp_delete_notification`, `warapp_mark_chat_read`, `warapp_join_game` and `warapp_link_session` are confirmation-gated:
214
+ `warapp_submit_picks`, `warapp_submit_turn`, `warapp_send_chat`, `warapp_leave_game`, `warapp_surrender`, `warapp_accept_surrender`, `warapp_begin_turn`, `warapp_uncommit_turn`, `warapp_dismiss_notification`, `warapp_delete_notification`, `warapp_mark_chat_read`, `warapp_join_game`, `warapp_import_state` and `warapp_link_session` are confirmation-gated:
183
215
 
184
216
  - **Clients that support MCP elicitation** show a confirmation prompt describing the change.
185
217
  - **Other clients** make **no** change on the first call: it returns a preview and a
@@ -289,6 +321,10 @@ games' histories and replays the opening on today's planner, aggregates only: a
289
321
  (`<data dir>/finished/`): it reads no history itself, so it has nothing to score until the end-of-game pass has
290
322
  run on finished games.
291
323
 
324
+ War.app ships a new web client every few weeks. How releases ship, what each kind breaks here, how long
325
+ war.app keeps answering an older protocol, and the checklist for updating are in
326
+ [docs/CLIENT-RELEASES.md](docs/CLIENT-RELEASES.md).
327
+
292
328
  ## License
293
329
 
294
330
  MIT
@@ -9,7 +9,8 @@
9
9
  // players from the turn after it is played; Sanctions cut the target's income from its next turn (a
10
10
  // negative percentage raises it); an Airlift lands after the deploys and before every attack, and armies
11
11
  // landing on a teammate's territory become the teammate's; a Gift moves a territory and its armies after
12
- // the airlifts and before the attacks. The card plays' encodings are UNVERIFIED live (V9).
12
+ // the airlifts and before the attacks. The card plays' encodings are UNVERIFIED live (V9) save Airlift's (#296)
13
+ // and Diplomacy's (#369: played live 2026-11-18 and read in force on later boards).
13
14
  import { bonusTerritories } from './bonuses.js';
14
15
  import { COMMANDER_STRENGTH } from './combat.js';
15
16
  import { reader } from './card-threats.js';
@@ -1,7 +1,8 @@
1
1
  // Cards the planner does not play, read against its plan (#163): my Bomb (where halving a stack
2
2
  // changes a hold, a capture or a commander kill, else hold it), an opponent's Bomb (borders that
3
3
  // hold only while unbombed), an opponent's Emergency Blockade (attacks that would die against the
4
- // wall) and my own (a conceded border where the wall kills more than I give up). Pure and
4
+ // wall) and my own (a conceded border where the wall pays: what it kills plus the bonuses and
5
+ // commander behind it the stack could reach only through it, against what I give up; #369). Pure and
5
6
  // deterministic (ties on ascending territory id); no I/O.
6
7
  //
7
8
  // Rules (the wiki's Bomb_Card, Turn_phases, Emergency Blockade; docs/STRATEGY.md): a Bomb hits a
@@ -196,27 +197,33 @@ export function wallThreats(cb, multiplier) {
196
197
  return out;
197
198
  }
198
199
  /**
199
- * Where my Emergency Blockade pays: a border the plan concedes, where the wall of my armies there
200
- * (this turn's deploy included) times the multiplier kills more of the stack that can reach it
201
- * than the armies I give up — never on my commander's territory (it would be lost with it),
202
- * never on one the plan moves armies out of (they would be lost with it: the wall comes before the
203
- * moves) and never on a member of a bonus I hold whole at the start of the turn (I need it). The best by
204
- * kills over armies given up, then ascending id; `undefined` when none pays.
200
+ * Where my Emergency Blockade pays (#163, #369): a border the plan concedes (it cannot hold it),
201
+ * walled with my armies there (this turn's deploy included) times the multiplier. Priced by the board:
202
+ * it gives up the territory and its armies, against what the wall kills of the stack that can reach
203
+ * it (if it attacks) plus what it protects — the income of the bonuses I hold behind it that the stack
204
+ * could reach next turn only through it (one turn of it), and my commander behind it, which always pays.
205
+ * Never when the opponent can go around: something of mine lies behind the wall but the stack reaches
206
+ * all of it as fast another way, so it need never attack the wall. Never on my commander's territory (it
207
+ * would be lost with it), never on one the plan moves armies out of (they would be lost with it: the
208
+ * wall comes before the moves) and never on a member of a bonus I hold whole at the start of the turn
209
+ * (the wall breaks it). The best shields my commander, then by kills plus income over armies given up,
210
+ * then ascending id; `undefined` when none pays.
205
211
  */
206
212
  export function wallOffer(cb, multiplier, conceded) {
207
213
  const r = reader(cb);
208
214
  const defence = cb.settings?.defensiveKillRate ?? DEFAULT_DEFENSIVE_KILL_RATE;
209
- const held = (id) => cb.graph.map.bonuses.some((bonus) => {
215
+ const heldBonuses = (id) => cb.graph.map.bonuses.filter((bonus) => {
210
216
  if (bonus.value <= 0)
211
217
  return false;
212
218
  const members = bonusTerritories(cb.graph, bonus.id);
213
219
  return members.includes(id) && members.every(r.isMine);
214
220
  });
221
+ const worth = (o) => o.kills + o.protects.income - o.givesUp;
215
222
  let best;
216
223
  for (const c of [...conceded].sort((a, b) => a - b)) {
217
224
  // A border the plan withdraws from is skipped: the wall turns it neutral before the moves, so
218
225
  // the armies the plan moves out of it would be lost with it.
219
- if (!r.isMine(c) || r.commanderOf(c, (q) => q === cb.me) || held(c) || r.outOf(c) > 0)
226
+ if (!r.isMine(c) || r.commanderOf(c, (q) => q === cb.me) || heldBonuses(c).length || r.outOf(c) > 0)
220
227
  continue;
221
228
  const reach = r.reachOf(c);
222
229
  if (!reach)
@@ -224,11 +231,51 @@ export function wallOffer(cb, multiplier, conceded) {
224
231
  const givesUp = r.armiesOf(c) + r.deployAt(c);
225
232
  const wall = wallOf(givesUp, multiplier);
226
233
  const kills = Math.min(reach.reach, straightKills(wall, defence));
227
- if (kills <= givesUp)
234
+ const shield = wallShield(cb, r, c, reach.player);
235
+ if (shield.goesAround)
228
236
  continue;
229
- const offer = { territory: c, givesUp, wall, player: reach.player, reach: reach.reach, kills };
230
- if (!best || kills - givesUp > best.kills - best.givesUp)
237
+ // A wall the stack can take blocks nothing: it walks through and on.
238
+ const blocks = r.toTake(wall) > reach.reach;
239
+ const protects = blocks ? shield.protects : { territories: [], bonuses: [], income: 0, commander: false };
240
+ const offer = { territory: c, givesUp, wall, player: reach.player, reach: reach.reach, kills, protects };
241
+ if (!protects.commander && worth(offer) <= 0)
242
+ continue;
243
+ if (!best ||
244
+ (protects.commander && !best.protects.commander) ||
245
+ (protects.commander === best.protects.commander && worth(offer) > worth(best)))
231
246
  best = offer;
232
247
  }
233
248
  return best;
234
249
  }
250
+ /**
251
+ * Behind the wall on `c` (#369): my territories next to `c` that `player`'s stacks beside `c` can reach
252
+ * next turn only through it. One is reachable another way when the player already borders it, or a
253
+ * territory other than `c` borders both it and one of those stacks (two steps either way).
254
+ * `goesAround`: something of mine lies next to `c`, and every piece of it is reachable another way.
255
+ */
256
+ function wallShield(cb, r, c, player) {
257
+ const stacks = neighborsOf(cb.graph, c).filter((n) => r.ownerOf(n) === player);
258
+ const behind = neighborsOf(cb.graph, c)
259
+ .filter((n) => n !== c && r.isMine(n))
260
+ .sort((a, b) => a - b);
261
+ const around = (y) => neighborsOf(cb.graph, y).some((x) => r.ownerOf(x) === player || (x !== c && stacks.some((s) => neighborsOf(cb.graph, s).includes(x))));
262
+ const territories = behind.filter((y) => !around(y));
263
+ const bonuses = new Map();
264
+ for (const bonus of cb.graph.map.bonuses) {
265
+ if (bonus.value <= 0)
266
+ continue;
267
+ const members = bonusTerritories(cb.graph, bonus.id);
268
+ if (members.every(r.isMine) && territories.some((y) => members.includes(y)))
269
+ bonuses.set(bonus.id, bonus.value);
270
+ }
271
+ const list = [...bonuses].sort((a, b) => a[0] - b[0]).map(([bonus, value]) => ({ bonus, value }));
272
+ return {
273
+ protects: {
274
+ territories,
275
+ bonuses: list,
276
+ income: list.reduce((a, b) => a + b.value, 0),
277
+ commander: territories.some((y) => r.commanderOf(y, (q) => q === cb.me)),
278
+ },
279
+ goesAround: behind.length > 0 && territories.length === 0,
280
+ };
281
+ }
@@ -52,10 +52,9 @@ export function incomeCurve(turns, player) {
52
52
  })
53
53
  .sort((a, b) => a.afterTurn - b.afterTurn);
54
54
  }
55
- /** The turns of no growth that make an income flat (#312: "slope ≈ 0 for 3+ turns"). */
56
- export const FLAT_TURNS = 3;
57
- /** What counts as no growth over those turns: at most this share of the income (and at least 1 army). */
58
- export const FLAT_TOLERANCE = 0.1;
55
+ // #303: one definition of "flat", shared with the planner's income trend.
56
+ import { FLAT_TOLERANCE, FLAT_TURNS } from './income-trend.js';
57
+ export { FLAT_TOLERANCE, FLAT_TURNS };
59
58
  /**
60
59
  * The first board (by completed turns, the opening's board 0 left out) from which my income stayed
61
60
  * within {@link FLAT_TOLERANCE} of it (at least 1) on each of the next {@link FLAT_TURNS} consecutive
@@ -21,6 +21,8 @@ import { COMMANDER_STRENGTH } from './combat.js';
21
21
  import { neighborsOf } from './graph.js';
22
22
  import { neutralizeSeats } from './static-seats.js';
23
23
  import { simTerritories, simulateTurn } from './turn-sim.js';
24
+ /** #306: the least shortfall warapp_check_plan and warapp_submit_turn name; smaller ones are the plan's surplus. */
25
+ export const BELOW_PLAN_MIN_SHORT = 3;
24
26
  /** Every border the given orders leave below what the default plan leaves there, the largest shortfall first. */
25
27
  export function holdsBelowPlan(input) {
26
28
  const { graph, me, teams } = input;
@@ -57,7 +59,7 @@ export function holdsBelowPlan(input) {
57
59
  for (const id of borders) {
58
60
  const planLeaves = planned(id);
59
61
  const left = given(id);
60
- if (left < planLeaves)
62
+ if (planLeaves - left >= Math.max(1, input.minShort ?? 1))
61
63
  out.push({ territory: id, planLeaves, left, short: planLeaves - left });
62
64
  }
63
65
  return out.sort((a, b) => b.short - a.short || a.territory - b.territory);
@@ -0,0 +1,38 @@
1
+ // #303: my income over the last turns — the points, a least-squares slope and whether it is flat.
2
+ // Pure. The flat test is #312's (`flatTurn` in game-lessons.ts), on the turns that end at this one.
3
+ /** The turns of no growth that make an income flat (#312: "slope ≈ 0 for 3+ turns"). */
4
+ export const FLAT_TURNS = 3;
5
+ /** What counts as no growth over those turns: at most this share of the income (and at least 1 army). */
6
+ export const FLAT_TOLERANCE = 0.1;
7
+ /** The turns the trend reports, the current one included (#303: "the last five turns"). */
8
+ export const TREND_POINTS = 5;
9
+ /**
10
+ * The trend over `earlier` boards' incomes and `current` (later readings of a turn win; a turn at or after the
11
+ * current one is ignored). Absent with no earlier turn.
12
+ */
13
+ export function incomeTrend(earlier, current) {
14
+ const by = new Map();
15
+ for (const p of earlier)
16
+ if (p.turn < current.turn)
17
+ by.set(p.turn, p.income);
18
+ if (by.size === 0)
19
+ return undefined;
20
+ by.set(current.turn, current.income);
21
+ const turns = [...by.entries()]
22
+ .sort((a, b) => a[0] - b[0])
23
+ .slice(-TREND_POINTS)
24
+ .map(([turn, income]) => ({ turn, income }));
25
+ const n = turns.length;
26
+ const mx = turns.reduce((s, p) => s + p.turn, 0) / n;
27
+ const my = turns.reduce((s, p) => s + p.income, 0) / n;
28
+ const sxx = turns.reduce((s, p) => s + (p.turn - mx) ** 2, 0);
29
+ const sxy = turns.reduce((s, p) => s + (p.turn - mx) * (p.income - my), 0);
30
+ const slope = sxx > 0 ? Math.round((sxy / sxx) * 10) / 10 : 0;
31
+ const tail = turns.slice(-(FLAT_TURNS + 1));
32
+ const first = tail[0];
33
+ const tol = Math.max(1, FLAT_TOLERANCE * first.income);
34
+ const flat = tail.length === FLAT_TURNS + 1 &&
35
+ first.income > 0 &&
36
+ tail.every((p, i) => p.turn === first.turn + i && p.income > 0 && Math.abs(p.income - first.income) <= tol);
37
+ return { turns, slope: slope === 0 ? 0 : slope, flat };
38
+ }
@@ -0,0 +1,75 @@
1
+ // #386: what the player learnt in diplomacy and wants every plan to apply, kept per game in the agreement
2
+ // ledger (src/relations-store.ts) by `warapp_record_intel`: territories promised to someone, players I
3
+ // promised not to attack outside any truce (with a reason from a fixed list: the ledger is name-free, no
4
+ // message), and a player's stated income with the turn it was stated. `warapp_plan_turn` and
5
+ // `warapp_check_plan` apply them by default (`resolveIntel`); an explicit `avoid_territories`,
6
+ // `avoid_players` or `known_income` replaces the stored list of its kind for that call, and a stored
7
+ // income older than `INCOME_STALE_TURNS` turns is not applied (the estimate stands, with a warning). Pure.
8
+ /** Why a player is not to be attacked: a fixed list, so the ledger holds no free text. */
9
+ export const AVOID_REASONS = ['promised', 'asked-by-them', 'joint-enemy', 'kingmaker', 'other'];
10
+ /** A stored income is applied while `turn - statedTurn` is at most this; older, the estimate stands. */
11
+ export const INCOME_STALE_TURNS = 3;
12
+ export const emptyIntel = () => ({ avoidTerritories: [], avoidPlayers: [], incomes: [] });
13
+ export const intelIsEmpty = (i) => !i || (i.avoidTerritories.length === 0 && i.avoidPlayers.length === 0 && i.incomes.length === 0);
14
+ /**
15
+ * The arguments a plan uses: each kind given explicitly as it is, else the stored entries (incomes only
16
+ * while fresh on `turn`; `null` turn: every stored income applies, none can be judged stale).
17
+ */
18
+ export function resolveIntel(stored, turn, args) {
19
+ const out = {
20
+ ...(args.knownIncome !== undefined ? { knownIncome: [...args.knownIncome] } : {}),
21
+ ...(args.avoidTerritories !== undefined ? { avoidTerritories: [...args.avoidTerritories] } : {}),
22
+ ...(args.avoidPlayers !== undefined ? { avoidPlayers: [...args.avoidPlayers] } : {}),
23
+ warnings: [],
24
+ };
25
+ if (intelIsEmpty(stored))
26
+ return out;
27
+ const s = stored;
28
+ const report = { applied: { avoidTerritories: [], avoidPlayers: [], knownIncome: [] }, overridden: [], stale: [] };
29
+ if (s.avoidTerritories.length) {
30
+ if (args.avoidTerritories !== undefined)
31
+ report.overridden.push('avoid_territories');
32
+ else {
33
+ report.applied.avoidTerritories = s.avoidTerritories.map((a) => ({ territory: a.territory, ...(a.promisedTo !== undefined ? { promisedTo: a.promisedTo } : {}) }));
34
+ out.avoidTerritories = s.avoidTerritories.map((a) => a.territory);
35
+ }
36
+ }
37
+ if (s.avoidPlayers.length) {
38
+ if (args.avoidPlayers !== undefined)
39
+ report.overridden.push('avoid_players');
40
+ else {
41
+ report.applied.avoidPlayers = s.avoidPlayers.map((a) => ({ player: a.player, reason: a.reason }));
42
+ out.avoidPlayers = s.avoidPlayers.map((a) => a.player);
43
+ }
44
+ }
45
+ if (s.incomes.length) {
46
+ if (args.knownIncome !== undefined)
47
+ report.overridden.push('known_income');
48
+ else {
49
+ const fresh = [];
50
+ for (const i of s.incomes) {
51
+ const age = turn === null ? 0 : turn - i.turn;
52
+ if (age > INCOME_STALE_TURNS)
53
+ report.stale.push({ player: i.player, income: i.income, statedTurn: i.turn, turnsOld: age });
54
+ else
55
+ fresh.push(i);
56
+ }
57
+ report.applied.knownIncome = fresh.map((i) => ({ player: i.player, income: i.income, statedTurn: i.turn }));
58
+ if (fresh.length)
59
+ out.knownIncome = fresh.map((i) => ({ player: i.player, income: i.income }));
60
+ }
61
+ }
62
+ for (const st of report.stale)
63
+ out.warnings.push(`The income ${st.income} recorded for player ${st.player} (stated on turn ${st.statedTurn}) is ${st.turnsOld} turns old, past ` +
64
+ `${INCOME_STALE_TURNS}: it is not applied and the estimate stands. Record a fresh figure with warapp_record_intel, or forget it.`);
65
+ const a = report.applied;
66
+ const parts = [
67
+ ...(a.avoidTerritories.length ? [`avoids territor${a.avoidTerritories.length === 1 ? 'y' : 'ies'} ${a.avoidTerritories.map((t) => t.territory).join(', ')}`] : []),
68
+ ...(a.avoidPlayers.length ? [`avoids player${a.avoidPlayers.length === 1 ? '' : 's'} ${a.avoidPlayers.map((p) => p.player).join(', ')}`] : []),
69
+ ...(a.knownIncome.length ? [`takes the stated income of player${a.knownIncome.length === 1 ? '' : 's'} ${a.knownIncome.map((k) => `${k.player} (${k.income}, turn ${k.statedTurn})`).join(', ')}`] : []),
70
+ ];
71
+ if (parts.length)
72
+ out.warnings.push(`Recorded intel (warapp_record_intel) applied: the plan ${parts.join('; ')}. Pass the argument explicitly to override it for this call.`);
73
+ out.report = report;
74
+ return out;
75
+ }
@@ -0,0 +1,64 @@
1
+ // #291: what the loss of a territory of mine OPENS to the enemy. #235 counts what a loss cuts off from my own
2
+ // holdings; a gate cuts nothing off — it is the only way the enemy gets in. Its opened set is every territory of
3
+ // mine that every route from an enemy or the fog (a `source`) reaches only through it: with it taken out of the
4
+ // graph, no source reaches them, yet they lie behind it. Routes run through any territory (an enemy can take a
5
+ // neutral or one of mine on its way), so this is the map's own chokepoint, not a guess at the enemy's path.
6
+ // Pure and deterministic (neighbours as the graph lists them, ids ascending in the result).
7
+ import { bonusTerritories } from './bonuses.js';
8
+ import { neighborsOf } from './graph.js';
9
+ const byNum = (a, b) => a - b;
10
+ /**
11
+ * What losing my `t` opens (see the header). `holdings`: my territories; `isSource(x)`: `x` is an enemy's or
12
+ * hidden. A bonus already counted elsewhere — one with a member in `skip` (what losing `t` cuts off, #235; a
13
+ * guard-off breach, #275) — and one containing `t` (its own value already counts in full) are left out, so nothing
14
+ * is counted twice. Empty when `t` is no chokepoint.
15
+ */
16
+ export function opensBehind(g, holdings, isSource, t, skip) {
17
+ const empty = { ids: [], bonuses: [], income: 0 };
18
+ const ids = g.map.territories.map((x) => x.id);
19
+ const sources = ids.filter((x) => x !== t && isSource(x));
20
+ if (!sources.length)
21
+ return empty;
22
+ // Everything a source reaches with `t` taken out.
23
+ const reached = new Set(sources);
24
+ const queue = [...sources];
25
+ while (queue.length) {
26
+ const x = queue.shift();
27
+ for (const n of neighborsOf(g, x))
28
+ if (n !== t && !reached.has(n)) {
29
+ reached.add(n);
30
+ queue.push(n);
31
+ }
32
+ }
33
+ // Behind `t`: what it reaches through territories no source reaches. Mine among them are what it opens.
34
+ const behind = new Set();
35
+ const q2 = neighborsOf(g, t).filter((n) => !reached.has(n));
36
+ for (const n of q2)
37
+ behind.add(n);
38
+ while (q2.length) {
39
+ const x = q2.shift();
40
+ for (const n of neighborsOf(g, x))
41
+ if (n !== t && !reached.has(n) && !behind.has(n)) {
42
+ behind.add(n);
43
+ q2.push(n);
44
+ }
45
+ }
46
+ const opened = [...behind].filter((x) => holdings.has(x)).sort(byNum);
47
+ if (!opened.length)
48
+ return empty;
49
+ const set = new Set(opened);
50
+ const bonuses = [];
51
+ let income = 0;
52
+ for (const b of [...g.map.bonuses].sort((x, y) => x.id - y.id)) {
53
+ if (b.value <= 0)
54
+ continue;
55
+ const ts = bonusTerritories(g, b.id);
56
+ if (!ts.length || ts.includes(t) || !ts.every((x) => holdings.has(x)))
57
+ continue;
58
+ if (!ts.some((x) => set.has(x)) || ts.some((x) => skip.has(x)))
59
+ continue;
60
+ bonuses.push(b.id);
61
+ income += b.value;
62
+ }
63
+ return { ids: opened, bonuses, income };
64
+ }