@chrischall/warapp-mcp 0.6.0 → 0.7.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 +99 -6
- package/dist/analysis/accept-surrender.js +20 -2
- package/dist/analysis/calibrate.js +1 -0
- package/dist/analysis/card-support.js +175 -16
- package/dist/analysis/card-threats.js +68 -3
- package/dist/analysis/chat-advice.js +182 -0
- package/dist/analysis/chat-blocks.js +106 -0
- package/dist/analysis/chat-intent.js +559 -0
- package/dist/analysis/chat-read.js +159 -0
- package/dist/analysis/decision-replay.js +279 -0
- package/dist/analysis/decision-truth.js +146 -0
- package/dist/analysis/finished-game.js +62 -3
- package/dist/analysis/game-lessons.js +12 -6
- package/dist/analysis/opponent-profile.js +46 -3
- package/dist/analysis/opponents.js +245 -19
- package/dist/analysis/outlook.js +323 -17
- package/dist/analysis/plan/after-leftover.js +4 -1
- package/dist/analysis/plan/captures.js +4 -3
- package/dist/analysis/plan/estimates.js +70 -6
- package/dist/analysis/plan/guard-off.js +2 -1
- package/dist/analysis/plan/holds.js +79 -6
- package/dist/analysis/plan/leftover.js +145 -5
- package/dist/analysis/plan/relations.js +115 -2
- package/dist/analysis/plan/shared.js +201 -11
- package/dist/analysis/plan/stand-still.js +2 -2
- package/dist/analysis/plan/stockpile.js +104 -0
- package/dist/analysis/plan/strike.js +34 -7
- package/dist/analysis/plan/targets.js +168 -53
- package/dist/analysis/plan/threats.js +108 -5
- package/dist/analysis/plan/transfers.js +11 -0
- package/dist/analysis/plan/two-move.js +70 -0
- package/dist/analysis/plan/vacated.js +124 -2
- package/dist/analysis/planner.js +302 -42
- package/dist/analysis/since-last.js +18 -5
- package/dist/board.js +36 -2
- package/dist/build-id.js +106 -0
- package/dist/bundle.js +14943 -10146
- package/dist/chat-automation.js +22 -0
- package/dist/client.js +14 -0
- package/dist/decision-log.js +1093 -0
- package/dist/finished-store.js +5 -1
- package/dist/lessons-store.js +322 -21
- package/dist/open-games.js +36 -16
- package/dist/outlook-log.js +42 -1
- package/dist/protocol/methods.js +4 -2
- package/dist/review-export.js +198 -0
- package/dist/state-bundle.js +62 -3
- package/dist/state-cli.js +5 -3
- package/dist/strategy/notes.js +56 -0
- package/dist/tools/accept-surrender.js +23 -9
- package/dist/tools/award.js +5 -1
- package/dist/tools/card-advice.js +77 -23
- package/dist/tools/card-support-advice.js +36 -7
- package/dist/tools/chat-advice.js +330 -0
- package/dist/tools/chat-inbox.js +15 -4
- package/dist/tools/chat.js +41 -11
- package/dist/tools/check-plan.js +14 -2
- package/dist/tools/decision-capture.js +459 -0
- package/dist/tools/end-of-game.js +146 -18
- package/dist/tools/game-kind.js +92 -0
- package/dist/tools/how-lost.js +7 -2
- package/dist/tools/index.js +3 -0
- package/dist/tools/join-game.js +10 -4
- package/dist/tools/live-context.js +6 -0
- package/dist/tools/live.js +10 -1
- package/dist/tools/map-curves.js +73 -0
- package/dist/tools/notifications.js +4 -3
- package/dist/tools/opponents.js +2 -0
- package/dist/tools/past-games.js +74 -8
- package/dist/tools/picks.js +49 -10
- package/dist/tools/profile-hook.js +62 -3
- package/dist/tools/profile-opponents.js +2 -0
- package/dist/tools/push.js +2 -2
- package/dist/tools/relations.js +2 -0
- package/dist/tools/scout.js +16 -2
- package/dist/tools/state.js +6 -1
- package/dist/tools/strategy.js +3 -3
- package/dist/tools/stress-opponents.js +2 -0
- package/dist/tools/surrender-pending.js +10 -1
- package/dist/tools/surrender.js +18 -3
- package/dist/tools/turn.js +313 -18
- package/dist/tools/where.js +3 -1
- package/dist/version.js +1 -1
- package/manifest.json +23 -2
- package/mint.yaml +23 -0
- package/package.json +1 -1
- package/server.json +20 -2
- package/skills/warapp-mcp/SKILL.md +42 -8
package/dist/analysis/planner.js
CHANGED
|
@@ -76,6 +76,10 @@
|
|
|
76
76
|
// more than CONCEDE_FACTOR × its worth, so the captures go first) is held whole before the
|
|
77
77
|
// first advance when what is left covers it (best worth per army first, never weighed
|
|
78
78
|
// against spreading: `settleContested(true)`); the rest stays contested as before.
|
|
79
|
+
// #417, the race for vacated land: while a static seat's land is untaken, its captures
|
|
80
|
+
// costing at most VACATED_MAX_COST (`raceTargets`, the 2-defender price of its fogged land
|
|
81
|
+
// included) rank ahead of that rule — after the held-bonus units and my commander's hold,
|
|
82
|
+
// before every other candidate (`raceTier`); the contested units are settled before the first.
|
|
79
83
|
// 2. FFA with two or more opponents left: no second front — a break (also from a held
|
|
80
84
|
// border, rule 4a) against a player that can take no member of a bonus I hold next
|
|
81
85
|
// turn and loses nothing to this turn's strike / finishing off is skipped when a
|
|
@@ -199,6 +203,20 @@
|
|
|
199
203
|
// income every turn, breaks the opponent's biggest stack beside it soonest (its owner
|
|
200
204
|
// deploying there every turn), when that is not the border holding the most armies and
|
|
201
205
|
// breaks sooner than it ("Strike stack on … (#201): no border can strike this turn; …").
|
|
206
|
+
// #421: outside a 1v1 (not a siege, not No-Split, not `defend`), a stockpile on a flat income —
|
|
207
|
+
// my armies in view at least STOCKPILE_TURNS turns of my income while `incomeTrend` is flat —
|
|
208
|
+
// builds the same stack facing the opponent beside me whose visible armies mine outnumber
|
|
209
|
+
// STOCKPILE_LEAD× (fewest first, then id; never an income estimate), never on my commander's
|
|
210
|
+
// territory, and spends it as above ("Stockpile (#421): …").
|
|
211
|
+
// #421, the strike share: in contact on a flat income (a stack built as above), STRIKE_SHARE
|
|
212
|
+
// of the income is held out of captures for the stack (holds keep their exact need first),
|
|
213
|
+
// unless that lowers next income (`planShare`) ("Strike share (#421): …").
|
|
214
|
+
// #421, the break spend: on the pile (`pc.pile`), rule 4a runs the break of the strongest
|
|
215
|
+
// opponent's cheapest visible bonus before every other capture, never skipped as a second
|
|
216
|
+
// front ("Stockpile spend (#421): …").
|
|
217
|
+
// #421, the all-in completion: on the pile, each contested bonus is planned all-in through
|
|
218
|
+
// #298's push (`planPushed`, `PlanInput.stockpileAllIn`), kept only when taken whole
|
|
219
|
+
// ("Stockpile all-in (#421): …").
|
|
202
220
|
// 3d. Decided (#201): given `options.outlook` (#178) reporting winning or losing, the game is
|
|
203
221
|
// decided, and every payback test (PAYBACK_TURNS everywhere it appears in these rules)
|
|
204
222
|
// counts the turns it has left instead: the loser's strength over the winner's income a
|
|
@@ -243,6 +261,16 @@
|
|
|
243
261
|
// per-territory income, plus what the estimate holds beyond every such pool, with a
|
|
244
262
|
// warning). An enemy commander counts in
|
|
245
263
|
// the expected attack too (rule 1h's near miss, kept garrisons).
|
|
264
|
+
// #420 (owner decision of 2026-11-20, "One opponent's deploy"): an opponent deploys its income in
|
|
265
|
+
// one place, so its full deploy sizes only its single most valuable border of mine (by protected
|
|
266
|
+
// value, then its movable armies beside it, then id); its other borders of mine are sized at its
|
|
267
|
+
// stacks beside them plus its largest top-up seen (`OpponentTrack.topUp`: the most one of its
|
|
268
|
+
// stacks beside my land grew in one turn on the tracker's live boards), never above the full deploy
|
|
269
|
+
// (`oneBorder` in plan/threats.ts, read by `forceAt`), with a "deploys its ~D in one place (#420)"
|
|
270
|
+
// line. Not with no top-up seen (no track), under `enemyDeploy`, on my commander's territory, for an
|
|
271
|
+
// untrusted estimate (#275) there, or for an opponent facing a single border of mine.
|
|
272
|
+
// A quiet neighbour (`PlanInput.quiet`, #420's P1 amendment: 10+ contact turns at an attack rate of
|
|
273
|
+
// 0.1 or less, no attack on me since) has every border so sized, its most valuable included.
|
|
246
274
|
// enemyDeploy is estimated per opponent (`enemyDeployEstimates`): base
|
|
247
275
|
// income (the larger of MinimumArmyBonus and, with BonusArmyPer on, its
|
|
248
276
|
// visible territories / BonusArmyPer) plus the bonuses that player
|
|
@@ -292,7 +320,14 @@
|
|
|
292
320
|
// guard or beside no other player), never a hold an order `moves` does not carry touched (a
|
|
293
321
|
// Transfer Only, Attack Only or percentage order in `sent`, a card play in `cards`; orders cached
|
|
294
322
|
// before those were kept read nothing), and on a turn an opponent may have played a Bomb
|
|
295
|
-
// (`bombPossibleOn`, `PlannerSettings.bombFrom`) after taking out half the hold, rounded up.
|
|
323
|
+
// (`bombPossibleOn`, `PlannerSettings.bombFrom`) after taking out half the hold, rounded up. #418
|
|
324
|
+
// (owner decision of 2026-11-20: proof may always raise an estimate): a capture with every source
|
|
325
|
+
// army in view (`captureFloor`) bounds it from below too — what stands on the target plus the
|
|
326
|
+
// attacker its last defender surely killed, and at least the fewest armies that kill every defender
|
|
327
|
+
// however the attack was split, beyond what its stacks beside the target could send (less the
|
|
328
|
+
// guard) — counted when the target was a neutral or mine, every neighbour showed its owner and its
|
|
329
|
+
// own their armies, no other player borders it, Multi-Attack is off, and (beside or out of my land)
|
|
330
|
+
// my orders are known in full and none touches it; a Bomb it may have played halves the defenders. A
|
|
296
331
|
// capture of a neutral in view beside the fog that needed more attackers (`fewestAttackersToTake`)
|
|
297
332
|
// than its stacks in view sent (`unseenAttackers`) reads what stands there beyond those as deploy
|
|
298
333
|
// within #123's bound, the rest a move out of the fog. Its stacks in view beside a capture, hidden
|
|
@@ -343,6 +378,10 @@
|
|
|
343
378
|
// its lower bound (visible, tracked, a rising trend's next step) and its upper bound (the fog prior,
|
|
344
379
|
// else what it could earn), moved toward the lower bound as the coverage nears LOW_COVERAGE
|
|
345
380
|
// (`thinEvidence`); the warning names both bounds. Unmeasured.
|
|
381
|
+
// #419 (owner decision of 2026-11-20): with the fog prior on, that upper bound is the larger of the
|
|
382
|
+
// prior and the pace past winners set at this turn (`PlanGameContext.mapPace`, `FogPace`: this map's
|
|
383
|
+
// median winner over 3+ games of the format and settings, else my income × the format's median winner ÷
|
|
384
|
+
// mine), capped and scaled as the prior; the warning names the basis (`thinEvidence.pace`).
|
|
346
385
|
// In a 1v1 too, so it trades #119's prior back toward tracked figures #119 found 2-3x low:
|
|
347
386
|
// PRIOR_EVIDENCE_TURNS (4) is unmeasured against a finished 1v1.
|
|
348
387
|
// #164, exact income: under a fog setting that shows every owner (`OWNERS_SHOWN_FOG`: No, Light
|
|
@@ -465,6 +504,15 @@
|
|
|
465
504
|
// (fully visible, fewer territories than mine, deploy below my income) that
|
|
466
505
|
// threatens it now is never conceded economically (the rationale says so once its
|
|
467
506
|
// hold is deployed); under `balanced` its hold goes first.
|
|
507
|
+
// #420 (owner decision of 2026-11-20, "Total hold cap", `holdCapOf` in plan/holds.ts): plain holds
|
|
508
|
+
// take at most HOLD_CAP_EVEN (50%) of my income when even or ahead and HOLD_CAP_BEHIND (70%) when
|
|
509
|
+
// the profile reads me behind (rounded down). A held bonus's own gate (rule 1h's units) and my
|
|
510
|
+
// commander's hold (rule 1k) are funded first, outside it, and count nothing toward it. A plain hold
|
|
511
|
+
// past it — rule 1a's `defend` triage, rule 4a's greedy hold, a unit member judged alone, a deferred
|
|
512
|
+
// hold — is conceded with a "cannot be held within the hold cap (#420 …)" line (its armies may still
|
|
513
|
+
// attack out); a hold that breaks its one threat (rule 4a's hold-and-break) runs first, as a capture,
|
|
514
|
+
// and counts. The leftover's revival may still hold a capped border after all. Off under a `defend`
|
|
515
|
+
// goal the caller gave, and with `options.holdCap: false` (tests of earlier hold rules use it).
|
|
468
516
|
// 1a. Triage (every goal). Each threatened border's protected value is the sum
|
|
469
517
|
// of my complete bonuses containing it, plus incomplete bonuses containing it
|
|
470
518
|
// that I would lose all access to without it, plus (#122) its share of every other
|
|
@@ -989,7 +1037,7 @@
|
|
|
989
1037
|
// would then exceed the next income and the start-of-turn hold cost (in rule 4e's
|
|
990
1038
|
// contact/late fallback it is a cost instead, #114); a warning ("Frontier grows faster than
|
|
991
1039
|
// income") names it, and also fires when the plan's frontier ends so. #281: never a territory a
|
|
992
|
-
// static seat left (rule 0s) that costs at most VACATED_MAX_COST and borders a live opponent's
|
|
1040
|
+
// static seat left (rule 0s) that costs at most VACATED_MAX_COST (3, #417: what 2 defenders cost) and borders a live opponent's
|
|
993
1041
|
// stack able to take it with what stands there (`denialOf`): that border comes either way, so
|
|
994
1042
|
// it is let through, a line ("Take … though it faces player …") says so, and pass 3 ranks it by
|
|
995
1043
|
// capture cost plus the frontier without its own hold need, less the denial (1 + PAYBACK_TURNS ×
|
|
@@ -998,6 +1046,10 @@
|
|
|
998
1046
|
// may fall to 0 or below; a plain capture's never goes below one army), and a member of an
|
|
999
1047
|
// uneconomic bonus of mine is still eligible for it. Each denial is judged once per plan
|
|
1000
1048
|
// (`denialsOf`, `Targets.denials`). It spends only what stands above its source's hold (#121).
|
|
1049
|
+
// #417, the breach force: land a static seat left whose armies the fog hides is a target at
|
|
1050
|
+
// VACATED_FOG_ARMIES defenders (`fogVacated`, read by `defenceAt`), pass 3 takes vacated land outside
|
|
1051
|
+
// a negative bonus even in an uneconomic bonus, and rule 6 keeps the idle armies beside such land still
|
|
1052
|
+
// untaken and cheap (`breachOf`) until it is taken.
|
|
1001
1053
|
// #281, the owner's extension (2026-11-16; guard off, not under No-Split, `balanced`/`defend`):
|
|
1002
1054
|
// a live opponent's own territory beside mine in view at 0 (no special unit) whose owner holds
|
|
1003
1055
|
// no positive bonus it is in (#165 breaks those) and that was not mine on `previousBoard` (#276
|
|
@@ -1142,12 +1194,20 @@
|
|
|
1142
1194
|
// this income (armies to finish, counting the members I hold, over the income — and never
|
|
1143
1195
|
// fewer than its depth, #125: the farthest missing member's distance from what I hold, since
|
|
1144
1196
|
// a capture's armies attack no further this turn; "N turns (N layers deep)"), so a farther
|
|
1145
|
-
// bonus gets only armies the closer ones cannot use; bonuses as close as each other
|
|
1146
|
-
//
|
|
1147
|
-
//
|
|
1148
|
-
//
|
|
1149
|
-
//
|
|
1150
|
-
//
|
|
1197
|
+
// bonus gets only armies the closer ones cannot use; bonuses as close as each other go by the
|
|
1198
|
+
// income per army of every bonus their capture completes (#438: each bonus whose missing members
|
|
1199
|
+
// are all among its own, net values summed, over the score's cost; a "complete together" line
|
|
1200
|
+
// names it when another as close competes), then — given `previousBoard` — a bonus advanced last
|
|
1201
|
+
// turn (a member captured since), then the score order; the rationale lists the order and says
|
|
1202
|
+
// which advanced bonus kept or gave way. Armies to finish count every missing member: a fogged one
|
|
1203
|
+
// a static seat left at its #417 price (below); else (#428) at its last sighting on my boards
|
|
1204
|
+
// (`options.lastSeen`, unless the fog shows another owner now), else its picking-board size
|
|
1205
|
+
// (#201), else — its owner hidden too — the game's neutral size (`settings.neutralArmies`), else at
|
|
1206
|
+
// its bonus's costliest visible missing member (counted as free before, the figure jumped when it
|
|
1207
|
+
// came into view), named in every "N armies to finish". #439 (plan/two-move.ts): a single-territory bonus of
|
|
1208
|
+
// at least TWO_MOVE_MIN_VALUE two moves away through a visible neutral is a two-turn completion
|
|
1209
|
+
// (cost: that neutral plus the territory); the neutral in between is a `stage` candidate under
|
|
1210
|
+
// `balanced` (net over both costs, ranked as an advance), else taken before the advances.
|
|
1151
1211
|
// 3b. One surplus per territory (#121). A border that holds at the start of the turn (its armies
|
|
1152
1212
|
// beat its visible threat, rule 1) and is not conceded keeps what holds it, as my commander's
|
|
1153
1213
|
// territory does (rule 1k): a capture from it spends only its armies above that, plus deploys
|
|
@@ -1185,7 +1245,10 @@
|
|
|
1185
1245
|
// first, only that one lands before the opponent's first; when I am known to move first, the
|
|
1186
1246
|
// warning is "holds only if my first order is …"). The warning names why the leftover made no
|
|
1187
1247
|
// deploy there (too little left, Local Deployment, No-Split sending the stack with its order)
|
|
1188
|
-
// only when that was the reason.
|
|
1248
|
+
// only when that was the reason. #440: before the margins below, the territory with the most
|
|
1249
|
+
// protected value that carries a single-territory bonus of at least DETERRENT_MIN_VALUE
|
|
1250
|
+
// (DETERRENT_VALUE_RATIO × the borders' most, an opponent within two steps) gets a deterrent guard: taking it needs more than
|
|
1251
|
+
// COMFORT_MARGIN × that opponent's deploy (plan/leftover.ts `deterrentGuard`). Then it goes to the held
|
|
1189
1252
|
// border with the highest protected value still short of COMFORT_MARGIN × its threat (counting
|
|
1190
1253
|
// armies withdrawn into it) — but first (#121), when it would go to such margins (no strike stack;
|
|
1191
1254
|
// #215 review: judged and run before the worse-order deploys above), a conceded border the leftover can make hold is held after all, from what is left once
|
|
@@ -1368,13 +1431,17 @@
|
|
|
1368
1431
|
// warning ("Breaking player … without eliminating it invites retaliation"): what it has left is
|
|
1369
1432
|
// likeliest aimed at whoever broke it. In a 1v1 it attacks me anyway, so no warning there.
|
|
1370
1433
|
// Wastelands (#167, `settings.wastelands`): a fogged missing member of a bonus is costed at the
|
|
1371
|
-
// costliest visible missing member plus the expected surcharge of being a wasteland
|
|
1434
|
+
// neutral size or costliest visible missing member (#428) plus the expected surcharge of being a wasteland
|
|
1372
1435
|
// (ceil(count ÷ the map's territories × (a wasteland's capture cost − that))), with a rationale line.
|
|
1373
1436
|
// #201: given `options.rememberedNeutrals` (the picking board's neutrals, which warapp_plan_picks
|
|
1374
1437
|
// and warapp_submit_picks' preview keep per game), a fogged missing member the picking board showed
|
|
1375
1438
|
// as a neutral (and whose owner the fog does not show as a player now) is costed at that size
|
|
1376
1439
|
// instead, never attacked, with a rationale line ("… fogged now, was a neutral of N on the picking
|
|
1377
|
-
// board (#201)").
|
|
1440
|
+
// board (#201)"). #417: a fogged member a static seat left (`BoardCtx.vacated`: shown owner-only as
|
|
1441
|
+
// its, or fogged now and the seat's when last seen — `foggedLastSeen`, the newest earlier board that
|
|
1442
|
+
// showed it, else `previousBoard`) is costed at VACATED_FOG_ARMIES (2) defenders, never above the costliest member in view (its border stack says nothing about the
|
|
1443
|
+
// land behind it), with a "… was player N's (out, no AI) … (#417)" line; it raises no other fogged
|
|
1444
|
+
// member's figure and gets no wasteland surcharge.
|
|
1378
1445
|
// 7. Move order (#127; every goal, last). Orders zigzag — the first mover's 1st, the other's
|
|
1379
1446
|
// 1st and 2nd, the first mover's 2nd and 3rd, … — so `moves` is scheduled
|
|
1380
1447
|
// (`scheduleMoves`, src/analysis/schedule.ts), earliest first: the one order Order Priority
|
|
@@ -1577,18 +1644,20 @@ import { BREAK_WEIGHT, MIN_EXPANSION_SHARE, PLAIN_EXPANSION_LOSS, SECOND_FRONT_L
|
|
|
1577
1644
|
import { emptyPlan, noteEstimates, planContext } from './plan/estimates.js';
|
|
1578
1645
|
import { neutralizeSeats, seatTerritories, staticSeats } from './static-seats.js';
|
|
1579
1646
|
import { deployBook } from './plan/orders.js';
|
|
1580
|
-
import { holdsPhase } from './plan/holds.js';
|
|
1647
|
+
import { holdsPhase, priorOnlyHold } from './plan/holds.js';
|
|
1581
1648
|
import { threatsPhase } from './plan/threats.js';
|
|
1582
1649
|
import { targetsPhase } from './plan/targets.js';
|
|
1583
1650
|
import { capturesPhase } from './plan/captures.js';
|
|
1584
1651
|
import { completedMembers } from './plan/completed.js';
|
|
1585
1652
|
import { chooseStrikeStack, leadStrikes, spendStrikeStack, strikesPhase } from './plan/strike.js';
|
|
1653
|
+
import { contestedBonuses } from './plan/stockpile.js';
|
|
1586
1654
|
import { afterLeftoverCaptures, plainEconomy, plainEligible } from './plan/after-leftover.js';
|
|
1587
1655
|
import { fundFromSecondSizing } from './plan/second-sizing.js';
|
|
1588
1656
|
import { leftoverDeploy } from './plan/leftover.js';
|
|
1589
1657
|
import { fillSecondLine, guardOffRaids } from './plan/guard-off.js';
|
|
1590
1658
|
import { neverStandStill } from './plan/stand-still.js';
|
|
1591
|
-
import {
|
|
1659
|
+
import { stageTwoMove, twoMoveStages } from './plan/two-move.js';
|
|
1660
|
+
import { addEmptyEnemyTargets, dropEmptyEnemyTargets, foggedLastSeen, plainOrderCosts, raceLine, raceTargets, tryEmptyEnemy, withoutTransit } from './plan/vacated.js';
|
|
1592
1661
|
import { spendUnderCap } from './plan/cap-spend.js';
|
|
1593
1662
|
import { attackOutOfConceded } from './plan/conceded-out.js';
|
|
1594
1663
|
import { captureInsteadOfHold } from './plan/capture-instead.js';
|
|
@@ -1598,7 +1667,7 @@ import { commanderMoveWarning, placeCommanderMove, reserveCommanderMove } from '
|
|
|
1598
1667
|
import { finishPlan, reportExpected, reportOffence } from './plan/report.js';
|
|
1599
1668
|
import { newPlanState } from './plan/state.js';
|
|
1600
1669
|
import { teamFocusLine, teamReport } from './plan/team.js';
|
|
1601
|
-
import { applyBorderCaps, armiesFreed, partnerFronts, reportBreakLosses, reportTruce, trucePass } from './plan/relations.js';
|
|
1670
|
+
import { applyBorderCaps, armiesFreed, partnerFronts, reportBreakLosses, reportTruce, trucePass, warnTruceNeutrals } from './plan/relations.js';
|
|
1602
1671
|
export * from './plan/shared.js';
|
|
1603
1672
|
export { alliesOf, planEnemyEstimates } from './plan/estimates.js';
|
|
1604
1673
|
export { TRUCE_RELAX_VALUE } from './plan/relations.js';
|
|
@@ -1662,6 +1731,12 @@ function withoutStaticSeats(input, seats) {
|
|
|
1662
1731
|
for (const t of input.board.territories)
|
|
1663
1732
|
if (t.owner.kind === 'player' && seats.has(t.owner.playerId))
|
|
1664
1733
|
vacated.set(t.territoryId, t.owner.playerId);
|
|
1734
|
+
// #417: and the fogged ones last seen held by a seat — on the newest earlier board that showed them
|
|
1735
|
+
// (`foggedLastSeen`), not only the previous board, so the pricing outlasts the turn vision was lost.
|
|
1736
|
+
const lastSeen = input.foggedLastSeen ?? foggedLastSeen(input.board, input.previousBoard ? [{ turn: 0, board: input.previousBoard }] : []);
|
|
1737
|
+
for (const [t, p] of lastSeen)
|
|
1738
|
+
if (seats.has(p))
|
|
1739
|
+
vacated.set(t, p);
|
|
1665
1740
|
return {
|
|
1666
1741
|
...input,
|
|
1667
1742
|
...(vacated.size ? { vacated } : {}),
|
|
@@ -1675,6 +1750,60 @@ function withoutStaticSeats(input, seats) {
|
|
|
1675
1750
|
}
|
|
1676
1751
|
/** #298: per plan, the all-in pushes its pass sized (plan/targets.ts), by bonus id. */
|
|
1677
1752
|
const allInOutcome = new WeakMap();
|
|
1753
|
+
/**
|
|
1754
|
+
* #298's attempt memory ({@link planAttempts}), then #421's stockpile all-in completions: on a pile, the
|
|
1755
|
+
* contested bonuses a push could complete are planned all-in, those it does not take whole left out.
|
|
1756
|
+
*/
|
|
1757
|
+
function planPushed(input) {
|
|
1758
|
+
const plan = planAttempts(input);
|
|
1759
|
+
const candidates = pileAllInOutcome.get(plan);
|
|
1760
|
+
if (!candidates?.length)
|
|
1761
|
+
return plan;
|
|
1762
|
+
// #421 (owner decision, 2026-11-20): on a stockpile, every contested bonus whose missing members can all be
|
|
1763
|
+
// taken this turn — each an opponent holds sized for its owner's deploy, the push within the payback horizon ×
|
|
1764
|
+
// its value — is completed all-in. One the plan does not take whole is left out (no drop: it is no failed
|
|
1765
|
+
// attempt), and a push that would cost a #298 verdict its plan is not made.
|
|
1766
|
+
const missingOf = (id) => {
|
|
1767
|
+
const at = new Map(input.board.territories.map((t) => [t.territoryId, t.owner]));
|
|
1768
|
+
return bonusTerritories(input.graph, id).filter((t) => {
|
|
1769
|
+
const o = at.get(t);
|
|
1770
|
+
return !(o?.kind === 'player' && o.playerId === input.me);
|
|
1771
|
+
});
|
|
1772
|
+
};
|
|
1773
|
+
const pushed = new Set(candidates);
|
|
1774
|
+
for (;;) {
|
|
1775
|
+
const next = planAttempts({ ...input, stockpileAllIn: new Set(pushed) });
|
|
1776
|
+
const tries = allInOutcome.get(next);
|
|
1777
|
+
const taken = new Set(next.expected.captures);
|
|
1778
|
+
const failing = [...pushed].filter((id) => !tries?.get(id)?.feasible || missingOf(id).some((t) => !taken.has(t)));
|
|
1779
|
+
if (!failing.length) {
|
|
1780
|
+
if (JSON.stringify(next.bonusPush ?? []) !== JSON.stringify(plan.bonusPush ?? []))
|
|
1781
|
+
return plan;
|
|
1782
|
+
const name = (id) => `${input.graph.bonusById.get(id).name} (#${id})`;
|
|
1783
|
+
for (const id of [...pushed].sort((a, b) => a - b)) {
|
|
1784
|
+
const t = tries.get(id);
|
|
1785
|
+
next.rationale.push(`Stockpile all-in (#421): bonus ${name(id)} is contested and my armies stand idle on a flat income, so every missing member is taken this turn, each one another player holds sized for its owner's deploy: ${t.cost} armies, within the cap of ${t.cap} (the payback horizon × its value).`);
|
|
1786
|
+
}
|
|
1787
|
+
return next;
|
|
1788
|
+
}
|
|
1789
|
+
for (const id of failing)
|
|
1790
|
+
pushed.delete(id);
|
|
1791
|
+
if (!pushed.size)
|
|
1792
|
+
return plan;
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
/** #421: per plan, the contested bonuses a stockpile could push all-in (only on a plan made without such a push). */
|
|
1796
|
+
const pileAllInOutcome = new WeakMap();
|
|
1797
|
+
/** Merge the #421 stockpile pushes (`input.stockpileAllIn`) into #298's push and focus. */
|
|
1798
|
+
function withPush(input, allIn, dropped) {
|
|
1799
|
+
const ids = new Set([...allIn, ...(input.stockpileAllIn ?? [])]);
|
|
1800
|
+
const focus = [...new Set([...(input.options?.focusBonusIds ?? []), ...ids])];
|
|
1801
|
+
return {
|
|
1802
|
+
...input,
|
|
1803
|
+
bonusPush: { allIn: ids, dropped },
|
|
1804
|
+
options: { ...input.options, ...(ids.size ? { focusBonusIds: focus } : {}) },
|
|
1805
|
+
};
|
|
1806
|
+
}
|
|
1678
1807
|
/**
|
|
1679
1808
|
* #298: the plan with the attempt memory's verdicts (plan/bonus-attempts.ts). A bonus whose completion
|
|
1680
1809
|
* failed on two consecutive turns is pushed all-in (focused, every missing member sized for its owner's
|
|
@@ -1682,14 +1811,15 @@ const allInOutcome = new WeakMap();
|
|
|
1682
1811
|
* member, it is planned again with that bonus dropped for DROP_TURNS turns. With no verdict, the plan
|
|
1683
1812
|
* is exactly what it was without the memory.
|
|
1684
1813
|
*/
|
|
1685
|
-
function
|
|
1814
|
+
function planAttempts(input) {
|
|
1686
1815
|
const turn = input.turn;
|
|
1816
|
+
const none = new Set();
|
|
1687
1817
|
if (!input.bonusAttempts || turn === undefined)
|
|
1688
|
-
return
|
|
1818
|
+
return planShare(input.stockpileAllIn?.size ? withPush(input, none, none) : input);
|
|
1689
1819
|
const judged = judgeAttempts(input.bonusAttempts, turn, input.graph, input.board, input.me);
|
|
1690
1820
|
const verdicts = bonusVerdicts(judged, turn).filter((v) => input.graph.bonusById.has(v.bonusId));
|
|
1691
1821
|
if (!verdicts.length)
|
|
1692
|
-
return
|
|
1822
|
+
return planShare(input.stockpileAllIn?.size ? withPush(input, none, none) : input);
|
|
1693
1823
|
const entries = new Map();
|
|
1694
1824
|
for (const v of verdicts)
|
|
1695
1825
|
if (v.kind === 'dropped')
|
|
@@ -1714,12 +1844,7 @@ function planPushed(input) {
|
|
|
1714
1844
|
let plan;
|
|
1715
1845
|
for (;;) {
|
|
1716
1846
|
const ids = new Set(allIn.map((v) => v.bonusId));
|
|
1717
|
-
|
|
1718
|
-
plan = planSettled({
|
|
1719
|
-
...input,
|
|
1720
|
-
bonusPush: { allIn: ids, dropped: new Set([...entries.keys()]) },
|
|
1721
|
-
options: { ...input.options, ...(ids.size ? { focusBonusIds: focus } : {}) },
|
|
1722
|
-
});
|
|
1847
|
+
plan = planShare(withPush(input, ids, new Set([...entries.keys()])));
|
|
1723
1848
|
const tries = allInOutcome.get(plan);
|
|
1724
1849
|
const taken = new Set(plan.expected.captures);
|
|
1725
1850
|
const failing = allIn.flatMap((v) => {
|
|
@@ -1769,6 +1894,24 @@ function planPushed(input) {
|
|
|
1769
1894
|
plan.bonusPush = push;
|
|
1770
1895
|
return plan;
|
|
1771
1896
|
}
|
|
1897
|
+
/** #421: per plan, the strike share its pass held out of captures (absent when none). */
|
|
1898
|
+
const shareOutcome = new WeakMap();
|
|
1899
|
+
/**
|
|
1900
|
+
* #421 (owner decision, 2026-11-20): the strike share is held out of captures, ahead of comfort margins,
|
|
1901
|
+
* but never at the cost of next income — when the plan without it earns more next turn (a completion the
|
|
1902
|
+
* share starves), that plan stands and says why.
|
|
1903
|
+
*/
|
|
1904
|
+
function planShare(input) {
|
|
1905
|
+
const plan = planSettled(input);
|
|
1906
|
+
const share = shareOutcome.get(plan);
|
|
1907
|
+
if (!share)
|
|
1908
|
+
return plan;
|
|
1909
|
+
const without = planSettled({ ...input, options: { ...input.options, strikeShare: false } });
|
|
1910
|
+
if (without.expected.nextIncome <= plan.expected.nextIncome)
|
|
1911
|
+
return plan;
|
|
1912
|
+
without.rationale.push(`Strike share (#421) not held this turn: holding ${share} of the income out of captures for the strike stack would lower next income from ${without.expected.nextIncome} to ${plan.expected.nextIncome} (a capture it starves completes a bonus).`);
|
|
1913
|
+
return without;
|
|
1914
|
+
}
|
|
1772
1915
|
function planSettled(input) {
|
|
1773
1916
|
const plan = planRun(input, false);
|
|
1774
1917
|
const bare = runOutcome.get(plan);
|
|
@@ -1846,11 +1989,11 @@ function planPass(input, pass) {
|
|
|
1846
1989
|
// As the deploy book reads it, restated here so TypeScript narrows `pools` wherever it is tested.
|
|
1847
1990
|
const local = pools !== null && pools.bonuses.length > 0;
|
|
1848
1991
|
// ---- 1t. threat trend, 1. defence (plan/threats.ts) ----
|
|
1849
|
-
const threats = threatsPhase(pc, ps, input);
|
|
1992
|
+
const threats = threatsPhase(pc, ps, input, book.valueOf);
|
|
1850
1993
|
const { growthOf, reinforcementAt, borders, facing, borderAt } = threats;
|
|
1851
1994
|
// ---- 1. holds, #172, 1h, 1b, 1c, #122 garrisons (plan/holds.ts) ----
|
|
1852
1995
|
const hd = holdsPhase(pc, ps, book, threats, pass);
|
|
1853
|
-
const { acting, conceded, concedeUnaffordable, floorOrConcede, fundNearMiss, fundUnit, garrisonCompleted, heldBorders, heldStack, hold, holds, keepFor, kept, keptShort, leftFor, mayComplete, mayHold, noteRecent, pendingLocks, reconsider, settleContested, twoStepBound, twoStepKeep, uneconomic, units, withdraw, } = hd;
|
|
1996
|
+
const { acting, conceded, concedeUnaffordable, floorOrConcede, fundNearMiss, fundUnit, garrisonCompleted, heldBorders, heldStack, hold, holds, keepFor, kept, keptShort, leftFor, mayComplete, mayHold, noteRecent, pendingLocks, reconsider, settleContested, twoStepBound, twoStepKeep, uneconomic, units, withdraw, overCap, chargeCap, concedeCapped, } = hd;
|
|
1854
1997
|
// ---- 2. targets, 4d. frontier cost, bonus scoring, #101 (plan/targets.ts) ----
|
|
1855
1998
|
const tgt = targetsPhase(pc, ps, input, threats, hd);
|
|
1856
1999
|
const { breakable, counterAt, targets, leadSteps, landScoreCost, offence, skipOffence, plans, ratio, committing, byCloseness, retakeChecks, retakeWarning, } = tgt;
|
|
@@ -1862,6 +2005,8 @@ function planPass(input, pass) {
|
|
|
1862
2005
|
// ---- R3, No-Split, capture helper, 3a. combined, passes 1 and 2 (plan/captures.ts) ----
|
|
1863
2006
|
const caps = capturesPhase(pc, ps, pass, book, threats, hd, tgt);
|
|
1864
2007
|
const { strikes, worstCase, defendersAt, tryCapture, snapshot, complete, tryExpand, advance } = caps;
|
|
2008
|
+
/** #439: single-territory bonuses two moves away, each with its neutral in between. */
|
|
2009
|
+
const stages = twoMoveStages(pc, tgt);
|
|
1865
2010
|
// ---- 1e. finish off an opponent, 1s. strike an enemy commander, #165 guard-off breaks (plan/strike.ts) ----
|
|
1866
2011
|
const { struck } = strikesPhase(pc, ps, book, threats, hd, tgt, caps);
|
|
1867
2012
|
// ---- #276: guard off — free retakes and raids one step deeper (plan/guard-off.ts) ----
|
|
@@ -1948,7 +2093,9 @@ function planPass(input, pass) {
|
|
|
1948
2093
|
return enemyDeploy;
|
|
1949
2094
|
return Math.max(...[...byPlayer].map(([p, movable]) => movable + deployOf(p)));
|
|
1950
2095
|
};
|
|
1951
|
-
const rank = { unit: 0, hold: 0, complete: 1, advance: 2, break: 3, counter: 3 };
|
|
2096
|
+
const rank = { unit: 0, hold: 0, complete: 1, advance: 2, stage: 2, race: 2, break: 3, counter: 3 };
|
|
2097
|
+
/** A capture that completes no bonus this turn: an advance, a two-move stage (#439), a 1v1 race (#417), a break or a counter. */
|
|
2098
|
+
const completesNothing = (c) => c.kind === 'advance' || c.kind === 'stage' || c.kind === 'race' || c.kind === 'break' || c.kind === 'counter';
|
|
1952
2099
|
const candidates = [];
|
|
1953
2100
|
const deferred = [];
|
|
1954
2101
|
/** #215: pending holds this step conceded and unlocked, whose armies may still attack out. */
|
|
@@ -1968,8 +2115,12 @@ function planPass(input, pass) {
|
|
|
1968
2115
|
* this turn's captures may complete stays locked until they are known: rule 1c keeps it for a
|
|
1969
2116
|
* completed bonus, and an attack out would have emptied it first.
|
|
1970
2117
|
*/
|
|
1971
|
-
const concedePending = (t, room) => {
|
|
1972
|
-
|
|
2118
|
+
const concedePending = (t, room, capped = false) => {
|
|
2119
|
+
// #420: past the hold cap, said as such.
|
|
2120
|
+
if (capped)
|
|
2121
|
+
concedeCapped(t);
|
|
2122
|
+
else
|
|
2123
|
+
concedeUnaffordable(t, room);
|
|
1973
2124
|
if (heldBorders.has(t.id))
|
|
1974
2125
|
return;
|
|
1975
2126
|
if (mayComplete(t.id))
|
|
@@ -1997,6 +2148,31 @@ function planPass(input, pass) {
|
|
|
1997
2148
|
candidates.push({ kind: 'complete', score, cost: p.cost, id: p.bonusId, value: p.net, focus: p.focus, borders: p.borders, run: spend(() => complete(p)) });
|
|
1998
2149
|
candidates.push({ kind: 'advance', score, cost: p.cost, id: p.bonusId, value: p.net, focus: p.focus, borders: p.borders, run: spend(() => advance(p)) });
|
|
1999
2150
|
}
|
|
2151
|
+
// #439: a single-territory bonus two moves away is a two-turn completion: its neutral in between
|
|
2152
|
+
// competes as an advance does, on the income per army of both captures.
|
|
2153
|
+
for (const st of stages)
|
|
2154
|
+
candidates.push({ kind: 'stage', score: st.net / st.cost, cost: st.cost, id: st.bonusId, value: st.net, focus: false, borders: 0, target: st.via, run: spend(() => stageTwoMove(pc, ps, st, gainWith, tryExpand)) });
|
|
2155
|
+
// #417, the 1v1 race: while a static seat's land is still untaken, its cheap captures rank ahead of
|
|
2156
|
+
// rule 0p.1's "expansion last" (`ahead` below); held-bonus gates and my commander's hold go first.
|
|
2157
|
+
const races = oneVsOne ? raceTargets(pc, targets, captured) : [];
|
|
2158
|
+
if (races.length)
|
|
2159
|
+
rationale.push(raceLine(pc, races));
|
|
2160
|
+
for (const r of races)
|
|
2161
|
+
candidates.push({
|
|
2162
|
+
kind: 'race',
|
|
2163
|
+
score: 0,
|
|
2164
|
+
cost: r.cost,
|
|
2165
|
+
id: r.t,
|
|
2166
|
+
value: 0,
|
|
2167
|
+
focus: false,
|
|
2168
|
+
borders: 0,
|
|
2169
|
+
target: r.t,
|
|
2170
|
+
run: spend(() => {
|
|
2171
|
+
if (captured.has(r.t))
|
|
2172
|
+
return;
|
|
2173
|
+
withoutTransit(pc, tgt, r.t, () => tryExpand(r.t, `races for land player ${pc.vacated.get(r.t)} left (out, no AI), ahead of the 1v1 "expansion last" rule (#417)`));
|
|
2174
|
+
}),
|
|
2175
|
+
});
|
|
2000
2176
|
// Capturing a member of a breakable bonus: what survives it, and whether that holds next turn.
|
|
2001
2177
|
// A break is sized to land (#72): its score leaves out what holding it would need.
|
|
2002
2178
|
const breakOption = (t) => {
|
|
@@ -2065,6 +2241,7 @@ function planPass(input, pass) {
|
|
|
2065
2241
|
const before = ps.budget;
|
|
2066
2242
|
noteRecent(t);
|
|
2067
2243
|
deploy(t.id, t.holdCost);
|
|
2244
|
+
chargeCap(t.holdCost);
|
|
2068
2245
|
if (!tryCapture(n, breakReason(b), { from: t.id, keep: avail.get(t.id) })) {
|
|
2069
2246
|
// Refused (R3: it would complete a bonus I cannot hold next turn): just hold.
|
|
2070
2247
|
rationale.push(`Deploy ${t.holdCost} to ${label(t.id)} so it holds (protects +${t.value}): ${heldStack(t)} need ${toTake(t.have + t.units + t.holdCost)} to take, above the ~${t.threat} threat.`);
|
|
@@ -2088,6 +2265,32 @@ function planPass(input, pass) {
|
|
|
2088
2265
|
});
|
|
2089
2266
|
return true;
|
|
2090
2267
|
};
|
|
2268
|
+
/** The member a break of `b` takes: its cheapest visible member (#72: a break only has to land), then the least frontier, then id. */
|
|
2269
|
+
const breakOptionOf = (b) => bonusTerritories(g, b.bonusId)
|
|
2270
|
+
.filter((t) => targets.has(t))
|
|
2271
|
+
.map(breakOption)
|
|
2272
|
+
.sort((a, b) => a.cost - b.cost || a.scoreCost - b.scoreCost || a.t - b.t)[0];
|
|
2273
|
+
// #421 (owner decision, 2026-11-20): on a stockpile (`pc.pile`) the turn spends by breaking the strongest
|
|
2274
|
+
// opponent's cheapest visible bonus (every member in view: never a probable one) — ahead of every other
|
|
2275
|
+
// capture, never skipped as a second front. The strongest is the highest income estimate, then id.
|
|
2276
|
+
const pileBreak = (() => {
|
|
2277
|
+
if (!pc.pile)
|
|
2278
|
+
return undefined;
|
|
2279
|
+
const strongest = pc.estimateList
|
|
2280
|
+
.filter((e) => foe(e.playerId))
|
|
2281
|
+
.sort((a, b) => incomeOfPlayer(b.playerId) - incomeOfPlayer(a.playerId) || a.playerId - b.playerId)[0]?.playerId;
|
|
2282
|
+
if (strongest === undefined)
|
|
2283
|
+
return undefined;
|
|
2284
|
+
return breakable
|
|
2285
|
+
.filter((b) => b.player === strongest && !b.probable)
|
|
2286
|
+
.flatMap((b) => {
|
|
2287
|
+
const o = breakOptionOf(b);
|
|
2288
|
+
return o ? [{ b, o }] : [];
|
|
2289
|
+
})
|
|
2290
|
+
.sort((x, y) => x.o.cost - y.o.cost || y.b.value - x.b.value || x.b.bonusId - y.b.bonusId)[0];
|
|
2291
|
+
})();
|
|
2292
|
+
if (pileBreak)
|
|
2293
|
+
rationale.push(`Stockpile spend (#421): ${pc.pile.my} armies of mine stand on the board, ${pc.pile.turns} turns of my flat ${income} income, so the turn tries first to break the strongest opponent's cheapest visible bonus, player ${pileBreak.b.player}'s ${bonusName(pileBreak.b.bonusId)} (+${pileBreak.b.value}) through ${label(pileBreak.o.t)} (${pileBreak.o.cost} armies), before any other capture.`);
|
|
2091
2294
|
for (const b of breakable) {
|
|
2092
2295
|
// Its cheapest visible member (#72: a break only has to land), then the least frontier, then id.
|
|
2093
2296
|
const options = bonusTerritories(g, b.bonusId)
|
|
@@ -2108,18 +2311,24 @@ function planPass(input, pass) {
|
|
|
2108
2311
|
taken: false,
|
|
2109
2312
|
why: breakReason(b),
|
|
2110
2313
|
});
|
|
2314
|
+
const spendIt = pileBreak?.b === b;
|
|
2111
2315
|
// An FFA skips a second-front break, but only one the plan could pay for is named as
|
|
2112
|
-
// skipped: an unaffordable one is dropped quietly (it could not run either way).
|
|
2113
|
-
if (
|
|
2316
|
+
// skipped: an unaffordable one is dropped quietly (it could not run either way). #421: never the stockpile's.
|
|
2317
|
+
if (spendIt) {
|
|
2318
|
+
// #421: the stockpile's break runs whatever its front.
|
|
2319
|
+
}
|
|
2320
|
+
else if (opensSecondFront(b, score) && !affordable(o.t)) {
|
|
2114
2321
|
skipOffence(o.t, 'not affordable this turn');
|
|
2115
2322
|
continue;
|
|
2116
2323
|
}
|
|
2117
|
-
if (secondFront(b, score)) {
|
|
2324
|
+
if (!spendIt && secondFront(b, score)) {
|
|
2118
2325
|
skipOffence(o.t, `no second front in an FFA: player ${b.player} threatens no bonus of mine`);
|
|
2119
2326
|
continue;
|
|
2120
2327
|
}
|
|
2328
|
+
const reasonOf = (r) => (spendIt ? `${r} — the stockpile's spend on the strongest opponent (#421)` : r);
|
|
2121
2329
|
candidates.push({
|
|
2122
2330
|
kind: 'break',
|
|
2331
|
+
...(spendIt ? { spend: true } : {}),
|
|
2123
2332
|
score,
|
|
2124
2333
|
cost: o.cost,
|
|
2125
2334
|
id: b.bonusId,
|
|
@@ -2137,7 +2346,7 @@ function planPass(input, pass) {
|
|
|
2137
2346
|
const was = worstCase.get(o.t);
|
|
2138
2347
|
targets.set(o.t, { ...tg, cost: o.cost });
|
|
2139
2348
|
worstCase.set(o.t, defenceAt(o.t) + reinforcementAt(o.t));
|
|
2140
|
-
if (!tryCapture(o.t, `${breakReason(b)}, sized to land against player ${b.player}'s ~${reinforcementAt(o.t)} deploy (#201: I lead this free-for-all)`)) {
|
|
2349
|
+
if (!tryCapture(o.t, reasonOf(`${breakReason(b)}, sized to land against player ${b.player}'s ~${reinforcementAt(o.t)} deploy (#201: I lead this free-for-all)`))) {
|
|
2141
2350
|
targets.set(o.t, tg);
|
|
2142
2351
|
if (was === undefined)
|
|
2143
2352
|
worstCase.delete(o.t);
|
|
@@ -2146,7 +2355,7 @@ function planPass(input, pass) {
|
|
|
2146
2355
|
return;
|
|
2147
2356
|
}
|
|
2148
2357
|
}
|
|
2149
|
-
else if (!tryCapture(o.t, breakReason(b)))
|
|
2358
|
+
else if (!tryCapture(o.t, reasonOf(breakReason(b))))
|
|
2150
2359
|
return;
|
|
2151
2360
|
ps.anchor ??= moves[moves.length - 1].from;
|
|
2152
2361
|
warnRetake(b, o);
|
|
@@ -2184,7 +2393,7 @@ function planPass(input, pass) {
|
|
|
2184
2393
|
}
|
|
2185
2394
|
expansionLeft = candidates.length;
|
|
2186
2395
|
// Under rule 0p.1 an advance never outranks a hold, so it never defers one either.
|
|
2187
|
-
topValue = Math.max(0, ...candidates.filter((c) => !(oneVsOne && c.kind === 'advance')).map((c) => c.value));
|
|
2396
|
+
topValue = Math.max(0, ...candidates.filter((c) => c.kind !== 'stage' && !(oneVsOne && c.kind === 'advance')).map((c) => c.value));
|
|
2188
2397
|
let floor = expansionLeft ? Math.ceil(MIN_EXPANSION_SHARE * income) : 0;
|
|
2189
2398
|
// #167: a multi-turn view of the main front. Adapting in contact, the expansion share stands only
|
|
2190
2399
|
// when the front is no worse than a stand-off without those armies: my biggest stack facing the
|
|
@@ -2240,9 +2449,13 @@ function planPass(input, pass) {
|
|
|
2240
2449
|
rationale.push(`Front outlook (#167): ${pair}, ${f.outcome === 'breaks' ? `my stack breaks it on turn ${f.turn}` : 'it is a stand-off'} even with ${share} of income going to expansion (${f.pinnedHolds ? `the border pins ${f.pinned}` : `not even my whole ${every} keeps the border`}): the expansion share stands.${wholeText}`);
|
|
2241
2450
|
}
|
|
2242
2451
|
}
|
|
2243
|
-
for (const t of holds)
|
|
2452
|
+
for (const t of holds) {
|
|
2453
|
+
const b = borders.get(t.id);
|
|
2454
|
+
const prior = t.recentFrom === undefined && !t.critical && b ? priorOnlyHold(pc, b, t) : null;
|
|
2244
2455
|
candidates.push({
|
|
2245
2456
|
kind: 'hold',
|
|
2457
|
+
...(prior !== null ? { prior } : {}),
|
|
2458
|
+
...(t.critical ? { critical: true } : {}),
|
|
2246
2459
|
// A border just taken from a weak opponent is held first: conceding it hands it back.
|
|
2247
2460
|
score: t.recentFrom !== undefined ? Infinity : t.worth / t.holdCost,
|
|
2248
2461
|
cost: t.holdCost,
|
|
@@ -2254,8 +2467,12 @@ function planPass(input, pass) {
|
|
|
2254
2467
|
// Already garrisoned for a bonus this turn completed (#122).
|
|
2255
2468
|
if (heldBorders.has(t.id))
|
|
2256
2469
|
return;
|
|
2470
|
+
// #420: a hold that breaks its one threat is a capture first (its hold still counts toward the cap);
|
|
2471
|
+
// any other plain hold past the total hold cap is conceded (its armies may still attack out).
|
|
2257
2472
|
if (holdAndBreak(t))
|
|
2258
2473
|
return;
|
|
2474
|
+
if (overCap(t))
|
|
2475
|
+
return concedePending(t, roomAt(t.id), true);
|
|
2259
2476
|
const pending = expansionLeft > 0 && t.worth < topValue && t.recentFrom === undefined ? Math.max(0, floor - expansionSpent) : 0;
|
|
2260
2477
|
const room = roomAt(t.id);
|
|
2261
2478
|
// #215: conceded, its armies may attack out (rule 1a) in the passes still to run.
|
|
@@ -2269,6 +2486,7 @@ function planPass(input, pass) {
|
|
|
2269
2486
|
hold(t);
|
|
2270
2487
|
},
|
|
2271
2488
|
});
|
|
2489
|
+
}
|
|
2272
2490
|
// A conceded unit's members, judged on their own now (rule 1a, against what is left).
|
|
2273
2491
|
const singleNow = (t, quiet) => {
|
|
2274
2492
|
if (t.critical)
|
|
@@ -2287,6 +2505,8 @@ function planPass(input, pass) {
|
|
|
2287
2505
|
concedeUnaffordable(t, room);
|
|
2288
2506
|
return;
|
|
2289
2507
|
}
|
|
2508
|
+
if (overCap(t))
|
|
2509
|
+
return concedeCapped(t, quiet);
|
|
2290
2510
|
hold(t);
|
|
2291
2511
|
heldBorders.add(t.id);
|
|
2292
2512
|
};
|
|
@@ -2332,13 +2552,28 @@ function planPass(input, pass) {
|
|
|
2332
2552
|
}
|
|
2333
2553
|
// PLAN-TEAMS C3.4: a capture of a player my teammate attacks this turn ranks above an equal one.
|
|
2334
2554
|
const teamFocused = (c) => Number(c.owner !== undefined && pc.teamFocus.has(c.owner));
|
|
2555
|
+
/** #417: the 1v1 race's tier: 0 a held bonus's gate or my commander's hold, 1 a race, 2 any other. */
|
|
2556
|
+
const raceTier = (c) => (c.kind === 'unit' || (c.kind === 'hold' && c.critical) ? 0 : c.kind === 'race' ? 1 : 2);
|
|
2335
2557
|
const ahead = (a, b) => Number(b.focus) - Number(a.focus) ||
|
|
2558
|
+
// #420: a hold sized only on the fog prior ranks after every capture.
|
|
2559
|
+
Number(a.prior !== undefined) - Number(b.prior !== undefined) ||
|
|
2560
|
+
// #417, the 1v1 race: held-bonus gates and my commander's hold, then the races, then everything else.
|
|
2561
|
+
(races.length ? raceTier(a) - raceTier(b) : 0) ||
|
|
2336
2562
|
// #201: ahead, every held bonus is held for the worst case before any capture (said below).
|
|
2337
2563
|
(holdPasses === 'worst' ? Number(b.kind === 'unit') - Number(a.kind === 'unit') : 0) ||
|
|
2338
|
-
(oneVsOne ? Number(a.kind === 'advance') - Number(b.kind === 'advance') : 0) ||
|
|
2564
|
+
(oneVsOne ? Number(a.kind === 'advance' || a.kind === 'stage') - Number(b.kind === 'advance' || b.kind === 'stage') : 0) ||
|
|
2339
2565
|
b.score - a.score;
|
|
2340
2566
|
const after = (a, b) => a.cost - b.cost || a.borders - b.borders || rank[a.kind] - rank[b.kind] || a.id - b.id;
|
|
2341
2567
|
candidates.sort((a, b) => ahead(a, b) || teamFocused(b) - teamFocused(a) || after(a, b));
|
|
2568
|
+
for (const c of candidates) {
|
|
2569
|
+
if (c.prior === undefined)
|
|
2570
|
+
continue;
|
|
2571
|
+
const passed = candidates.filter((d) => d.kind !== 'hold' && d.kind !== 'unit' && d.score < c.score);
|
|
2572
|
+
if (!passed.length)
|
|
2573
|
+
continue;
|
|
2574
|
+
const b = borders.get(c.id);
|
|
2575
|
+
rationale.push(`Hold ${label(c.id)} after the captures (#420): it needs ${c.cost} only against player ${b.player}'s ~${b.deploy}, the fog prior; against the stacks beside it plus the ~${c.prior} the evidence gives, it holds as it stands.`);
|
|
2576
|
+
}
|
|
2342
2577
|
if (pc.teamFocus.size)
|
|
2343
2578
|
for (const [i, c] of candidates.entries()) {
|
|
2344
2579
|
if (!teamFocused(c))
|
|
@@ -2359,6 +2594,13 @@ function planPass(input, pass) {
|
|
|
2359
2594
|
slots.forEach((i, k) => (candidates[i] = sorted[k]));
|
|
2360
2595
|
}
|
|
2361
2596
|
}
|
|
2597
|
+
// #421: a stockpile spend runs before every other capture; the holds keep their places.
|
|
2598
|
+
if (candidates.some((c) => c.spend)) {
|
|
2599
|
+
const spends = candidates.filter((c) => c.spend);
|
|
2600
|
+
const rest = candidates.filter((c) => !c.spend);
|
|
2601
|
+
const at = rest.findIndex((c) => c.kind !== 'hold' && c.kind !== 'unit');
|
|
2602
|
+
candidates.splice(0, candidates.length, ...(at < 0 ? [...rest, ...spends] : [...rest.slice(0, at), ...spends, ...rest.slice(at)]));
|
|
2603
|
+
}
|
|
2362
2604
|
// A held-bonus unit that pays for itself is funded before any capture that completes
|
|
2363
2605
|
// no bonus (an advance or a break, unless focused): at the first such capture, every
|
|
2364
2606
|
// unit still pending runs first, with the completions that outscore the weakest of them.
|
|
@@ -2434,11 +2676,11 @@ function planPass(input, pass) {
|
|
|
2434
2676
|
// #215, rule 0p.1: an advance ranks below every hold, a contested held bonus's included
|
|
2435
2677
|
// (#118 lets the captures go first, but in a 1v1 in contact not one that completes nothing):
|
|
2436
2678
|
// live, a +4 bonus's one border was left to fall while 15 went to a bonus 47 armies from done.
|
|
2437
|
-
if (oneVsOne && c.kind === 'advance' && !c.focus && !contestedDue) {
|
|
2679
|
+
if (oneVsOne && (c.kind === 'advance' || c.kind === 'stage' || c.kind === 'race') && !c.focus && !contestedDue) {
|
|
2438
2680
|
contestedDue = true;
|
|
2439
2681
|
settleContested(true);
|
|
2440
2682
|
}
|
|
2441
|
-
if ((c
|
|
2683
|
+
if (completesNothing(c) && !c.focus && !unitsDue) {
|
|
2442
2684
|
unitsDue = true;
|
|
2443
2685
|
// Those waiting for the expansion share outscore everything still to run.
|
|
2444
2686
|
for (const u of waiting.splice(0))
|
|
@@ -2457,7 +2699,7 @@ function planPass(input, pass) {
|
|
|
2457
2699
|
// completes nothing: when this one leaves too little for a hold still waiting, it is undone,
|
|
2458
2700
|
// the waiting holds are funded first, and it runs again on what is left (if it still fits).
|
|
2459
2701
|
const owed = deferred.filter((t) => !heldBorders.has(t.id) && !conceded.has(t.id));
|
|
2460
|
-
if ((c
|
|
2702
|
+
if (completesNothing(c) && !c.focus && owed.length) {
|
|
2461
2703
|
const restore = snapshot();
|
|
2462
2704
|
const spent = expansionSpent;
|
|
2463
2705
|
const left = expansionLeft;
|
|
@@ -2470,7 +2712,7 @@ function planPass(input, pass) {
|
|
|
2470
2712
|
expansionSpent = spent;
|
|
2471
2713
|
expansionLeft = left;
|
|
2472
2714
|
for (const t of owed)
|
|
2473
|
-
if (t.holdCost <= roomAt(t.id)) {
|
|
2715
|
+
if (t.holdCost <= roomAt(t.id) && !overCap(t)) {
|
|
2474
2716
|
rationale.push(`Hold ${label(t.id)} now after all: the capture that would have gone first completes no bonus and would leave too little to hold it later.`);
|
|
2475
2717
|
hold(t);
|
|
2476
2718
|
heldBorders.add(t.id);
|
|
@@ -2488,8 +2730,8 @@ function planPass(input, pass) {
|
|
|
2488
2730
|
if (heldBorders.has(t.id))
|
|
2489
2731
|
continue;
|
|
2490
2732
|
const room = roomAt(t.id);
|
|
2491
|
-
if (t.holdCost > room)
|
|
2492
|
-
concedePending(t, room);
|
|
2733
|
+
if (t.holdCost > room || overCap(t))
|
|
2734
|
+
concedePending(t, room, t.holdCost <= room);
|
|
2493
2735
|
else
|
|
2494
2736
|
hold(t);
|
|
2495
2737
|
}
|
|
@@ -2529,6 +2771,12 @@ function planPass(input, pass) {
|
|
|
2529
2771
|
complete(p);
|
|
2530
2772
|
garrisonCompleted();
|
|
2531
2773
|
}
|
|
2774
|
+
// #439: the neutral in between toward a single-territory bonus two moves away, before any advance.
|
|
2775
|
+
if (goal !== 'complete-bonus')
|
|
2776
|
+
for (const st of stages) {
|
|
2777
|
+
stageTwoMove(pc, ps, st, gainWith, tryExpand);
|
|
2778
|
+
garrisonCompleted();
|
|
2779
|
+
}
|
|
2532
2780
|
for (const p of byCloseness) {
|
|
2533
2781
|
advance(p);
|
|
2534
2782
|
garrisonCompleted();
|
|
@@ -3102,6 +3350,8 @@ function planPass(input, pass) {
|
|
|
3102
3350
|
const team = teamReport(pc, { ps, threats, hd, deploys: plan.deploys });
|
|
3103
3351
|
if (team)
|
|
3104
3352
|
plan.team = team;
|
|
3353
|
+
// #457: a neutral taken beside a truce partner may read as a breach to it (plan/relations.ts).
|
|
3354
|
+
warnTruceNeutrals(pc, plan);
|
|
3105
3355
|
if (truceReport) {
|
|
3106
3356
|
// T6: what a break would cost, against the plan's final orders (plan/relations.ts).
|
|
3107
3357
|
reportBreakLosses(pc, truceReport.relations, plan);
|
|
@@ -3138,6 +3388,16 @@ function planPass(input, pass) {
|
|
|
3138
3388
|
runOutcome.set(plan, { bareSteps: [...caps.bareTaken].filter(gone).sort(byNum), held, unheld });
|
|
3139
3389
|
if (tgt.allInTries.size)
|
|
3140
3390
|
allInOutcome.set(plan, tgt.allInTries);
|
|
3391
|
+
if (pc.strikeShare > 0)
|
|
3392
|
+
shareOutcome.set(plan, pc.strikeShare);
|
|
3393
|
+
// #421: on a stockpile, the contested bonuses this plan does not complete that an all-in push could (planPushed).
|
|
3394
|
+
if (pc.pile && !input.stockpileAllIn) {
|
|
3395
|
+
const done = new Set(plan.expected.bonusesCompleted);
|
|
3396
|
+
const pushed = new Set([...(input.bonusPush?.allIn ?? []), ...(input.bonusPush?.dropped ?? [])]);
|
|
3397
|
+
const ids = contestedBonuses(g, state, mineSet, foe).filter((id) => !done.has(id) && !pushed.has(id));
|
|
3398
|
+
if (ids.length)
|
|
3399
|
+
pileAllInOutcome.set(plan, ids);
|
|
3400
|
+
}
|
|
3141
3401
|
// #274: a plan that walks my commander says so first.
|
|
3142
3402
|
if (pc.commanderAt?.retreat)
|
|
3143
3403
|
plan.warnings.unshift(commanderMoveWarning(pc.commanderAt.retreat, label));
|