@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
package/dist/analysis/picks.js
CHANGED
|
@@ -139,6 +139,14 @@
|
|
|
139
139
|
// 5c. Commanders (#129): the first pick awarded carries the commander, so the primary's
|
|
140
140
|
// safest pick (fewest other pickables within COMPACT_DISTANCE hops, then fewest
|
|
141
141
|
// neighbours outside the primary, then score) is listed first; the award reorder keeps it.
|
|
142
|
+
// 5d. Fragile 1v1 primaries (#429). In a two-player game with an answering fallback, when the
|
|
143
|
+
// fallback outscores the primary or the worst award outcome is under FRAGILE_WORST × the
|
|
144
|
+
// primary's own score, each primary pick 2…n is scored in the outcomes that grant it with a
|
|
145
|
+
// pick above it lost (as an answering fallback pick is), against every pick off the primary
|
|
146
|
+
// that keeps it as compact; the best that scores more there replaces it (the old pick drops to
|
|
147
|
+
// its slot) only when the list, its fallback built again, raises both its worst and its mean
|
|
148
|
+
// award outcome and the primary keeps at least PRIMARY_FLOOR of its original joint score (the
|
|
149
|
+
// owner's floor, 2026-11-22). A warning names each replacement and the figures.
|
|
142
150
|
// 6. Reasons. reasons[0] is the bonus the pick anchors (worth most to it alone) and its
|
|
143
151
|
// completion turn and the income it adds, or how much of it is held by the horizon;
|
|
144
152
|
// then the other bonuses it completes or advances. Each such line gives the bonus's entry
|
|
@@ -185,13 +193,59 @@ export const DEFAULT_NEUTRALS_IN_DISTRIBUTION = 4;
|
|
|
185
193
|
export const DEFAULT_NON_DISTRIBUTION_ARMIES = 2;
|
|
186
194
|
/** Seeds (best score first) each group search grows from; every one when the pool is no larger (#129). */
|
|
187
195
|
const MAX_SEEDS = 12;
|
|
196
|
+
/**
|
|
197
|
+
* Scaling on very large maps (the 3,066-territory / 173-bonus live case that could not be served): above
|
|
198
|
+
* `LARGE_PICKABLE` pickable territories every pickable is scored alone (its own opening, the first view's
|
|
199
|
+
* measure) and only the best of them form the candidate pool for the groups, fallback, award and alternative
|
|
200
|
+
* (#476: ranking by bonus value per member missed the best start on most real maps). The pool is `LARGE_POOL`
|
|
201
|
+
* territories at the default budget and grows or shrinks with `budgetMs` in proportion (never below
|
|
202
|
+
* `LARGE_POOL_MIN`), so a larger budget buys a wider search; one input plans the same on any machine. Every pickable territory
|
|
203
|
+
* still counts as a place an opponent may start (the threat model), and the contestedness is read from
|
|
204
|
+
* `CENTRALITY_SAMPLES` evenly spaced sources instead of every pair. Hop distances are then searched to
|
|
205
|
+
* `SCALE_HOP_DEPTH` steps only (farther reads as unconnected). At or below the limit nothing changes: smaller
|
|
206
|
+
* maps plan exactly as before.
|
|
207
|
+
*/
|
|
208
|
+
export const LARGE_PICKABLE = 400;
|
|
209
|
+
/** Candidate pool of a very large map at the default budget (`LARGE_POOL_BUDGET_MS`). */
|
|
210
|
+
export const LARGE_POOL = 400;
|
|
211
|
+
export const LARGE_POOL_MIN = 150;
|
|
212
|
+
/** The budget `LARGE_POOL` is sized for (`DEFAULT_PICKS_BUDGET_MS` in the tool). */
|
|
213
|
+
export const LARGE_POOL_BUDGET_MS = 20_000;
|
|
214
|
+
/** The candidate pool of a very large map for a time budget (`LARGE_POOL` per `LARGE_POOL_BUDGET_MS`). */
|
|
215
|
+
export function largePool(budgetMs) {
|
|
216
|
+
if (budgetMs === undefined || !Number.isFinite(budgetMs))
|
|
217
|
+
return LARGE_POOL;
|
|
218
|
+
return Math.max(LARGE_POOL_MIN, Math.round((LARGE_POOL * budgetMs) / LARGE_POOL_BUDGET_MS));
|
|
219
|
+
}
|
|
220
|
+
export const CENTRALITY_SAMPLES = 48;
|
|
221
|
+
export const SCALE_HOP_DEPTH = 8;
|
|
188
222
|
/** The primary's order is searched for the best worst outcome only up to this size (#129). */
|
|
189
223
|
const MAX_REORDER = 5;
|
|
224
|
+
/** #429: a two-player list whose worst award outcome is under this share of the primary's own score is fragile. */
|
|
225
|
+
export const FRAGILE_WORST = 0.6;
|
|
226
|
+
/** #429 (owner decision 2026-11-22): a replacement never leaves the primary's joint score under this share of the original's. */
|
|
227
|
+
export const PRIMARY_FLOOR = 0.8;
|
|
190
228
|
/** Neutral size used to compare attack hardness against the standard kill rates. */
|
|
191
229
|
const HARDNESS_PROBE = 10;
|
|
192
230
|
/** Territories a reason names before it says "and n more". */
|
|
193
231
|
const MAX_NAMED = 3;
|
|
194
232
|
const byNum = (a, b) => a - b;
|
|
233
|
+
/** Hop distances from `from` to every territory within `depth` steps (breadth first; the rest are absent). */
|
|
234
|
+
function boundedDistances(g, from, depth) {
|
|
235
|
+
const dist = new Map([[from, 0]]);
|
|
236
|
+
let frontier = [from];
|
|
237
|
+
for (let d = 1; d <= depth && frontier.length; d++) {
|
|
238
|
+
const next = [];
|
|
239
|
+
for (const t of frontier)
|
|
240
|
+
for (const n of neighborsOf(g, t))
|
|
241
|
+
if (!dist.has(n)) {
|
|
242
|
+
dist.set(n, d);
|
|
243
|
+
next.push(n);
|
|
244
|
+
}
|
|
245
|
+
frontier = next;
|
|
246
|
+
}
|
|
247
|
+
return dist;
|
|
248
|
+
}
|
|
195
249
|
const NO_TAKEN = new Set();
|
|
196
250
|
const round2 = (x) => Math.round(x * 100) / 100;
|
|
197
251
|
/** `a` sorts before `b`, compared element by element. */
|
|
@@ -686,7 +740,13 @@ function planCore(input, friendlyIds = []) {
|
|
|
686
740
|
const friendly = friendlyIds.length ? new Set(friendlyIds) : NO_TAKEN;
|
|
687
741
|
const s = input.settings ?? {};
|
|
688
742
|
const warnings = [];
|
|
743
|
+
if (input.fullDeal)
|
|
744
|
+
warnings.push('Every territory is dealt: each group is the best picks by score; no compact group was searched (it would not change what you are dealt).');
|
|
689
745
|
const rationale = [];
|
|
746
|
+
const clock = input.clock ?? Date.now;
|
|
747
|
+
const startedAt = clock();
|
|
748
|
+
const expired = () => input.budgetMs !== undefined && clock() - startedAt > input.budgetMs;
|
|
749
|
+
let partial = false;
|
|
690
750
|
// Pickable territories: known, unique, sorted.
|
|
691
751
|
const unknown = [];
|
|
692
752
|
// `pickSet` is every pickable territory (for neutral sizes); `pickable` leaves out a teammate's top
|
|
@@ -833,19 +893,43 @@ function planCore(input, friendlyIds = []) {
|
|
|
833
893
|
// Contestedness from centrality among the pickables.
|
|
834
894
|
const contestWeight = Math.min(CONTEST_MAX, Math.max(0, (players - 2) * CONTEST_PER_PLAYER));
|
|
835
895
|
const meanDist = new Map();
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
896
|
+
const large = pickable.length > (input.largeAbove ?? LARGE_PICKABLE);
|
|
897
|
+
if (large) {
|
|
898
|
+
// Mean distance to every other pickable, read from evenly spaced sources (distances are symmetric).
|
|
899
|
+
const samples = input.scale?.centralitySamples ?? CENTRALITY_SAMPLES;
|
|
900
|
+
const step = Math.max(1, Math.floor(pickable.length / samples));
|
|
901
|
+
const sources = pickable.filter((_, i) => i % step === 0).slice(0, samples);
|
|
902
|
+
const sums = new Map();
|
|
903
|
+
for (const q of sources) {
|
|
904
|
+
for (const [t, d] of bfsDistances(g, [q])) {
|
|
905
|
+
if (t === q)
|
|
906
|
+
continue;
|
|
907
|
+
const e = sums.get(t) ?? { sum: 0, count: 0 };
|
|
908
|
+
e.sum += d;
|
|
909
|
+
e.count++;
|
|
910
|
+
sums.set(t, e);
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
for (const t of pickable) {
|
|
914
|
+
const e = sums.get(t);
|
|
915
|
+
if (e?.count)
|
|
916
|
+
meanDist.set(t, e.sum / e.count);
|
|
845
917
|
}
|
|
846
|
-
if (count)
|
|
847
|
-
meanDist.set(t, sum / count);
|
|
848
918
|
}
|
|
919
|
+
else
|
|
920
|
+
for (const t of pickable) {
|
|
921
|
+
const d = bfsDistances(g, [t]);
|
|
922
|
+
let sum = 0;
|
|
923
|
+
let count = 0;
|
|
924
|
+
for (const o of pickable) {
|
|
925
|
+
if (o === t || !d.has(o))
|
|
926
|
+
continue;
|
|
927
|
+
sum += d.get(o);
|
|
928
|
+
count++;
|
|
929
|
+
}
|
|
930
|
+
if (count)
|
|
931
|
+
meanDist.set(t, sum / count);
|
|
932
|
+
}
|
|
849
933
|
const means = [...meanDist.values()];
|
|
850
934
|
const lo = Math.min(...means);
|
|
851
935
|
const hi = Math.max(...means);
|
|
@@ -977,12 +1061,33 @@ function planCore(input, friendlyIds = []) {
|
|
|
977
1061
|
taken,
|
|
978
1062
|
of: new Map(pool.map((t) => [t, assess(t, taken)])),
|
|
979
1063
|
});
|
|
980
|
-
|
|
1064
|
+
// Very large map (#476): rank every pickable by its own opening (the first view's measure) and keep the best as the
|
|
1065
|
+
// pool; the rest still count as places an opponent may start.
|
|
1066
|
+
let cands = pickable;
|
|
1067
|
+
let candidateReport;
|
|
1068
|
+
if (large) {
|
|
1069
|
+
const order = pickable
|
|
1070
|
+
.map((t) => [t, assess(t, NO_TAKEN).score])
|
|
1071
|
+
.sort((a, c) => c[1] - a[1] || a[0] - c[0])
|
|
1072
|
+
.map(([t]) => t);
|
|
1073
|
+
const size = Math.min(order.length, Math.max(input.scale?.candidateTerritories ?? largePool(input.budgetMs), maxPicks * 4));
|
|
1074
|
+
cands = order.slice(0, size).sort(byNum);
|
|
1075
|
+
const inPool = new Set(cands);
|
|
1076
|
+
const touched = new Set();
|
|
1077
|
+
for (const t of inPool)
|
|
1078
|
+
for (const id of bonusesOf.get(t) ?? [])
|
|
1079
|
+
touched.add(id);
|
|
1080
|
+
candidateReport = { ranked: cands.length, pickable: pickable.length, bonuses: touched.size };
|
|
1081
|
+
if (cands.length < pickable.length)
|
|
1082
|
+
warnings.push(`A very large map (${pickable.length} pickable territories): the ${cands.length} territories that score best alone are ranked; ` +
|
|
1083
|
+
'the others still count as places an opponent may start, but are not offered.');
|
|
1084
|
+
}
|
|
1085
|
+
const firstView = viewOf(cands, NO_TAKEN);
|
|
981
1086
|
// Hop distances on the map graph (the one warapp_plan_route uses), cached per territory.
|
|
982
1087
|
const bfsCache = new Map();
|
|
983
1088
|
const hops = (a, b) => {
|
|
984
1089
|
if (!bfsCache.has(a))
|
|
985
|
-
bfsCache.set(a, bfsDistances(g, [a]));
|
|
1090
|
+
bfsCache.set(a, large ? boundedDistances(g, a, input.scale?.hopDepth ?? SCALE_HOP_DEPTH) : bfsDistances(g, [a]));
|
|
986
1091
|
return bfsCache.get(a).get(b) ?? Infinity;
|
|
987
1092
|
};
|
|
988
1093
|
// Groups. A pick joins a group when it lies within `hop` hops of a pick already in it
|
|
@@ -998,6 +1103,10 @@ function planCore(input, friendlyIds = []) {
|
|
|
998
1103
|
let current = simulate(ctx, group, view.taken).score;
|
|
999
1104
|
const distTo = (c) => Math.min(...group.map((x) => hops(x, c)));
|
|
1000
1105
|
while (group.length < size) {
|
|
1106
|
+
if (expired()) {
|
|
1107
|
+
partial = true;
|
|
1108
|
+
return null;
|
|
1109
|
+
}
|
|
1001
1110
|
const anchored = new Set(group.map((t) => view.of.get(t).anchor));
|
|
1002
1111
|
const eligible = [...left].sort(byNum).filter((c) => {
|
|
1003
1112
|
const d = distTo(c);
|
|
@@ -1009,7 +1118,12 @@ function planCore(input, friendlyIds = []) {
|
|
|
1009
1118
|
if (!eligible.length)
|
|
1010
1119
|
return null;
|
|
1011
1120
|
let best = null;
|
|
1012
|
-
for (const c of eligible) {
|
|
1121
|
+
for (const [i, c] of eligible.entries()) {
|
|
1122
|
+
// One step can be thousands of openings (a 122-pick group over a 3,066-territory pool): watch the budget inside it too.
|
|
1123
|
+
if (i % 64 === 63 && expired()) {
|
|
1124
|
+
partial = true;
|
|
1125
|
+
return null;
|
|
1126
|
+
}
|
|
1013
1127
|
const total = simulate(ctx, [...group, c], view.taken).score;
|
|
1014
1128
|
const gain = round2((total - current) * contestFactor(c));
|
|
1015
1129
|
if (!best ||
|
|
@@ -1050,6 +1164,10 @@ function planCore(input, friendlyIds = []) {
|
|
|
1050
1164
|
// before the caller relaxes the limit (as the single-seed search did; #143).
|
|
1051
1165
|
if (!best)
|
|
1052
1166
|
for (const seed of seeds.slice(MAX_SEEDS)) {
|
|
1167
|
+
if (expired()) {
|
|
1168
|
+
partial = true;
|
|
1169
|
+
break;
|
|
1170
|
+
}
|
|
1053
1171
|
const group = tryGroup(view, pool, size, seed, hop);
|
|
1054
1172
|
if (group)
|
|
1055
1173
|
return group;
|
|
@@ -1063,6 +1181,14 @@ function planCore(input, friendlyIds = []) {
|
|
|
1063
1181
|
const byScore = (a, b) => score(b) - score(a) || a - b;
|
|
1064
1182
|
const groupScore = (ids) => simulate(ctx, ids, view.taken).score;
|
|
1065
1183
|
const seeds = [...pool].sort(byScore);
|
|
1184
|
+
// Every territory is dealt: a compact group answers nothing the game asks, so the best picks by score.
|
|
1185
|
+
if (input.fullDeal)
|
|
1186
|
+
return seeds.slice(0, size).sort(byScore);
|
|
1187
|
+
// Out of time: the best picks by score, no search for a compact group.
|
|
1188
|
+
if (expired()) {
|
|
1189
|
+
partial = true;
|
|
1190
|
+
return seeds.slice(0, size).sort(byScore);
|
|
1191
|
+
}
|
|
1066
1192
|
if (size === 1) {
|
|
1067
1193
|
if (!away.length)
|
|
1068
1194
|
return [seeds[0]];
|
|
@@ -1080,6 +1206,11 @@ function planCore(input, friendlyIds = []) {
|
|
|
1080
1206
|
if (a < b && hops(a, b) < Infinity)
|
|
1081
1207
|
widest = Math.max(widest, hops(a, b));
|
|
1082
1208
|
for (let hop = COMPACT_DISTANCE;; hop++) {
|
|
1209
|
+
// Out of time between hop limits: the best picks by score, as at the start.
|
|
1210
|
+
if (expired()) {
|
|
1211
|
+
partial = true;
|
|
1212
|
+
return seeds.slice(0, size).sort(byScore);
|
|
1213
|
+
}
|
|
1083
1214
|
// Past every connected distance (and never at the compact limit itself): the
|
|
1084
1215
|
// last try allows any distance, so it is a recorded relaxation, not "compact".
|
|
1085
1216
|
const last = hop > Math.max(widest, COMPACT_DISTANCE);
|
|
@@ -1122,11 +1253,11 @@ function planCore(input, friendlyIds = []) {
|
|
|
1122
1253
|
return group.sort(byScore);
|
|
1123
1254
|
}
|
|
1124
1255
|
};
|
|
1125
|
-
const primarySize = Math.min(limit, maxPicks,
|
|
1256
|
+
const primarySize = Math.min(limit, maxPicks, cands.length);
|
|
1126
1257
|
if (pickable.length < limit)
|
|
1127
1258
|
warnings.push(`Only ${pickable.length} pickable territor${pickable.length === 1 ? 'y' : 'ies'} for a limit of ${limit}: the list has no full fallback.`);
|
|
1128
|
-
const primary = buildGroup(firstView,
|
|
1129
|
-
let rest =
|
|
1259
|
+
const primary = buildGroup(firstView, cands, primarySize, 'primary');
|
|
1260
|
+
let rest = cands.filter((t) => !primary.includes(t));
|
|
1130
1261
|
// Commanders (#129): the first pick awarded carries the commander, so the primary's safest
|
|
1131
1262
|
// pick goes first — the fewest other pickable territories (where other players may start)
|
|
1132
1263
|
// within COMPACT_DISTANCE hops, then the fewest neighbours outside the primary, then score.
|
|
@@ -1234,6 +1365,18 @@ function planCore(input, friendlyIds = []) {
|
|
|
1234
1365
|
add(answerTier(order, out.firstView, others), out.firstView);
|
|
1235
1366
|
}
|
|
1236
1367
|
while (done < fallbackSize && pool.length) {
|
|
1368
|
+
// Out of time, or every territory is dealt: the rest of the list is the best remaining picks by their first score.
|
|
1369
|
+
if (input.fullDeal || expired()) {
|
|
1370
|
+
if (!input.fullDeal)
|
|
1371
|
+
partial = true;
|
|
1372
|
+
if (!out.tiers.length)
|
|
1373
|
+
out.firstView = firstView;
|
|
1374
|
+
const score = (t) => firstView.of.get(t)?.score ?? 0;
|
|
1375
|
+
const tier = [...pool].sort((a, b) => score(b) - score(a) || a - b).slice(0, fallbackSize - done);
|
|
1376
|
+
if (tier.length)
|
|
1377
|
+
add(tier, firstView);
|
|
1378
|
+
break;
|
|
1379
|
+
}
|
|
1237
1380
|
const view = viewOf(pool, new Set([...order, ...out.tiers.flat()]));
|
|
1238
1381
|
if (!out.tiers.length)
|
|
1239
1382
|
out.firstView = view;
|
|
@@ -1260,26 +1403,28 @@ function planCore(input, friendlyIds = []) {
|
|
|
1260
1403
|
pair = [a, b];
|
|
1261
1404
|
}
|
|
1262
1405
|
}
|
|
1263
|
-
// The longest step needed to link every pick into one cluster (minimax spanning tree
|
|
1406
|
+
// The longest step needed to link every pick into one cluster (minimax spanning tree; Prim with each pick's
|
|
1407
|
+
// nearest tree member kept, so n² hops, not n³ — the 3,000-pick list of a full distribution took minutes).
|
|
1264
1408
|
let link = 0;
|
|
1265
1409
|
if (ids.length > 1) {
|
|
1266
|
-
const
|
|
1267
|
-
|
|
1268
|
-
|
|
1410
|
+
const near = new Map();
|
|
1411
|
+
for (const a of ids.slice(1))
|
|
1412
|
+
near.set(a, hops(a, ids[0]));
|
|
1413
|
+
while (near.size) {
|
|
1269
1414
|
let next = -1;
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
if (next < 0 || d < step) {
|
|
1276
|
-
step = d;
|
|
1277
|
-
next = a;
|
|
1278
|
-
}
|
|
1415
|
+
let step = Infinity;
|
|
1416
|
+
for (const [a, d] of near)
|
|
1417
|
+
if (next < 0 || d < step) {
|
|
1418
|
+
step = d;
|
|
1419
|
+
next = a;
|
|
1279
1420
|
}
|
|
1280
|
-
|
|
1281
|
-
inTree.add(next);
|
|
1421
|
+
near.delete(next);
|
|
1282
1422
|
link = Math.max(link, step);
|
|
1423
|
+
for (const [a, d] of near) {
|
|
1424
|
+
const viaNext = hops(a, next);
|
|
1425
|
+
if (viaNext < d)
|
|
1426
|
+
near.set(a, viaNext);
|
|
1427
|
+
}
|
|
1283
1428
|
}
|
|
1284
1429
|
}
|
|
1285
1430
|
return { far, pair, link };
|
|
@@ -1319,7 +1464,7 @@ function planCore(input, friendlyIds = []) {
|
|
|
1319
1464
|
if (!spread && tier.length > 1 && tier.length === primary.length && spreadOf(tier).link <= COMPACT_DISTANCE && now > was) {
|
|
1320
1465
|
const byFirst = (a, b) => firstView.of.get(b).score - firstView.of.get(a).score || a - b;
|
|
1321
1466
|
primary.splice(0, primary.length, ...[...tier].sort(byFirst));
|
|
1322
|
-
rest =
|
|
1467
|
+
rest = cands.filter((t) => !primary.includes(t));
|
|
1323
1468
|
if (relaxedTo.delete('primary')) {
|
|
1324
1469
|
for (let i = warnings.length - 1; i >= 0; i--)
|
|
1325
1470
|
if (warnings[i].startsWith('No compact primary group'))
|
|
@@ -1390,6 +1535,89 @@ function planCore(input, friendlyIds = []) {
|
|
|
1390
1535
|
reordered,
|
|
1391
1536
|
};
|
|
1392
1537
|
}
|
|
1538
|
+
// #429: a primary pick below the first is granted, more often than not, with a pick above it gone to the
|
|
1539
|
+
// opponent — and the greedy group search chose it for the joint opening, so it may only pay beside that pick
|
|
1540
|
+
// (live: picks that only worked beside the top one, which went to the opponent). In a two-player game with an
|
|
1541
|
+
// answering fallback, when the list looks fragile (the fallback outscores the primary, or the worst award
|
|
1542
|
+
// outcome is under FRAGILE_WORST of the primary's own score), each primary pick 2…n is scored in the outcomes
|
|
1543
|
+
// that grant it with a pick above it lost, as an answering fallback pick is (my opening less OPPONENT_WEIGHT ×
|
|
1544
|
+
// the opponent's from the picks lost). A pick off the primary that scores more there and keeps the primary as
|
|
1545
|
+
// compact as it was takes its place (the pick it replaces drops to its slot), and the swap stands only when the
|
|
1546
|
+
// list, its fallback built again, has a better worst outcome than the award order's (after any reorder) and a
|
|
1547
|
+
// better mean outcome, and the primary keeps PRIMARY_FLOOR of its original joint score.
|
|
1548
|
+
let nominal = 0;
|
|
1549
|
+
const replaced = [];
|
|
1550
|
+
if (answerSets && award && outcomeSets?.length && !expired()) {
|
|
1551
|
+
const n = primary.length;
|
|
1552
|
+
const listNow = () => [...primary, ...listed.tiers.flat()];
|
|
1553
|
+
let worstNow = award.worst.score;
|
|
1554
|
+
const meanOf = (list) => round2(outcomeSets.reduce((sum, set) => sum + outcomeScore(list, set.map((i) => list[i])), 0) / outcomeSets.length);
|
|
1555
|
+
let meanNow = meanOf(listNow());
|
|
1556
|
+
nominal = round2(simScore(primary, []));
|
|
1557
|
+
const fallbackScore = round2(simScore(listed.tiers[0] ?? [], primary));
|
|
1558
|
+
if (fallbackScore > nominal || worstNow < FRAGILE_WORST * nominal) {
|
|
1559
|
+
const compactLink = Math.max(COMPACT_DISTANCE, spreadOf(primary).link);
|
|
1560
|
+
for (let k = 1; k < n; k++) {
|
|
1561
|
+
// The outcomes (of a list of 2n) that grant position k with a position above it lost.
|
|
1562
|
+
const sets = answerSets.filter((o) => o.includes(k) && o.filter((i) => i < k).length < k);
|
|
1563
|
+
if (!sets.length)
|
|
1564
|
+
continue;
|
|
1565
|
+
const base = listNow().slice(0, 2 * n);
|
|
1566
|
+
/** Mean over those outcomes of my opening less OPPONENT_WEIGHT × the opponent's, `list` laid on the positions. */
|
|
1567
|
+
const netOf = (list) => {
|
|
1568
|
+
let sum = 0;
|
|
1569
|
+
for (const o of sets) {
|
|
1570
|
+
const granted = o.map((i) => list[i]);
|
|
1571
|
+
const last = o[o.length - 1];
|
|
1572
|
+
const lost = list.slice(0, last).filter((_, i) => !o.includes(i));
|
|
1573
|
+
sum += simScore(granted, lost) - OPPONENT_WEIGHT * simScore(lost, granted);
|
|
1574
|
+
}
|
|
1575
|
+
return round2(sum / sets.length);
|
|
1576
|
+
};
|
|
1577
|
+
/** The list with `x` at position k; the pick there drops to x's slot when x was listed. */
|
|
1578
|
+
const swapped = (x) => base.map((t, i) => (i === k ? x : t === x ? base[k] : t));
|
|
1579
|
+
const incumbent = netOf(base);
|
|
1580
|
+
let best = null;
|
|
1581
|
+
for (const x of cands) {
|
|
1582
|
+
if (primary.includes(x))
|
|
1583
|
+
continue;
|
|
1584
|
+
const next = primary.map((t, i) => (i === k ? x : t));
|
|
1585
|
+
if (spreadOf(next).link > compactLink)
|
|
1586
|
+
continue;
|
|
1587
|
+
const value = netOf(swapped(x));
|
|
1588
|
+
if (value > incumbent && (!best || value > best.value || (value === best.value && x < best.t)))
|
|
1589
|
+
best = { t: x, value };
|
|
1590
|
+
}
|
|
1591
|
+
if (!best)
|
|
1592
|
+
continue;
|
|
1593
|
+
const nextPrimary = primary.map((t, i) => (i === k ? best.t : t));
|
|
1594
|
+
// The owner's floor (2026-11-22): the intact start may cost at most a fifth of the original primary's joint
|
|
1595
|
+
// score — the mean below counts every award outcome once, most of them losses, and alone it accepted a
|
|
1596
|
+
// swap that halved the start (a 42-territory map: 3.75 to 1.80).
|
|
1597
|
+
if (simScore(nextPrimary, []) < PRIMARY_FLOOR * nominal)
|
|
1598
|
+
continue;
|
|
1599
|
+
const nextListed = buildFallback(nextPrimary, cands.filter((t) => !nextPrimary.includes(t)));
|
|
1600
|
+
const nextWorst = worstOf([...nextPrimary, ...nextListed.tiers.flat()], outcomeSets);
|
|
1601
|
+
const w = nextWorst.score;
|
|
1602
|
+
// Not at any price: the list's mean outcome (every set the award can grant, each once) must rise too, or
|
|
1603
|
+
// a pick that is only good alone would trade the intact start away for a slightly better worst case.
|
|
1604
|
+
const meanNext = meanOf([...nextPrimary, ...nextListed.tiers.flat()]);
|
|
1605
|
+
if (w <= worstNow || meanNext <= meanNow)
|
|
1606
|
+
continue;
|
|
1607
|
+
replaced.push({ position: k + 1, was: primary[k], now: best.t, wasValue: incumbent, nowValue: best.value, outcomes: sets.length, worst: [worstNow, w], mean: [meanNow, meanNext] });
|
|
1608
|
+
primary.splice(k, 1, best.t);
|
|
1609
|
+
rest = cands.filter((t) => !primary.includes(t));
|
|
1610
|
+
listed = nextListed;
|
|
1611
|
+
worstNow = w;
|
|
1612
|
+
meanNow = meanNext;
|
|
1613
|
+
award.worst = { ...nextWorst, opponentStarts: impliedOpponentStarts(listNow(), nextWorst.territoryIds) };
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
for (const r of replaced)
|
|
1618
|
+
warnings.push(`Primary pick ${r.position} is ${terrName(r.now)}, not ${terrName(r.was)}: in the ${r.outcomes} award outcomes that grant it with a pick above it ` +
|
|
1619
|
+
`lost to the opponent, ${terrName(r.was)} nets ${r.wasValue} and ${terrName(r.now)} ${r.nowValue}, and the list's worst outcome rises from ` +
|
|
1620
|
+
`${r.worst[0]} to ${r.worst[1]}, its mean outcome from ${r.mean[0]} to ${r.mean[1]} (#429). The primary's joint score is ${round2(simScore(primary, []))}, against ${nominal} before; weigh it before submitting.`);
|
|
1393
1621
|
const { tiers } = listed;
|
|
1394
1622
|
const fallback = tiers.flat();
|
|
1395
1623
|
const firstTier = tiers[0] ?? [];
|
|
@@ -1547,13 +1775,13 @@ function planCore(input, friendlyIds = []) {
|
|
|
1547
1775
|
let alternative;
|
|
1548
1776
|
if (players === 2 && !spread && primary.length >= 2) {
|
|
1549
1777
|
const score = (t) => firstView.of.get(t).score;
|
|
1550
|
-
const seeds = [...
|
|
1551
|
-
const pair = bestGroup(firstView,
|
|
1778
|
+
const seeds = [...cands].sort((a, b) => score(b) - score(a) || a - b);
|
|
1779
|
+
const pair = bestGroup(firstView, cands, 2, seeds, COMPACT_DISTANCE);
|
|
1552
1780
|
if (pair) {
|
|
1553
1781
|
const alt = [...pair].sort((a, b) => score(b) - score(a) || a - b);
|
|
1554
1782
|
while (alt.length < primary.length) {
|
|
1555
1783
|
let best = null;
|
|
1556
|
-
for (const c of
|
|
1784
|
+
for (const c of cands) {
|
|
1557
1785
|
if (alt.includes(c))
|
|
1558
1786
|
continue;
|
|
1559
1787
|
const covered = coverageOf([...alt, c]).covered;
|
|
@@ -1572,7 +1800,7 @@ function planCore(input, friendlyIds = []) {
|
|
|
1572
1800
|
const altCoverage = coverageOf(alt);
|
|
1573
1801
|
const same = alt.length === primary.length && alt.every((t) => primary.includes(t));
|
|
1574
1802
|
if (!same && altCoverage.covered > primaryCoverage.covered) {
|
|
1575
|
-
const altFallback = buildFallback(alt,
|
|
1803
|
+
const altFallback = buildFallback(alt, cands.filter((t) => !alt.includes(t))).tiers.flat();
|
|
1576
1804
|
alternative = {
|
|
1577
1805
|
group: groupOf(alt, NO_TAKEN),
|
|
1578
1806
|
coverage: altCoverage,
|
|
@@ -1587,6 +1815,8 @@ function planCore(input, friendlyIds = []) {
|
|
|
1587
1815
|
}
|
|
1588
1816
|
}
|
|
1589
1817
|
}
|
|
1818
|
+
if (partial)
|
|
1819
|
+
warnings.push(`The ${input.budgetMs} ms time budget ran out: the list is valid, but its later groups are the best remaining picks by score, not a searched compact group.`);
|
|
1590
1820
|
const plain = { ...ctx, friendly: NO_TAKEN };
|
|
1591
1821
|
return {
|
|
1592
1822
|
plan: {
|
|
@@ -1599,6 +1829,9 @@ function planCore(input, friendlyIds = []) {
|
|
|
1599
1829
|
...(alternative ? { alternative } : {}),
|
|
1600
1830
|
warnings,
|
|
1601
1831
|
rationale,
|
|
1832
|
+
...(partial ? { partial: true } : {}),
|
|
1833
|
+
...(candidateReport ? { candidates: candidateReport } : {}),
|
|
1834
|
+
...(input.evaluate ? { evaluated: round2(simulate(ctx, [...input.evaluate], NO_TAKEN).score) } : {}),
|
|
1602
1835
|
},
|
|
1603
1836
|
completes: (start, taken) => new Set(simulate(plain, start, new Set(taken)).completions.keys()),
|
|
1604
1837
|
bonuses,
|
|
@@ -21,18 +21,43 @@ export function plainEconomy(pc, tgt, id, gain) {
|
|
|
21
21
|
return null;
|
|
22
22
|
const lost = straightKills(pc.defenceAt(id), pc.rates.defensiveKillRate);
|
|
23
23
|
const worth = pc.plainWorth(id, gain);
|
|
24
|
-
return (worth > 0 ? lost > pc.
|
|
24
|
+
return (worth > 0 ? lost > pc.capturePaybackTurns * worth : lost > PLAIN_EXPANSION_LOSS) ? { lost, worth } : null;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* #426: a neutral in view whose defenders kill none of my attackers (0 armies at the usual 70% defensive
|
|
28
|
+
* rate): its capture costs only the armies that land on it, which stay mine. Live (a guard-off game of
|
|
29
|
+
* 0-army neutrals, turn 4), 25 of them beside idle stacks were skipped as members of bonuses too costly to
|
|
30
|
+
* finish, though a bonus's cost says nothing about a territory that loses nothing. Never a negative
|
|
31
|
+
* bonus's member (it would cut income).
|
|
32
|
+
*/
|
|
33
|
+
export function noLossNeutral(pc, tgt, id) {
|
|
34
|
+
const st = pc.territories.get(id);
|
|
35
|
+
return (st?.owner.kind === 'neutral' &&
|
|
36
|
+
st.armies !== null &&
|
|
37
|
+
!tgt.negativeMember.has(id) &&
|
|
38
|
+
straightKills(pc.defenceAt(id), pc.rates.defensiveKillRate) === 0);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* #426: whether pass 3 takes `id` only as a no-loss capture ({@link noLossNeutral}): a member of an
|
|
42
|
+
* uneconomic bonus no other exemption lets through. Its reason line says so.
|
|
43
|
+
*/
|
|
44
|
+
export function onlyNoLoss(pc, tgt, id) {
|
|
45
|
+
return tgt.uneconomicMember.has(id) && !tgt.economicMember.has(id) && !plainEligible(pc, tgt, id, false, false) && noLossNeutral(pc, tgt, id);
|
|
25
46
|
}
|
|
26
47
|
/**
|
|
27
48
|
* Pass 3's eligibility (#125): not a player's under `balanced` (but #281's empty enemy territory), and
|
|
28
49
|
* not only a member of an uneconomic bonus (but #281's denial: what it denies the opponent beside it is
|
|
29
|
-
* its worth, not my bonus
|
|
50
|
+
* its worth, not my bonus; #417's land a static seat left, outside a negative bonus: the breach force
|
|
51
|
+
* takes it while it is up for taking; and #426's no-loss neutral). `noLoss` false leaves #426 out.
|
|
30
52
|
*/
|
|
31
|
-
export function plainEligible(pc, tgt, id, enemy) {
|
|
53
|
+
export function plainEligible(pc, tgt, id, enemy, noLoss = true) {
|
|
32
54
|
return (!(pc.balanced && enemy && !tgt.emptyEnemies.has(id)) &&
|
|
33
55
|
(tgt.economicMember.has(id) ||
|
|
34
56
|
!tgt.uneconomicMember.has(id) ||
|
|
35
57
|
tgt.denials.has(id) ||
|
|
58
|
+
(noLoss && noLossNeutral(pc, tgt, id)) ||
|
|
59
|
+
// #417, the breach force: land a static seat left is taken while it is up for taking.
|
|
60
|
+
(pc.vacated.has(id) && !tgt.negativeMember.has(id)) ||
|
|
36
61
|
(pc.territoryShare(1) > 0 && !tgt.negativeMember.has(id))));
|
|
37
62
|
}
|
|
38
63
|
/**
|