@chrischall/warapp-mcp 0.18.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +1 -1
- package/dist/analysis/arena.js +389 -0
- package/dist/analysis/plan/captures.js +35 -60
- package/dist/analysis/plan/dead-advance.js +77 -0
- package/dist/analysis/plan/deploy-estimates.js +38 -2
- package/dist/analysis/plan/estimates.js +15 -46
- package/dist/analysis/plan/fogged-break.js +86 -0
- package/dist/analysis/plan/guard-off.js +1 -2
- package/dist/analysis/plan/holds.js +28 -9
- package/dist/analysis/plan/orders.js +39 -2
- package/dist/analysis/plan/report.js +5 -11
- package/dist/analysis/plan/shared.js +18 -0
- package/dist/analysis/plan/siege.js +1 -49
- package/dist/analysis/plan/stand-still.js +3 -4
- package/dist/analysis/plan/state.js +1 -0
- package/dist/analysis/plan/stockpile.js +0 -16
- package/dist/analysis/plan/strike-stack.js +1 -6
- package/dist/analysis/plan/strike.js +10 -0
- package/dist/analysis/plan/targets.js +34 -31
- package/dist/analysis/plan/threats.js +26 -9
- package/dist/analysis/plan/withdraw.js +3 -3
- package/dist/analysis/planner.js +181 -48
- package/dist/bundle.js +800 -347
- package/dist/tools/check-plan.js +4 -1
- package/dist/tools/stress-opponents.js +1 -0
- package/dist/tools/turn.js +7 -4
- package/dist/version.js +1 -1
- package/manifest.json +1 -1
- package/package.json +3 -3
- package/server.json +2 -2
- package/dist/analysis/plan/horizon.js +0 -42
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
import { bonusTerritories } from '../bonuses.js';
|
|
6
6
|
import { armiesToTake, straightKills } from '../combat.js';
|
|
7
7
|
import { neighborsOf } from '../graph.js';
|
|
8
|
-
import { poolShortfall } from '../local-deploy.js';
|
|
9
8
|
import { noLossNeutral } from './after-leftover.js';
|
|
9
|
+
import { deadAdvanceLine, deadAdvanceOf } from './dead-advance.js';
|
|
10
10
|
import { visibleState } from './observe.js';
|
|
11
11
|
import { captureCost } from './shared.js';
|
|
12
12
|
import { byNum } from './util.js';
|
|
@@ -556,9 +556,8 @@ export function captureHelper(pc, ps, pass, book, threats, hd, tgt, prev) {
|
|
|
556
556
|
}
|
|
557
557
|
return true;
|
|
558
558
|
};
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
rationale.push(`Hold a reserve of ${reserve - pc.strikeShare} out of captures.`);
|
|
559
|
+
if (reserve)
|
|
560
|
+
rationale.push(`Hold a reserve of ${reserve} out of captures.`);
|
|
562
561
|
// ---- 3a. combined (multi-source) captures (R4) ----
|
|
563
562
|
/**
|
|
564
563
|
* The cheapest combined capture of `t` (fewest sources) under exact 0%-luck,
|
|
@@ -897,8 +896,8 @@ export function bonusPasses(pc, ps, book, hd, tgt, prev) {
|
|
|
897
896
|
const { g, s, guarded, capturePaybackTurns: paybackTurns, territories: state, label, bonusName, mineSet, incomeGain, incomeAfter, defenceAt, bonusTs, completedBy, inFocus, } = pc;
|
|
898
897
|
const { warnings, rationale, deployed, avail, captured, combined, moves, survivorsAt, captureOrder, staged, incoming, } = ps;
|
|
899
898
|
const { heldNow, gainWith } = book;
|
|
900
|
-
const { heldBorders, keptIncome,
|
|
901
|
-
const { targets, leadSteps, leadTry, leadNote, bonusTarget, frontierDelta, targetScoreCost, frontierOf,
|
|
899
|
+
const { heldBorders, keptIncome, stayAt } = hd;
|
|
900
|
+
const { targets, leadSteps, leadTry, leadNote, bonusTarget, frontierDelta, targetScoreCost, frontierOf, startHold, toFinish, byCloseness, committing, denials, emptyEnemies, } = tgt;
|
|
902
901
|
const { worstCase, tryCapture, siblings, fundedOnConceded, bareOn } = prev;
|
|
903
902
|
// ---- pass 1: complete a bonus this turn (all or nothing) ----
|
|
904
903
|
/** Snapshot the captures, deploys and notes so far; the result undoes everything since. */
|
|
@@ -1072,45 +1071,6 @@ export function bonusPasses(pc, ps, book, hd, tgt, prev) {
|
|
|
1072
1071
|
const denied = new Map();
|
|
1073
1072
|
/** The start of rule 4d's rationale line for a stopped `t` (one per attempt that differed). */
|
|
1074
1073
|
const stoppedLine = (t) => `Do not take ${label(t)}: it adds a border facing an enemy without completing a bonus,`;
|
|
1075
|
-
/**
|
|
1076
|
-
* #297: in a 1v1, the gate budget's veto: a capture of `t` that opens another border facing the opponent (a gate,
|
|
1077
|
-
* each sized for its stack plus the whole floating deploy) is stopped when the frontier would then need more next
|
|
1078
|
-
* turn than the next income, and more than it needs without that capture. Its rationale line, else `null`. Rule
|
|
1079
|
-
* 4d runs it in a 1v1 in place of its start-of-turn escape, and rule 4e's contact fallback runs it where rule 4d is
|
|
1080
|
-
* only a cost (#114): a gate the income cannot hold is lost next turn, armies and all.
|
|
1081
|
-
*/
|
|
1082
|
-
const gateStop = (t) => {
|
|
1083
|
-
if (pc.profile.format !== '1v1' || !guarded || inFocus(t))
|
|
1084
|
-
return null;
|
|
1085
|
-
const held = heldNow();
|
|
1086
|
-
if (completedBy(held).some((id) => g.bonusById.get(id).value > 0 && bonusTs.get(id).includes(t)))
|
|
1087
|
-
return null;
|
|
1088
|
-
const stays = (x) => (mineSet.has(x) ? stayAt(x) : (survivorsAt.get(x) ?? 0));
|
|
1089
|
-
const without = new Set([...held].filter((x) => x !== t));
|
|
1090
|
-
if (frontierDelta(without, [t], stays).enemy <= 0)
|
|
1091
|
-
return null;
|
|
1092
|
-
const f = frontierOf(held, stays);
|
|
1093
|
-
const next = keptIncome(held);
|
|
1094
|
-
// #433: under Local Deployment a bonus's armies deploy only on its own territories, so the gates get only the
|
|
1095
|
-
// free income and the pools of the bonuses they are in: the whole income read "not short" when that was short.
|
|
1096
|
-
const pooled = s.localDeployments ? poolShortfall(g, keptHeld(held), next, frontierNeeds(held, stays)) : null;
|
|
1097
|
-
const short = pooled ? pooled.short : Math.max(0, f.holdCost - next);
|
|
1098
|
-
if (short <= 0 || f.holdCost <= frontierOf(without, stays).holdCost)
|
|
1099
|
-
return null;
|
|
1100
|
-
const byPools = pooled !== null && f.holdCost <= next;
|
|
1101
|
-
if (!stopped.some((x) => x.t === t))
|
|
1102
|
-
stopped.push({ t, holdCost: f.holdCost, income: next, ...(byPools ? { deployable: pooled.deployable } : {}) });
|
|
1103
|
-
return byPools
|
|
1104
|
-
? `${stoppedLine(t)} and in this 1v1 it opens another gate${gateFoe(t)}: the gates would then need ${f.holdCost} next turn against its one floating deploy; under Local Deployment only ${pooled.deployable} of the next income of ${next} can be deployed on them (the free income and the pools of the bonuses they are in): ${short} short (#297, #433).`
|
|
1105
|
-
: `${stoppedLine(t)} and in this 1v1 it opens another gate${gateFoe(t)}: the gates would then need ${f.holdCost} next turn against its one floating deploy, more than the next income of ${next} (#297).`;
|
|
1106
|
-
};
|
|
1107
|
-
/** #297: " facing player P" for the opponent beside `t` (in a 1v1, the one opponent), else nothing. */
|
|
1108
|
-
const gateFoe = (t) => {
|
|
1109
|
-
const o = neighborsOf(g, t)
|
|
1110
|
-
.map((n) => state.get(n)?.owner)
|
|
1111
|
-
.find((x) => x?.kind === 'player' && pc.foe(x.playerId));
|
|
1112
|
-
return o?.kind === 'player' ? ` facing player ${o.playerId}` : '';
|
|
1113
|
-
};
|
|
1114
1074
|
/**
|
|
1115
1075
|
* #426: whether only the fog faces `t` once taken: no neighbour not mine is a player's territory shown with
|
|
1116
1076
|
* its armies (a stack in view). A player's territory whose armies the fog hides, or one not shown at all,
|
|
@@ -1126,7 +1086,7 @@ export function bonusPasses(pc, ps, book, hd, tgt, prev) {
|
|
|
1126
1086
|
* Rule 4d's frontier budget, judged with `t` just captured: under a guarded goal, a capture
|
|
1127
1087
|
* that adds a border facing an enemy without completing a bonus (and not focused) is stopped
|
|
1128
1088
|
* when holding the frontier next turn would then need more than the next income, and more than
|
|
1129
|
-
* it needed at the start of the turn
|
|
1089
|
+
* it needed at the start of the turn. Returns the rationale line when stopped, else `null`.
|
|
1130
1090
|
*/
|
|
1131
1091
|
const outgrows = (t) => {
|
|
1132
1092
|
if (!guarded || inFocus(t))
|
|
@@ -1141,13 +1101,9 @@ export function bonusPasses(pc, ps, book, hd, tgt, prev) {
|
|
|
1141
1101
|
const f = frontierOf(held, stays);
|
|
1142
1102
|
const next = keptIncome(held);
|
|
1143
1103
|
const start = startHold();
|
|
1144
|
-
|
|
1145
|
-
// cannot hold is stopped even when this turn's other orders bring the total back under where it started.
|
|
1146
|
-
// #433: nor, under Local Deployment, is a next income the gates' pools and free income cannot carry there.
|
|
1147
|
-
const gate = pc.profile.format === '1v1' ? gateStop(t) : null;
|
|
1148
|
-
if (f.holdCost <= next && !gate)
|
|
1104
|
+
if (f.holdCost <= next)
|
|
1149
1105
|
return null;
|
|
1150
|
-
if (f.holdCost <= start
|
|
1106
|
+
if (f.holdCost <= start)
|
|
1151
1107
|
return null;
|
|
1152
1108
|
// #281: land a static seat left, which a live stack beside it takes free next turn: the border
|
|
1153
1109
|
// comes either way, so the hold cost alone never refuses it (the capture still spends only what
|
|
@@ -1170,20 +1126,23 @@ export function bonusPasses(pc, ps, book, hd, tgt, prev) {
|
|
|
1170
1126
|
// The owner's cap (2026-11-22): only while the hold the capture adds is at most the next income (1×);
|
|
1171
1127
|
// over it, rule 4d decides as before (a golden synthetic board let one through at 85 against an income of 9).
|
|
1172
1128
|
const adds = f.holdCost - frontierOf(without, stays).holdCost;
|
|
1173
|
-
if (
|
|
1129
|
+
if (adds <= next && noLossNeutral(pc, tgt, t) && fogOnlyFaces(t)) {
|
|
1174
1130
|
denied.set(t, `Take ${label(t)} though holding the frontier next turn would then need ${f.holdCost} (the next income is ${next}): its defenders kill none of the attackers, only the fog faces its new border and the ${adds} it adds are within that income, so all it risks is the armies that land there (#426).`);
|
|
1175
1131
|
return null;
|
|
1176
1132
|
}
|
|
1177
|
-
|
|
1178
|
-
if (gate && (f.holdCost <= start || f.holdCost <= next))
|
|
1179
|
-
return gate;
|
|
1180
|
-
const why = `${stoppedLine(t)} and the frontier would then need ${f.holdCost} next turn to hold (${f.enemyBorders} enemy-facing borders), more than the next income of ${next} and more than the ${start} it needed at the start of the turn.${gate ? ` In this 1v1 that is another gate${gateFoe(t)} (#297).` : ''}`;
|
|
1133
|
+
const why = `${stoppedLine(t)} and the frontier would then need ${f.holdCost} next turn to hold (${f.enemyBorders} enemy-facing borders), more than the next income of ${next} and more than the ${start} it needed at the start of the turn.`;
|
|
1181
1134
|
if (!stopped.some((x) => x.t === t))
|
|
1182
1135
|
stopped.push({ t, holdCost: f.holdCost, income: next });
|
|
1183
1136
|
return why;
|
|
1184
1137
|
};
|
|
1138
|
+
/** #593: the bonuses this turn's captures could complete (rule 4f's plans): their steps are no dead advance. */
|
|
1139
|
+
const completableIds = new Set(tgt.plans.filter((p) => p.completable).map((p) => p.bonusId));
|
|
1140
|
+
const completableNow = (id) => completableIds.has(id);
|
|
1141
|
+
/** #593: every attack on `t` leaves a conceded border with no deploy: it spends only armies given up anyway. */
|
|
1142
|
+
const givenUp = (t) => moves.every((m) => m.kind !== 'attack' || m.to !== t || (hd.conceded.has(m.from) && !(deployed.get(m.from) ?? 0)));
|
|
1185
1143
|
/**
|
|
1186
|
-
* Capture `t` for expansion, unless rule 4d's frontier budget stops it (then everything is undone)
|
|
1144
|
+
* Capture `t` for expansion, unless rule 4d's frontier budget stops it (then everything is undone), or (#593) it
|
|
1145
|
+
* advances only bonuses whose other member this plan concedes ({@link deadAdvanceOf}).
|
|
1187
1146
|
* `bare` (#214): a lead step toward the closest bonus, which may be retried at its bare cost.
|
|
1188
1147
|
* `force` (rule 5b, #218): the source, and the armies on it that stay out of the attack.
|
|
1189
1148
|
*/
|
|
@@ -1191,9 +1150,25 @@ export function bonusPasses(pc, ps, book, hd, tgt, prev) {
|
|
|
1191
1150
|
const restore = snapshot();
|
|
1192
1151
|
if (!tryCapture(t, reason, force, undefined, bare))
|
|
1193
1152
|
return false;
|
|
1153
|
+
// #593: never advance a bonus whose other member this plan concedes (its armies go to the next candidate). A
|
|
1154
|
+
// capture every attack of which leaves a conceded border with no deploy spends armies given up anyway; a
|
|
1155
|
+
// no-loss one (#426) risks only what lands.
|
|
1156
|
+
const dead = noLossNeutral(pc, tgt, t) ? null : deadAdvanceOf(pc, t, heldNow(), hd.conceded, tgt.deadBonuses, completableNow);
|
|
1157
|
+
if (dead && !givenUp(t)) {
|
|
1158
|
+
restore();
|
|
1159
|
+
// Said once per territory and bonus (an outer undo may take the line back with the rest).
|
|
1160
|
+
for (const d of dead) {
|
|
1161
|
+
const line = deadAdvanceLine(pc, t, d);
|
|
1162
|
+
if (!rationale.includes(line))
|
|
1163
|
+
rationale.push(line);
|
|
1164
|
+
}
|
|
1165
|
+
return false;
|
|
1166
|
+
}
|
|
1194
1167
|
const why = outgrows(t);
|
|
1195
|
-
if (why === null)
|
|
1168
|
+
if (why === null) {
|
|
1169
|
+
ps.expanded.add(t);
|
|
1196
1170
|
return true;
|
|
1171
|
+
}
|
|
1197
1172
|
restore();
|
|
1198
1173
|
if (leadSteps.has(t))
|
|
1199
1174
|
leadTry.set(t, { kind: 'frontier' });
|
|
@@ -1305,5 +1280,5 @@ export function bonusPasses(pc, ps, book, hd, tgt, prev) {
|
|
|
1305
1280
|
if (closest)
|
|
1306
1281
|
run(todo.filter((t) => leadSteps.has(t) && !captured.has(t)), true);
|
|
1307
1282
|
};
|
|
1308
|
-
return { snapshot, complete, unstaged, stage, stopped, stoppedLine, denied, outgrows,
|
|
1283
|
+
return { snapshot, complete, unstaged, stage, stopped, stoppedLine, denied, outgrows, givenUp, completableNow, tryExpand, advance };
|
|
1309
1284
|
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bonuses a capture of `t` would advance though this plan concedes another member of them I hold, when every
|
|
3
|
+
* positive bonus `t` is in is such a bonus and the capture (with `held`, what I hold once this turn's captures so
|
|
4
|
+
* far land) completes none of them; else `null`. Called on expansion captures only (a break or a strike is no
|
|
5
|
+
* advance); never for a focused territory or land a static seat left (#281, #417). `conceded` is the plan's
|
|
6
|
+
* conceded borders as they stand; `carried` the bonuses an earlier plan of this turn found dead; `completable` the
|
|
7
|
+
* bonuses this turn's captures could complete (their steps are exempt).
|
|
8
|
+
*/
|
|
9
|
+
export function deadAdvanceOf(pc, t, held, conceded, carried, completable = () => false) {
|
|
10
|
+
if (pc.inFocus(t) || pc.vacated.has(t) || pc.mineSet.has(t))
|
|
11
|
+
return null;
|
|
12
|
+
const bonuses = (pc.bonusesWith.get(t) ?? []).filter((id) => (pc.g.bonusById.get(id)?.value ?? 0) > 0);
|
|
13
|
+
if (!bonuses.length)
|
|
14
|
+
return null;
|
|
15
|
+
const after = new Set([...held, t]);
|
|
16
|
+
const dead = [];
|
|
17
|
+
for (const id of bonuses) {
|
|
18
|
+
const ts = pc.bonusTs.get(id) ?? [];
|
|
19
|
+
// A capture that completes the bonus is no advance (rule 1c then keeps its conceded member, #18).
|
|
20
|
+
if (ts.every((x) => after.has(x)))
|
|
21
|
+
return null;
|
|
22
|
+
const now = ts.filter((x) => x !== t && pc.mineSet.has(x) && conceded.has(x));
|
|
23
|
+
const was = carried.get(id)?.filter((x) => x !== t && pc.mineSet.has(x));
|
|
24
|
+
// A bonus an earlier plan advanced and left incomplete beside a concession is dead whatever this one finds.
|
|
25
|
+
if (was?.length) {
|
|
26
|
+
dead.push({ bonusId: id, members: now.length ? now : [...was], carried: !now.length });
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
// A step of a bonus this turn's captures can complete (every missing member a target) is left to the
|
|
30
|
+
// finished plan: the completion keeps its conceded member (rule 1c), and a step taken first (#214's order)
|
|
31
|
+
// must not block it; one the plan then leaves incomplete is carried into the next plan.
|
|
32
|
+
if (completable(id) || !now.length)
|
|
33
|
+
return null;
|
|
34
|
+
// Owner, 2026-11-27: an advance that breaks the bonus for the opponent attacking a conceded member is no dead
|
|
35
|
+
// advance — the capture takes his own member of it, or the one member he would still lack once mine fall.
|
|
36
|
+
if (breaksForAttacker(pc, t, ts, now))
|
|
37
|
+
return null;
|
|
38
|
+
dead.push({ bonusId: id, members: now, carried: false });
|
|
39
|
+
}
|
|
40
|
+
return dead;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Owner, 2026-11-27: the foes with a stack beside one of my conceded members `now` of the bonus `ts` (the attackers
|
|
44
|
+
* the concession gives them to), and whether taking `t` breaks the bonus for one of them: `t` is that attacker's, or
|
|
45
|
+
* `t` is neutral and every other member is already that attacker's or one of the conceded members. Pure.
|
|
46
|
+
*/
|
|
47
|
+
export function breaksForAttacker(pc, t, ts, now) {
|
|
48
|
+
const ownerOf = (x) => {
|
|
49
|
+
const o = pc.territories.get(x)?.owner;
|
|
50
|
+
return o?.kind === 'player' ? o.playerId : null;
|
|
51
|
+
};
|
|
52
|
+
const attackers = new Set();
|
|
53
|
+
for (const m of now)
|
|
54
|
+
for (const n of pc.g.neighbors.get(m) ?? []) {
|
|
55
|
+
const p = ownerOf(n);
|
|
56
|
+
const st = pc.territories.get(n);
|
|
57
|
+
if (p !== null && pc.foe(p) && (st?.armies ?? 0) > 0)
|
|
58
|
+
attackers.add(p);
|
|
59
|
+
}
|
|
60
|
+
if (!attackers.size)
|
|
61
|
+
return false;
|
|
62
|
+
const owner = ownerOf(t);
|
|
63
|
+
if (owner !== null)
|
|
64
|
+
return attackers.has(owner);
|
|
65
|
+
if (pc.territories.get(t)?.owner.kind !== 'neutral')
|
|
66
|
+
return false;
|
|
67
|
+
const conceded = new Set(now);
|
|
68
|
+
return [...attackers].some((a) => ts.every((x) => x === t || conceded.has(x) || ownerOf(x) === a));
|
|
69
|
+
}
|
|
70
|
+
/** The rationale line for a refused advance of `t` (one per bonus). */
|
|
71
|
+
export function deadAdvanceLine(pc, t, d) {
|
|
72
|
+
const members = d.members.map(pc.label).join(', ');
|
|
73
|
+
const its = d.members.length === 1 ? 'its member' : 'its members';
|
|
74
|
+
return d.carried
|
|
75
|
+
? `Do not take ${pc.label(t)} toward bonus ${pc.bonusName(d.bonusId)}: the plan that took it conceded ${its} ${members}, so the capture builds a bonus this turn gives up: its armies are left to the plan's other orders (#593).`
|
|
76
|
+
: `Do not take ${pc.label(t)} toward bonus ${pc.bonusName(d.bonusId)}: this plan concedes ${its} ${members}, so the capture builds a bonus this turn gives up: its armies are left to the plan's other orders (#593).`;
|
|
77
|
+
}
|
|
@@ -6,6 +6,29 @@ import { armyCapIncome, boardIncome, DEFAULT_BASE_INCOME, incomeRules, territory
|
|
|
6
6
|
import { byNum } from './util.js';
|
|
7
7
|
import { LOW_COVERAGE, MIN_ENEMY_DEPLOY, OWNERS_SHOWN_FOG, PRIOR_EVIDENCE_TURNS, TRACKED_MIN_TURNS, bombPossibleOn, fogPaceIncome, localFreeOn, reinforcementArmiesFor } from './shared.js';
|
|
8
8
|
import { observeDeploy, ownerShown, trackCoverage, visibleState } from './observe.js';
|
|
9
|
+
import { coverageBucket } from '../game-lessons.js';
|
|
10
|
+
/** #436's gate, repeated for the planner (#568): a band's calibration counts only from this many samples. */
|
|
11
|
+
const MIN_TRACK_CALIBRATION_SAMPLES = 5;
|
|
12
|
+
/**
|
|
13
|
+
* #568 (owner decision 2026-11-27): the tracked figure is divided by its band's past estimate ÷ truth
|
|
14
|
+
* to this power — the square root, as #567's `STATED_DAMPING` damps a stated ratio — so a band that read 0.3×
|
|
15
|
+
* truth raises the tracked figure ~1.8×, not ~3.3×: the factor is a geometric mean over a spread wide enough
|
|
16
|
+
* that the full correction would put half the estimates above the truth.
|
|
17
|
+
*/
|
|
18
|
+
export const TRACK_CALIBRATION_DAMPING = 0.5;
|
|
19
|
+
/**
|
|
20
|
+
* #568: the factor a tracked figure read from `share` of its frontier is divided by: its coverage band's past
|
|
21
|
+
* geometric mean of estimate ÷ truth (`calibration`, from lessons.json) to the {@link TRACK_CALIBRATION_DAMPING}
|
|
22
|
+
* power; `undefined` when the band has under {@link MIN_TRACK_CALIBRATION_SAMPLES} samples or read at least the
|
|
23
|
+
* truth (the correction only ever raises).
|
|
24
|
+
*/
|
|
25
|
+
export function trackCalibrationFactor(calibration, share) {
|
|
26
|
+
const band = coverageBucket(share);
|
|
27
|
+
const c = calibration?.[band];
|
|
28
|
+
if (!c || c.n < MIN_TRACK_CALIBRATION_SAMPLES || !(c.geoMean > 0) || c.geoMean >= 1)
|
|
29
|
+
return undefined;
|
|
30
|
+
return { band, geoMean: c.geoMean, n: c.n, factor: c.geoMean ** TRACK_CALIBRATION_DAMPING };
|
|
31
|
+
}
|
|
9
32
|
/**
|
|
10
33
|
* The army count every visible player territory holds, when they all hold the same one (the
|
|
11
34
|
* initial allotment). Neutrals are left out (#128): their stacks are not the starting stacks on
|
|
@@ -279,6 +302,20 @@ export function enemyDeployEstimates(g, board, me, settings = {}, previous, trac
|
|
|
279
302
|
const observedCap = observation ? couldEarn : null;
|
|
280
303
|
const observedRaw = observation?.deploy ?? null;
|
|
281
304
|
const observed = observation ? Math.min(observation.deploy, observedCap) : null;
|
|
305
|
+
// #294: what its tracked figure was read from (#368: while that is little, thin evidence below).
|
|
306
|
+
const coverage = usable ? trackCoverage(usable.turns.filter((x) => usable.incomeTurns.includes(x.from))) : null;
|
|
307
|
+
// #568: the tracker reads low under fog (every observed deploy a lower bound); past games' estimate ÷
|
|
308
|
+
// truth in its coverage band raises the tracked figure from here on (never above what it could earn, never
|
|
309
|
+
// lowered). The #123 bound above keeps the tracker's own figure.
|
|
310
|
+
let trackCalibration = null;
|
|
311
|
+
if (usable && tracked !== null && tracked > 0) {
|
|
312
|
+
const c = trackCalibrationFactor(when.calibration, coverage ? coverage.share : null);
|
|
313
|
+
const figure = c ? Math.min(Math.max(couldEarn, tracked), Math.round(tracked / c.factor)) : tracked;
|
|
314
|
+
if (c && figure > tracked) {
|
|
315
|
+
trackCalibration = { raw: tracked, band: c.band, geoMean: c.geoMean, n: c.n, factor: c.factor, figure };
|
|
316
|
+
tracked = figure;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
282
319
|
// A usable track replaces the single-turn observed figure (S3; #235 1c: its newest reading too).
|
|
283
320
|
const seenSource = tracked !== null
|
|
284
321
|
? tracked > visible
|
|
@@ -316,8 +353,6 @@ export function enemyDeployEstimates(g, board, me, settings = {}, previous, trac
|
|
|
316
353
|
}
|
|
317
354
|
const priorUsed = priorBlend ? priorBlend.figure : priorFigure;
|
|
318
355
|
const source = exact !== null ? 'exact' : priorUsed !== null && priorUsed > seen ? 'prior' : seenSource;
|
|
319
|
-
// #294: what its tracked figure was read from (#368: while that is little, thin evidence below).
|
|
320
|
-
const coverage = usable ? trackCoverage(usable.turns.filter((x) => usable.incomeTurns.includes(x.from))) : null;
|
|
321
356
|
// #444: an untracked opponent whose prior a stated income scaled: #368's midpoint between what is in
|
|
322
357
|
// view (or observed) and that prior.
|
|
323
358
|
const statedMid = statedRatio !== null && source === 'prior' && !usable ? seen + Math.ceil((priorUsed - seen) / 2 - 1e-9) : null;
|
|
@@ -455,6 +490,7 @@ export function enemyDeployEstimates(g, board, me, settings = {}, previous, trac
|
|
|
455
490
|
cardPlayed,
|
|
456
491
|
...(cardSeen ? { cardSeen: true } : {}),
|
|
457
492
|
...(cardInTrack ? { cardInTrack } : {}),
|
|
493
|
+
...(trackCalibration ? { trackCalibration } : {}),
|
|
458
494
|
...(priorFull !== null && priorFigure < priorFull ? { stated: { full: priorFull, scaled: priorFigure, lower: seen, midpoint: statedMid } } : {}),
|
|
459
495
|
};
|
|
460
496
|
});
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
// territories are worth (#70, #85, #125), where I stand on armies (#167, #201, rule 0p.3) — and the
|
|
5
5
|
// rationale and warnings that state them. Pure: it reads the input and writes only
|
|
6
6
|
// `state.warnings` / `state.rationale`.
|
|
7
|
-
import {
|
|
8
|
-
import { pileOf
|
|
7
|
+
import { siegeOf } from './siege.js';
|
|
8
|
+
import { pileOf } from './stockpile.js';
|
|
9
9
|
import { armiesForGold } from '../../commerce.js';
|
|
10
10
|
import { holdsSeat } from '../../player-states.js';
|
|
11
11
|
import { isTeamGame, teammatesOf } from '../../teams.js';
|
|
@@ -98,6 +98,7 @@ export function planEnemyEstimates(input) {
|
|
|
98
98
|
reinforcement: ctx.reinforcement,
|
|
99
99
|
...(ctx.reinforcementPlays ? { plays: ctx.reinforcementPlays } : {}),
|
|
100
100
|
...(previousBoard && input.previousOrders ? { previousOrders: input.previousOrders } : {}),
|
|
101
|
+
...(ctx.trackCalibration ? { calibration: ctx.trackCalibration } : {}),
|
|
101
102
|
});
|
|
102
103
|
const priced = applyKnown(applyArmyPrice(applySanctions(estimates, input.sanctions ?? [], turn), input.settings?.armyCostMultiplier ?? 0), input.known ?? []);
|
|
103
104
|
return { estimates: priced, prior, ...(skipped ? { priorSkipped: skipped } : {}) };
|
|
@@ -344,9 +345,8 @@ function opponentsCtx(input) {
|
|
|
344
345
|
/** Rule 0p.3 (#72): behind on income in a 1v1 — strike (stay balanced, break first), never defend. */
|
|
345
346
|
const strike = behind && profile.format === '1v1';
|
|
346
347
|
// #382: a siege plans as balanced; `siege` below carries what differs.
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
let balanced = goal === 'balanced';
|
|
348
|
+
const goal = opts.goal === 'siege' ? 'balanced' : (opts.goal ?? (behind && !strike ? 'defend' : 'balanced'));
|
|
349
|
+
const balanced = goal === 'balanced';
|
|
350
350
|
/** Rule 0p.3: behind — size attacks at the minimum (no pressure margin). */
|
|
351
351
|
const minimal = behind;
|
|
352
352
|
/** #303: my income over the last turns, this one (what I deploy, card armies out) last. */
|
|
@@ -358,7 +358,7 @@ function opponentsCtx(input) {
|
|
|
358
358
|
/** The pressure margin over an estimated deploy: none when sizing at the minimum. */
|
|
359
359
|
const marginFor = (d) => (minimal ? 0 : pressureMargin(d));
|
|
360
360
|
/** Goals that refuse to complete a bonus they cannot hold (R3); the others only warn. */
|
|
361
|
-
|
|
361
|
+
const guarded = balanced || goal === 'defend';
|
|
362
362
|
const focus = new Set(opts.focusBonusIds ?? []);
|
|
363
363
|
const reserve = Math.min(income, Math.max(0, Math.floor(opts.reserve ?? 0)));
|
|
364
364
|
const custom = opts.enemyDeploy !== undefined;
|
|
@@ -409,25 +409,7 @@ function opponentsCtx(input) {
|
|
|
409
409
|
...(input.siegeMemory ? { memory: input.siegeMemory } : {}),
|
|
410
410
|
};
|
|
411
411
|
const sieged = opts.goal === 'siege' ? siegeOf({ ...siegeArgs, target: opts.siegeTarget }) : undefined;
|
|
412
|
-
|
|
413
|
-
// once its assault trigger fires or the fit is gone.
|
|
414
|
-
let siege = sieged && 'siege' in sieged ? sieged.siege : undefined;
|
|
415
|
-
let siegeHandBack;
|
|
416
|
-
if (auto && opts.siegeAuto !== false && (profile.format === '1v1' || profile.format === 'ffa') && (profile.phase === 'contact' || profile.phase === 'late')) {
|
|
417
|
-
const c = siegeOf({ ...siegeArgs, target: undefined });
|
|
418
|
-
if ('siege' in c) {
|
|
419
|
-
const fit = siegeFit(c.siege, { format: profile.format, phase: profile.phase, standing: profile.standing, leader: profile.ranking?.commonThreat });
|
|
420
|
-
if (fit.fits) {
|
|
421
|
-
siege = { ...c.siege, auto: fit.fit };
|
|
422
|
-
// The siege wins over the profile's own goal (a `defend` it picked included): it plans as balanced.
|
|
423
|
-
goal = 'balanced';
|
|
424
|
-
balanced = true;
|
|
425
|
-
guarded = true;
|
|
426
|
-
}
|
|
427
|
-
else if (fit.handBack)
|
|
428
|
-
siegeHandBack = `A siege on player ${c.siege.target} would fit (#382), but its assault trigger has fired (${fit.handBack}): the profile hands back to its own goal for the assault.`;
|
|
429
|
-
}
|
|
430
|
-
}
|
|
412
|
+
const siege = sieged && 'siege' in sieged ? sieged.siege : undefined;
|
|
431
413
|
// Until the trigger fires, no pass attacks the target's territories but its breakable bonuses' members.
|
|
432
414
|
const held = siege && !siege.ready ? siege : undefined;
|
|
433
415
|
const heldLand = new Set(held
|
|
@@ -500,7 +482,6 @@ function opponentsCtx(input) {
|
|
|
500
482
|
balanced,
|
|
501
483
|
...(siege ? { siege } : {}),
|
|
502
484
|
...(sieged && 'warning' in sieged ? { siegeWarning: sieged.warning } : {}),
|
|
503
|
-
...(siegeHandBack ? { siegeHandBack } : {}),
|
|
504
485
|
minimal,
|
|
505
486
|
...(trendNow ? { incomeTrend: trendNow } : {}),
|
|
506
487
|
pressureFactor,
|
|
@@ -860,25 +841,15 @@ export function planContext(input) {
|
|
|
860
841
|
const o = opponentsCtx(input);
|
|
861
842
|
const b = boardCtx(input, o);
|
|
862
843
|
const c = combatCtx(o, b);
|
|
863
|
-
// #421 (owner decision, 2026-11-20): in contact on a flat income the strike share is held out of
|
|
864
|
-
// captures (the reserve holds back captures only, so holds keep their exact need first).
|
|
865
|
-
const contact = new Set();
|
|
866
|
-
for (const id of b.mine)
|
|
867
|
-
for (const n of neighborsOf(o.g, id)) {
|
|
868
|
-
const st = b.territories.get(n);
|
|
869
|
-
if (st?.owner.kind === 'player' && st.armies !== null && o.foe(st.owner.playerId))
|
|
870
|
-
contact.add(st.owner.playerId);
|
|
871
|
-
}
|
|
872
844
|
const pileArgs = {
|
|
873
845
|
territories: b.territories, mineSet: b.mineSet, unitsAt: b.unitsAt, foe: o.foe, income: o.income,
|
|
874
846
|
...(o.incomeTrend ? { incomeTrend: o.incomeTrend } : {}), auto: o.auto, goal: o.goal, noSplit: c.noSplit,
|
|
875
847
|
};
|
|
876
|
-
const
|
|
877
|
-
const reserve = Math.min(o.income, o.reserve + strikeShare);
|
|
848
|
+
const reserve = o.reserve;
|
|
878
849
|
// #421: the pile itself, for the break and all-in spends.
|
|
879
850
|
const pile = pileOf(pileArgs);
|
|
880
851
|
return {
|
|
881
|
-
...o, ...b, ...c, ...standingCtx(o, b), reserve,
|
|
852
|
+
...o, ...b, ...c, ...standingCtx(o, b), reserve,
|
|
882
853
|
...(pile ? { pile: { my: pile.my, turns: pile.turns } } : {}),
|
|
883
854
|
};
|
|
884
855
|
}
|
|
@@ -889,7 +860,7 @@ export function planContext(input) {
|
|
|
889
860
|
* every plan, in this order.
|
|
890
861
|
*/
|
|
891
862
|
export function noteEstimates(ctx, state) {
|
|
892
|
-
const { board, s, opts, earnedIncome: income, estimateList, profile, auto, strike, minimal, pressureFactor, decidedGame
|
|
863
|
+
const { board, s, opts, earnedIncome: income, estimateList, profile, auto, strike, minimal, pressureFactor, decidedGame } = ctx;
|
|
893
864
|
const { rates, minWin, exactCombat, bombOn, luck, weightedRounding, noSplit, armiesBehindVs } = ctx;
|
|
894
865
|
const { warnings, rationale } = state;
|
|
895
866
|
const profileText = `${profile.format}, ${profile.phase}, ${profile.standing}`;
|
|
@@ -906,13 +877,11 @@ export function noteEstimates(ctx, state) {
|
|
|
906
877
|
const behindWhy = income <= BEHIND_RATIO * strongest
|
|
907
878
|
? `behind on income (${income} against ~${strongest})`
|
|
908
879
|
: `behind on the board, not on income (${income} against ~${strongest}: the standing says why)`;
|
|
909
|
-
rationale.push(
|
|
910
|
-
? `Goal
|
|
911
|
-
:
|
|
912
|
-
? `Goal
|
|
913
|
-
:
|
|
914
|
-
? `Goal defend from the game profile (${profileText}): ${behindWhy}, so defend first and size attacks at the minimum (no extra margin beyond what the rules require).`
|
|
915
|
-
: `Goal balanced from the game profile (${profileText}): the base goal.`);
|
|
880
|
+
rationale.push(strike
|
|
881
|
+
? `Goal balanced from the game profile (${profileText}): ${behindWhy} in a 1v1 — strike: break the opponent's bonuses with minimal attacks before expansion that completes nothing (holds of my own bonuses that pay for themselves still come first), sized at the minimum (no extra margin beyond what the rules require).`
|
|
882
|
+
: minimal
|
|
883
|
+
? `Goal defend from the game profile (${profileText}): ${behindWhy}, so defend first and size attacks at the minimum (no extra margin beyond what the rules require).`
|
|
884
|
+
: `Goal balanced from the game profile (${profileText}): the base goal.`);
|
|
916
885
|
if (pressureFactor !== PRESSURE_FACTOR)
|
|
917
886
|
rationale.push(`Ahead in a 1v1 (${income} against ~${strongest}): keep attacking — pressure on an opponent next to the fog is allowed when each capture costs up to ${pressureFactor}× a typical neutral capture (instead of ${PRESSURE_FACTOR}×).`);
|
|
918
887
|
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { bonusTerritories } from '../bonuses.js';
|
|
2
|
+
import { neighborsOf } from '../graph.js';
|
|
3
|
+
import { ownerShown, visibleState } from './shared.js';
|
|
4
|
+
/** A one-short denial (item 5a) is worth this share of the bonus: the opponent does not earn it yet. */
|
|
5
|
+
export const ONE_SHORT_WEIGHT = 0.5;
|
|
6
|
+
/** Item 5a's opening: the turns a one-short denial is tried on. */
|
|
7
|
+
export const OPENING_STRIKE_FIRST = 2;
|
|
8
|
+
export const OPENING_STRIKE_LAST = 4;
|
|
9
|
+
/**
|
|
10
|
+
* The opponent bonuses a 1v1 may break behind the fog, and (on the opening turns) the ones it is one
|
|
11
|
+
* territory short of. `known`: the bonuses already breakable (visible, or the tracker's #72 inference),
|
|
12
|
+
* which are left out. Sorted by bonus id.
|
|
13
|
+
*/
|
|
14
|
+
export function foggedBreakables(g, state, foe, mine, known, turn) {
|
|
15
|
+
const opening = turn !== null && turn >= OPENING_STRIKE_FIRST && turn <= OPENING_STRIKE_LAST;
|
|
16
|
+
const out = [];
|
|
17
|
+
for (const b of [...g.map.bonuses].sort((x, y) => x.id - y.id)) {
|
|
18
|
+
if (b.value <= 0 || known.has(b.id))
|
|
19
|
+
continue;
|
|
20
|
+
const ts = bonusTerritories(g, b.id);
|
|
21
|
+
if (!ts.length)
|
|
22
|
+
continue;
|
|
23
|
+
const players = new Set();
|
|
24
|
+
const others = [];
|
|
25
|
+
let fogged = 0;
|
|
26
|
+
for (const t of ts) {
|
|
27
|
+
const st = state.get(t);
|
|
28
|
+
const shown = ownerShown(st);
|
|
29
|
+
if (!shown) {
|
|
30
|
+
fogged++;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (shown.owner.kind === 'player' && foe(shown.owner.playerId)) {
|
|
34
|
+
players.add(shown.owner.playerId);
|
|
35
|
+
if (!visibleState(st))
|
|
36
|
+
fogged++;
|
|
37
|
+
}
|
|
38
|
+
else
|
|
39
|
+
others.push(t);
|
|
40
|
+
}
|
|
41
|
+
if (players.size !== 1)
|
|
42
|
+
continue;
|
|
43
|
+
const player = [...players][0];
|
|
44
|
+
const members = ts
|
|
45
|
+
.filter((t) => {
|
|
46
|
+
const st = visibleState(state.get(t));
|
|
47
|
+
return st?.owner.kind === 'player' && st.owner.playerId === player && neighborsOf(g, t).some((n) => mine.has(n));
|
|
48
|
+
})
|
|
49
|
+
.sort((x, y) => x - y);
|
|
50
|
+
if (!members.length)
|
|
51
|
+
continue;
|
|
52
|
+
if (!others.length) {
|
|
53
|
+
if (!fogged)
|
|
54
|
+
continue;
|
|
55
|
+
out.push({
|
|
56
|
+
bonusId: b.id,
|
|
57
|
+
value: b.value,
|
|
58
|
+
player,
|
|
59
|
+
probable: `a member in view is its and its ${fogged} fogged member${fogged > 1 ? 's' : ''} could all be its, #593`,
|
|
60
|
+
members,
|
|
61
|
+
fogged,
|
|
62
|
+
});
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (!opening || others.length !== 1 || state.get(others[0])?.owner.kind !== 'neutral')
|
|
66
|
+
continue;
|
|
67
|
+
out.push({
|
|
68
|
+
bonusId: b.id,
|
|
69
|
+
value: b.value,
|
|
70
|
+
player,
|
|
71
|
+
probable: `one territory short of complete, ${others[0]} still neutral, #593`,
|
|
72
|
+
members,
|
|
73
|
+
fogged,
|
|
74
|
+
shortOf: others[0],
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return out;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The deploy a #593 break is sized for: the opponent's deploy estimate on the target (`estimate`) split
|
|
81
|
+
* over `fronts`, the territories of its in view beside my land (it cannot tell which one I strike, and one
|
|
82
|
+
* deploy floats to one place), rounded up; with one such territory, the whole estimate.
|
|
83
|
+
*/
|
|
84
|
+
export function partialDeploy(estimate, fronts) {
|
|
85
|
+
return Math.ceil(Math.max(0, estimate) / Math.max(1, fronts));
|
|
86
|
+
}
|
|
@@ -82,8 +82,7 @@ export function fillSecondLine(pc, ps, book) {
|
|
|
82
82
|
const owed = e.size - secondLineKept.get(id);
|
|
83
83
|
if (owed <= 0)
|
|
84
84
|
continue;
|
|
85
|
-
|
|
86
|
-
const k = Math.min(owed, Math.max(0, ps.budget - (reserve - pc.strikeShare)), roomAt(id));
|
|
85
|
+
const k = Math.min(owed, Math.max(0, ps.budget - reserve), roomAt(id));
|
|
87
86
|
if (k > 0) {
|
|
88
87
|
deploy(id, k);
|
|
89
88
|
// The deployed armies join the garrison: they stay, as the guard would.
|