@chrischall/warapp-mcp 0.18.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +1 -1
- package/dist/analysis/arena.js +389 -0
- package/dist/analysis/plan/captures.js +35 -60
- package/dist/analysis/plan/dead-advance.js +77 -0
- package/dist/analysis/plan/deploy-estimates.js +38 -2
- package/dist/analysis/plan/estimates.js +15 -46
- package/dist/analysis/plan/fogged-break.js +86 -0
- package/dist/analysis/plan/guard-off.js +1 -2
- package/dist/analysis/plan/holds.js +28 -9
- package/dist/analysis/plan/orders.js +39 -2
- package/dist/analysis/plan/report.js +5 -11
- package/dist/analysis/plan/shared.js +18 -0
- package/dist/analysis/plan/siege.js +1 -49
- package/dist/analysis/plan/stand-still.js +3 -4
- package/dist/analysis/plan/state.js +1 -0
- package/dist/analysis/plan/stockpile.js +0 -16
- package/dist/analysis/plan/strike-stack.js +1 -6
- package/dist/analysis/plan/strike.js +10 -0
- package/dist/analysis/plan/targets.js +34 -31
- package/dist/analysis/plan/threats.js +26 -9
- package/dist/analysis/plan/withdraw.js +3 -3
- package/dist/analysis/planner.js +181 -48
- package/dist/bundle.js +800 -347
- package/dist/tools/check-plan.js +4 -1
- package/dist/tools/stress-opponents.js +1 -0
- package/dist/tools/turn.js +7 -4
- package/dist/version.js +1 -1
- package/manifest.json +1 -1
- package/package.json +3 -3
- package/server.json +2 -2
- package/dist/analysis/plan/horizon.js +0 -42
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
},
|
|
8
8
|
"metadata": {
|
|
9
9
|
"description": "MCP server for war.app (Warzone) — your games, players, settings, map bonuses and chokepoints, board analysis and route planning through war.app's per-player GameFeed API, plus the live board, territory picks, cards, turn planning and submission, turn notifications and game chat through your signed-in war.app tab (joining, leaving or surrendering a game, closing out a finished game, accepting another player's surrender, Begin on a speed first turn, picks, turn orders, withdrawing them, chat sends, marking notifications and chat read, deleting notifications, importing local history and linking a session are confirm-gated).",
|
|
10
|
-
"version": "0.
|
|
10
|
+
"version": "0.20.0"
|
|
11
11
|
},
|
|
12
12
|
"plugins": [
|
|
13
13
|
{
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"displayName": "war.app (Warzone)",
|
|
16
16
|
"source": "./",
|
|
17
17
|
"description": "war.app (Warzone) game advisor for Claude — games, maps, bonuses, routes, live board, picks, turns, cards and chat",
|
|
18
|
-
"version": "0.
|
|
18
|
+
"version": "0.20.0",
|
|
19
19
|
"author": {
|
|
20
20
|
"name": "Chris Hall"
|
|
21
21
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "warapp-mcp",
|
|
3
3
|
"displayName": "war.app (Warzone)",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.20.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
|
@@ -153,7 +153,7 @@ Locally `WARAPP_AUTH_TOKEN` is ignored.
|
|
|
153
153
|
| `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). |
|
|
154
154
|
| `warapp_get_my_picks` | Your submitted territory picks in priority order, and how many the game allows. |
|
|
155
155
|
| `warapp_get_my_orders` | Your orders for the current turn read back from war.app (what the web client shows in "Modify orders"), read-only: `committed`, `orders` in exactly the shape `warapp_submit_turn` takes (card GUIDs and targets, players by GameFeed id, move options, Order Delay `before`) and `shown` (one line per order, with names). Resubmit them after `warapp_uncommit_turn` to change a committed turn without losing hand-made orders. `null` is unknown, never "none"; `unread` lists orders it could not read back. Committed orders verified live 2026-11-22; entered-but-uncommitted ones unverified. |
|
|
156
|
-
| `warapp_plan_turn` | A plan for your turn from the live board (defaults to the signed-in account): income, your cards and whether you must play one, deploys and moves by name and id, expected captures, bonuses and next income, the `frontier` budget (borders left, those facing an enemy, what they need to hold next turn, next income), warnings and reasoning, and an `orders` array (card plays included); `chat.unread` counts the chat messages not yet marked seen (counts only, from GameFeed, so every count is under `unknown`; its `note` says so); `surrenderPending` lists other players' surrenders still pending (from the game details, unverified live; `null` when unreadable), and when one waits on your acceptance the first warning says so. `goal`: balanced (default: best income per army across holds, bonuses and breaking enemy bonuses, with at least 30% on expansion) / expand / complete-bonus / defend / siege (one opponent, `siege_target` by GameFeed id, default the strongest one bordering you: its bonus breaks are funded cheapest per income lost first, its other territories are left alone and the spare deploys build one strike stack facing it until the assault trigger fires — its income at 0.6× its baseline — the most the tracker saw it deploy over its window, or its income when the siege began — yours at 1.8× its, or a stack of yours able to take a member of its held bonus against its whole deploy — then the stack strikes; `siege` reports `target`, `opponentIncome`, `baseline`, `ratio`, `fallenTo`, `breaks`, `brokenThisTurn`, `ready`, `trigger` and `memory` — the siege's first turn, its turns, the target's income trend and the bonuses broken and broken again, kept per game while the siege runs, a gap of more than 3 turns starting a new one) — omit it and the game profile (`profile`: the One Army Must Stand Guard case and what it means for interior defence, format, phase, standing) picks it: siege when it fits — in contact and not ahead, against one opponent (in an FFA the leader, earning 1.5× any other opponent beside you) with a bonus break in view costing at most twice its value and at most your income; the plan's reported `goal` is then `siege` (with no `goal` passed it may read `siege` where it read `balanced` or `defend` before: an additive value, so a caller should accept it) and `siege.auto` is set, a line saying why the profile chose the siege (the break that made it fit); `siege.auto` is absent when you passed `goal: 'siege'` yourself; once the assault trigger fires the profile hands back to its own goal (a rationale line says so, and there is no `siege` block) — else defend when behind on income outside a 1v1, else balanced tuned to the format (1v1 in contact: holds and breaks before expansion that completes nothing; behind on income in a 1v1: strike — break their bonuses, inferred ones too, sized to land; behind on armies: no trade below even; in a 1v1, spare deploys build one strike stack facing the opponent; FFA: no second front; ahead in a 1v1: more fog pressure); an explicit goal overrides it; `focus` bonuses; `reserve`; `enemy_deploy` (armies an enemy is assumed to deploy; default per opponent from its visible bonuses, or what it was observed to deploy when that is larger — its tracked income, carried across turns, once `warapp_track_opponents` has 2+ turns of it; growth beside the fog beyond twice what it was expected to deploy reads as a move out of the fog, not a deploy; in an even-start 1v1 or free-for-all an opponent bordering the fog is assumed to earn at least your income, a player out of a free-for-all having its share of the hidden board split among the rest; while its income was read from under half its frontier, an opponent is sized at the midpoint between its lower bound — its tracked figure, raised to its trend's next step when its tracked income rose two turns running — and its upper bound — that fog prior, else the most it could earn — moving toward what the evidence gives as more of its frontier is read; a rising track read from more of its frontier raises it to that lower bound); the `outlook` adds `leaning: behind` when it read even for 3 turns while a bonus of yours fell on each; `known_income` (per-player incomes you know, by GameFeed id — what a player said in chat, say: each replaces that opponent's estimate, a Reinforcement card the clock adds kept on top, said in its warning; `enemy_deploy` wins over it; the commander block keeps the submit's sizing); `min_win_chance` (0.5–1; default 1 = certain captures with no luck, 0.95 with luck on; below 1, each capture is sized for that exact win chance, and the captures a bonus still needs reach it together); `first_mover` (`me` or `opponent`, when you know who moves first this turn — Cycle move orders swap the first mover every turn; when you move first, Order Priority is not advised; the same argument as `warapp_check_plan`'s). Every attack carries `winChance` (its exact probability of capturing at the game's kill rates, luck and rounding); idle armies top an attack up to its next efficient size when the extra kill can matter. Reports the borders it gives up (`conceded`: not worth or not affordable to hold, never deployed to unless every territory you hold is conceded; it may still attack out with the armies already on it; an idle interior stack beside one that would make it hold transfers in, and it is then held), `cardAdvice` (`order-priority` when you hold one and it protects your first order: a commander strike while your commander is threatened, or a move out of a conceded border carrying enough armies to be worth a card — any size when the card must go anyway; never when `first_mover` is `me`; otherwise `order-delay` when you hold Order Delay and the schedule puts an attack last — the orders then carry the card with `before`, placed above the first non-urgent order, see `cards.advice.orderDelay`; an Order Delay that must leave the hand is played there rather than discarded), `cards.advice` for the cards `warapp_submit_turn` plays but the plan never does — `diplomacy` (the opponent tying down most of your border armies, only with two or more in contact, never a truce partner the truce already covers unless the card adds protection), `sanctions` (the leader, passing over a truce partner or a player a Diplomacy card keeps at peace with you, with the reason; yourself when the game's Sanctions percentage is negative — the card then raises the target's income — with `income`: your next income before and after the boost, by the client's rule (not under Local Deployment); never a negative card on an opponent nor a positive one on you), `airlift` (a border of yours or a teammate's that falls without it), `gift` (the members that complete a teammate's bonus), `spy` / `reconnaissance` / `surveillance` (only where the fog hides what the plan needs: an opponent out of view, a hidden territory on your border, a fogged member of a bonus you are completing; never with fog off) — each with an `order` to pass as is, never added to the orders save a completing `gift` (its play verified live 2026-11-23, #435: its card plays go into `orders` and the transfers out of or into the gifted members are dropped; never a territory with a special unit such as your commander, never one an attack leaves from) and a Reconnaissance (in a team game only cards read under you are played, discarded or advised; unverified live) and `trendSource` (where last turn's board came from — `history`, `cache` or null — for growing enemy stacks). Obeys the game's kill rates, Local Deployment and No-Split (`view: "full"` echoes the settings it assumed: `idleTransfers`, the planner's own switch for moving idle armies, beside the game's own `allowTransferOnly` and `allowAttackOnly`, `null` when GameFeed does not state them). Read-only; refuses outside a turn phase. In a Commanders game a commander counts as 7 armies, your commander's territory is never conceded (it gets the deploys it needs to hold against the worst case — the opponent's whole deploy, at least your own income, plus every enemy stack within two moves — or every army when that is not enough), and an adjacent enemy commander is attacked first, sized for its owner's full deploy. Within three moves of an enemy or the fog, with a safer territory of yours reachable, your commander walks one step a turn toward safety: a move in `orders` with `commander: true` (encoding not yet verified live), said in the first warning; the territory it leaves is held only for its own worth, plus what survives the attacks that may land before the walk (every enemy stack beside it, even when you move first: `warapp_submit_turn` checks both move orders; when that does not fit, each player's strongest attack, with the walk as your first order), no other order leaves it before the walk but a strike that ends a player, and Order Priority is advised for the walk only when even that falls short or the fog borders it; under No-Split a commander kill the walk displaces is named in a warning. Every turn of such a game `commander` reports your commander (#274): its territory, the armies there after the plan, `movesToEnemy` (to the nearest enemy or fog), `killedBy` (the smallest deploy, made by each opponent at once, at which a reply kills it: `player`, and `partner` when it is two opponents striking together; null when none reaches it this turn), and `safe` / `needs` at the larger of the estimate and your income; when it is not safe the first warning says so and whether `warapp_submit_turn` would refuse those orders (it does not without Commanders in the settings, nor when only an `enemy_deploy` what-if makes the commander unsafe). When the server kept your pick list, `award` says what the award of picks showed: the territories of your list that are another player's start for certain (in a two-player game planned as the opponent's while still fogged), whether you were awarded first or second and who moves first this turn under a `Cycle` move order, and with commanders the opponent's first award when the award pins it. `relations` reports each truce recorded with `warapp_record_agreement` as the plan treated it (honoured in a free-for-all; in a team or two-player game only its covered territories stay off-limits): while active or in notice no covered territory of the partner is attacked, a covered border facing only the partner is held against its stacks without a deploy (never your commander's, a border worth more than a quarter of your income, or any while trust is `watch`), and a border cap is kept: no move of yours fills that border past it, and the excess moves one step back (a warning when your own deploy for a hold is what exceeds it — deploy less, or give notice and ask before exceeding it — or when the cap leaves a border that also faces another opponent, or your commander's, short of its hold); `advice` says `give-notice` when the endgame or the partner outgrowing you made the trust `watch`; a truce the board shows broken is planned as an ordinary opponent, with the evidence (record it as `broken-by-them` before submitting: `warapp_submit_turn` reads only the ledger); each honoured truce reports `lossIfBroken` (what you would lose this turn if the partner landed its whole deploy beside your costliest covered territory, from any territory of its there, and attacked, carried out against the plan's orders: territories, armies, bonuses and income; logged per turn in the ledger beside the armies it freed); `tacit` lists quiet borders with no agreement (a report, never a truce). A Diplomacy card in effect between you and a player, read from the live board, is honoured in any format (that player is no threat and no target this turn), and Sanctions on you cut the plan's income (Sanctions on an opponent cut its estimate when that is read off the board, `sanctionsOnOthers`), when the decoder is sure of them (the card in play, its expiry within the game's duration); `cardsInEffect` lists them, marked `verified: false` (the active-card decoder is not yet checked live). Otherwise a warning says what was read and why it was not relied on. In a team game a bonus with a teammate's territory in it is never planned toward (a bonus pays one holder), and `team.sharedBonuses` lists each bonus you and a teammate both hold members of and who is `nearer` to holding it (advisory; team vision unverified). With your teammate's entered orders on the live board (unverified live): of two otherwise equal captures the one on the opponent they attack goes first (a "Team focus" rationale line); `team.support` lists a teammate's border that falls given their orders where your idle armies beside it would make it hold (each idle army offered to one border only, the border needing fewest first: the most borders held, not the most worth); `team.jointCaptures` a target neither of you takes alone but both together, resolved on the turn simulator in both orders (under a cyclic move order, `mustGoFirst`); and `cards.team` says who plays each card of the team hand — a card your teammate has entered is left to them and kept out of your plays. Support and joint captures are advice only (a move onto a teammate's territory is unverified live): never in `orders`. When one opponent touches two or more of your borders and no fixed split of the deploys there holds them all, `guess` offers a randomized split weighted by what each border is worth (each border's chance of being held, the best fixed split's worst case, the mix's expected loss, one draw seeded by the game, the turn and a local secret, so re-planning gives the same draw and the public code cannot reproduce it) and `guessOrders`, the plan's `orders` with that draw in place of its deploys on those borders — optional, a model of one opponent with one deploy, never taking armies off the territory your commander stands on or walks to, and dropped when its draw would be refused by the submit's commander check; the plan's `orders` are unchanged (`view: "full"` says why there is none). Holding an Airlift card, `airliftPlan` is an alternative beside the plan, its `orders` unchanged: the same planner on the board after the Airlifts (an interior stack flown onto a border the plan concedes, or a conceded border's armies flown to the border most pressed), the best compared by the plan's own measure — next income if its conceded borders fall, then next income, fewer concessions, more captures — with `airlifts`, `orders` (Airlift plays included), `expected`, `delta` (income, captures, borders saved, bonuses kept or completed), `cardsSpent` and `cardsLeft`; `keep_cards` holds cards in reserve; `null` with `airliftPlanNote` when none beats the plan. Airlifted armies cannot attack that turn, so a capture is staged for next turn instead (`staging`: an interior stack flown beside a target the plan does not take whose capture completes a bonus of yours or breaks an opponent's, with `nextTurnAttack` and the bonus value), scored on a two-turn objective — this turn's measure plus 0.8 × that bonus (`delta.twoTurn`) — and only when the staged stack holds against the plan's threat at that border; a plan the submit's commander check would refuse is not offered. Holding a Bomb card, `bombPlan` is the same kind of alternative: the planner on the board the Bomb leaves (its target keeps half its armies, rounded down, as the client bundle's Bomb result does) — an opponent's territory beside yours, a held bonus's member first, then the largest stacks, never a player at peace with you — with `bomb`, `orders` (the Bomb play included), `expected` and `delta`; `null` with `bombPlanNote` when none beats the plan. Holding an Emergency Blockade, `blockadePlan` walls off a border the plan concedes (neutral at its armies × the game's multiplier, before every move), worth the bonus its fall would hand an opponent when the wall holds this turn; holding a Blockade, the plain orders plus a Blockade on a territory of yours the stress-tested line keeps through the attacks (it walls it after them), worth the same denial less any bonus of yours it gives up — the better of the two is offered (owner-approved 2026-11-24). `reads` (opponent profiles, reported only — the plan never uses them): each opponent in contact with a habit at confidence 0.5 or a label, its `labels`, those habits with `n` and `basis`, and `gamesMet` (full adds the counter-play lines); absent with `WARAPP_PLAYER_PROFILE=off` or while a game's teams cannot be read. `headroom` (#275), weakest first: each border of yours with the smallest single deploy by a neighbouring opponent that takes it after the plan's orders, whether that is below your income, and what falls with it (bonuses, the territories behind it and their bonus income, and `breach`: the hollow territories within two moves behind it that only it shields, with their bonus income). The whole turn is carried out for it, so it may differ from the leftover spread's "~D" line (#268, reckoned on the deploys before any move); a player out of the game whose seat no AI plays gets no row. With the guard off the plan counts half of a border's breach income in its value. When one observation broke an opponent's estimate by 1.5× or more (a stack out of the fog, a capture, or an attack of yours it held), the first warning says so for 3 turns and the borders of your held bonuses facing it are sized for the larger of what it implied and your income (no `guess` is drawn against it then). Nothing is read once an opponent may hold an Airlift card or while the game's teams cannot be read (each `headroom` row then says `mayBeTeammate`); under Multi-Attack only a stack out of the fog is read. After turns 4 and 8 on a map you have finished games on, `pace` puts your income beside the median winner's there (reported only). `chat.messages` lists the newest unread messages other players sent (text delimited) with their `intent` and `advice` (compact: the stance and one reason; `messagesOmitted` counts the rest), from the plan's own standing: reported only, the orders never read chat. `chat.chatBlocks` lists the unread messages that would block the submit under `WARAPP_CHAT_BLOCKS_TURN` (report only). Once the outlook's surrender line (advice only) is crossed in a free-for-all with three or more still playing, `coalition` says whether a coalition against the leader is viable: the trailing players together out-earning it on the calibrated estimates, now or once a bonus of its that one of you borders breaks. While viable, for 2 turns from the crossing and as long as the leader's lead over you is not growing, "Try a coalition first" replaces the surrender warning; `coalition.partners` ranks every player who borders the leader, is not at war with you and has not broken a truce with you on the cross-game record (`leftOut` says why the others are not), and `coalition.drafts` holds a `propose` message for the top two naming the leader's bonus you could break together. Nothing is sent: send a draft yourself with `warapp_send_chat`, or with `WARAPP_CHAT_AUTOMATION=on` a draft carries `send`, still confirm-gated. |
|
|
156
|
+
| `warapp_plan_turn` | A plan for your turn from the live board (defaults to the signed-in account): income, your cards and whether you must play one, deploys and moves by name and id, expected captures, bonuses and next income, the `frontier` budget (borders left, those facing an enemy, what they need to hold next turn, next income), warnings and reasoning, and an `orders` array (card plays included); `chat.unread` counts the chat messages not yet marked seen (counts only, from GameFeed, so every count is under `unknown`; its `note` says so); `surrenderPending` lists other players' surrenders still pending (from the game details, unverified live; `null` when unreadable), and when one waits on your acceptance the first warning says so. `goal`: balanced (default: best income per army across holds, bonuses and breaking enemy bonuses, with at least 30% on expansion) / expand / complete-bonus / defend / siege (one opponent, `siege_target` by GameFeed id, default the strongest one bordering you: its bonus breaks are funded cheapest per income lost first, its other territories are left alone and the spare deploys build one strike stack facing it until the assault trigger fires — its income at 0.6× its baseline — the most the tracker saw it deploy over its window, or its income when the siege began — yours at 1.8× its, or a stack of yours able to take a member of its held bonus against its whole deploy — then the stack strikes; `siege` reports `target`, `opponentIncome`, `baseline`, `ratio`, `fallenTo`, `breaks`, `brokenThisTurn`, `ready`, `trigger` and `memory` — the siege's first turn, its turns, the target's income trend and the bonuses broken and broken again, kept per game while the siege runs, a gap of more than 3 turns starting a new one) — omit it and the game profile (`profile`: the One Army Must Stand Guard case and what it means for interior defence, format, phase, standing) picks it (never the siege, which plays only when you pass `goal: 'siege'`, #603): defend when behind on income outside a 1v1, else balanced tuned to the format (1v1 in contact: holds and breaks before expansion that completes nothing; behind on income in a 1v1: strike — break their bonuses, inferred ones too, sized to land; behind on armies: no trade below even; in a 1v1, spare deploys build one strike stack facing the opponent; FFA: no second front; ahead in a 1v1: more fog pressure); an explicit goal overrides it; `focus` bonuses; `reserve`; `enemy_deploy` (armies an enemy is assumed to deploy; default per opponent from its visible bonuses, or what it was observed to deploy when that is larger — its tracked income, carried across turns, once `warapp_track_opponents` has 2+ turns of it; growth beside the fog beyond twice what it was expected to deploy reads as a move out of the fog, not a deploy; in an even-start 1v1 or free-for-all an opponent bordering the fog is assumed to earn at least your income, a player out of a free-for-all having its share of the hidden board split among the rest; while its income was read from under half its frontier, an opponent is sized at the midpoint between its lower bound — its tracked figure, raised to its trend's next step when its tracked income rose two turns running — and its upper bound — that fog prior, else the most it could earn — moving toward what the evidence gives as more of its frontier is read; a rising track read from more of its frontier raises it to that lower bound); the `outlook` adds `leaning: behind` when it read even for 3 turns while a bonus of yours fell on each; `known_income` (per-player incomes you know, by GameFeed id — what a player said in chat, say: each replaces that opponent's estimate, a Reinforcement card the clock adds kept on top, said in its warning; `enemy_deploy` wins over it; the commander block keeps the submit's sizing); `min_win_chance` (0.5–1; default 1 = certain captures with no luck, 0.95 with luck on; below 1, each capture is sized for that exact win chance, and the captures a bonus still needs reach it together); `first_mover` (`me` or `opponent`, when you know who moves first this turn — Cycle move orders swap the first mover every turn; when you move first, Order Priority is not advised; the same argument as `warapp_check_plan`'s). Every attack carries `winChance` (its exact probability of capturing at the game's kill rates, luck and rounding); idle armies top an attack up to its next efficient size when the extra kill can matter. Reports the borders it gives up (`conceded`: not worth or not affordable to hold, never deployed to unless every territory you hold is conceded; it may still attack out with the armies already on it; an idle interior stack beside one that would make it hold transfers in, and it is then held), `cardAdvice` (`order-priority` when you hold one and it protects your first order: a commander strike while your commander is threatened, or a move out of a conceded border carrying enough armies to be worth a card — any size when the card must go anyway; never when `first_mover` is `me`; otherwise `order-delay` when you hold Order Delay and the schedule puts an attack last — the orders then carry the card with `before`, placed above the first non-urgent order, see `cards.advice.orderDelay`; an Order Delay that must leave the hand is played there rather than discarded), `cards.advice` for the cards `warapp_submit_turn` plays but the plan never does — `diplomacy` (the opponent tying down most of your border armies, only with two or more in contact, never a truce partner the truce already covers unless the card adds protection), `sanctions` (the leader, passing over a truce partner or a player a Diplomacy card keeps at peace with you, with the reason; yourself when the game's Sanctions percentage is negative — the card then raises the target's income — with `income`: your next income before and after the boost, by the client's rule (not under Local Deployment); never a negative card on an opponent nor a positive one on you), `airlift` (a border of yours or a teammate's that falls without it), `gift` (the members that complete a teammate's bonus), `spy` / `reconnaissance` / `surveillance` (only where the fog hides what the plan needs: an opponent out of view, a hidden territory on your border, a fogged member of a bonus you are completing; never with fog off) — each with an `order` to pass as is, never added to the orders save a completing `gift` (its play verified live 2026-11-23, #435: its card plays go into `orders` and the transfers out of or into the gifted members are dropped; never a territory with a special unit such as your commander, never one an attack leaves from) and a Reconnaissance (in a team game only cards read under you are played, discarded or advised; unverified live) and `trendSource` (where last turn's board came from — `history`, `cache` or null — for growing enemy stacks). Obeys the game's kill rates, Local Deployment and No-Split (`view: "full"` echoes the settings it assumed: `idleTransfers`, the planner's own switch for moving idle armies, beside the game's own `allowTransferOnly` and `allowAttackOnly`, `null` when GameFeed does not state them). Read-only; refuses outside a turn phase. In a Commanders game a commander counts as 7 armies, your commander's territory is never conceded (it gets the deploys it needs to hold against the worst case — the opponent's whole deploy, at least your own income, plus every enemy stack within two moves — or every army when that is not enough), and an adjacent enemy commander is attacked first, sized for its owner's full deploy. Within three moves of an enemy or the fog, with a safer territory of yours reachable, your commander walks one step a turn toward safety: a move in `orders` with `commander: true` (encoding not yet verified live), said in the first warning; the territory it leaves is held only for its own worth, plus what survives the attacks that may land before the walk (every enemy stack beside it, even when you move first: `warapp_submit_turn` checks both move orders; when that does not fit, each player's strongest attack, with the walk as your first order), no other order leaves it before the walk but a strike that ends a player, and Order Priority is advised for the walk only when even that falls short or the fog borders it; under No-Split a commander kill the walk displaces is named in a warning. Every turn of such a game `commander` reports your commander (#274): its territory, the armies there after the plan, `movesToEnemy` (to the nearest enemy or fog), `killedBy` (the smallest deploy, made by each opponent at once, at which a reply kills it: `player`, and `partner` when it is two opponents striking together; null when none reaches it this turn), and `safe` / `needs` at the larger of the estimate and your income; when it is not safe the first warning says so and whether `warapp_submit_turn` would refuse those orders (it does not without Commanders in the settings, nor when only an `enemy_deploy` what-if makes the commander unsafe). When the server kept your pick list, `award` says what the award of picks showed: the territories of your list that are another player's start for certain (in a two-player game planned as the opponent's while still fogged), whether you were awarded first or second and who moves first this turn under a `Cycle` move order, and with commanders the opponent's first award when the award pins it. `relations` reports each truce recorded with `warapp_record_agreement` as the plan treated it (honoured in a free-for-all; in a team or two-player game only its covered territories stay off-limits): while active or in notice no covered territory of the partner is attacked, a covered border facing only the partner is held against its stacks without a deploy (never your commander's, a border worth more than a quarter of your income, or any while trust is `watch`), and a border cap is kept: no move of yours fills that border past it, and the excess moves one step back (a warning when your own deploy for a hold is what exceeds it — deploy less, or give notice and ask before exceeding it — or when the cap leaves a border that also faces another opponent, or your commander's, short of its hold); `advice` says `give-notice` when the endgame or the partner outgrowing you made the trust `watch`; a truce the board shows broken is planned as an ordinary opponent, with the evidence (record it as `broken-by-them` before submitting: `warapp_submit_turn` reads only the ledger); each honoured truce reports `lossIfBroken` (what you would lose this turn if the partner landed its whole deploy beside your costliest covered territory, from any territory of its there, and attacked, carried out against the plan's orders: territories, armies, bonuses and income; logged per turn in the ledger beside the armies it freed); `tacit` lists quiet borders with no agreement (a report, never a truce). A Diplomacy card in effect between you and a player, read from the live board, is honoured in any format (that player is no threat and no target this turn), and Sanctions on you cut the plan's income (Sanctions on an opponent cut its estimate when that is read off the board, `sanctionsOnOthers`), when the decoder is sure of them (the card in play, its expiry within the game's duration); `cardsInEffect` lists them, marked `verified: false` (the active-card decoder is not yet checked live). Otherwise a warning says what was read and why it was not relied on. In a team game a bonus with a teammate's territory in it is never planned toward (a bonus pays one holder), and `team.sharedBonuses` lists each bonus you and a teammate both hold members of and who is `nearer` to holding it (advisory; team vision unverified). With your teammate's entered orders on the live board (unverified live): of two otherwise equal captures the one on the opponent they attack goes first (a "Team focus" rationale line); `team.support` lists a teammate's border that falls given their orders where your idle armies beside it would make it hold (each idle army offered to one border only, the border needing fewest first: the most borders held, not the most worth); `team.jointCaptures` a target neither of you takes alone but both together, resolved on the turn simulator in both orders (under a cyclic move order, `mustGoFirst`); and `cards.team` says who plays each card of the team hand — a card your teammate has entered is left to them and kept out of your plays. Support and joint captures are advice only (a move onto a teammate's territory is unverified live): never in `orders`. When one opponent touches two or more of your borders and no fixed split of the deploys there holds them all, `guess` offers a randomized split weighted by what each border is worth (each border's chance of being held, the best fixed split's worst case, the mix's expected loss, one draw seeded by the game, the turn and a local secret, so re-planning gives the same draw and the public code cannot reproduce it) and `guessOrders`, the plan's `orders` with that draw in place of its deploys on those borders — optional, a model of one opponent with one deploy, never taking armies off the territory your commander stands on or walks to, and dropped when its draw would be refused by the submit's commander check; the plan's `orders` are unchanged (`view: "full"` says why there is none). Holding an Airlift card, `airliftPlan` is an alternative beside the plan, its `orders` unchanged: the same planner on the board after the Airlifts (an interior stack flown onto a border the plan concedes, or a conceded border's armies flown to the border most pressed), the best compared by the plan's own measure — next income if its conceded borders fall, then next income, fewer concessions, more captures — with `airlifts`, `orders` (Airlift plays included), `expected`, `delta` (income, captures, borders saved, bonuses kept or completed), `cardsSpent` and `cardsLeft`; `keep_cards` holds cards in reserve; `null` with `airliftPlanNote` when none beats the plan. Airlifted armies cannot attack that turn, so a capture is staged for next turn instead (`staging`: an interior stack flown beside a target the plan does not take whose capture completes a bonus of yours or breaks an opponent's, with `nextTurnAttack` and the bonus value), scored on a two-turn objective — this turn's measure plus 0.8 × that bonus (`delta.twoTurn`) — and only when the staged stack holds against the plan's threat at that border; a plan the submit's commander check would refuse is not offered. Holding a Bomb card, `bombPlan` is the same kind of alternative: the planner on the board the Bomb leaves (its target keeps half its armies, rounded down, as the client bundle's Bomb result does) — an opponent's territory beside yours, a held bonus's member first, then the largest stacks, never a player at peace with you — with `bomb`, `orders` (the Bomb play included), `expected` and `delta`; `null` with `bombPlanNote` when none beats the plan. Holding an Emergency Blockade, `blockadePlan` walls off a border the plan concedes (neutral at its armies × the game's multiplier, before every move), worth the bonus its fall would hand an opponent when the wall holds this turn; holding a Blockade, the plain orders plus a Blockade on a territory of yours the stress-tested line keeps through the attacks (it walls it after them), worth the same denial less any bonus of yours it gives up — the better of the two is offered (owner-approved 2026-11-24). `reads` (opponent profiles, reported only — the plan never uses them): each opponent in contact with a habit at confidence 0.5 or a label, its `labels`, those habits with `n` and `basis`, and `gamesMet` (full adds the counter-play lines); absent with `WARAPP_PLAYER_PROFILE=off` or while a game's teams cannot be read. `headroom` (#275), weakest first: each border of yours with the smallest single deploy by a neighbouring opponent that takes it after the plan's orders, whether that is below your income, and what falls with it (bonuses, the territories behind it and their bonus income, and `breach`: the hollow territories within two moves behind it that only it shields, with their bonus income). The whole turn is carried out for it, so it may differ from the leftover spread's "~D" line (#268, reckoned on the deploys before any move); a player out of the game whose seat no AI plays gets no row. With the guard off the plan counts half of a border's breach income in its value. When one observation broke an opponent's estimate by 1.5× or more (a stack out of the fog, a capture, or an attack of yours it held), the first warning says so for 3 turns and the borders of your held bonuses facing it are sized for the larger of what it implied and your income (no `guess` is drawn against it then). Nothing is read once an opponent may hold an Airlift card or while the game's teams cannot be read (each `headroom` row then says `mayBeTeammate`); under Multi-Attack only a stack out of the fog is read. After turns 4 and 8 on a map you have finished games on, `pace` puts your income beside the median winner's there (reported only). `chat.messages` lists the newest unread messages other players sent (text delimited) with their `intent` and `advice` (compact: the stance and one reason; `messagesOmitted` counts the rest), from the plan's own standing: reported only, the orders never read chat. `chat.chatBlocks` lists the unread messages that would block the submit under `WARAPP_CHAT_BLOCKS_TURN` (report only). Once the outlook's surrender line (advice only) is crossed in a free-for-all with three or more still playing, `coalition` says whether a coalition against the leader is viable: the trailing players together out-earning it on the calibrated estimates, now or once a bonus of its that one of you borders breaks. While viable, for 2 turns from the crossing and as long as the leader's lead over you is not growing, "Try a coalition first" replaces the surrender warning; `coalition.partners` ranks every player who borders the leader, is not at war with you and has not broken a truce with you on the cross-game record (`leftOut` says why the others are not), and `coalition.drafts` holds a `propose` message for the top two naming the leader's bonus you could break together. Nothing is sent: send a draft yourself with `warapp_send_chat`, or with `WARAPP_CHAT_AUTOMATION=on` a draft carries `send`, still confirm-gated. |
|
|
157
157
|
| `warapp_check_plan` | A stress test of a list of orders before you submit it (`warapp_plan_turn`'s `orders`, or your own edit): the orders are carried out on the live board by the game's turn rules (deploys, then attacks and transfers in the zigzag move order, each an attack or a transfer by who holds its target when it runs) against the replies each opponent could make with one deploy — all of it on one stack and an attack on a territory you hold or are about to take, all of it on a territory you attack, or every stack attacking at once — with you moving first and with the opponent moving first unless `first_mover` says which. Returns `safe` (`null` when no reply could be tried), a one-line `summary`, the `worst` reply and the `otherReplies` that cost something (territories lost, captures that fail or are taken straight back, bonuses and income, your commander), everything `atRisk` to some single reply, `commander` (with your commander on the board: its territory, the armies there and `needs`, the armies that survive every reply tried — by `warapp_submit_turn`'s own check, each reply at the larger of the estimate and your income, `enemy_deploy` only raising it, both move orders, your Airlifts counted; when a reply kills it the `summary` starts with it), what the orders do unanswered, `blindBorders` (your territories next to the fog, where nothing could be tested) and `exposedNextTurn` (territories no stack touches today that one could take next turn by first taking the territory in between, each with the armies it would need to hold). Exact with no luck and straight rounding; otherwise `exact` is false. `known_income` (as `warapp_plan_turn`'s) tries a per-player income you know in place of that opponent's estimate (`enemyDeploy` source `known_income`; `enemy_deploy` wins over it; `commander` keeps the submit's sizing). Not tried: hidden stacks, a deploy above the estimate (`enemy_deploy` tests one), split deploys, opponents acting together, under Multi-Attack any chain but the one most damaging per stack, cards other than your own Order Priority, Airlifts, Bombs and Blockades: a Bomb is carried out after every deploy, its target keeping half its armies, rounded down; an Emergency Blockade (before the moves) and a Blockade (after them) turn their territory neutral at its armies × the game's multiplier, and the walled border is never counted lost (a wall with no multiplier in the settings is warned of as not simulated). An Airlift in the orders is carried out at its phase — after every deploy, before every move: its source loses the armies, its destination gains them, and they cannot move again that turn — so every reply is tried on the board it leaves. `award` (when the server kept your pick list) is the same reading `warapp_plan_turn` gives; its `firstMover` can be passed as `first_mover`. In a free-for-all with a recorded truce in force its partner is still tried (`safe` is safe against a break), a reply that attacks a territory the truce covers is marked `breaksTruce`, and `safeIfTruceHolds` is the verdict over the rest (`null` when every reply is a break); a Diplomacy card in effect that the decoder is sure of counts as such a truce in any format (`enforced`, `verified: false`). In a team game it warns, as `warapp_submit_turn` does, of a card play or discard your teammate has already entered. `headroom` (as `warapp_plan_turn`'s) gives each border the smallest single deploy that takes it after these orders; an opponent whose estimate an observation broke is tried at the larger of what it implied and your income (`enemyDeploy` source `untrusted`, said in the first warning). `belowPlan` (#275) compares the orders with the default plan made now on the same board, as `warapp_plan_turn` makes it with no options (or with its border guess when the deploys are the guess's: `belowPlanAgainst`): each border they leave below what that plan leaves standing there, with `planLeaves`, `left` and `short`, the largest shortfall first. `planLeaves` includes the plan's surplus, so a border named may still hold (see `headroom`). A Sanctions card in the orders is projected onto next turn in `sanctionsPlayed` (`nextIncome`: before, after and the change — yours from this turn's income when the game's percentage is negative and you play it on yourself, an opponent's estimate when positive); a card on the wrong side for its sign is a warning (`warapp_submit_turn` refuses it). Read-only. |
|
|
158
158
|
| `warapp_turn_history` | A game turn by turn as you saw it, beside what this server planned, sent and expected (read from the game's decision log; ids only): per turn the board in view (summary, or whole with `board: true`), `changedHands` since the turn before, every player's visible `orders` that turn (deploys, moves, card plays, discards — kept from the next turn's live board since #570), the `plan`, the orders `sent` and `differsFromPlan`, the `outcome` next turn, cards, events, and once finished the turn's `truth` and `accuracy`. `from_turn`/`to_turn` (default the newest 5, at most 20 per call, `next` pages on); `view: "full"` adds the plan's rationale and warnings, checks, times and first mover; `read_last_turn: true` reads the live board once to keep the turn just resolved. Read-only; attack results are not decoded. |
|
|
159
159
|
| `warapp_track_opponents` | Each opponent over your own board history (the boards `warapp_plan_turn` and this tool read, the last 10 turns, or the game history when war.app sends it), by name: its observed deploy each turn (territories visible both turns only — a stack that came out of the fog is not income), an income estimate (each observed deploy is a lower bound under fog, so the largest of its last three observed turns, or its visible army growth plus losses per turn (stacks out of the fog left out) when that is more; capped at what it could earn, at least its base plus the bonuses it visibly holds; `method` and `observedRange` say which term set it and how spread the observations were), `unexplainedArmies` (income earned since first seen minus its visible army change, its visible losses and its likely combat deaths: armies in the fog, spent there, or a misread) and `inferredBonuses` (the combinations of bonuses it could hold that best explain the gap, only those within 4 hops of its territories that it could have paid for, nearest first — candidates, never one asserted; none listed when more than 8 fit), with confidence notes. Every opponent still playing is listed, even with no territory in view (`visible` territories in view, `turnsUnseen` — a floor, `turnsUnseenAtLeast`, when your boards do not reach back to when it was last seen); one with nothing in view gets `earnedAtLeast` — its starting armies plus the base income for every turn so far, a lower bound on armies received (not held: its expansion cost some) — and a warning, also in `warapp_plan_turn`, when that beats your largest stack or your total visible armies. Once an opponent has 2+ observed turns, `warapp_plan_turn` uses this income in place of the single-turn observed figure. `view`: compact / full. Read-only on war.app (it caches the board it read); refuses outside a turn phase. `full` adds `pastGames`: the lessons of your finished games — how they were lost, when your income went flat, and this tracker's estimate ÷ the true income by format and coverage band (reported only). |
|
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
import { armiesToTake } from './combat.js';
|
|
2
|
+
import { bfsDistances, buildGraph, neighborsOf } from './graph.js';
|
|
3
|
+
import { trackOpponents } from './opponents.js';
|
|
4
|
+
import { boardIncome } from './player.js';
|
|
5
|
+
import { planTurn } from './planner.js';
|
|
6
|
+
import { simulateTurn } from './turn-sim.js';
|
|
7
|
+
/** The rules every arena game is played under. */
|
|
8
|
+
export const ARENA_SETTINGS = {
|
|
9
|
+
offensiveKillRate: 60,
|
|
10
|
+
defensiveKillRate: 70,
|
|
11
|
+
luckModifier: 0,
|
|
12
|
+
roundingMode: 'StraightRound',
|
|
13
|
+
oneArmyStandsGuard: true,
|
|
14
|
+
baseIncome: 5,
|
|
15
|
+
};
|
|
16
|
+
const BASE_INCOME = 5;
|
|
17
|
+
const NEUTRAL = 2;
|
|
18
|
+
const WASTELAND = 10;
|
|
19
|
+
const STARTS = 3;
|
|
20
|
+
const START_ARMIES = 4;
|
|
21
|
+
/** A small deterministic PRNG (mulberry32). */
|
|
22
|
+
export class ArenaRng {
|
|
23
|
+
s;
|
|
24
|
+
constructor(seed) {
|
|
25
|
+
this.s = seed >>> 0;
|
|
26
|
+
}
|
|
27
|
+
next() {
|
|
28
|
+
let t = (this.s = (this.s + 0x6d2b79f5) >>> 0);
|
|
29
|
+
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
30
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
31
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
32
|
+
}
|
|
33
|
+
int(lo, hi) {
|
|
34
|
+
return lo + Math.floor(this.next() * (hi - lo + 1));
|
|
35
|
+
}
|
|
36
|
+
pick(xs) {
|
|
37
|
+
return xs[Math.floor(this.next() * xs.length)];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A world-like map: a `w` × `h` grid of territories, each linked to its four neighbours and, at random,
|
|
42
|
+
* a diagonal one, a few links cut (never disconnecting it); bonuses grown as contiguous regions of 2 to 6
|
|
43
|
+
* territories worth their size less one (at least 1); `wastelands` territories start at 10.
|
|
44
|
+
*/
|
|
45
|
+
export function arenaMap(seed, w = 11, h = 10) {
|
|
46
|
+
const r = new ArenaRng(seed);
|
|
47
|
+
const id = (x, y) => 1 + y * w + x;
|
|
48
|
+
const links = new Map();
|
|
49
|
+
const link = (a, b) => {
|
|
50
|
+
links.get(a).add(b);
|
|
51
|
+
links.get(b).add(a);
|
|
52
|
+
};
|
|
53
|
+
for (let y = 0; y < h; y++)
|
|
54
|
+
for (let x = 0; x < w; x++)
|
|
55
|
+
links.set(id(x, y), new Set());
|
|
56
|
+
for (let y = 0; y < h; y++)
|
|
57
|
+
for (let x = 0; x < w; x++) {
|
|
58
|
+
if (x + 1 < w)
|
|
59
|
+
link(id(x, y), id(x + 1, y));
|
|
60
|
+
if (y + 1 < h)
|
|
61
|
+
link(id(x, y), id(x, y + 1));
|
|
62
|
+
if (x + 1 < w && y + 1 < h && r.next() < 0.35)
|
|
63
|
+
link(id(x, y), r.next() < 0.5 ? id(x + 1, y + 1) : id(x + 1, y));
|
|
64
|
+
if (x > 0 && y + 1 < h && r.next() < 0.2)
|
|
65
|
+
link(id(x, y), id(x - 1, y + 1));
|
|
66
|
+
}
|
|
67
|
+
// Cut some links where both ends keep three or more (the grid stays connected: checked below).
|
|
68
|
+
for (const a of [...links.keys()])
|
|
69
|
+
for (const b of [...links.get(a)])
|
|
70
|
+
if (a < b && r.next() < 0.12 && links.get(a).size > 3 && links.get(b).size > 3) {
|
|
71
|
+
links.get(a).delete(b);
|
|
72
|
+
links.get(b).delete(a);
|
|
73
|
+
if (!connected(links))
|
|
74
|
+
link(a, b);
|
|
75
|
+
}
|
|
76
|
+
const ids = [...links.keys()].sort((a, b) => a - b);
|
|
77
|
+
const territories = ids.map((t) => ({ id: t, name: `T${t}`, connectedTo: [...links.get(t)].sort((a, b) => a - b) }));
|
|
78
|
+
// Bonuses: regions grown from random seeds over unassigned territories.
|
|
79
|
+
const owner = new Map();
|
|
80
|
+
const bonuses = [];
|
|
81
|
+
let bid = 1;
|
|
82
|
+
for (const seedT of shuffle(r, ids)) {
|
|
83
|
+
if (owner.has(seedT))
|
|
84
|
+
continue;
|
|
85
|
+
const size = r.int(2, 6);
|
|
86
|
+
const members = [seedT];
|
|
87
|
+
owner.set(seedT, bid);
|
|
88
|
+
while (members.length < size) {
|
|
89
|
+
const open = members.flatMap((m) => [...links.get(m)]).filter((n) => !owner.has(n));
|
|
90
|
+
if (!open.length)
|
|
91
|
+
break;
|
|
92
|
+
const n = r.pick(open.sort((a, b) => a - b));
|
|
93
|
+
owner.set(n, bid);
|
|
94
|
+
members.push(n);
|
|
95
|
+
}
|
|
96
|
+
bonuses.push({ id: bid, name: `B${bid}`, value: Math.max(1, members.length - 1), territoryIds: members.sort((a, b) => a - b), bonusIds: [] });
|
|
97
|
+
bid++;
|
|
98
|
+
}
|
|
99
|
+
const wastelands = shuffle(r, ids).slice(0, Math.max(1, Math.round(ids.length / 18)));
|
|
100
|
+
return { map: { id: 990000 + (seed % 1000), name: `Arena ${seed}`, territories, bonuses, distributionModes: [] }, wastelands };
|
|
101
|
+
}
|
|
102
|
+
function connected(links) {
|
|
103
|
+
const ids = [...links.keys()];
|
|
104
|
+
const seen = new Set([ids[0]]);
|
|
105
|
+
const queue = [ids[0]];
|
|
106
|
+
while (queue.length)
|
|
107
|
+
for (const n of links.get(queue.shift()))
|
|
108
|
+
if (!seen.has(n)) {
|
|
109
|
+
seen.add(n);
|
|
110
|
+
queue.push(n);
|
|
111
|
+
}
|
|
112
|
+
return seen.size === ids.length;
|
|
113
|
+
}
|
|
114
|
+
function shuffle(r, xs) {
|
|
115
|
+
const out = [...xs];
|
|
116
|
+
for (let i = out.length - 1; i > 0; i--) {
|
|
117
|
+
const j = Math.floor(r.next() * (i + 1));
|
|
118
|
+
[out[i], out[j]] = [out[j], out[i]];
|
|
119
|
+
}
|
|
120
|
+
return out;
|
|
121
|
+
}
|
|
122
|
+
/** The planner as warapp_plan_turn calls it (adapting, its tracks and income history), with `options` on top. */
|
|
123
|
+
export function plannerBot(name, options = {}, onPlan) {
|
|
124
|
+
return {
|
|
125
|
+
name,
|
|
126
|
+
orders(v) {
|
|
127
|
+
const boards = v.history.map((h) => h);
|
|
128
|
+
const tracks = boards.length ? trackOpponents(v.graph, [...boards, { turn: v.turn, board: v.board }], v.me, ARENA_SETTINGS) : undefined;
|
|
129
|
+
const plan = planTurn({
|
|
130
|
+
graph: v.graph,
|
|
131
|
+
board: v.board,
|
|
132
|
+
me: v.me,
|
|
133
|
+
income: v.income,
|
|
134
|
+
turn: v.turn,
|
|
135
|
+
...(boards.length ? { previousBoard: boards[boards.length - 1].board, previousOrders: boards[boards.length - 1].orders } : {}),
|
|
136
|
+
...(tracks ? { tracks } : {}),
|
|
137
|
+
incomeHistory: v.incomes,
|
|
138
|
+
settings: ARENA_SETTINGS,
|
|
139
|
+
game: {
|
|
140
|
+
players: v.players.map((id) => ({ id })),
|
|
141
|
+
turn: v.turn,
|
|
142
|
+
fog: v.fog ? 'Foggy' : 'NoFog',
|
|
143
|
+
symmetricStart: true,
|
|
144
|
+
cards: false,
|
|
145
|
+
},
|
|
146
|
+
options: { adapt: true, ...options },
|
|
147
|
+
});
|
|
148
|
+
onPlan?.(plan, v);
|
|
149
|
+
return {
|
|
150
|
+
deploys: plan.deploys.map((d) => ({ territoryId: d.territoryId, armies: d.armies })),
|
|
151
|
+
moves: plan.moves.map((m) => ({ from: m.from, to: m.to, armies: m.armies })),
|
|
152
|
+
};
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* A plain greedy expander, the play our 1v1 opponents showed: every turn it takes as many cheap
|
|
158
|
+
* territories as it can, nearest-to-complete bonus first, with exactly what each needs; it attacks an
|
|
159
|
+
* enemy territory only when the armies beside it are twice what defends it; leftover income goes to the
|
|
160
|
+
* border facing the largest enemy stack, and idle interior armies walk toward the nearest border.
|
|
161
|
+
*/
|
|
162
|
+
export function spreaderBot(name = 'spreader') {
|
|
163
|
+
return {
|
|
164
|
+
name,
|
|
165
|
+
orders(v) {
|
|
166
|
+
const { graph: g, me } = v;
|
|
167
|
+
const st = new Map(v.board.territories.map((t) => [t.territoryId, t]));
|
|
168
|
+
const mine = (t) => {
|
|
169
|
+
const x = st.get(t);
|
|
170
|
+
return x?.owner.kind === 'player' && x.owner.playerId === me;
|
|
171
|
+
};
|
|
172
|
+
const armies = new Map();
|
|
173
|
+
for (const t of v.board.territories)
|
|
174
|
+
if (mine(t.territoryId))
|
|
175
|
+
armies.set(t.territoryId, t.armies ?? 0);
|
|
176
|
+
const held = new Set(armies.keys());
|
|
177
|
+
const spare = new Map([...armies].map(([t, a]) => [t, Math.max(0, a - 1)]));
|
|
178
|
+
let budget = v.income;
|
|
179
|
+
const deploys = new Map();
|
|
180
|
+
const moves = [];
|
|
181
|
+
const taken = new Set();
|
|
182
|
+
const need = (t) => {
|
|
183
|
+
const x = st.get(t);
|
|
184
|
+
const def = x?.armies ?? (x?.owner.kind === 'unknown' ? NEUTRAL : NEUTRAL);
|
|
185
|
+
return armiesToTake(def, ARENA_SETTINGS) ?? def * 2 + 1;
|
|
186
|
+
};
|
|
187
|
+
// Each bonus's members still missing (for the "nearest to complete" order).
|
|
188
|
+
const missing = new Map();
|
|
189
|
+
for (const b of g.map.bonuses)
|
|
190
|
+
missing.set(b.id, b.territoryIds.filter((t) => !held.has(t)).length);
|
|
191
|
+
const bonusOf = new Map();
|
|
192
|
+
for (const b of g.map.bonuses)
|
|
193
|
+
for (const t of b.territoryIds)
|
|
194
|
+
bonusOf.set(t, [...(bonusOf.get(t) ?? []), b.id]);
|
|
195
|
+
const rank = (t) => Math.min(...(bonusOf.get(t) ?? []).map((b) => missing.get(b)), 99);
|
|
196
|
+
const candidates = [...new Set([...held].flatMap((t) => neighborsOf(g, t)))]
|
|
197
|
+
.filter((t) => !held.has(t))
|
|
198
|
+
.filter((t) => {
|
|
199
|
+
const x = st.get(t);
|
|
200
|
+
return x !== undefined && x.owner.kind !== 'unknown';
|
|
201
|
+
})
|
|
202
|
+
.sort((a, b) => rank(a) - rank(b) || need(a) - need(b) || a - b);
|
|
203
|
+
for (const t of candidates) {
|
|
204
|
+
const x = st.get(t);
|
|
205
|
+
const enemy = x.owner.kind === 'player';
|
|
206
|
+
const cost = enemy ? Math.max(need(t), 2 * (x.armies ?? 0)) : need(t);
|
|
207
|
+
const sources = neighborsOf(g, t).filter((n) => held.has(n)).sort((a, b) => (spare.get(b) ?? 0) - (spare.get(a) ?? 0) || a - b);
|
|
208
|
+
const src = sources[0];
|
|
209
|
+
if (src === undefined)
|
|
210
|
+
continue;
|
|
211
|
+
const have = spare.get(src) ?? 0;
|
|
212
|
+
const add = Math.max(0, cost - have);
|
|
213
|
+
if (add > budget)
|
|
214
|
+
continue;
|
|
215
|
+
if (enemy && have < cost / 2)
|
|
216
|
+
continue;
|
|
217
|
+
budget -= add;
|
|
218
|
+
if (add)
|
|
219
|
+
deploys.set(src, (deploys.get(src) ?? 0) + add);
|
|
220
|
+
spare.set(src, have + add - cost);
|
|
221
|
+
moves.push({ from: src, to: t, armies: cost });
|
|
222
|
+
taken.add(t);
|
|
223
|
+
}
|
|
224
|
+
// Leftover: the border facing the largest enemy stack, else the territory with the most spare.
|
|
225
|
+
if (budget > 0) {
|
|
226
|
+
let best;
|
|
227
|
+
let bestThreat = -1;
|
|
228
|
+
for (const t of [...held].sort((a, b) => a - b)) {
|
|
229
|
+
const threat = Math.max(0, ...neighborsOf(g, t).map((n) => {
|
|
230
|
+
const x = st.get(n);
|
|
231
|
+
return x?.owner.kind === 'player' && x.owner.playerId !== me ? (x.armies ?? 0) : 0;
|
|
232
|
+
}));
|
|
233
|
+
if (threat > bestThreat) {
|
|
234
|
+
best = t;
|
|
235
|
+
bestThreat = threat;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (best !== undefined)
|
|
239
|
+
deploys.set(best, (deploys.get(best) ?? 0) + budget);
|
|
240
|
+
}
|
|
241
|
+
// Idle interior armies walk one step toward the nearest territory not mine.
|
|
242
|
+
const outside = [...st.keys()].filter((t) => !held.has(t));
|
|
243
|
+
const dist = bfsDistances(g, outside);
|
|
244
|
+
for (const t of [...held].sort((a, b) => a - b)) {
|
|
245
|
+
const left = spare.get(t) ?? 0;
|
|
246
|
+
if (left <= 0 || neighborsOf(g, t).some((n) => !held.has(n)))
|
|
247
|
+
continue;
|
|
248
|
+
const step = neighborsOf(g, t)
|
|
249
|
+
.filter((n) => held.has(n))
|
|
250
|
+
.sort((a, b) => (dist.get(a) ?? 99) - (dist.get(b) ?? 99) || a - b)[0];
|
|
251
|
+
if (step !== undefined)
|
|
252
|
+
moves.push({ from: t, to: step, armies: left });
|
|
253
|
+
}
|
|
254
|
+
return { deploys: [...deploys].map(([territoryId, a]) => ({ territoryId, armies: a })), moves };
|
|
255
|
+
},
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
const PLAYERS = [101, 202];
|
|
259
|
+
/** Play one game. */
|
|
260
|
+
export function playArena(o) {
|
|
261
|
+
const { map, wastelands } = arenaMap(o.seed, o.width, o.height);
|
|
262
|
+
const g = buildGraph(map);
|
|
263
|
+
const r = new ArenaRng(o.seed ^ 0x51ed);
|
|
264
|
+
const maxTurns = o.maxTurns ?? 40;
|
|
265
|
+
const cells = new Map();
|
|
266
|
+
const waste = new Set(wastelands);
|
|
267
|
+
for (const t of map.territories)
|
|
268
|
+
cells.set(t.id, { owner: 'neutral', armies: waste.has(t.id) ? WASTELAND : NEUTRAL });
|
|
269
|
+
// Starts: alternately, the free territory farthest from every start taken (ties at random), never a wasteland.
|
|
270
|
+
const starts = [];
|
|
271
|
+
const pool = map.territories.map((t) => t.id).filter((t) => !waste.has(t));
|
|
272
|
+
for (let k = 0; k < STARTS * 2; k++) {
|
|
273
|
+
const player = PLAYERS[k % 2];
|
|
274
|
+
let choice;
|
|
275
|
+
if (!starts.length)
|
|
276
|
+
choice = r.pick(pool);
|
|
277
|
+
else {
|
|
278
|
+
const d = bfsDistances(g, starts);
|
|
279
|
+
const far = Math.max(...pool.filter((t) => !starts.includes(t)).map((t) => d.get(t) ?? 0));
|
|
280
|
+
// Spread, not maximal: anything at least half the farthest distance.
|
|
281
|
+
choice = r.pick(pool.filter((t) => !starts.includes(t) && (d.get(t) ?? 0) >= Math.max(2, Math.floor(far / 2))));
|
|
282
|
+
}
|
|
283
|
+
starts.push(choice);
|
|
284
|
+
cells.set(choice, { owner: player, armies: START_ARMIES });
|
|
285
|
+
}
|
|
286
|
+
const history = [[], []];
|
|
287
|
+
const incomeLog = [[], []];
|
|
288
|
+
const result = { winner: null, by: 'draw', turns: 0, incomes: [[], []], territories: [[], []] };
|
|
289
|
+
for (let turn = 1; turn <= maxTurns; turn++) {
|
|
290
|
+
const held = PLAYERS.map((p) => new Set([...cells].filter(([, c]) => c.owner === p).map(([t]) => t)));
|
|
291
|
+
const alive = held.map((h) => h.size > 0);
|
|
292
|
+
if (!alive[0] || !alive[1]) {
|
|
293
|
+
result.winner = alive[0] ? 0 : 1;
|
|
294
|
+
result.by = 'eliminated';
|
|
295
|
+
return result;
|
|
296
|
+
}
|
|
297
|
+
result.turns = turn;
|
|
298
|
+
const incomes = held.map((h) => boardIncome(g, h, { base: BASE_INCOME, per: 0 }).total);
|
|
299
|
+
const orders = PLAYERS.map((p, i) => {
|
|
300
|
+
result.incomes[i].push(incomes[i]);
|
|
301
|
+
result.territories[i].push(held[i].size);
|
|
302
|
+
const board = viewOf(g, cells, p, o.fog === true);
|
|
303
|
+
const view = {
|
|
304
|
+
graph: g,
|
|
305
|
+
board,
|
|
306
|
+
me: p,
|
|
307
|
+
income: incomes[i],
|
|
308
|
+
turn,
|
|
309
|
+
history: history[i],
|
|
310
|
+
incomes: incomeLog[i],
|
|
311
|
+
players: PLAYERS,
|
|
312
|
+
fog: o.fog === true,
|
|
313
|
+
};
|
|
314
|
+
const out = legal(o.bots[i].orders(view), p, held[i], incomes[i]);
|
|
315
|
+
history[i].push({ turn, board, orders: myOrders(out) });
|
|
316
|
+
incomeLog[i].push({ turn, income: incomes[i] });
|
|
317
|
+
return out;
|
|
318
|
+
});
|
|
319
|
+
const full = { source: 'browser', verified: true, territories: boardOf(cells) };
|
|
320
|
+
const sim = simulateTurn({
|
|
321
|
+
graph: g,
|
|
322
|
+
board: full,
|
|
323
|
+
deploys: orders.flatMap((x, i) => x.deploys.map((d) => ({ player: PLAYERS[i], ...d }))),
|
|
324
|
+
orders: orders.map((x, i) => ({ player: PLAYERS[i], orders: x.moves })),
|
|
325
|
+
moveOrder: turn % 2 === 1 ? [PLAYERS[0], PLAYERS[1]] : [PLAYERS[1], PLAYERS[0]],
|
|
326
|
+
settings: ARENA_SETTINGS,
|
|
327
|
+
});
|
|
328
|
+
cells.clear();
|
|
329
|
+
for (const [t, c] of sim.territories)
|
|
330
|
+
cells.set(t, { owner: c.owner, armies: c.armies });
|
|
331
|
+
}
|
|
332
|
+
// Decided on points: income, then armies, then territories.
|
|
333
|
+
const score = PLAYERS.map((p) => {
|
|
334
|
+
const h = new Set([...cells].filter(([, c]) => c.owner === p).map(([t]) => t));
|
|
335
|
+
const armies = [...cells].filter(([, c]) => c.owner === p).reduce((n, [, c]) => n + c.armies, 0);
|
|
336
|
+
return [boardIncome(g, h, { base: BASE_INCOME, per: 0 }).total, armies, h.size];
|
|
337
|
+
});
|
|
338
|
+
const cmp = score[0][0] - score[1][0] || score[0][1] - score[1][1] || score[0][2] - score[1][2];
|
|
339
|
+
if (cmp !== 0) {
|
|
340
|
+
result.winner = cmp > 0 ? 0 : 1;
|
|
341
|
+
result.by = 'points';
|
|
342
|
+
}
|
|
343
|
+
return result;
|
|
344
|
+
}
|
|
345
|
+
/** The board as `player` sees it: with fog, territories neither its own nor beside its own are hidden. */
|
|
346
|
+
export function viewOf(g, cells, player, fog) {
|
|
347
|
+
const own = new Set([...cells].filter(([, c]) => c.owner === player).map(([t]) => t));
|
|
348
|
+
const seen = new Set(own);
|
|
349
|
+
for (const t of own)
|
|
350
|
+
for (const n of neighborsOf(g, t))
|
|
351
|
+
seen.add(n);
|
|
352
|
+
const territories = [];
|
|
353
|
+
for (const [t, c] of [...cells].sort((a, b) => a[0] - b[0])) {
|
|
354
|
+
if (fog && !seen.has(t))
|
|
355
|
+
territories.push({ territoryId: t, owner: { kind: 'unknown' }, armies: null, fogLevel: 'Fogged' });
|
|
356
|
+
else
|
|
357
|
+
territories.push(stateOf(t, c));
|
|
358
|
+
}
|
|
359
|
+
return { source: 'browser', verified: true, territories };
|
|
360
|
+
}
|
|
361
|
+
function boardOf(cells) {
|
|
362
|
+
return [...cells].sort((a, b) => a[0] - b[0]).map(([t, c]) => stateOf(t, c));
|
|
363
|
+
}
|
|
364
|
+
function stateOf(t, c) {
|
|
365
|
+
return {
|
|
366
|
+
territoryId: t,
|
|
367
|
+
owner: typeof c.owner === 'number' ? { kind: 'player', playerId: c.owner } : { kind: 'neutral' },
|
|
368
|
+
armies: c.armies,
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
/** A bot's orders cut to what war.app would take: deploys on its own territories, within its income. */
|
|
372
|
+
export function legal(out, player, held, income) {
|
|
373
|
+
let left = income;
|
|
374
|
+
const deploys = [];
|
|
375
|
+
for (const d of out.deploys) {
|
|
376
|
+
if (!held.has(d.territoryId) || d.armies <= 0)
|
|
377
|
+
continue;
|
|
378
|
+
const a = Math.min(d.armies, left);
|
|
379
|
+
if (a <= 0)
|
|
380
|
+
continue;
|
|
381
|
+
left -= a;
|
|
382
|
+
deploys.push({ territoryId: d.territoryId, armies: a });
|
|
383
|
+
}
|
|
384
|
+
void player;
|
|
385
|
+
return { deploys, moves: out.moves.filter((m) => held.has(m.from) && m.armies > 0) };
|
|
386
|
+
}
|
|
387
|
+
function myOrders(o) {
|
|
388
|
+
return { deploys: o.deploys, moves: o.moves.map((m) => ({ from: m.from, to: m.to, armies: m.armies })), sent: o.moves.map((m) => ({ from: m.from, to: m.to })), cards: [] };
|
|
389
|
+
}
|