@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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { commerceRules } from '../../commerce.js';
|
|
2
|
+
import { LEAD_ARMIES } from '../opponents.js';
|
|
2
3
|
import { bonusTerritories } from '../bonuses.js';
|
|
3
|
-
import { armiesForChance, armiesToTake, DEFAULT_DEFENSIVE_KILL_RATE, DEFAULT_OFFENSIVE_KILL_RATE, fewestAttackersToKill, fewestAttackersToTake, luckFraction, specialUnitStrength, straightKills, } from '../combat.js';
|
|
4
|
+
import { armiesForChance, armiesToTake, DEFAULT_DEFENSIVE_KILL_RATE, DEFAULT_OFFENSIVE_KILL_RATE, fewestAttackersToKill, fewestAttackersToTake, guaranteedKills, luckFraction, specialUnitStrength, straightKills, } from '../combat.js';
|
|
4
5
|
import { neighborsOf } from '../graph.js';
|
|
5
6
|
import { armyCapIncome, boardIncome, DEFAULT_BASE_INCOME, incomeRules, territoryIncome } from '../player.js';
|
|
6
7
|
import { byNum } from './util.js';
|
|
@@ -279,6 +280,10 @@ export function guaranteedFallsReaching(saveCosts, reaches, deploy) {
|
|
|
279
280
|
const savable = saveCosts.filter((c, i) => c <= (reaches[i] ?? deploy));
|
|
280
281
|
return saveCosts.length - savable.length + guaranteedFalls(savable, deploy);
|
|
281
282
|
}
|
|
283
|
+
/** #419: the income a pace stands for, given my income. */
|
|
284
|
+
export function fogPaceIncome(p, myIncome) {
|
|
285
|
+
return p.basis === 'map' ? Math.max(0, Math.floor(p.income ?? 0)) : Math.ceil(Math.max(0, myIncome) * (p.ratio ?? 0) - 1e-9);
|
|
286
|
+
}
|
|
282
287
|
/**
|
|
283
288
|
* Fog levels that hide a territory's armies. The live board names war.app's StandingFogLevel
|
|
284
289
|
* (1 You, 2 Visible, 3 OwnerOnly, 4 Fogged; the client refuses a deploy on 3 or 4 as "fogged");
|
|
@@ -582,6 +587,123 @@ export function repelledFloor(g, before, after, me, playerId, orders, settings =
|
|
|
582
587
|
}
|
|
583
588
|
return best;
|
|
584
589
|
}
|
|
590
|
+
/**
|
|
591
|
+
* #418 (the owner's decision of 2026-11-20: proof may always raise an estimate): the fewest armies that
|
|
592
|
+
* can kill `defenders` however the attack is split into orders. One attack of `a` kills at most
|
|
593
|
+
* round(a × the best kill rate luck allows) (straight; weighted rounding rounds up a fraction); a split
|
|
594
|
+
* gains most per army at the smallest attack, so the most kills per army is the best over small attacks.
|
|
595
|
+
*/
|
|
596
|
+
function fewestAttackersAnySplit(defenders, settings) {
|
|
597
|
+
if (defenders <= 0)
|
|
598
|
+
return 0;
|
|
599
|
+
let perArmy = 0;
|
|
600
|
+
for (let a = 1; a <= 20; a++) {
|
|
601
|
+
// The most kills `a` attackers can make: the largest k with fewestAttackersToKill(k) ≤ a.
|
|
602
|
+
let k = 0;
|
|
603
|
+
for (;;) {
|
|
604
|
+
const need = fewestAttackersToKill(k + 1, settings, settings.luckModifier, settings.roundingMode);
|
|
605
|
+
if (need === null || need > a)
|
|
606
|
+
break;
|
|
607
|
+
k++;
|
|
608
|
+
}
|
|
609
|
+
perArmy = Math.max(perArmy, k / a);
|
|
610
|
+
}
|
|
611
|
+
return perArmy > 0 ? Math.ceil(defenders / perArmy - 1e-9) : null;
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* #418: a capture with every source army in view proves a minimum deploy. Without Multi-Attack each army
|
|
615
|
+
* moves once, so every attacker on a territory it took — and every army that then moved in — came from
|
|
616
|
+
* its territories beside the target at the start of the turn: their armies then (less the guard, a
|
|
617
|
+
* commander as 7) plus what it deployed on them. What arrived is at least what stands there now plus the
|
|
618
|
+
* attacker the last defender surely killed ({@link guaranteedKills} of one), and at least the fewest
|
|
619
|
+
* armies that kill every defender however the attack was split ({@link fewestAttackersAnySplit}); what
|
|
620
|
+
* that leaves beyond the supply was deployed.
|
|
621
|
+
* A capture reads only when: the target was a neutral or mine, shown with its armies, and its now, shown
|
|
622
|
+
* with its armies, no special unit on it; every neighbour of the target showed its owner on the earlier
|
|
623
|
+
* board and each of its showed its armies (a hidden one may have sent a stack); no other player borders
|
|
624
|
+
* the target on either board (it may have worn the defenders down first); and, when the target was mine
|
|
625
|
+
* or borders mine, my orders are known in full (`sent` and `cards`) and none of them leaves the target,
|
|
626
|
+
* enters it or plays a card on it (a move of mine out of it leaves fewer defenders; an attack of mine in
|
|
627
|
+
* kills some first). A Bomb it may have played (`bomb`) halves the defenders first. Over every such
|
|
628
|
+
* capture the floor is the larger of the best single capture and all of them together (their attackers
|
|
629
|
+
* summed against the stacks beside any of them, each counted once), as {@link repelledFloor} does.
|
|
630
|
+
*/
|
|
631
|
+
export function captureFloor(g, before, after, playerId, settings = {}, guard = (settings.oneArmyStandsGuard ?? true) ? 1 : 0, opts = {}) {
|
|
632
|
+
const none = { territories: [], attackers: 0, supply: 0, floor: 0 };
|
|
633
|
+
if (settings.multiAttack)
|
|
634
|
+
return none;
|
|
635
|
+
const was = new Map(before.territories.map((t) => [t.territoryId, t]));
|
|
636
|
+
const now = new Map(after.territories.map((t) => [t.territoryId, t]));
|
|
637
|
+
const { me, orders } = opts;
|
|
638
|
+
const ordersKnown = !!orders?.sent && !!orders.cards;
|
|
639
|
+
const touchedByMe = (id) => !ordersKnown ||
|
|
640
|
+
orders.sent.some((m) => m.from === id || m.to === id) ||
|
|
641
|
+
orders.moves.some((m) => m.from === id || m.to === id) ||
|
|
642
|
+
orders.cards.some((c) => c.from === id || c.to === id || c.target === id);
|
|
643
|
+
const its = (t) => t?.owner.kind === 'player' && t.owner.playerId === playerId;
|
|
644
|
+
const sendable = (id) => {
|
|
645
|
+
const st = visibleState(was.get(id));
|
|
646
|
+
return Math.max(0, st.armies - guard) + specialUnitStrength(st.specialUnits?.filter((u) => u.playerId === playerId));
|
|
647
|
+
};
|
|
648
|
+
const lastKill = guaranteedKills(1, settings.defensiveKillRate ?? DEFAULT_DEFENSIVE_KILL_RATE, settings.luckModifier, settings.roundingMode);
|
|
649
|
+
const caps = [];
|
|
650
|
+
for (const t of [...after.territories].sort((a, b) => a.territoryId - b.territoryId)) {
|
|
651
|
+
const id = t.territoryId;
|
|
652
|
+
if (!g.territoryById.has(id))
|
|
653
|
+
continue;
|
|
654
|
+
const a = visibleState(t);
|
|
655
|
+
const b = visibleState(was.get(id));
|
|
656
|
+
if (!its(a) || !b || its(b) || a.specialUnits?.length || b.specialUnits?.length)
|
|
657
|
+
continue;
|
|
658
|
+
const mineBefore = me !== undefined && b.owner.kind === 'player' && b.owner.playerId === me;
|
|
659
|
+
if (b.owner.kind !== 'neutral' && !mineBefore)
|
|
660
|
+
continue;
|
|
661
|
+
const ns = neighborsOf(g, id);
|
|
662
|
+
let ok = true;
|
|
663
|
+
let bordersMe = false;
|
|
664
|
+
const beside = [];
|
|
665
|
+
for (const n of ns) {
|
|
666
|
+
const o = ownerShown(was.get(n));
|
|
667
|
+
if (!o) {
|
|
668
|
+
ok = false;
|
|
669
|
+
break;
|
|
670
|
+
}
|
|
671
|
+
for (const side of [o, ownerShown(now.get(n))]) {
|
|
672
|
+
if (side?.owner.kind !== 'player' || side.owner.playerId === playerId)
|
|
673
|
+
continue;
|
|
674
|
+
if (side.owner.playerId === me)
|
|
675
|
+
bordersMe = true;
|
|
676
|
+
else
|
|
677
|
+
ok = false;
|
|
678
|
+
}
|
|
679
|
+
if (its(o)) {
|
|
680
|
+
if (!visibleState(o))
|
|
681
|
+
ok = false;
|
|
682
|
+
else
|
|
683
|
+
beside.push(n);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
if (!ok || ((mineBefore || bordersMe) && touchedByMe(id)))
|
|
687
|
+
continue;
|
|
688
|
+
const defenders = opts.bomb ? Math.floor(b.armies / 2) : b.armies;
|
|
689
|
+
const kill = fewestAttackersAnySplit(defenders, settings);
|
|
690
|
+
if (kill === null)
|
|
691
|
+
continue;
|
|
692
|
+
const attackers = Math.max(kill, a.armies + (defenders > 0 ? lastKill : 0));
|
|
693
|
+
caps.push({ id, attackers, beside });
|
|
694
|
+
}
|
|
695
|
+
if (!caps.length)
|
|
696
|
+
return none;
|
|
697
|
+
const supplyOf = (ids) => [...new Set(ids)].reduce((n, id) => n + sendable(id), 0);
|
|
698
|
+
const all = { attackers: caps.reduce((n, c) => n + c.attackers, 0), supply: supplyOf(caps.flatMap((c) => c.beside)) };
|
|
699
|
+
let best = { territories: caps.map((c) => c.id), ...all, floor: Math.max(0, all.attackers - all.supply) };
|
|
700
|
+
for (const c of caps) {
|
|
701
|
+
const supply = supplyOf(c.beside);
|
|
702
|
+
if (c.attackers - supply > best.floor)
|
|
703
|
+
best = { ...best, attackers: c.attackers, supply, floor: c.attackers - supply };
|
|
704
|
+
}
|
|
705
|
+
return best;
|
|
706
|
+
}
|
|
585
707
|
/** #240: the turns {@link repulsedAttacks} looks back over, ending on the board being planned. */
|
|
586
708
|
export const REPULSE_WINDOW = 3;
|
|
587
709
|
/** #240: failed, reinforced attacks on one territory within the window that make it repulsed. */
|
|
@@ -684,7 +806,8 @@ export function repulsedAttacks(g, boards, me, rates = {}) {
|
|
|
684
806
|
* before + deploy + transfers in − kills, so deploy ≥ after + kills − before — beside the fog an
|
|
685
807
|
* ambiguous growth like any other, read as deploy up to the turn's bound. #271: given those orders,
|
|
686
808
|
* a failed attack on a hold of mine bounds the deploy from below ({@link repelledFloor}: `deploy`,
|
|
687
|
-
* `low` and `high` never below it)
|
|
809
|
+
* `low` and `high` never below it), and so does a capture with every source army in view (#418,
|
|
810
|
+
* {@link captureFloor}: proof may always raise an estimate). A capture also claims, after the visible sources, what its stacks
|
|
688
811
|
* in view last turn and hidden now could have sent (`arrivals`: no figure counts them but `high`); a
|
|
689
812
|
* capture of a neutral beside the fog that no visible source sent into reads the attackers it needed
|
|
690
813
|
* beyond its cost ({@link fewestAttackersToTake}) as ambiguous, deploy up to the bound
|
|
@@ -993,7 +1116,13 @@ export function observeSigned(g, board, previous, playerId, rates = {}, context
|
|
|
993
1116
|
const repelled = context.me !== undefined && context.myOrders
|
|
994
1117
|
? repelledFloor(g, previous, board, context.me, playerId, context.myOrders, rates, guard, context.bomb === true)
|
|
995
1118
|
: { territories: [], floor: 0 };
|
|
996
|
-
|
|
1119
|
+
// #418: a capture with every source army in view proves a minimum deploy, fog or not.
|
|
1120
|
+
const proof = captureFloor(g, previous, board, playerId, rates, guard, {
|
|
1121
|
+
...(context.me !== undefined ? { me: context.me } : {}),
|
|
1122
|
+
orders: context.myOrders,
|
|
1123
|
+
bomb: context.bomb === true,
|
|
1124
|
+
});
|
|
1125
|
+
const floor = Math.max(repelled.floor, proof.floor);
|
|
997
1126
|
return {
|
|
998
1127
|
stacks,
|
|
999
1128
|
deploy: Math.max(0, total, floor),
|
|
@@ -1016,7 +1145,9 @@ export function observeSigned(g, board, previous, playerId, rates = {}, context
|
|
|
1016
1145
|
unseenAttackers,
|
|
1017
1146
|
unseenAttackerArmies,
|
|
1018
1147
|
repelled: repelled.territories,
|
|
1019
|
-
repelledFloor: floor,
|
|
1148
|
+
repelledFloor: repelled.floor,
|
|
1149
|
+
proven: proof.territories,
|
|
1150
|
+
captureFloor: proof.floor,
|
|
1020
1151
|
low: Math.max(0, total + lowExtra, floor),
|
|
1021
1152
|
high: Math.max(0, total + highExtra, floor),
|
|
1022
1153
|
};
|
|
@@ -1112,6 +1243,15 @@ export function enemyDeployEstimates(g, board, me, settings = {}, previous, trac
|
|
|
1112
1243
|
g.map.territories.every((t) => ownerShown(seenNow.get(t.id)) !== undefined);
|
|
1113
1244
|
const minimum = Math.max(0, Math.floor(settings.baseIncome ?? DEFAULT_BASE_INCOME));
|
|
1114
1245
|
const per = settings.bonusArmyPer ?? 0;
|
|
1246
|
+
// #418: my income on the board (cards aside) and my armies in view, against which a rising track is weighed.
|
|
1247
|
+
const myLand = new Set();
|
|
1248
|
+
let myArmies = 0;
|
|
1249
|
+
for (const [t, p] of owner)
|
|
1250
|
+
if (p === me) {
|
|
1251
|
+
myLand.add(t);
|
|
1252
|
+
myArmies += armies.get(t) ?? 0;
|
|
1253
|
+
}
|
|
1254
|
+
const myBoardIncome = boardIncome(g, myLand, { base: minimum, per }).total;
|
|
1115
1255
|
return players.map((playerId) => {
|
|
1116
1256
|
// Its visible territories are a lower bound on what it holds, so on its
|
|
1117
1257
|
// per-territory income too.
|
|
@@ -1181,7 +1321,15 @@ export function enemyDeployEstimates(g, board, me, settings = {}, previous, trac
|
|
|
1181
1321
|
const priorCap = prior && k > 0
|
|
1182
1322
|
? Math.min(couldEarn, territoryIncome(held + Math.ceil((couldHold - held) / k), minimum, per) + possibleOwn + Math.ceil((possible - possibleOwn) / k))
|
|
1183
1323
|
: null;
|
|
1184
|
-
const
|
|
1324
|
+
const priorFull = prior && fogBeside ? Math.min(Math.max(0, Math.floor(priorBase)), priorCap ?? couldEarn) : null;
|
|
1325
|
+
// #444: incomes other players stated scale this one's prior down by their ratio to mine (never up).
|
|
1326
|
+
const statedRatio = prior?.stated && !prior.stated.players.some((x) => x.id === playerId) ? prior.stated.ratio : null;
|
|
1327
|
+
const priorFigure = priorFull !== null && statedRatio !== null ? Math.min(priorFull, Math.ceil(priorFull * statedRatio - 1e-9)) : priorFull;
|
|
1328
|
+
// #419: the past winners' pace, as the prior is figured (capped, scaled, only beside the fog), when above it.
|
|
1329
|
+
const paceIncome = prior?.winnerPace ? fogPaceIncome(prior.winnerPace, prior.myIncome) : null;
|
|
1330
|
+
const paceFull = paceIncome !== null && fogBeside && paceIncome > priorBase ? Math.min(paceIncome, priorCap ?? couldEarn) : null;
|
|
1331
|
+
const paceFigure = paceFull !== null && statedRatio !== null ? Math.min(paceFull, Math.ceil(paceFull * statedRatio - 1e-9)) : paceFull;
|
|
1332
|
+
const paceTop = paceFigure !== null && priorFigure !== null && paceFigure > priorFigure ? paceFigure : null;
|
|
1185
1333
|
// A track over enough turns replaces the single-turn observed figure (S3).
|
|
1186
1334
|
const track = tracks?.find((t) => t.playerId === playerId);
|
|
1187
1335
|
const usable = track && track.income !== null && track.turns.length >= TRACKED_MIN_TURNS ? track : undefined;
|
|
@@ -1203,7 +1351,7 @@ export function enemyDeployEstimates(g, board, me, settings = {}, previous, trac
|
|
|
1203
1351
|
? observeDeploy(g, board, previous, playerId, settings, {
|
|
1204
1352
|
me,
|
|
1205
1353
|
guard: (settings.oneArmyStandsGuard ?? true) ? 1 : 0,
|
|
1206
|
-
expected: Math.max(visible, trackBound ?? tracked ??
|
|
1354
|
+
expected: Math.max(visible, trackBound ?? tracked ?? priorFull ?? 0),
|
|
1207
1355
|
most: couldEarn,
|
|
1208
1356
|
// #293: under Local Deployment, growth beside the fog outside every bonus it could hold is
|
|
1209
1357
|
// deploy only up to its free income.
|
|
@@ -1272,22 +1420,40 @@ export function enemyDeployEstimates(g, board, me, settings = {}, previous, trac
|
|
|
1272
1420
|
const source = exact !== null ? 'exact' : priorUsed !== null && priorUsed > seen ? 'prior' : seenSource;
|
|
1273
1421
|
// #294: what its tracked figure was read from (#368: while that is little, thin evidence below).
|
|
1274
1422
|
const coverage = usable ? trackCoverage(usable.turns.filter((x) => usable.incomeTurns.includes(x.from))) : null;
|
|
1275
|
-
|
|
1423
|
+
// #444: an untracked opponent whose prior a stated income scaled: #368's midpoint between what is in
|
|
1424
|
+
// view (or observed) and that prior.
|
|
1425
|
+
const statedMid = statedRatio !== null && source === 'prior' && !usable ? seen + Math.ceil((priorUsed - seen) / 2 - 1e-9) : null;
|
|
1426
|
+
const chosen = source === 'exact' ? exact : source === 'prior' ? (statedMid ?? priorUsed) : seen;
|
|
1276
1427
|
// #368 (owner decision of 2026-11-19: on a hidden opponent, choose the middle until we learn
|
|
1277
1428
|
// otherwise): thin evidence — its tracked figure read from under LOW_COVERAGE of its frontier —
|
|
1278
1429
|
// sizes it for the midpoint between the lower bound (what is in view or tracked, raised to the
|
|
1279
|
-
// trend's next step when its tracked figure rose two turns running
|
|
1430
|
+
// trend's next step when its tracked figure rose two turns running, #418: unless I lead it on armies
|
|
1431
|
+
// in view and on income — above its tracked figure, or with LEAD_ARMIES × its armies above what it
|
|
1432
|
+
// earned before the newest rise) and the upper bound (the fog
|
|
1280
1433
|
// prior whole, else the most it could earn), moved toward what the evidence gives as the coverage
|
|
1281
1434
|
// nears LOW_COVERAGE. A rising track read from more of its frontier only raises the estimate to that
|
|
1282
1435
|
// lower bound. Never the maximum.
|
|
1283
1436
|
let thinEvidence = null;
|
|
1284
1437
|
if (source !== 'exact' && usable && tracked !== null) {
|
|
1285
|
-
|
|
1438
|
+
// #418: no trend step on an opponent I lead on income (its tracked figure) and on armies in view.
|
|
1439
|
+
// #418 review: with LEAD_ARMIES × its armies in view, the income lead is judged against what it
|
|
1440
|
+
// earned before the newest rise (or its visible income) instead: an over-read tracked figure must
|
|
1441
|
+
// not switch off the gate meant to stop it. (On that judgement alone, with a bare army lead, the
|
|
1442
|
+
// calibration lost 3 of 4 changed samples further below truth.)
|
|
1443
|
+
let theirArmies = 0;
|
|
1444
|
+
for (const t of theirs)
|
|
1445
|
+
theirArmies += armies.get(t) ?? 0;
|
|
1446
|
+
const risen = risingTracked(usable.turns);
|
|
1447
|
+
const leadIt = risen !== null &&
|
|
1448
|
+
myArmies > theirArmies &&
|
|
1449
|
+
(myBoardIncome > Math.max(visible, tracked) || (myArmies >= LEAD_ARMIES * theirArmies && myBoardIncome > Math.max(visible, risen[1])));
|
|
1450
|
+
const rising = leadIt ? null : risen;
|
|
1286
1451
|
const thinCoverage = coverage !== null && coverage.share < LOW_COVERAGE;
|
|
1287
1452
|
if (thinCoverage || rising) {
|
|
1288
1453
|
const trend = rising ? Math.min(couldEarn, rising[2] + Math.ceil((rising[2] - rising[0]) / 2 - 1e-9)) : null;
|
|
1289
1454
|
const lower = Math.min(couldEarn, Math.max(visible, tracked, trend ?? 0));
|
|
1290
|
-
|
|
1455
|
+
// #419: the top of its range is the larger of the prior and the past winners' pace.
|
|
1456
|
+
const upper = Math.max(lower, Math.min(couldEarn, paceTop ?? priorFigure ?? couldEarn));
|
|
1291
1457
|
const midpoint = lower + Math.ceil((upper - lower) / 2 - 1e-9);
|
|
1292
1458
|
// What the evidence gives without thin evidence (the track, or #235's prior shrunk toward it),
|
|
1293
1459
|
// never below the lower bound: the figure meets it at LOW_COVERAGE, so it does not jump there.
|
|
@@ -1296,7 +1462,30 @@ export function enemyDeployEstimates(g, board, me, settings = {}, previous, trac
|
|
|
1296
1462
|
const figure = toward + Math.ceil(weight * (midpoint - toward) - 1e-9);
|
|
1297
1463
|
// Thin coverage: the figure replaces the estimate, up or down. A rising track alone: a raise only.
|
|
1298
1464
|
if (thinCoverage || figure > chosen)
|
|
1299
|
-
thinEvidence = {
|
|
1465
|
+
thinEvidence = {
|
|
1466
|
+
coverage: coverage ? coverage.share : null,
|
|
1467
|
+
rising,
|
|
1468
|
+
tracked,
|
|
1469
|
+
prior: priorFigure,
|
|
1470
|
+
trend,
|
|
1471
|
+
lower,
|
|
1472
|
+
upper,
|
|
1473
|
+
midpoint,
|
|
1474
|
+
toward,
|
|
1475
|
+
weight,
|
|
1476
|
+
figure,
|
|
1477
|
+
...(paceTop !== null && prior?.winnerPace
|
|
1478
|
+
? {
|
|
1479
|
+
pace: {
|
|
1480
|
+
figure: paceTop,
|
|
1481
|
+
basis: prior.winnerPace.basis,
|
|
1482
|
+
afterTurn: prior.winnerPace.afterTurn,
|
|
1483
|
+
games: prior.winnerPace.games,
|
|
1484
|
+
...(prior.winnerPace.ratio !== undefined ? { ratio: prior.winnerPace.ratio } : {}),
|
|
1485
|
+
},
|
|
1486
|
+
}
|
|
1487
|
+
: {}),
|
|
1488
|
+
};
|
|
1300
1489
|
}
|
|
1301
1490
|
}
|
|
1302
1491
|
const income = thinEvidence ? thinEvidence.figure : chosen;
|
|
@@ -1375,6 +1564,7 @@ export function enemyDeployEstimates(g, board, me, settings = {}, previous, trac
|
|
|
1375
1564
|
exact,
|
|
1376
1565
|
card,
|
|
1377
1566
|
cardPlayed,
|
|
1567
|
+
...(priorFull !== null && priorFigure < priorFull ? { stated: { full: priorFull, scaled: priorFigure, lower: seen, midpoint: statedMid } } : {}),
|
|
1378
1568
|
};
|
|
1379
1569
|
});
|
|
1380
1570
|
}
|
|
@@ -431,7 +431,7 @@ export function neverStandStill(pc, ps, book, threats, hd, tgt, caps) {
|
|
|
431
431
|
]
|
|
432
432
|
: []),
|
|
433
433
|
].join('; ');
|
|
434
|
-
const reasonOf = ({ id, f }) => `cheapest expansion toward bonus ${bonusName(id)} (+${f.value}, ${toFinish(f.cost, f
|
|
434
|
+
const reasonOf = ({ id, f }) => `cheapest expansion toward bonus ${bonusName(id)} (+${f.value}, ${toFinish(f.cost, f)}, ${f.cost === fewest ? 'the fewest of any bonus in reach' : 'the fewest of any bonus with a capture affordable this turn'})`;
|
|
435
435
|
// ---- #107, in contact: enemy captures ----
|
|
436
436
|
/** Rule 0p.2's setting: an FFA with two or more opponents left. Applied here with or without adapt. */
|
|
437
437
|
const ffaFronts = profile.format === 'ffa' && profile.opponents >= 2 && !leadLever;
|
|
@@ -503,7 +503,7 @@ export function neverStandStill(pc, ps, book, threats, hd, tgt, caps) {
|
|
|
503
503
|
if (e.bonus.breaks)
|
|
504
504
|
return `cheapest capture: breaks bonus ${bonusName(e.bonus.id)} (+${v}) of player ${e.player}`;
|
|
505
505
|
const f = finishCost.get(e.bonus.id);
|
|
506
|
-
return `cheapest capture: advances bonus ${bonusName(e.bonus.id)} (+${v}, ${toFinish(f.cost, f
|
|
506
|
+
return `cheapest capture: advances bonus ${bonusName(e.bonus.id)} (+${v}, ${toFinish(f.cost, f)}) from player ${e.player}`;
|
|
507
507
|
};
|
|
508
508
|
// #240 review: what fits is judged on a repulsed territory's sure size.
|
|
509
509
|
const shortOf = (x) => Math.max(0, sizeOf(x.t, x.cost) - x.reach);
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { bonusTerritories } from '../bonuses.js';
|
|
2
|
+
import { neighborsOf } from '../graph.js';
|
|
3
|
+
/** #421: armies of mine in view, in turns of my income, that make a stockpile on a flat income. */
|
|
4
|
+
export const STOCKPILE_TURNS = 4;
|
|
5
|
+
/** #421: the visible-army lead over one opponent beside me that turns a stockpile into a strike stack facing it. */
|
|
6
|
+
export const STOCKPILE_LEAD = 2;
|
|
7
|
+
/** #421 (owner decision, 2026-11-20): the share of a flat income held out of captures for the strike stack. */
|
|
8
|
+
export const STRIKE_SHARE = 0.25;
|
|
9
|
+
/** My armies in view and each other player's (special units counted), visible territories only. */
|
|
10
|
+
export function armiesInView(a) {
|
|
11
|
+
const by = new Map();
|
|
12
|
+
let my = 0;
|
|
13
|
+
for (const [id, st] of a.territories) {
|
|
14
|
+
if (st.owner.kind !== 'player' || st.armies === null)
|
|
15
|
+
continue;
|
|
16
|
+
if (a.mineSet.has(id))
|
|
17
|
+
my += st.armies + a.unitsAt(id);
|
|
18
|
+
else
|
|
19
|
+
by.set(st.owner.playerId, (by.get(st.owner.playerId) ?? 0) + st.armies + a.unitsAt(id));
|
|
20
|
+
}
|
|
21
|
+
return { my, by };
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* #421: the pile — adapting (not `defend`, not No-Split), my income flat and my armies in view at least
|
|
25
|
+
* {@link STOCKPILE_TURNS} turns of it. `undefined` otherwise.
|
|
26
|
+
*/
|
|
27
|
+
export function pileOf(a) {
|
|
28
|
+
if (!a.auto || a.goal === 'defend' || a.noSplit || !a.incomeTrend?.flat || a.income <= 0)
|
|
29
|
+
return undefined;
|
|
30
|
+
const { my, by } = armiesInView(a);
|
|
31
|
+
if (my < STOCKPILE_TURNS * a.income)
|
|
32
|
+
return undefined;
|
|
33
|
+
return { my, by, turns: Math.round((my / a.income) * 10) / 10 };
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* #421 (#450): outside a 1v1 and a siege, the pile builds the strike stack facing the opponent in
|
|
37
|
+
* `facing` whose armies in view mine outnumber {@link STOCKPILE_LEAD}× or more (the fewest first, then
|
|
38
|
+
* id). Visible armies only, never an income estimate.
|
|
39
|
+
*/
|
|
40
|
+
export function stockpileOf(a) {
|
|
41
|
+
if (a.siege || a.format === '1v1')
|
|
42
|
+
return undefined;
|
|
43
|
+
const pile = pileOf(a);
|
|
44
|
+
if (!pile)
|
|
45
|
+
return undefined;
|
|
46
|
+
const { my, by, turns } = pile;
|
|
47
|
+
const p = [...a.facing]
|
|
48
|
+
.filter((q) => a.foe(q) && my >= STOCKPILE_LEAD * (by.get(q) ?? 0))
|
|
49
|
+
.sort((x, y) => (by.get(x) ?? 0) - (by.get(y) ?? 0) || x - y)[0];
|
|
50
|
+
if (p === undefined)
|
|
51
|
+
return undefined;
|
|
52
|
+
const ratio = by.get(p) ? `${(Math.round((my / by.get(p)) * 10) / 10).toFixed(1)}×` : 'unbounded';
|
|
53
|
+
return {
|
|
54
|
+
p,
|
|
55
|
+
why: `the opponent whose armies in view mine outnumber ${ratio} (#421)`,
|
|
56
|
+
line: `${my} armies of mine stand on the board, ${turns} turns of my flat ${a.income} income, ${ratio} player ${p}'s in view`,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* #421 (owner decision, 2026-11-20): in contact on a flat income — where rule 0p.3c builds a strike stack
|
|
61
|
+
* (a 1v1 adapting, a siege, or the stockpile above) — {@link STRIKE_SHARE} of my income, rounded down, is
|
|
62
|
+
* held out of captures for the stack. Holds still take their exact need first; the leftover deploy then
|
|
63
|
+
* gives the stack what the captures left, ahead of comfort margins. 0 otherwise.
|
|
64
|
+
*/
|
|
65
|
+
export function strikeShareOf(a) {
|
|
66
|
+
if (!a.incomeTrend?.flat || a.income <= 0)
|
|
67
|
+
return 0;
|
|
68
|
+
const stack = (a.siege !== undefined && a.contact.has(a.siege)) ||
|
|
69
|
+
(a.auto && a.format === '1v1' && a.goal !== 'defend' && a.contact.size > 0) ||
|
|
70
|
+
stockpileOf({ ...a, siege: a.siege !== undefined, facing: a.contact }) !== undefined;
|
|
71
|
+
return stack ? Math.floor(STRIKE_SHARE * a.income) : 0;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* #421 (owner decision, 2026-11-20): the contested bonuses an all-in completion could take on the pile — a
|
|
75
|
+
* positive bonus I hold a member of, whose every missing member is in view (armies shown) beside a territory of
|
|
76
|
+
* mine, at least one of them an opponent's, none a teammate's. By id.
|
|
77
|
+
*/
|
|
78
|
+
export function contestedBonuses(g, territories, mineSet, foe) {
|
|
79
|
+
return g.map.bonuses
|
|
80
|
+
.filter((b) => {
|
|
81
|
+
const ts = bonusTerritories(g, b.id);
|
|
82
|
+
if (b.value <= 0 || !ts.some((t) => mineSet.has(t)))
|
|
83
|
+
return false;
|
|
84
|
+
const missing = ts.filter((t) => !mineSet.has(t));
|
|
85
|
+
if (!missing.length)
|
|
86
|
+
return false;
|
|
87
|
+
let opponent = false;
|
|
88
|
+
for (const t of missing) {
|
|
89
|
+
const st = territories.get(t);
|
|
90
|
+
if (!st || st.armies === null || st.owner.kind === 'unknown' || st.owner.kind === 'available')
|
|
91
|
+
return false;
|
|
92
|
+
if (!neighborsOf(g, t).some((n) => mineSet.has(n)))
|
|
93
|
+
return false;
|
|
94
|
+
if (st.owner.kind === 'player') {
|
|
95
|
+
if (!foe(st.owner.playerId))
|
|
96
|
+
return false;
|
|
97
|
+
opponent = true;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return opponent;
|
|
101
|
+
})
|
|
102
|
+
.map((b) => b.id)
|
|
103
|
+
.sort((a, b) => a - b);
|
|
104
|
+
}
|
|
@@ -11,6 +11,12 @@ import { guardOffExposure } from '../guard-off.js';
|
|
|
11
11
|
import { captureCost, CONCEDE_FACTOR, guaranteedFallsReaching, MIN_ENEMY_DEPLOY, SECOND_FRONT_LEAD, visibleState, } from './shared.js';
|
|
12
12
|
import { commanderStaysLine, commanderTransit } from './commander.js';
|
|
13
13
|
import { byNum, pct } from './util.js';
|
|
14
|
+
import { STRIKE_SHARE, stockpileOf } from './stockpile.js';
|
|
15
|
+
export { STOCKPILE_LEAD, STOCKPILE_TURNS } from './stockpile.js';
|
|
16
|
+
/** Who a strike stack faces, for the rationale: the siege target, a stockpile's (#421) or the strongest opponent. */
|
|
17
|
+
export function stackFacing(pc, s) {
|
|
18
|
+
return pc.siege?.target === s.player ? 'the siege target' : (s.facing ?? 'the strongest opponent');
|
|
19
|
+
}
|
|
14
20
|
/**
|
|
15
21
|
* The strikes that run before triage, in the order planPass ran them: rule 1e's finishing off is
|
|
16
22
|
* defined, the commander strikes (rule 1s) are made, then finishing off and pressure (rule 1e),
|
|
@@ -893,7 +899,7 @@ export function guardOffBreaks(pc, ps, book, hd, tgt) {
|
|
|
893
899
|
}
|
|
894
900
|
}
|
|
895
901
|
}
|
|
896
|
-
/** Rule 0p.3c (#72, #120, #201): the
|
|
902
|
+
/** Rule 0p.3c (#72, #120, #201, #421): the strike stack's border (a 1v1, a siege or a stockpile), chosen before the leftover deploy. */
|
|
897
903
|
export function chooseStrikeStack(pc, ps, book, threats, open, stays) {
|
|
898
904
|
const { g, income, profile, auto, goal, estimates, deployOf, incomeOfPlayer, paybackTurns, territories: state, label, mine, armiesOf, unitsAt, defenceAt, completedBy, inFocus, guard, rates, costAt, noSplit, } = pc;
|
|
899
905
|
const { rationale, captured, combined, staged } = ps;
|
|
@@ -902,7 +908,7 @@ export function chooseStrikeStack(pc, ps, book, threats, open, stays) {
|
|
|
902
908
|
// Concentrate (#72, adapting in a 1v1 facing the opponent): the spare deploys go to one strike stack
|
|
903
909
|
// on the border facing the strongest opponent (the highest income estimate, tracked when its
|
|
904
910
|
// track is trusted), the stack that keeps the most there, rather than to comfort margins.
|
|
905
|
-
// A 1v1 rule: in an FFA or a team game the comfort margins keep the leftover (several fronts).
|
|
911
|
+
// A 1v1 rule: in an FFA or a team game the comfort margins keep the leftover (several fronts), unless a stockpile (#421, below).
|
|
906
912
|
// Chosen even when holds and captures leave no leftover (#102): the stack is still spent.
|
|
907
913
|
let stack;
|
|
908
914
|
/**
|
|
@@ -924,12 +930,23 @@ export function chooseStrikeStack(pc, ps, book, threats, open, stays) {
|
|
|
924
930
|
// #382: a siege builds the stack facing its target in any format (its attacks held until the trigger:
|
|
925
931
|
// the target's other territories are no targets then, so the stack only grows or breaks).
|
|
926
932
|
const siege = pc.siege && facing.has(pc.siege.target) ? pc.siege : undefined;
|
|
927
|
-
|
|
933
|
+
// #421: outside a 1v1, a stockpile on a flat income — my armies in view at least STOCKPILE_TURNS
|
|
934
|
+
// turns of income while it has not grown — builds the stack facing the opponent beside me whose
|
|
935
|
+
// armies in view mine outnumber STOCKPILE_LEAD× or more (the fewest first, then id). Visible armies
|
|
936
|
+
// only, never an income estimate: the pile is spent where it dominates. Not under No-Split (an order
|
|
937
|
+
// carries the whole stack), and never on my commander's territory.
|
|
938
|
+
const stockpile = stockpileOf({
|
|
939
|
+
territories: state, mineSet: pc.mineSet, unitsAt, foe: pc.foe, income, ...(pc.incomeTrend ? { incomeTrend: pc.incomeTrend } : {}),
|
|
940
|
+
auto, goal, noSplit, format: profile.format, siege: siege !== undefined, facing,
|
|
941
|
+
});
|
|
942
|
+
if ((auto && profile.format === '1v1' && goal !== 'defend' && facing.size) || siege || stockpile) {
|
|
928
943
|
const player = siege
|
|
929
944
|
? { p: siege.target, e: estimates.get(siege.target) }
|
|
930
|
-
:
|
|
931
|
-
|
|
932
|
-
|
|
945
|
+
: stockpile
|
|
946
|
+
? { p: stockpile.p, e: estimates.get(stockpile.p) }
|
|
947
|
+
: [...facing]
|
|
948
|
+
.map((p) => ({ p, e: estimates.get(p) }))
|
|
949
|
+
.sort((a, b) => (b.e?.estimate ?? 0) - (a.e?.estimate ?? 0) || a.p - b.p)[0];
|
|
933
950
|
/** The opponent's territories next to `x` a strike could aim at. */
|
|
934
951
|
const aims = (x) => neighborsOf(g, x).filter((n) => {
|
|
935
952
|
const st = state.get(n);
|
|
@@ -939,6 +956,8 @@ export function chooseStrikeStack(pc, ps, book, threats, open, stays) {
|
|
|
939
956
|
.filter((x) => open(x) &&
|
|
940
957
|
// No-Split: a territory whose one order is not a small expansion has nothing left to strike with.
|
|
941
958
|
(!orderOf(x) || smallExpansion(x) !== undefined) &&
|
|
959
|
+
// #421: a stockpile's stack never stands on my commander's territory.
|
|
960
|
+
!(stockpile && pc.myCommanders.has(x)) &&
|
|
942
961
|
aims(x).length > 0)
|
|
943
962
|
.sort((a, b) => stackAt(b) - stackAt(a) || a - b);
|
|
944
963
|
/**
|
|
@@ -1014,14 +1033,22 @@ export function chooseStrikeStack(pc, ps, book, threats, open, stays) {
|
|
|
1014
1033
|
? `, rather than ${label(most)}, which holds more armies but ${able.some((a) => a.x === most) ? `has less to spare after its best strike` : 'can take nothing next to it so sized'}`
|
|
1015
1034
|
: ''}.`);
|
|
1016
1035
|
}
|
|
1036
|
+
if (id !== undefined && stockpile)
|
|
1037
|
+
rationale.push(`Stockpile (#421): ${stockpile.line}, so the spare deploys build one strike stack on ${label(id)} facing it, spent on what it can take every turn, rather than comfort margins.`);
|
|
1017
1038
|
if (id !== undefined)
|
|
1018
1039
|
stack = {
|
|
1019
1040
|
id,
|
|
1020
1041
|
player: player.p,
|
|
1021
1042
|
income: player.e?.estimate ?? MIN_ENEMY_DEPLOY,
|
|
1022
1043
|
source: player.e?.source === 'tracked' ? 'tracked' : player.e?.source === 'observed' ? 'observed' : 'estimated',
|
|
1044
|
+
...(stockpile ? { facing: stockpile.why } : {}),
|
|
1023
1045
|
};
|
|
1024
1046
|
}
|
|
1047
|
+
// #421 (owner decision, 2026-11-20): the share the estimates phase held out of captures.
|
|
1048
|
+
if (pc.strikeShare > 0)
|
|
1049
|
+
rationale.push(stack
|
|
1050
|
+
? `Strike share (#421): ${pc.strikeShare} of my flat ${income} income (${STRIKE_SHARE * 100}%) was held out of captures for the strike stack on ${label(stack.id)}, ahead of comfort margins; holds took their exact need first.`
|
|
1051
|
+
: `Strike share (#421): ${pc.strikeShare} of my flat ${income} income (${STRIKE_SHARE * 100}%) was held out of captures for a strike stack, but no border could carry one this turn: it goes to the leftover as usual.`);
|
|
1025
1052
|
return { stack, smallExpansion };
|
|
1026
1053
|
}
|
|
1027
1054
|
/** #102: spend the strike stack on the enemy territories next to it, once the leftover deploy is in. */
|
|
@@ -1311,7 +1338,7 @@ export function spendStrikeStack(pc, ps, input, book, threats, tgt, cap, strikeS
|
|
|
1311
1338
|
why: `not made from the strike stack ${label(S)} — ${refused.get(c.id) ?? 'not worth it'}${effect ? `: ${effect}` : ''}`,
|
|
1312
1339
|
});
|
|
1313
1340
|
}
|
|
1314
|
-
const builds = `the spare deploys build one strike stack facing player ${strikeStack.player}, ${pc
|
|
1341
|
+
const builds = `the spare deploys build one strike stack facing player ${strikeStack.player}, ${stackFacing(pc, strikeStack)} (~${strikeStack.income} income, ${strikeStack.source})`;
|
|
1315
1342
|
if (!taken.length) {
|
|
1316
1343
|
const held = candidates.length
|
|
1317
1344
|
? candidates.map((c) => `${label(c.id)}: ${refused.get(c.id) ?? 'not worth it'}`).join('; ')
|