@chrischall/warapp-mcp 0.6.0 → 0.8.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 +100 -7
- package/dist/analysis/accept-surrender.js +20 -2
- package/dist/analysis/calibrate.js +1 -0
- package/dist/analysis/card-support.js +187 -20
- 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/coalition.js +55 -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/local-deploy.js +14 -0
- package/dist/analysis/opponent-profile.js +46 -3
- package/dist/analysis/opponents.js +246 -19
- package/dist/analysis/outlook.js +323 -17
- package/dist/analysis/picks.js +270 -37
- package/dist/analysis/plan/after-leftover.js +28 -3
- package/dist/analysis/plan/captures.js +80 -16
- package/dist/analysis/plan/completed.js +8 -1
- package/dist/analysis/plan/conceded-out.js +16 -11
- package/dist/analysis/plan/deploy-estimates.js +513 -0
- package/dist/analysis/plan/doomed-out.js +135 -0
- package/dist/analysis/plan/estimates.js +73 -7
- package/dist/analysis/plan/free-capture.js +34 -0
- package/dist/analysis/plan/guard-off.js +2 -1
- package/dist/analysis/plan/holds.js +85 -313
- package/dist/analysis/plan/horizon.js +42 -0
- package/dist/analysis/plan/leftover.js +188 -10
- package/dist/analysis/plan/observe.js +896 -0
- package/dist/analysis/plan/orders.js +35 -1
- package/dist/analysis/plan/relations.js +115 -2
- package/dist/analysis/plan/report.js +10 -4
- package/dist/analysis/plan/shared.js +7 -1189
- package/dist/analysis/plan/stand-still.js +7 -5
- package/dist/analysis/plan/state.js +12 -0
- package/dist/analysis/plan/stockpile.js +104 -0
- package/dist/analysis/plan/strike-stack.js +467 -0
- package/dist/analysis/plan/strike.js +8 -441
- package/dist/analysis/plan/targets.js +374 -72
- package/dist/analysis/plan/threats.js +120 -9
- package/dist/analysis/plan/transfers.js +35 -1
- package/dist/analysis/plan/two-move.js +70 -0
- package/dist/analysis/plan/vacated.js +124 -2
- package/dist/analysis/plan/withdraw.js +316 -0
- package/dist/analysis/planner.js +356 -53
- package/dist/analysis/player.js +4 -0
- package/dist/analysis/relations.js +8 -2
- package/dist/analysis/since-last.js +18 -5
- package/dist/analysis/stress.js +1 -1
- package/dist/board.js +36 -2
- package/dist/build-id.js +106 -0
- package/dist/bundle.js +15863 -10242
- 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/my-games.js +2 -0
- package/dist/open-games.js +122 -18
- 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 +102 -33
- package/dist/tools/card-support-advice.js +53 -8
- 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 +16 -3
- package/dist/tools/commander-check.js +2 -1
- package/dist/tools/decision-capture.js +461 -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 +51 -9
- package/dist/tools/live-context.js +6 -0
- package/dist/tools/live.js +43 -6
- package/dist/tools/map-curves.js +73 -0
- package/dist/tools/notifications.js +4 -3
- package/dist/tools/open-games.js +2 -2
- package/dist/tools/opponents.js +2 -0
- package/dist/tools/past-games.js +74 -8
- package/dist/tools/picks.js +169 -57
- 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 +353 -19
- 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
|
@@ -4,13 +4,17 @@
|
|
|
4
4
|
// planPass runs them where they ran before: the commander strikes and finishing off right after
|
|
5
5
|
// the capture passes are defined, the strike stack's choice before the leftover deploy and its
|
|
6
6
|
// attacks after it, the lead strikes after No-Split's whole-stack orders.
|
|
7
|
-
import { forecastBorder } from '../exchange.js';
|
|
8
7
|
import { COMMANDER_STRENGTH, straightKills } from '../combat.js';
|
|
9
8
|
import { neighborsOf } from '../graph.js';
|
|
10
9
|
import { guardOffExposure } from '../guard-off.js';
|
|
11
|
-
import { captureCost, CONCEDE_FACTOR, guaranteedFallsReaching,
|
|
10
|
+
import { captureCost, CONCEDE_FACTOR, guaranteedFallsReaching, SECOND_FRONT_LEAD, } from './shared.js';
|
|
12
11
|
import { commanderStaysLine, commanderTransit } from './commander.js';
|
|
13
|
-
import { byNum,
|
|
12
|
+
import { byNum, } from './util.js';
|
|
13
|
+
export { STOCKPILE_LEAD, STOCKPILE_TURNS } from './stockpile.js';
|
|
14
|
+
/** Who a strike stack faces, for the rationale: the siege target, a stockpile's (#421) or the strongest opponent. */
|
|
15
|
+
export function stackFacing(pc, s) {
|
|
16
|
+
return pc.siege?.target === s.player ? 'the siege target' : (s.facing ?? 'the strongest opponent');
|
|
17
|
+
}
|
|
14
18
|
/**
|
|
15
19
|
* The strikes that run before triage, in the order planPass ran them: rule 1e's finishing off is
|
|
16
20
|
* defined, the commander strikes (rule 1s) are made, then finishing off and pressure (rule 1e),
|
|
@@ -893,444 +897,6 @@ export function guardOffBreaks(pc, ps, book, hd, tgt) {
|
|
|
893
897
|
}
|
|
894
898
|
}
|
|
895
899
|
}
|
|
896
|
-
/** Rule 0p.3c (#72, #120, #201): the 1v1 strike stack's border, chosen before the leftover deploy. */
|
|
897
|
-
export function chooseStrikeStack(pc, ps, book, threats, open, stays) {
|
|
898
|
-
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
|
-
const { rationale, captured, combined, staged } = ps;
|
|
900
|
-
const { guardAt, heldNow, gainWith, orderOf, roomAt } = book;
|
|
901
|
-
const { reinforcementAt, holdArmies, threatAt, facing } = threats;
|
|
902
|
-
// Concentrate (#72, adapting in a 1v1 facing the opponent): the spare deploys go to one strike stack
|
|
903
|
-
// on the border facing the strongest opponent (the highest income estimate, tracked when its
|
|
904
|
-
// 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).
|
|
906
|
-
// Chosen even when holds and captures leave no leftover (#102): the stack is still spent.
|
|
907
|
-
let stack;
|
|
908
|
-
/**
|
|
909
|
-
* No-Split (#124): `x`'s one order when it is a small expansion a strike may take over — a single
|
|
910
|
-
* attack on a neutral that completes no bonus this turn, stages none and is not focused.
|
|
911
|
-
*/
|
|
912
|
-
const smallExpansion = (x) => {
|
|
913
|
-
const m = orderOf(x);
|
|
914
|
-
if (!m || m.kind !== 'attack' || !captured.has(m.to) || combined.has(m.to))
|
|
915
|
-
return undefined;
|
|
916
|
-
if (state.get(m.to)?.owner.kind !== 'neutral' || staged.has(m.to) || inFocus(m.to))
|
|
917
|
-
return undefined;
|
|
918
|
-
const now = heldNow();
|
|
919
|
-
const before = completedBy(new Set([...now].filter((y) => y !== m.to)));
|
|
920
|
-
return completedBy(now).some((id) => !before.includes(id)) ? undefined : m;
|
|
921
|
-
};
|
|
922
|
-
/** The stack on `x` a strike could send: what stays, plus a small expansion's armies (No-Split). */
|
|
923
|
-
const stackAt = (x) => stays(x) + (smallExpansion(x)?.armies ?? 0);
|
|
924
|
-
// #382: a siege builds the stack facing its target in any format (its attacks held until the trigger:
|
|
925
|
-
// the target's other territories are no targets then, so the stack only grows or breaks).
|
|
926
|
-
const siege = pc.siege && facing.has(pc.siege.target) ? pc.siege : undefined;
|
|
927
|
-
if ((auto && profile.format === '1v1' && goal !== 'defend' && facing.size) || siege) {
|
|
928
|
-
const player = siege
|
|
929
|
-
? { p: siege.target, e: estimates.get(siege.target) }
|
|
930
|
-
: [...facing]
|
|
931
|
-
.map((p) => ({ p, e: estimates.get(p) }))
|
|
932
|
-
.sort((a, b) => (b.e?.estimate ?? 0) - (a.e?.estimate ?? 0) || a.p - b.p)[0];
|
|
933
|
-
/** The opponent's territories next to `x` a strike could aim at. */
|
|
934
|
-
const aims = (x) => neighborsOf(g, x).filter((n) => {
|
|
935
|
-
const st = state.get(n);
|
|
936
|
-
return !captured.has(n) && st?.owner.kind === 'player' && st.owner.playerId === player.p && st.armies !== null;
|
|
937
|
-
});
|
|
938
|
-
const fronts = mine
|
|
939
|
-
.filter((x) => open(x) &&
|
|
940
|
-
// No-Split: a territory whose one order is not a small expansion has nothing left to strike with.
|
|
941
|
-
(!orderOf(x) || smallExpansion(x) !== undefined) &&
|
|
942
|
-
aims(x).length > 0)
|
|
943
|
-
.sort((a, b) => stackAt(b) - stackAt(a) || a - b);
|
|
944
|
-
/**
|
|
945
|
-
* #120: the best strike `x` could make this turn with every leftover army on it — an adjacent
|
|
946
|
-
* target sized for its defenders plus what its owner may deploy there first (rule 3) — and the
|
|
947
|
-
* armies it would have to spare, after what holds `x` once that target falls. `null` when none
|
|
948
|
-
* fits.
|
|
949
|
-
*/
|
|
950
|
-
const bestStrike = (x) => {
|
|
951
|
-
const room = Math.max(0, Math.min(ps.budget, roomAt(x)));
|
|
952
|
-
let best = null;
|
|
953
|
-
for (const n of aims(x)) {
|
|
954
|
-
const extra = reinforcementAt(n);
|
|
955
|
-
const cost = costAt(n, defenceAt(n) + extra);
|
|
956
|
-
if (cost === null || gainWith([n]) < 0)
|
|
957
|
-
continue;
|
|
958
|
-
const threat = Math.max(threatAt(x, (y) => captured.has(y) || y === n)?.threat ?? 0, deployOf(player.p));
|
|
959
|
-
const hold = Math.max(0, holdArmies(threat) - unitsAt(x));
|
|
960
|
-
const can = stackAt(x) + room - guardAt(x);
|
|
961
|
-
const spare = Math.min(can - cost, stackAt(x) + room - cost - hold);
|
|
962
|
-
if (spare < 0)
|
|
963
|
-
continue;
|
|
964
|
-
if (!best || spare > best.spare || (spare === best.spare && n < best.n))
|
|
965
|
-
best = { n, cost, extra, spare, can };
|
|
966
|
-
}
|
|
967
|
-
return best;
|
|
968
|
-
};
|
|
969
|
-
// Rule 0p.3c (#120): the stack goes where it can strike — the border with the most to spare
|
|
970
|
-
// after its best strike — and only with no border able to strike, to the one holding the most
|
|
971
|
-
// armies (live, 180 armies fed the front facing the opponent's biggest stack while a strike on
|
|
972
|
-
// a 1-army territory elsewhere was affordable every turn).
|
|
973
|
-
const able = noSplit ? [] : fronts.flatMap((x) => {
|
|
974
|
-
const b = bestStrike(x);
|
|
975
|
-
return b ? [{ x, ...b }] : [];
|
|
976
|
-
});
|
|
977
|
-
able.sort((a, b) => b.spare - a.spare || stackAt(b.x) - stackAt(a.x) || a.x - b.x);
|
|
978
|
-
const pick = able[0];
|
|
979
|
-
// #201: with no border able to strike this turn, the multi-turn forecast (`forecastBorder`):
|
|
980
|
-
// the border whose stack, with the leftover and then the income every turn, breaks the
|
|
981
|
-
// opponent's biggest stack beside it soonest (its owner deploying there every turn too); ties,
|
|
982
|
-
// and none breaking within the horizon, keep the border holding the most armies.
|
|
983
|
-
const forecastPick = (() => {
|
|
984
|
-
if (pick || noSplit || fronts.length < 2)
|
|
985
|
-
return undefined;
|
|
986
|
-
const rows = fronts.flatMap((x) => {
|
|
987
|
-
const at = aims(x).sort((a, b) => armiesOf(b) + unitsAt(b) - (armiesOf(a) + unitsAt(a)) || a - b)[0];
|
|
988
|
-
const theirs = armiesOf(at) + unitsAt(at);
|
|
989
|
-
const f = forecastBorder({
|
|
990
|
-
mine: stackAt(x) + Math.max(0, Math.min(ps.budget, roomAt(x))),
|
|
991
|
-
theirs,
|
|
992
|
-
myIncome: income,
|
|
993
|
-
theirIncome: incomeOfPlayer(player.p),
|
|
994
|
-
turns: paybackTurns,
|
|
995
|
-
settings: { offensiveKillRate: rates.offensiveKillRate, defensiveKillRate: rates.defensiveKillRate, oneArmyStandsGuard: guard === 1 },
|
|
996
|
-
});
|
|
997
|
-
return f.outcome === 'breaks' && f.turn !== null ? [{ x, at, theirs, turn: f.turn }] : [];
|
|
998
|
-
});
|
|
999
|
-
rows.sort((a, b) => a.turn - b.turn || stackAt(b.x) - stackAt(a.x) || a.x - b.x);
|
|
1000
|
-
const best = rows[0];
|
|
1001
|
-
if (!best)
|
|
1002
|
-
return undefined;
|
|
1003
|
-
const most = fronts[0];
|
|
1004
|
-
const other = rows.find((r) => r.x === most);
|
|
1005
|
-
if (best.x === most || (other && other.turn === best.turn))
|
|
1006
|
-
return undefined;
|
|
1007
|
-
rationale.push(`Strike stack on ${label(best.x)} (#201): no border can strike this turn; pressing every turn with the income, ${label(best.x)} breaks player ${player.p}'s ${best.theirs} on ${label(best.at)} on turn ${best.turn} (the multi-turn forecast), sooner than ${label(most)}, which holds more armies but ${other ? `breaks its front only on turn ${other.turn}` : `breaks nothing within ${paybackTurns} turns`}.`);
|
|
1008
|
-
return best.x;
|
|
1009
|
-
})();
|
|
1010
|
-
const id = pick?.x ?? forecastPick ?? fronts[0];
|
|
1011
|
-
if (pick) {
|
|
1012
|
-
const most = fronts[0];
|
|
1013
|
-
rationale.push(`Strike stack on ${label(pick.x)}: ${label(pick.x)} can take ${label(pick.n)} this turn (${pick.cost} of the ${pick.can} it could send with the leftover, sized for its ${defenceAt(pick.n)} defenders plus the ~${pick.extra} player ${player.p} may deploy there first; ${pick.spare} to spare once it holds)${most !== pick.x
|
|
1014
|
-
? `, 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
|
-
: ''}.`);
|
|
1016
|
-
}
|
|
1017
|
-
if (id !== undefined)
|
|
1018
|
-
stack = {
|
|
1019
|
-
id,
|
|
1020
|
-
player: player.p,
|
|
1021
|
-
income: player.e?.estimate ?? MIN_ENEMY_DEPLOY,
|
|
1022
|
-
source: player.e?.source === 'tracked' ? 'tracked' : player.e?.source === 'observed' ? 'observed' : 'estimated',
|
|
1023
|
-
};
|
|
1024
|
-
}
|
|
1025
|
-
return { stack, smallExpansion };
|
|
1026
|
-
}
|
|
1027
|
-
/** #102: spend the strike stack on the enemy territories next to it, once the leftover deploy is in. */
|
|
1028
|
-
export function spendStrikeStack(pc, ps, input, book, threats, tgt, cap, strikeStack, poolDeployed, holdLocked, smallExpansion) {
|
|
1029
|
-
const { g, me, foe, deployOf, territories: state, label, bonusName, mineSet, unitsAt, uncounted, defenceAt, bonusTs, completedBy, rates, chanceOf, costAt, noSplit, myCommanders, } = pc;
|
|
1030
|
-
const { warnings, rationale, avail, locked, captured, combined, moves, incoming, survivorsAt, captureOrder, captureUndo, } = ps;
|
|
1031
|
-
const { guardAt, coverOf, heldNow, gainWith, orderOf, valueOf } = book;
|
|
1032
|
-
const { reinforcementAt, holdArmies, threatAt } = threats;
|
|
1033
|
-
const { breakable, offence, skipOffence } = tgt;
|
|
1034
|
-
const { mustHold, strikes, worstCase } = cap;
|
|
1035
|
-
// ---- spend the strike stack (#102) ----
|
|
1036
|
-
// Once rule 0p.3c builds a strike stack, it attacks every adjacent enemy territory it can take
|
|
1037
|
-
// at the plan's win chance (the ordinary capture sizing; rule 4c re-checked as its captures
|
|
1038
|
-
// accumulate), breaking or retaking a bonus first (re-ranked after each capture: a bonus breaks
|
|
1039
|
-
// once), then by bonus value, then cheapest, then id — while what stays on it holds against the threat
|
|
1040
|
-
// left after those attacks (rule 1's arithmetic: the captured territories no longer threaten
|
|
1041
|
-
// it). It grows (deploy, no attack) only when nothing in reach is worth taking.
|
|
1042
|
-
if (strikeStack) {
|
|
1043
|
-
const S = strikeStack.id;
|
|
1044
|
-
if (strikeStack.deployed === 0)
|
|
1045
|
-
rationale.push(`No leftover reaches the strike stack ${label(S)} this turn (holds, captures or Local Deployment pools took the income): it is spent with the armies already on it.`);
|
|
1046
|
-
const prev = new Map((input.previousBoard?.territories ?? []).map((t) => [t.territoryId, t]));
|
|
1047
|
-
/** Bonuses I held in full on the previous board and no longer do: lost, and retakable. */
|
|
1048
|
-
const lost = new Set(g.map.bonuses
|
|
1049
|
-
.filter((b) => {
|
|
1050
|
-
const ts = bonusTs.get(b.id) ?? [];
|
|
1051
|
-
if (b.value <= 0 || !ts.length || ts.every((t) => mineSet.has(t)))
|
|
1052
|
-
return false;
|
|
1053
|
-
return ts.every((t) => {
|
|
1054
|
-
const was = visibleState(prev.get(t));
|
|
1055
|
-
return was?.owner.kind === 'player' && was.owner.playerId === me;
|
|
1056
|
-
});
|
|
1057
|
-
})
|
|
1058
|
-
.map((b) => b.id));
|
|
1059
|
-
const candidates = [];
|
|
1060
|
-
for (const n of neighborsOf(g, S)) {
|
|
1061
|
-
const st = state.get(n);
|
|
1062
|
-
if (captured.has(n) || st?.owner.kind !== 'player' || !foe(st.owner.playerId) || st.armies === null || uncounted(n))
|
|
1063
|
-
continue;
|
|
1064
|
-
// B2 (T1): never a truce's covered territory.
|
|
1065
|
-
if (pc.truce.noTarget(n))
|
|
1066
|
-
continue;
|
|
1067
|
-
// #240: a territory my attacks failed on repeatedly is sized for its owner's deploy (#240
|
|
1068
|
-
// review: and ranked on its plain cost, like any other).
|
|
1069
|
-
const cost = costAt(n);
|
|
1070
|
-
const size = tgt.costFor(n);
|
|
1071
|
-
// Never a capture that lowers income (rule 4c): it completes a negative bonus. Re-checked
|
|
1072
|
-
// below against the strike's own captures, which can complete one only together.
|
|
1073
|
-
if (cost === null || size === null || gainWith([n]) < 0)
|
|
1074
|
-
continue;
|
|
1075
|
-
const owner = st.owner.playerId;
|
|
1076
|
-
candidates.push({
|
|
1077
|
-
id: n,
|
|
1078
|
-
cost,
|
|
1079
|
-
size,
|
|
1080
|
-
chance: chanceOf(size, defenceAt(n)),
|
|
1081
|
-
breaks: breakable.filter((b) => b.player === owner && bonusTs.get(b.bonusId).includes(n)),
|
|
1082
|
-
retakes: [...lost].filter((id) => bonusTs.get(id).includes(n)).sort(byNum),
|
|
1083
|
-
});
|
|
1084
|
-
}
|
|
1085
|
-
/** Captures planned from the stack so far, in order. */
|
|
1086
|
-
const plannedHere = new Set();
|
|
1087
|
-
/** The opponent bonuses `c` breaks: only the first member of each to fall this turn breaks it. */
|
|
1088
|
-
const breaksOf = (c) => c.breaks.filter((b) => !bonusTs.get(b.bonusId).some((t) => t !== c.id && captured.has(t)));
|
|
1089
|
-
const strikeValue = (c) => Math.max(0, ...breaksOf(c).map((b) => b.value), ...c.retakes.map((id) => g.bonusById.get(id).value));
|
|
1090
|
-
/** What taking `c` does, against the captures planned so far (a retake completes only with every member held). */
|
|
1091
|
-
const effectOf = (c) => {
|
|
1092
|
-
const held = heldNow();
|
|
1093
|
-
held.add(c.id);
|
|
1094
|
-
const effects = [
|
|
1095
|
-
...breaksOf(c).map((b) => `breaks ${b.probable ? 'probable ' : ''}enemy bonus ${bonusName(b.bonusId)} (+${b.value} from player ${b.player})`),
|
|
1096
|
-
...c.retakes.map((id) => `${bonusTs.get(id).every((t) => held.has(t)) ? 'retakes' : 'toward retaking'} bonus ${bonusName(id)} (+${g.bonusById.get(id).value}), which I held last turn`),
|
|
1097
|
-
];
|
|
1098
|
-
return effects.length ? effects.join('; ') : null;
|
|
1099
|
-
};
|
|
1100
|
-
const rank = () => [...candidates].sort((a, b) => Number(breaksOf(b).length + b.retakes.length > 0) - Number(breaksOf(a).length + a.retakes.length > 0) ||
|
|
1101
|
-
strikeValue(b) - strikeValue(a) ||
|
|
1102
|
-
a.cost - b.cost ||
|
|
1103
|
-
a.id - b.id);
|
|
1104
|
-
/** What may never leave the stack this turn: a Local Deployment pool's deploys (#103). */
|
|
1105
|
-
const pinned = poolDeployed.get(S) ?? 0;
|
|
1106
|
-
/**
|
|
1107
|
-
* The threat on the stack once `gone` (and this turn's other captures) fall, and the armies that
|
|
1108
|
-
* hold it. Never below the opponent's deploy alone: orders interleave, so it may land its deploy
|
|
1109
|
-
* on a target before my attack resolves, and that territory then still borders the stack.
|
|
1110
|
-
*/
|
|
1111
|
-
const holdAfter = (gone) => {
|
|
1112
|
-
const th = threatAt(S, (x) => captured.has(x) || gone.has(x));
|
|
1113
|
-
const threat = Math.max(th?.threat ?? 0, deployOf(strikeStack.player));
|
|
1114
|
-
return { threat, need: Math.max(0, holdArmies(threat) - unitsAt(S)) };
|
|
1115
|
-
};
|
|
1116
|
-
const taken = [];
|
|
1117
|
-
const refused = new Map();
|
|
1118
|
-
let sent = 0;
|
|
1119
|
-
/**
|
|
1120
|
-
* No-Split (#124): the stack's one order goes to the strike on `t`, not to the small expansion
|
|
1121
|
-
* `m` it already made: that capture is taken back, and its armies rejoin the stack.
|
|
1122
|
-
*/
|
|
1123
|
-
const dropExpansion = (m, t) => {
|
|
1124
|
-
const undo = captureUndo.get(m.to);
|
|
1125
|
-
if (undo)
|
|
1126
|
-
undo();
|
|
1127
|
-
else
|
|
1128
|
-
avail.set(S, avail.get(S) + m.armies);
|
|
1129
|
-
captured.delete(m.to);
|
|
1130
|
-
survivorsAt.delete(m.to);
|
|
1131
|
-
moves.splice(moves.indexOf(m), 1);
|
|
1132
|
-
const head = `Attack ${label(m.to)} from ${label(S)} with `;
|
|
1133
|
-
for (let i = rationale.length - 1; i >= 0; i--)
|
|
1134
|
-
if (rationale[i].startsWith(head))
|
|
1135
|
-
rationale.splice(i, 1);
|
|
1136
|
-
rationale.push(`No-Split: ${label(S)}'s one order goes to the strike on ${label(t)}, not the expansion into ${label(m.to)} (it completes no bonus): the whole stack strikes.`);
|
|
1137
|
-
skipOffence(m.to, `No-Split: ${label(S)}'s one order goes to the strike on ${label(t)}`);
|
|
1138
|
-
};
|
|
1139
|
-
for (let again = true; again;) {
|
|
1140
|
-
again = false;
|
|
1141
|
-
for (const c of rank()) {
|
|
1142
|
-
if (plannedHere.has(c.id))
|
|
1143
|
-
continue;
|
|
1144
|
-
if (gainWith([c.id]) < 0) {
|
|
1145
|
-
const held = heldNow();
|
|
1146
|
-
held.add(c.id);
|
|
1147
|
-
const negs = completedBy(held)
|
|
1148
|
-
.filter((id) => g.bonusById.get(id).value < 0 && bonusTs.get(id).includes(c.id))
|
|
1149
|
-
.map((id) => `negative bonus ${bonusName(id)} (${g.bonusById.get(id).value})`);
|
|
1150
|
-
refused.set(c.id, `with this turn's other captures it lowers next income: it completes ${negs.join(', ')} (rule 4c)`);
|
|
1151
|
-
continue;
|
|
1152
|
-
}
|
|
1153
|
-
const expansion = noSplit && !taken.length ? smallExpansion(S) : undefined;
|
|
1154
|
-
if (noSplit && ((orderOf(S) && !expansion) || taken.length)) {
|
|
1155
|
-
refused.set(c.id, `No-Split: ${label(S)} issues one order this turn`);
|
|
1156
|
-
continue;
|
|
1157
|
-
}
|
|
1158
|
-
if (noSplit) {
|
|
1159
|
-
// The whole stack goes (#124): nothing stays to hold S but the guard, so it strikes only
|
|
1160
|
-
// when it need not hold (it protects nothing, or the strike leaves no visible threat to it).
|
|
1161
|
-
const whole = avail.get(S) + (expansion?.armies ?? 0);
|
|
1162
|
-
if (pinned > 0) {
|
|
1163
|
-
refused.set(c.id, `No-Split: the ${pinned} Local Deployment armies defending ${label(S)} would leave with the whole stack`);
|
|
1164
|
-
continue;
|
|
1165
|
-
}
|
|
1166
|
-
if (c.size > whole) {
|
|
1167
|
-
refused.set(c.id, `it needs ${c.size}, more than the ${Math.max(0, whole)} the stack can send`);
|
|
1168
|
-
continue;
|
|
1169
|
-
}
|
|
1170
|
-
const h = mustHold(S, c.id, whole);
|
|
1171
|
-
if (h) {
|
|
1172
|
-
refused.set(c.id, `No-Split: the whole stack would go, leaving ${h.stays} against the ~${h.threat} threat, and ${label(S)} must hold (${h.value > 0 ? `protects +${h.value}` : 'my commander stands there'})`);
|
|
1173
|
-
continue;
|
|
1174
|
-
}
|
|
1175
|
-
if (expansion)
|
|
1176
|
-
dropExpansion(expansion, c.id);
|
|
1177
|
-
const armies = avail.get(S);
|
|
1178
|
-
plannedHere.add(c.id);
|
|
1179
|
-
refused.delete(c.id);
|
|
1180
|
-
taken.push({ c, effect: effectOf(c), value: strikeValue(c), armies, chance: chanceOf(armies, defenceAt(c.id)) });
|
|
1181
|
-
avail.set(S, 0);
|
|
1182
|
-
sent += armies;
|
|
1183
|
-
captured.add(c.id);
|
|
1184
|
-
survivorsAt.set(c.id, armies - straightKills(defenceAt(c.id), rates.defensiveKillRate));
|
|
1185
|
-
captureOrder.push(c.id);
|
|
1186
|
-
again = true;
|
|
1187
|
-
break;
|
|
1188
|
-
}
|
|
1189
|
-
const gone = new Set([...plannedHere, c.id]);
|
|
1190
|
-
const { threat, need } = holdAfter(gone);
|
|
1191
|
-
// #179: what covers a finished-off player's exit stays too.
|
|
1192
|
-
const movable = avail.get(S) - Math.max(pinned, coverOf(S));
|
|
1193
|
-
const stay = avail.get(S) + guardAt(S) + (incoming.get(S) ?? 0) - c.size;
|
|
1194
|
-
if (c.size > movable) {
|
|
1195
|
-
refused.set(c.id, `it needs ${c.size}, more than the ${Math.max(0, movable)} the stack can send`);
|
|
1196
|
-
continue;
|
|
1197
|
-
}
|
|
1198
|
-
if (stay < need) {
|
|
1199
|
-
refused.set(c.id, `it would leave the stack ${stay}, below the ${need} that hold it against the ~${threat} threat after the attacks`);
|
|
1200
|
-
continue;
|
|
1201
|
-
}
|
|
1202
|
-
const effect = effectOf(c);
|
|
1203
|
-
const value = strikeValue(c);
|
|
1204
|
-
plannedHere.add(c.id);
|
|
1205
|
-
refused.delete(c.id);
|
|
1206
|
-
taken.push({ c, effect, value, armies: c.size, chance: c.chance });
|
|
1207
|
-
avail.set(S, avail.get(S) - c.size);
|
|
1208
|
-
sent += c.size;
|
|
1209
|
-
captured.add(c.id);
|
|
1210
|
-
survivorsAt.set(c.id, c.size - straightKills(defenceAt(c.id), rates.defensiveKillRate));
|
|
1211
|
-
captureOrder.push(c.id);
|
|
1212
|
-
again = true;
|
|
1213
|
-
break;
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
// #120: each attack is then sized for its defenders plus what their owner may deploy there
|
|
1217
|
-
// first, in the order taken, while the stack still covers it and keeps its hold after every
|
|
1218
|
-
// attack. One the stack cannot cover keeps its size (its warning gives the reinforced odds).
|
|
1219
|
-
const reinforced = new Map();
|
|
1220
|
-
// #240 review: a repulsed territory was costed at that size when the stack took it (and No-Split
|
|
1221
|
-
// sends at least as much): it is sized for its owner's deploy already, and says so.
|
|
1222
|
-
for (const x of taken) {
|
|
1223
|
-
const rep = tgt.repulsed.get(x.c.id);
|
|
1224
|
-
// #272 review: one sized below its owner's deploy estimate is no worst case (#120 below may still size it up).
|
|
1225
|
-
if (!rep?.sure || x.armies < rep.cost)
|
|
1226
|
-
continue;
|
|
1227
|
-
worstCase.set(x.c.id, rep.defenders + rep.extra);
|
|
1228
|
-
reinforced.set(x.c.id, rep.extra);
|
|
1229
|
-
}
|
|
1230
|
-
if (!noSplit) {
|
|
1231
|
-
const { need } = holdAfter(new Set());
|
|
1232
|
-
const room = () => Math.min(avail.get(S) - Math.max(pinned, coverOf(S)), avail.get(S) + guardAt(S) + (incoming.get(S) ?? 0) - need);
|
|
1233
|
-
// The stack's earlier attacks on a player (a break or counter-attack from it) first.
|
|
1234
|
-
for (const m of moves) {
|
|
1235
|
-
if (m.from !== S || m.kind !== 'attack' || combined.has(m.to) || worstCase.has(m.to) || strikes.has(m.to))
|
|
1236
|
-
continue;
|
|
1237
|
-
const extra = reinforcementAt(m.to);
|
|
1238
|
-
const full = extra > 0 ? costAt(m.to, defenceAt(m.to) + extra) : null;
|
|
1239
|
-
if (full === null || full <= m.armies || full - m.armies > room())
|
|
1240
|
-
continue;
|
|
1241
|
-
const add = full - m.armies;
|
|
1242
|
-
const before = m.armies;
|
|
1243
|
-
avail.set(S, avail.get(S) - add);
|
|
1244
|
-
m.armies = full;
|
|
1245
|
-
m.winChance = chanceOf(full, defenceAt(m.to));
|
|
1246
|
-
if (survivorsAt.has(m.to))
|
|
1247
|
-
survivorsAt.set(m.to, survivorsAt.get(m.to) + add);
|
|
1248
|
-
worstCase.set(m.to, defenceAt(m.to) + extra);
|
|
1249
|
-
const w = warnings.indexOf(`Attack on enemy ${label(m.to)} assumes its owner does not reinforce it first.`);
|
|
1250
|
-
if (w >= 0)
|
|
1251
|
-
warnings.splice(w, 1);
|
|
1252
|
-
rationale.push(`Size the attack on ${label(m.to)} from the strike stack ${label(S)} up from ${before} to ${full}: ${full} take it even if player ${strikeStack.player} deploys its ~${extra} there first, and the stack still holds.`);
|
|
1253
|
-
}
|
|
1254
|
-
for (const x of taken) {
|
|
1255
|
-
const extra = reinforcementAt(x.c.id);
|
|
1256
|
-
const full = extra > 0 ? costAt(x.c.id, defenceAt(x.c.id) + extra) : null;
|
|
1257
|
-
if (full === null || full <= x.armies)
|
|
1258
|
-
continue;
|
|
1259
|
-
const add = full - x.armies;
|
|
1260
|
-
if (add > room())
|
|
1261
|
-
continue;
|
|
1262
|
-
avail.set(S, avail.get(S) - add);
|
|
1263
|
-
sent += add;
|
|
1264
|
-
x.armies = full;
|
|
1265
|
-
x.chance = chanceOf(full, defenceAt(x.c.id));
|
|
1266
|
-
survivorsAt.set(x.c.id, survivorsAt.get(x.c.id) + add);
|
|
1267
|
-
worstCase.set(x.c.id, defenceAt(x.c.id) + extra);
|
|
1268
|
-
reinforced.set(x.c.id, extra);
|
|
1269
|
-
}
|
|
1270
|
-
}
|
|
1271
|
-
// What stays on the stack is its hold: an efficient-size top-up (S2) never draws on it, and
|
|
1272
|
-
// the transfer step never moves it (its captures can leave it interior; it may have got no deploys).
|
|
1273
|
-
if (taken.length) {
|
|
1274
|
-
holdLocked.add(S);
|
|
1275
|
-
locked.add(S);
|
|
1276
|
-
}
|
|
1277
|
-
const { threat: finalThreat, need: finalNeed } = holdAfter(new Set());
|
|
1278
|
-
const stays = avail.get(S) + guardAt(S) + (incoming.get(S) ?? 0);
|
|
1279
|
-
for (const { c, effect, value, armies, chance } of taken) {
|
|
1280
|
-
const reason = `the strike stack ${effect ?? 'takes an adjacent enemy territory'}`;
|
|
1281
|
-
moves.push({ from: S, to: c.id, armies, kind: 'attack', reason, winChance: chance });
|
|
1282
|
-
const extra = reinforced.get(c.id);
|
|
1283
|
-
if (extra === undefined)
|
|
1284
|
-
warnings.push(`Attack on enemy ${label(c.id)} assumes its owner does not reinforce it first.`);
|
|
1285
|
-
const keeps = noSplit
|
|
1286
|
-
? `No-Split sends the whole stack (${c.size} would take it), and ${label(S)} need not hold: ${valueOf(S) > 0 || myCommanders.has(S) ? 'no visible threat to it is left' : 'it protects nothing'}`
|
|
1287
|
-
: `the stack keeps ${stays}, enough to hold against the ~${finalThreat} threat after the attacks (needs ${finalNeed})`;
|
|
1288
|
-
const sized = extra === undefined
|
|
1289
|
-
? ''
|
|
1290
|
-
: ` — sized for its ${defenceAt(c.id)} defenders plus the ~${extra} player ${strikeStack.player} may deploy there first (${c.cost} would take it as it stands)`;
|
|
1291
|
-
rationale.push(`Attack ${label(c.id)} from the strike stack ${label(S)} with ${armies} (win chance ${pct(chance)}${sized}): ${effect ?? 'it can take this adjacent enemy territory'}; ${keeps}.`);
|
|
1292
|
-
offence.set(`strike:${c.id}`, {
|
|
1293
|
-
target: c.id,
|
|
1294
|
-
kind: 'strike-attack',
|
|
1295
|
-
cost: armies,
|
|
1296
|
-
value,
|
|
1297
|
-
taken: true,
|
|
1298
|
-
why: `from the strike stack ${label(S)} with ${armies} (win chance ${pct(chance)}): ${effect ?? 'takes an adjacent enemy territory'}`,
|
|
1299
|
-
});
|
|
1300
|
-
}
|
|
1301
|
-
for (const c of rank()) {
|
|
1302
|
-
if (plannedHere.has(c.id))
|
|
1303
|
-
continue;
|
|
1304
|
-
const effect = effectOf(c);
|
|
1305
|
-
offence.set(`strike:${c.id}`, {
|
|
1306
|
-
target: c.id,
|
|
1307
|
-
kind: 'strike-attack',
|
|
1308
|
-
cost: c.size,
|
|
1309
|
-
value: strikeValue(c),
|
|
1310
|
-
taken: false,
|
|
1311
|
-
why: `not made from the strike stack ${label(S)} — ${refused.get(c.id) ?? 'not worth it'}${effect ? `: ${effect}` : ''}`,
|
|
1312
|
-
});
|
|
1313
|
-
}
|
|
1314
|
-
const builds = `the spare deploys build one strike stack facing player ${strikeStack.player}, ${pc.siege?.target === strikeStack.player ? 'the siege target' : 'the strongest opponent'} (~${strikeStack.income} income, ${strikeStack.source})`;
|
|
1315
|
-
if (!taken.length) {
|
|
1316
|
-
const held = candidates.length
|
|
1317
|
-
? candidates.map((c) => `${label(c.id)}: ${refused.get(c.id) ?? 'not worth it'}`).join('; ')
|
|
1318
|
-
: 'no visible enemy territory next to it can be taken';
|
|
1319
|
-
rationale.push(`Grow the strike stack ${label(S)}: nothing next to it is worth taking this turn (${held}).`);
|
|
1320
|
-
}
|
|
1321
|
-
if (strikeStack.deployed > 0 || taken.length)
|
|
1322
|
-
offence.set(`strike:${S}`, {
|
|
1323
|
-
target: S,
|
|
1324
|
-
kind: 'strike',
|
|
1325
|
-
cost: strikeStack.deployed,
|
|
1326
|
-
value: strikeStack.income,
|
|
1327
|
-
taken: taken.length > 0,
|
|
1328
|
-
why: taken.length
|
|
1329
|
-
? `${builds}; it attacks ${taken.map(({ c }) => label(c.id)).join(', ')} this turn (${sent} armies sent)`
|
|
1330
|
-
: `${builds}; it grows: nothing next to it is worth taking this turn`,
|
|
1331
|
-
});
|
|
1332
|
-
}
|
|
1333
|
-
}
|
|
1334
900
|
/** #167: adapting in an FFA with a clear army lead, idle stacks take the weak enemy territories beside them. */
|
|
1335
901
|
export function leadStrikes(pc, ps, book, threats, hd, tgt, cap, holdLocked, strikeStack) {
|
|
1336
902
|
const { g, foe, profile, auto, balanced, territories: state, label, bonusName, mine, mineSet, unitsAt, uncounted, defenceAt, bonusTs, rates, chanceOf, costAt, noSplit, armyLead, leadLever, leadText, myCommanders, } = pc;
|
|
@@ -1419,3 +985,4 @@ export function leadStrikes(pc, ps, book, threats, hd, tgt, cap, holdLocked, str
|
|
|
1419
985
|
}
|
|
1420
986
|
return { leadSpareFor };
|
|
1421
987
|
}
|
|
988
|
+
export * from './strike-stack.js';
|