@chrischall/warapp-mcp 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +3 -3
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +133 -8
- package/dist/analysis/accept-surrender.js +20 -2
- package/dist/analysis/calibrate.js +1 -0
- package/dist/analysis/card-support.js +177 -17
- package/dist/analysis/card-threats.js +126 -14
- package/dist/analysis/chat-advice.js +182 -0
- package/dist/analysis/chat-blocks.js +106 -0
- package/dist/analysis/chat-intent.js +559 -0
- package/dist/analysis/chat-read.js +159 -0
- package/dist/analysis/decision-replay.js +279 -0
- package/dist/analysis/decision-truth.js +146 -0
- package/dist/analysis/finished-game.js +62 -3
- package/dist/analysis/game-lessons.js +15 -10
- package/dist/analysis/hold-diff.js +3 -1
- package/dist/analysis/income-trend.js +38 -0
- package/dist/analysis/intel.js +75 -0
- package/dist/analysis/opens.js +64 -0
- package/dist/analysis/opponent-profile.js +121 -10
- package/dist/analysis/opponents.js +246 -20
- package/dist/analysis/outlook.js +360 -15
- package/dist/analysis/picks.js +91 -12
- package/dist/analysis/plan/after-leftover.js +4 -1
- package/dist/analysis/plan/bonus-attempts.js +105 -0
- package/dist/analysis/plan/capture-instead.js +116 -0
- package/dist/analysis/plan/captures.js +49 -7
- package/dist/analysis/plan/conceded-out.js +13 -2
- package/dist/analysis/plan/estimates.js +203 -30
- package/dist/analysis/plan/guard-off.js +2 -1
- package/dist/analysis/plan/holds.js +110 -9
- package/dist/analysis/plan/jabs.js +113 -0
- package/dist/analysis/plan/leftover.js +393 -8
- package/dist/analysis/plan/orders.js +76 -4
- package/dist/analysis/plan/relations.js +135 -2
- package/dist/analysis/plan/report.js +69 -3
- package/dist/analysis/plan/second-sizing.js +133 -0
- package/dist/analysis/plan/shared.js +279 -27
- package/dist/analysis/plan/siege.js +303 -0
- package/dist/analysis/plan/stand-still.js +9 -5
- package/dist/analysis/plan/state.js +8 -0
- package/dist/analysis/plan/stockpile.js +104 -0
- package/dist/analysis/plan/strike.js +39 -7
- package/dist/analysis/plan/targets.js +256 -110
- package/dist/analysis/plan/threats.js +148 -10
- package/dist/analysis/plan/transfers.js +57 -6
- package/dist/analysis/plan/two-move.js +70 -0
- package/dist/analysis/plan/vacated.js +124 -2
- package/dist/analysis/planner.js +527 -49
- package/dist/analysis/profile.js +13 -2
- package/dist/analysis/since-last.js +18 -5
- package/dist/analysis/stress.js +8 -2
- package/dist/board.js +36 -2
- package/dist/bonus-attempt-store.js +55 -0
- package/dist/build-id.js +106 -0
- package/dist/bundle.js +54138 -41059
- package/dist/cards.js +7 -5
- package/dist/chat-automation.js +22 -0
- package/dist/chat.js +35 -1
- package/dist/client.js +14 -0
- package/dist/commerce.js +111 -0
- package/dist/decision-log.js +1093 -0
- package/dist/finished-store.js +5 -1
- package/dist/index.js +9 -1
- package/dist/lessons-store.js +322 -21
- package/dist/live.js +43 -0
- package/dist/move-order.js +64 -3
- package/dist/normalize.js +17 -0
- package/dist/open-games.js +36 -16
- package/dist/outlook-log.js +42 -1
- package/dist/profile-store.js +12 -2
- package/dist/protocol/methods.js +62 -5
- package/dist/protocol/rpc.js +8 -0
- package/dist/relations-store.js +38 -4
- package/dist/review-export.js +198 -0
- package/dist/siege-store.js +49 -0
- package/dist/state-bundle.js +584 -0
- package/dist/state-cli.js +71 -0
- package/dist/strategy/notes.js +56 -0
- package/dist/team-cards.js +25 -0
- package/dist/tools/accept-surrender.js +23 -9
- package/dist/tools/award.js +20 -2
- package/dist/tools/card-advice.js +93 -28
- package/dist/tools/card-plays.js +2 -2
- package/dist/tools/card-support-advice.js +37 -7
- package/dist/tools/chat-advice.js +330 -0
- package/dist/tools/chat-inbox.js +19 -4
- package/dist/tools/chat.js +106 -17
- package/dist/tools/check-plan.js +68 -12
- package/dist/tools/commerce-deploy.js +33 -0
- package/dist/tools/common.js +31 -0
- package/dist/tools/decision-capture.js +459 -0
- package/dist/tools/end-of-game.js +151 -21
- package/dist/tools/game-kind.js +92 -0
- package/dist/tools/how-lost.js +7 -2
- package/dist/tools/index.js +10 -0
- package/dist/tools/join-game.js +10 -4
- package/dist/tools/live-context.js +6 -0
- package/dist/tools/live.js +10 -1
- package/dist/tools/map-curves.js +73 -0
- package/dist/tools/notifications.js +4 -3
- package/dist/tools/opponents.js +2 -0
- package/dist/tools/past-games.js +74 -8
- package/dist/tools/picks.js +61 -10
- package/dist/tools/profile-hook.js +62 -3
- package/dist/tools/profile-opponents.js +4 -0
- package/dist/tools/push.js +2 -2
- package/dist/tools/relations.js +139 -0
- package/dist/tools/scout.js +16 -2
- package/dist/tools/state.js +232 -0
- package/dist/tools/strategy.js +3 -3
- package/dist/tools/stress-opponents.js +7 -2
- package/dist/tools/surrender-pending.js +10 -1
- package/dist/tools/surrender.js +18 -3
- package/dist/tools/survival.js +11 -3
- package/dist/tools/team-brief.js +2 -2
- package/dist/tools/team.js +12 -3
- package/dist/tools/turn.js +643 -76
- package/dist/tools/where.js +3 -1
- package/dist/version.js +1 -1
- package/manifest.json +32 -3
- package/mint.yaml +37 -4
- package/package.json +4 -4
- package/server.json +20 -2
- package/skills/warapp-mcp/SKILL.md +73 -17
package/dist/analysis/outlook.js
CHANGED
|
@@ -83,6 +83,27 @@
|
|
|
83
83
|
// LOW_COVERAGE, or none measured, under fog is thin evidence, and the basis says "even" is then not safe.
|
|
84
84
|
// Reporting only: the state never reads it.
|
|
85
85
|
//
|
|
86
|
+
// #436 (owner decision of 2026-11-20): the outlook follows both incomes and their trend. Each turn reads my
|
|
87
|
+
// side's income against the strongest opponent side's income (`income`): its range under fog — `low` the
|
|
88
|
+
// income the tracker reads (its visible income at least), `high` the most the likely high lets it earn a turn
|
|
89
|
+
// while its frontier read is thin (else `low`) — and its ESTIMATE, the tracked figure divided by the
|
|
90
|
+
// estimate ÷ truth past games measured in its coverage band (`calibration`, from lessons.json, a band with
|
|
91
|
+
// at least MIN_CALIBRATION_SAMPLES), never below its visible income; uncalibrated, the tracked figure. Its
|
|
92
|
+
// lean: `unknown` when the range spans both thresholds (mine ÷ high at most INCOME_BEHIND_RATIO and mine ÷
|
|
93
|
+
// low at least INCOME_AHEAD_RATIO), `behind` / `ahead` when the whole range, else the estimate, is past one,
|
|
94
|
+
// else `even` — unless each side's income, moved one more turn at its change per turn over the turns judged
|
|
95
|
+
// (`trend`), crosses a threshold the ratio is already heading to (`byTrend`). No lead is claimed at low
|
|
96
|
+
// coverage (any opponent's evidence thin, #304): an `ahead` lean reads `unknown`, and a win on the likely
|
|
97
|
+
// high alone is not read (`noLeadClaim`); a win on the bound still is. #454: the state keeps its four values
|
|
98
|
+
// (winning, losing, even, stalemate — the tool contract); a lean (`ahead`, `behind` or `unknown`) beside an
|
|
99
|
+
// `even` state rides in the additive `lean` field, per turn and on the outlook, and every internal reader of the
|
|
100
|
+
// finer reading uses {@link readingOf}; the planner acts on winning and losing only (#201). `pace` is the income line: both incomes and
|
|
101
|
+
// their change per turn over the turns judged. `surrenderLine` is ADVICE ONLY (the server never acts on it):
|
|
102
|
+
// crossed when my income stayed under INCOME_BEHIND_RATIO × the strongest's estimate for SURRENDER_TURNS
|
|
103
|
+
// consecutive turns and no bonus in reach closes the gap (`bonusesInReach`: a positive bonus I do not hold
|
|
104
|
+
// whose every missing member borders my land and whose visible defenders are fewer than my armies beside them
|
|
105
|
+
// plus my income; it closes the gap when my income plus its value reaches the line).
|
|
106
|
+
//
|
|
86
107
|
// OUTLOOK_RATIO (2.4×) is borrowed from a published bot's "lost" rule and has never been measured
|
|
87
108
|
// for war.app: the outlook is a basis for a decision, not a verdict. The planner acts on it in one
|
|
88
109
|
// way only (#201): once winning or losing, its payback tests count the turns the game has left.
|
|
@@ -99,6 +120,7 @@ import { BEHIND_RATIO, STRENGTH_INCOME_TURNS } from './profile.js';
|
|
|
99
120
|
import { FORECAST_TURNS, forecastBorder, mainFront } from './exchange.js';
|
|
100
121
|
import { specialUnitStrength } from './combat.js';
|
|
101
122
|
import { coverageText, LOW_COVERAGE } from './plan/shared.js';
|
|
123
|
+
import { coverageBucket } from './game-lessons.js';
|
|
102
124
|
/** Turns a state must hold before it is reported. */
|
|
103
125
|
export const OUTLOOK_TURNS = 3;
|
|
104
126
|
/** Winning at this strength ratio or more, losing at its inverse or less (borrowed, unmeasured). */
|
|
@@ -121,6 +143,30 @@ export const LIKELY_LOSING_RATIO = 1 / (OUTLOOK_RATIO * LIKELY_INCOME_MARGIN);
|
|
|
121
143
|
export function peerPace(p) {
|
|
122
144
|
return Math.max(p.floor ?? 0, Math.min(p.ceiling, Math.max(p.base, LIKELY_INCOME_MARGIN * Math.max(p.mine, p.peers))));
|
|
123
145
|
}
|
|
146
|
+
const STATES = new Set(['winning', 'losing', 'even', 'stalemate']);
|
|
147
|
+
const LEANS = new Set(['ahead', 'behind', 'unknown']);
|
|
148
|
+
/** #454: the finer reading of a state and its lean (`null`: no state). */
|
|
149
|
+
export function readingOf(o) {
|
|
150
|
+
return o.lean ?? o.state;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* #454: a reading split back into the contract's state and the additive lean. #453 wrote the lean as the state
|
|
154
|
+
* for a few hours (outlook log, decision log, finished records): `ahead`, `behind` and `unknown` read as `even`
|
|
155
|
+
* — exact, since a lean only ever replaced an even state — with that lean. An unrecognised value reads `null`.
|
|
156
|
+
*/
|
|
157
|
+
export function splitReading(r) {
|
|
158
|
+
if (typeof r === 'string' && LEANS.has(r))
|
|
159
|
+
return { state: 'even', lean: r };
|
|
160
|
+
return { state: typeof r === 'string' && STATES.has(r) ? r : null };
|
|
161
|
+
}
|
|
162
|
+
/** #436: behind on incomes at this share of the strongest opponent's or less — the owner's surrender line (two-thirds). */
|
|
163
|
+
export const INCOME_BEHIND_RATIO = 2 / 3;
|
|
164
|
+
/** #436: ahead on incomes at this multiple of the strongest opponent's or more (the line's inverse). */
|
|
165
|
+
export const INCOME_AHEAD_RATIO = 1.5;
|
|
166
|
+
/** #436: consecutive turns under the line before the surrender line is crossed (owner). */
|
|
167
|
+
export const SURRENDER_TURNS = 3;
|
|
168
|
+
/** #436: the samples a coverage band needs before its estimate ÷ truth calibrates an estimate (unmeasured). */
|
|
169
|
+
export const MIN_CALIBRATION_SAMPLES = 5;
|
|
124
170
|
const round2 = (n) => Math.round(n * 100) / 100;
|
|
125
171
|
/** The armies the special units on a territory fight as (commanders), as the planner counts them. */
|
|
126
172
|
const unitsOn = (b, id) => specialUnitStrength(b.territories.find((t) => t.territoryId === id)?.specialUnits);
|
|
@@ -341,14 +387,15 @@ export function gameOutlook(input) {
|
|
|
341
387
|
const seen = { armies: a, income };
|
|
342
388
|
const none = { likely: undefined, source: undefined, why: undefined };
|
|
343
389
|
if (open)
|
|
344
|
-
return { playerId, low, high: low, seen, ...none };
|
|
390
|
+
return { playerId, low, high: low, seen, paceIncome: income, capIncome: income, ...none };
|
|
391
|
+
// #436: the most it could earn this turn (never below what it visibly earns): no income estimate exceeds it.
|
|
392
|
+
const cap = Math.max(income, turnCap(turn, playerId));
|
|
345
393
|
if (start === null || likelyStart === null || cardsBound === undefined)
|
|
346
|
-
return { playerId, low, high: null, seen, ...none };
|
|
394
|
+
return { playerId, low, high: null, seen, paceIncome: cap, capIncome: cap, ...none };
|
|
347
395
|
// Each turn's could-earn cap: from that turn's board when I have it, else the ceiling.
|
|
348
396
|
let received = start;
|
|
349
397
|
for (let t = 1; t <= turn; t++)
|
|
350
398
|
received += turnCap(t, playerId);
|
|
351
|
-
const cap = Math.max(income, turnCap(turn, playerId));
|
|
352
399
|
// Cards: what the clock lets it have played by now, and over the next k turns.
|
|
353
400
|
const now = cardsBound ? cardArmiesBy(cardsBound, turn) : 0;
|
|
354
401
|
const ahead = cardsBound ? cardArmiesBy(cardsBound, turn + k) - now : 0;
|
|
@@ -378,7 +425,9 @@ export function gameOutlook(input) {
|
|
|
378
425
|
for (let t = last.turn + 1; t <= turn; t++)
|
|
379
426
|
since += Math.min(turnCap(t, playerId), paceAt(t));
|
|
380
427
|
const likely = Math.max(a, likelyReceived + now, since) + k * Math.max(income, last?.income ?? 0, Math.min(cap, pace)) + ahead;
|
|
381
|
-
|
|
428
|
+
// #436: the most it likely earns a turn, as the likely high counts it.
|
|
429
|
+
const paceIncome = Math.max(income, last?.income ?? 0, Math.min(cap, pace));
|
|
430
|
+
return { playerId, low, high, seen, paceIncome, capIncome: cap, likely: Math.min(high, Math.max(low, likely)), source, why };
|
|
382
431
|
});
|
|
383
432
|
// PLAN-TEAMS C3: an enemy team is one side, its figures summed; elsewhere a side is a player.
|
|
384
433
|
const teamOf = (p) => {
|
|
@@ -567,7 +616,125 @@ export function gameOutlook(input) {
|
|
|
567
616
|
opponents: evidenceRows,
|
|
568
617
|
thin: evidenceRows.some((r) => r.thin),
|
|
569
618
|
};
|
|
570
|
-
|
|
619
|
+
// #436: each opponent's income range and estimate, summed per side; the strongest side by estimate.
|
|
620
|
+
const calibrationFor = (share) => {
|
|
621
|
+
const c = input.calibration?.[coverageBucket(share)];
|
|
622
|
+
return c && c.n >= MIN_CALIBRATION_SAMPLES && c.geoMean > 0 ? c.geoMean : undefined;
|
|
623
|
+
};
|
|
624
|
+
const incomeSides = new Map();
|
|
625
|
+
for (const r of rows) {
|
|
626
|
+
const tr = trackedOf(r.playerId);
|
|
627
|
+
const row = evidenceRows.find((x) => x.playerId === r.playerId);
|
|
628
|
+
const low = row.income;
|
|
629
|
+
const factor = tr?.income != null ? calibrationFor(tr.coverage?.share ?? null) : undefined;
|
|
630
|
+
// The calibrated estimate and the top of the range never pass what it could earn this turn (`capIncome`, the
|
|
631
|
+
// bound `paceIncome` keeps to): dividing a low-coverage reading by ~0.3 must not read an income it cannot reach.
|
|
632
|
+
const capped = (n) => Math.min(Math.max(r.capIncome, low), n);
|
|
633
|
+
const estimate = open ? low : factor !== undefined ? capped(Math.max(r.seen.income, Math.round(tr.income / factor))) : low;
|
|
634
|
+
const high = open ? low : capped(Math.max(estimate, low, row.thin ? r.paceIncome : low));
|
|
635
|
+
const t = teamOf(r.playerId);
|
|
636
|
+
const key = t === undefined ? `p${r.playerId}` : `t${t}`;
|
|
637
|
+
const side = incomeSides.get(key);
|
|
638
|
+
if (!side)
|
|
639
|
+
incomeSides.set(key, {
|
|
640
|
+
playerId: r.playerId,
|
|
641
|
+
...(t !== undefined ? { team: t, players: [r.playerId] } : {}),
|
|
642
|
+
low: Math.min(low, estimate),
|
|
643
|
+
high,
|
|
644
|
+
estimate,
|
|
645
|
+
calibrated: factor !== undefined,
|
|
646
|
+
});
|
|
647
|
+
else {
|
|
648
|
+
side.low += Math.min(low, estimate);
|
|
649
|
+
side.high += high;
|
|
650
|
+
side.estimate += estimate;
|
|
651
|
+
side.calibrated ||= factor !== undefined;
|
|
652
|
+
side.players.push(r.playerId);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
const theirs = [...incomeSides.values()].sort((a, b) => b.estimate - a.estimate || b.high - a.high || a.playerId - b.playerId)[0];
|
|
656
|
+
const income = theirs
|
|
657
|
+
? {
|
|
658
|
+
mine: myNow,
|
|
659
|
+
theirs: {
|
|
660
|
+
playerId: theirs.playerId,
|
|
661
|
+
...(theirs.team !== undefined ? { team: theirs.team, players: theirs.players } : {}),
|
|
662
|
+
low: theirs.low,
|
|
663
|
+
high: theirs.high,
|
|
664
|
+
estimate: theirs.estimate,
|
|
665
|
+
},
|
|
666
|
+
ratio: {
|
|
667
|
+
low: theirs.high > 0 ? round2(myNow / theirs.high) : null,
|
|
668
|
+
high: theirs.low > 0 ? round2(myNow / theirs.low) : null,
|
|
669
|
+
estimate: theirs.estimate > 0 ? round2(myNow / theirs.estimate) : null,
|
|
670
|
+
},
|
|
671
|
+
calibrated: theirs.calibrated,
|
|
672
|
+
lean: 'even',
|
|
673
|
+
}
|
|
674
|
+
: undefined;
|
|
675
|
+
// #436: the bonuses I could complete next turn (the latest turn only: the surrender line reads them).
|
|
676
|
+
const bonusesInReach = [];
|
|
677
|
+
if (turn === run.at(-1)) {
|
|
678
|
+
const side = new Set([me, ...mates]);
|
|
679
|
+
const ownerOfT = (id) => ownerById.get(id);
|
|
680
|
+
const isMine = (id) => {
|
|
681
|
+
const o = ownerOfT(id);
|
|
682
|
+
return o?.kind === 'player' && side.has(o.playerId);
|
|
683
|
+
};
|
|
684
|
+
for (const bonus of [...g.bonusById.values()].sort((a, b) => a.id - b.id)) {
|
|
685
|
+
if (bonus.value <= 0)
|
|
686
|
+
continue;
|
|
687
|
+
const ts = bonusTerritories(g, bonus.id);
|
|
688
|
+
const missing = ts.filter((t) => !isMine(t));
|
|
689
|
+
if (!ts.length || !missing.length)
|
|
690
|
+
continue;
|
|
691
|
+
const beside = new Set();
|
|
692
|
+
let reachable = true;
|
|
693
|
+
for (const t of missing) {
|
|
694
|
+
const mineNext = neighborsOf(g, t).filter(isMine);
|
|
695
|
+
if (!mineNext.length)
|
|
696
|
+
reachable = false;
|
|
697
|
+
for (const n of mineNext)
|
|
698
|
+
beside.add(n);
|
|
699
|
+
}
|
|
700
|
+
if (!reachable)
|
|
701
|
+
continue;
|
|
702
|
+
const defenders = missing.reduce((n, t) => n + (armiesById.get(t) ?? 0) + unitsOn(board, t), 0);
|
|
703
|
+
const attackers = [...beside].reduce((n, t) => n + (armiesById.get(t) ?? 0), 0) + myNow;
|
|
704
|
+
if (defenders < attackers)
|
|
705
|
+
bonusesInReach.push({ bonus: bonus.id, value: bonus.value, defenders });
|
|
706
|
+
}
|
|
707
|
+
bonusesInReach.sort((a, b) => b.value - a.value || a.bonus - b.bonus);
|
|
708
|
+
}
|
|
709
|
+
// #368: the bonuses my side held in full on the board before and does not now.
|
|
710
|
+
const bonusesLost = prev
|
|
711
|
+
? (() => {
|
|
712
|
+
const side = new Set([me, ...mates]);
|
|
713
|
+
const sideHeld = (b) => {
|
|
714
|
+
const ts = new Set();
|
|
715
|
+
for (const x of b.territories)
|
|
716
|
+
if (g.territoryById.has(x.territoryId) && x.owner.kind === 'player' && side.has(x.owner.playerId))
|
|
717
|
+
ts.add(x.territoryId);
|
|
718
|
+
return ts;
|
|
719
|
+
};
|
|
720
|
+
const before = sideHeld(prev);
|
|
721
|
+
const now = sideHeld(board);
|
|
722
|
+
const lost = [];
|
|
723
|
+
for (const bonus of [...g.bonusById.values()].sort((a, b) => a.id - b.id)) {
|
|
724
|
+
if (bonus.value <= 0)
|
|
725
|
+
continue;
|
|
726
|
+
const ts = bonusTerritories(g, bonus.id);
|
|
727
|
+
if (ts.length && ts.every((t) => before.has(t)) && !ts.every((t) => now.has(t)))
|
|
728
|
+
lost.push(bonus.id);
|
|
729
|
+
}
|
|
730
|
+
return lost;
|
|
731
|
+
})()
|
|
732
|
+
: [];
|
|
733
|
+
// #436: no lead is claimed at low coverage — a win on the likely high alone needs evidence that is not thin.
|
|
734
|
+
const claimWin = estimated && !evidence.thin;
|
|
735
|
+
if (income && estimated && !claimWin)
|
|
736
|
+
income.noLeadClaim = true;
|
|
737
|
+
const state = bound || claimWin
|
|
571
738
|
? 'winning'
|
|
572
739
|
: lostOnBound || lostOnEstimate
|
|
573
740
|
? 'losing'
|
|
@@ -585,16 +752,160 @@ export function gameOutlook(input) {
|
|
|
585
752
|
changed,
|
|
586
753
|
...(forecast ? { front: forecast } : {}),
|
|
587
754
|
state,
|
|
588
|
-
...(
|
|
755
|
+
...(claimWin || lostOnEstimate ? { estimated: true } : {}),
|
|
589
756
|
...(lowLikely ? { lowLikely: { myIncome: myNow, mostTracked: mostTracked(), groundDown, losing: lostOnEstimate } } : {}),
|
|
590
757
|
evidence,
|
|
758
|
+
...(bonusesLost.length ? { bonusesLost } : {}),
|
|
759
|
+
...(income ? { income } : {}),
|
|
760
|
+
...(bonusesInReach.length ? { bonusesInReach } : {}),
|
|
591
761
|
};
|
|
592
762
|
});
|
|
763
|
+
// #436: each turn's income lean, with each side's change per turn over the turns judged up to it; it
|
|
764
|
+
// replaces an `even` state (winning, losing and stalemate keep their own tests).
|
|
765
|
+
// Calibration deepens a deficit the tracked figure shows, never creates one: a behind lean on the
|
|
766
|
+
// calibrated estimate (or its trend), and a turn under the surrender line, need my income under the
|
|
767
|
+
// tracked figure (the range's low) too. In-sample, on 10 lost games, past games' estimate ÷ truth alone put
|
|
768
|
+
// 5 of 25 truly-even turns past the surrender line; with this rule 1 (see CLAUDE.md, #436).
|
|
769
|
+
const trackedBehind = (inc) => inc.mine < inc.theirs.low;
|
|
770
|
+
const first = turns[0];
|
|
771
|
+
for (const t of turns) {
|
|
772
|
+
const inc = t.income;
|
|
773
|
+
if (!inc)
|
|
774
|
+
continue;
|
|
775
|
+
if (first && first !== t && first.income) {
|
|
776
|
+
const span = t.turn - first.turn;
|
|
777
|
+
inc.trend = { mine: round2((inc.mine - first.income.mine) / span), theirs: round2((inc.theirs.estimate - first.income.theirs.estimate) / span) };
|
|
778
|
+
}
|
|
779
|
+
const r = inc.ratio;
|
|
780
|
+
const spans = r.low !== null && r.low <= INCOME_BEHIND_RATIO && (r.high === null || r.high >= INCOME_AHEAD_RATIO);
|
|
781
|
+
let lean;
|
|
782
|
+
if (spans)
|
|
783
|
+
lean = 'unknown';
|
|
784
|
+
else if (r.high !== null && r.high <= INCOME_BEHIND_RATIO)
|
|
785
|
+
lean = 'behind';
|
|
786
|
+
else if (r.low === null || r.low >= INCOME_AHEAD_RATIO)
|
|
787
|
+
lean = 'ahead';
|
|
788
|
+
else if (r.estimate !== null && r.estimate <= INCOME_BEHIND_RATIO) {
|
|
789
|
+
if (trackedBehind(inc))
|
|
790
|
+
lean = 'behind';
|
|
791
|
+
else {
|
|
792
|
+
lean = 'unknown';
|
|
793
|
+
inc.calibratedOnly = true;
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
else if (r.estimate === null || r.estimate >= INCOME_AHEAD_RATIO)
|
|
797
|
+
lean = 'ahead';
|
|
798
|
+
else {
|
|
799
|
+
lean = 'even';
|
|
800
|
+
// The trend: one more turn at each side's change per turn, toward a threshold the ratio is heading to.
|
|
801
|
+
if (inc.trend && r.estimate !== null) {
|
|
802
|
+
const mineNext = Math.max(0, inc.mine + inc.trend.mine);
|
|
803
|
+
const theirsNext = Math.max(0, inc.theirs.estimate + inc.trend.theirs);
|
|
804
|
+
const next = theirsNext > 0 ? mineNext / theirsNext : null;
|
|
805
|
+
if (next !== null && r.estimate < 1 && next <= INCOME_BEHIND_RATIO && trackedBehind(inc))
|
|
806
|
+
lean = 'behind';
|
|
807
|
+
else if ((next === null || next >= INCOME_AHEAD_RATIO) && r.estimate > 1)
|
|
808
|
+
lean = 'ahead';
|
|
809
|
+
if (lean !== 'even')
|
|
810
|
+
inc.byTrend = true;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
if (lean === 'ahead' && t.evidence?.thin) {
|
|
814
|
+
lean = 'unknown';
|
|
815
|
+
inc.noLeadClaim = true;
|
|
816
|
+
delete inc.byTrend;
|
|
817
|
+
}
|
|
818
|
+
inc.lean = lean;
|
|
819
|
+
// #454: beside the even state, never in it.
|
|
820
|
+
if (t.state === 'even' && lean !== 'even')
|
|
821
|
+
t.lean = lean;
|
|
822
|
+
}
|
|
593
823
|
const last = turns.at(-1);
|
|
824
|
+
// #436: an income lean moves from turn to turn; the turns that read even on strength are one run, so a
|
|
825
|
+
// lean that changes (even, behind, behind on a slide) does not reset the hold. The run reports its lean
|
|
826
|
+
// when every turn judged read it, else `even`.
|
|
827
|
+
const evenOnStrength = (t) => t.state === 'even';
|
|
828
|
+
/** #454: a turn's finer reading (its lean, else its state). */
|
|
829
|
+
const fine = (t) => t.lean ?? t.state;
|
|
830
|
+
const sameRun = (t) => (last && evenOnStrength(last) ? evenOnStrength(t) : t.state === last?.state);
|
|
594
831
|
let heldTurns = 0;
|
|
595
|
-
for (let i = turns.length - 1; i >= 0 && turns[i]
|
|
832
|
+
for (let i = turns.length - 1; i >= 0 && sameRun(turns[i]); i--)
|
|
596
833
|
heldTurns++;
|
|
597
|
-
const
|
|
834
|
+
const held = turns.slice(turns.length - heldTurns);
|
|
835
|
+
const fineState = !last || heldTurns < OUTLOOK_TURNS
|
|
836
|
+
? null
|
|
837
|
+
: evenOnStrength(last)
|
|
838
|
+
? held.every((t) => fine(t) === fine(last))
|
|
839
|
+
? fine(last)
|
|
840
|
+
: 'even'
|
|
841
|
+
: last.state;
|
|
842
|
+
// #454: the contract's state, and the lean beside it.
|
|
843
|
+
const { state, lean } = splitReading(fineState);
|
|
844
|
+
// #368: even on strength for OUTLOOK_TURNS turns running while a bonus of mine fell on each: leaning
|
|
845
|
+
// behind. #436: whatever the income lean (the lean is the incomes; the slide is the board), unless the run
|
|
846
|
+
// already reads behind.
|
|
847
|
+
const leaning = state !== null &&
|
|
848
|
+
fineState !== 'behind' &&
|
|
849
|
+
turns.length >= OUTLOOK_TURNS &&
|
|
850
|
+
turns.every(evenOnStrength) &&
|
|
851
|
+
turns.every((t) => t.bonusesLost?.length)
|
|
852
|
+
? {
|
|
853
|
+
toward: 'behind',
|
|
854
|
+
turns: turns.length,
|
|
855
|
+
lost: turns.map((t) => ({
|
|
856
|
+
turn: t.turn,
|
|
857
|
+
value: t.bonusesLost.reduce((n, id) => n + Math.max(0, input.graph.bonusById.get(id)?.value ?? 0), 0),
|
|
858
|
+
})),
|
|
859
|
+
}
|
|
860
|
+
: undefined;
|
|
861
|
+
// #436: the pace line, over the turns judged.
|
|
862
|
+
const lastIncome = last?.income;
|
|
863
|
+
const firstIncome = turns[0]?.income;
|
|
864
|
+
const pace = last && lastIncome && firstIncome && turns.length >= 2 && lastIncome.trend
|
|
865
|
+
? {
|
|
866
|
+
from: turns[0].turn,
|
|
867
|
+
to: last.turn,
|
|
868
|
+
mine: { income: lastIncome.mine, perTurn: lastIncome.trend.mine },
|
|
869
|
+
theirs: {
|
|
870
|
+
playerId: lastIncome.theirs.playerId,
|
|
871
|
+
...(lastIncome.theirs.team !== undefined ? { team: lastIncome.theirs.team } : {}),
|
|
872
|
+
income: lastIncome.theirs.estimate,
|
|
873
|
+
perTurn: lastIncome.trend.theirs,
|
|
874
|
+
},
|
|
875
|
+
}
|
|
876
|
+
: undefined;
|
|
877
|
+
// #436: the surrender line (advice only): my income under the line for SURRENDER_TURNS turns running.
|
|
878
|
+
const below = (t) => !!t.income && t.income.mine < INCOME_BEHIND_RATIO * t.income.theirs.estimate && trackedBehind(t.income);
|
|
879
|
+
let turnsBelow = 0;
|
|
880
|
+
for (let i = turns.length - 1; i >= 0 && below(turns[i]) && (i === turns.length - 1 || turns[i + 1].turn === turns[i].turn + 1); i--)
|
|
881
|
+
turnsBelow++;
|
|
882
|
+
let surrenderLine;
|
|
883
|
+
if (last && lastIncome && turnsBelow > 0) {
|
|
884
|
+
const line = round2(INCOME_BEHIND_RATIO * lastIncome.theirs.estimate);
|
|
885
|
+
const closer = (last.bonusesInReach ?? []).find((b) => lastIncome.mine + b.value >= line);
|
|
886
|
+
const crossed = turnsBelow >= SURRENDER_TURNS && !closer;
|
|
887
|
+
const who = lastIncome.theirs.team !== undefined ? `team ${lastIncome.theirs.team}` : `player ${lastIncome.theirs.playerId}`;
|
|
888
|
+
const est = `${who}'s ~${lastIncome.theirs.estimate} (${lastIncome.calibrated ? "calibrated on past games' estimate ÷ truth" : 'the tracked figure, uncalibrated'})`;
|
|
889
|
+
const mineText = `my ${teamGame ? "team's " : ''}income ${lastIncome.mine}`;
|
|
890
|
+
const advice = crossed
|
|
891
|
+
? `Surrender line crossed (advice only; the server never acts on it): ${mineText} has stayed below two-thirds of ${est} for ${turnsBelow} turns running (the line is ${line}), and no bonus in reach closes the gap.`
|
|
892
|
+
: closer
|
|
893
|
+
? `Under the surrender line for ${turnsBelow} turn${turnsBelow === 1 ? '' : 's'} (advice only): ${mineText} is below two-thirds of ${est} (the line is ${line}), but bonus ${closer.bonus} (+${closer.value}) is in reach and would close the gap.`
|
|
894
|
+
: `Under the surrender line for ${turnsBelow} of the ${SURRENDER_TURNS} turns it needs (advice only): ${mineText} is below two-thirds of ${est} (the line is ${line}).`;
|
|
895
|
+
surrenderLine = {
|
|
896
|
+
crossed,
|
|
897
|
+
turnsBelow,
|
|
898
|
+
needed: SURRENDER_TURNS,
|
|
899
|
+
myIncome: lastIncome.mine,
|
|
900
|
+
theirIncome: lastIncome.theirs.estimate,
|
|
901
|
+
playerId: lastIncome.theirs.playerId,
|
|
902
|
+
...(lastIncome.theirs.team !== undefined ? { team: lastIncome.theirs.team } : {}),
|
|
903
|
+
line,
|
|
904
|
+
calibrated: lastIncome.calibrated,
|
|
905
|
+
...(closer ? { closer } : {}),
|
|
906
|
+
advice,
|
|
907
|
+
};
|
|
908
|
+
}
|
|
598
909
|
const measure = teamGame
|
|
599
910
|
? `Strength = armies + ${k} × income; an opponent's is a range under fog (low: what is in view; high: the most it could have received and earn). By team: my team's strength (mine and my teammates' still playing) against the strongest enemy team's, each the sum of its players'; summed, a teammate's transfers stay inside its team's high.`
|
|
600
911
|
: `Strength = armies + ${k} × income; an opponent's is a range under fog (low: what is in view; high: the most it could have received and earn). Per player: my strength alone against the single strongest opponent, teams not summed.`;
|
|
@@ -622,15 +933,19 @@ export function gameOutlook(input) {
|
|
|
622
933
|
: `each turn at most ${LIKELY_INCOME_MARGIN}× the income the tracker reads off my boards`;
|
|
623
934
|
let est = '';
|
|
624
935
|
if (l && (l.high !== s?.high || l.source === 'prior'))
|
|
625
|
-
est = ` The likely high — an estimate, not a bound: ${rests} — is ${sideName(l)} at ${l.high}, ratio ${l.ratio}×${last.estimated ? `; ${last
|
|
936
|
+
est = ` The likely high — an estimate, not a bound: ${rests} — is ${sideName(l)} at ${l.high}, ratio ${l.ratio}×${last.estimated ? `; ${fine(last)} rests on it` : ''}.`;
|
|
626
937
|
if (l && l.high > 0 && last.state !== 'winning')
|
|
627
938
|
est += ` ${cap(sideName(l))} blocks a win on the estimate: winning needs mine at ${OUTLOOK_RATIO}× its likely high (${round2(OUTLOOK_RATIO * l.high)}), and mine is ${last.mine}.`;
|
|
628
939
|
reading =
|
|
629
940
|
turns.length < OUTLOOK_TURNS
|
|
630
941
|
? `Only ${turns.length} turn${turns.length === 1 ? '' : 's'} of boards in a row (${OUTLOOK_TURNS} needed), so no state yet; ${figures}.`
|
|
631
|
-
:
|
|
632
|
-
?
|
|
633
|
-
|
|
942
|
+
: evenOnStrength(last) && !held.every((t) => fine(t) === fine(last))
|
|
943
|
+
? fineState
|
|
944
|
+
? `Even on strength for ${OUTLOOK_TURNS} turns running, the incomes reading ${turns.map(fine).join(', ')}; ${figures}.`
|
|
945
|
+
: `Even on strength for ${heldTurns} of the ${OUTLOOK_TURNS} turns (${turns.map(fine).join(', ')}), so no state yet; ${figures}.`
|
|
946
|
+
: fineState
|
|
947
|
+
? `${fineState[0].toUpperCase()}${fineState.slice(1)} for ${OUTLOOK_TURNS} turns running; ${figures}.`
|
|
948
|
+
: `${fine(last)[0].toUpperCase()}${fine(last).slice(1)} for ${heldTurns} of the ${OUTLOOK_TURNS} turns (${turns.map(fine).join(', ')}), so no state yet; ${figures}.`;
|
|
634
949
|
// #304: the incomes compared and each opponent's frontier read, said beside the state, and thin
|
|
635
950
|
// evidence named so that "even" does not read as safe.
|
|
636
951
|
const ev = last.evidence;
|
|
@@ -646,9 +961,33 @@ export function gameOutlook(input) {
|
|
|
646
961
|
.filter((r) => r.thin)
|
|
647
962
|
.map((r) => `player ${r.playerId} (${r.coverage === null ? 'not measured' : `${Math.round(r.coverage * 100)}%`})`)
|
|
648
963
|
.join(', ');
|
|
649
|
-
reading += ` Thin evidence: the income of ${which} was read from under ${pct}% of its frontier, so "${last
|
|
964
|
+
reading += ` Thin evidence: the income of ${which} was read from under ${pct}% of its frontier, so "${fine(last)}" is not a safe reading: an opponent may be stronger than the fog shows.`;
|
|
650
965
|
}
|
|
651
966
|
reading += est;
|
|
967
|
+
// #436: the incomes, their range and lean, and the pace line.
|
|
968
|
+
const inc = last.income;
|
|
969
|
+
if (inc) {
|
|
970
|
+
const t = inc.theirs;
|
|
971
|
+
const whose = t.team !== undefined ? `team ${t.team}` : `player ${t.playerId}`;
|
|
972
|
+
const range = t.low === t.high ? `${t.estimate}` : `~${t.estimate} (range ${t.low}–${t.high})`;
|
|
973
|
+
const leanText = inc.lean === 'unknown'
|
|
974
|
+
? inc.noLeadClaim
|
|
975
|
+
? 'unknown: the evidence is thin, so no lead is claimed'
|
|
976
|
+
: inc.calibratedOnly
|
|
977
|
+
? `unknown: only the calibrated estimate reads behind (mine under ${round2(INCOME_BEHIND_RATIO)}× of it), not the tracked ${t.low}, so it is not counted against the surrender line`
|
|
978
|
+
: `unknown: the range spans both thresholds (${round2(INCOME_BEHIND_RATIO)}× and ${INCOME_AHEAD_RATIO}×)`
|
|
979
|
+
: `${inc.lean}${inc.byTrend ? ' on the trend' : ''}`;
|
|
980
|
+
reading += ` On incomes: ${teamGame ? "my team's" : 'mine'} ${inc.mine} against the strongest, ${whose}, at ${range}${inc.calibrated ? ", calibrated on past games' estimate ÷ truth" : ''}: ${leanText}.`;
|
|
981
|
+
if (inc.noLeadClaim && inc.lean !== 'unknown')
|
|
982
|
+
reading += ' No lead is claimed on the likely high: the evidence is thin.';
|
|
983
|
+
}
|
|
984
|
+
if (pace) {
|
|
985
|
+
const sign = (n) => (n >= 0 ? `+${n}` : `${n}`);
|
|
986
|
+
const gap = pace.mine.perTurn > pace.theirs.perTurn ? 'my income gains on it' : pace.mine.perTurn < pace.theirs.perTurn ? 'its income gains on mine' : 'both move alike';
|
|
987
|
+
reading += ` Pace: my income ${pace.mine.income} (${sign(pace.mine.perTurn)}/turn over turns ${pace.from}–${pace.to}) against ${pace.theirs.team !== undefined ? `team ${pace.theirs.team}` : `player ${pace.theirs.playerId}`}'s ~${pace.theirs.income} (${sign(pace.theirs.perTurn)}/turn): ${gap}.`;
|
|
988
|
+
}
|
|
989
|
+
if (surrenderLine)
|
|
990
|
+
reading += ` ${surrenderLine.advice}`;
|
|
652
991
|
// #228: a likely ratio far below parity, said with what it took (or lacked) to read losing.
|
|
653
992
|
const low = last.lowLikely;
|
|
654
993
|
if (low) {
|
|
@@ -663,10 +1002,12 @@ export function gameOutlook(input) {
|
|
|
663
1002
|
? ` Losing on the estimate: ${share}, corroborated by ${[low.groundDown ? 'the main front grinding me down on the incomes read off my boards' : '', behind ? incomeText : ''].filter(Boolean).join(' and ')}.`
|
|
664
1003
|
: ` ${share[0].toUpperCase()}${share.slice(1)}, but that alone is no loss: the likely high counts every army an opponent could have received at ${LIKELY_INCOME_MARGIN}× its pace and none it lost, so it reads every fogged opponent strong. Losing on it needs the main front grinding me down on the incomes read off my boards (not the plan's, so the plan acts on the state shown) or my income at most ${BEHIND_RATIO}× the most an opponent is tracked earning${low.mostTracked > 0 ? ` (mine ${low.myIncome}, the most tracked ${low.mostTracked})` : ' (none is tracked)'}.`;
|
|
665
1004
|
}
|
|
1005
|
+
if (leaning)
|
|
1006
|
+
reading += ` Leaning behind: even for ${leaning.turns} turns running while I lost bonuses on each (${leaning.lost.map((x) => `turn ${x.turn} +${x.value}`).join(', ')}): the strength ratio lags a slide the board already shows, so read "even" as falling behind.`;
|
|
666
1007
|
// #228: the plan's profile standing is a different measure (incomes, then the armies in view).
|
|
667
1008
|
const standing = input.standing;
|
|
668
|
-
if ((last
|
|
669
|
-
reading += ` The profile's standing reads ${standing} (my income against the strongest opponent's estimate, overruled by the armies in view); this outlook reads ${last
|
|
1009
|
+
if ((fine(last) === 'even' || fine(last) === 'stalemate') && (standing === 'ahead' || standing === 'behind'))
|
|
1010
|
+
reading += ` The profile's standing reads ${standing} (my income against the strongest opponent's estimate, overruled by the armies in view); this outlook reads ${fine(last)} because neither the winning nor the losing threshold was met on strength (armies + ${k} × income, and the likely high), a stricter test for a decided game.`;
|
|
670
1011
|
// #218: the main front, said with what it assumes, so it reads with the plan's front outlook.
|
|
671
1012
|
const fr = last.front;
|
|
672
1013
|
if (fr) {
|
|
@@ -685,11 +1026,15 @@ export function gameOutlook(input) {
|
|
|
685
1026
|
}
|
|
686
1027
|
return {
|
|
687
1028
|
state,
|
|
1029
|
+
...(lean ? { lean } : {}),
|
|
688
1030
|
heldTurns,
|
|
689
1031
|
turns,
|
|
690
1032
|
k,
|
|
691
1033
|
threshold: OUTLOOK_RATIO,
|
|
692
1034
|
basis: `${reading} ${measure} ${thresholdsText}`,
|
|
693
1035
|
...(last?.evidence ? { evidence: last.evidence } : {}),
|
|
1036
|
+
...(leaning ? { leaning } : {}),
|
|
1037
|
+
...(pace ? { pace } : {}),
|
|
1038
|
+
...(surrenderLine ? { surrenderLine } : {}),
|
|
694
1039
|
};
|
|
695
1040
|
}
|
package/dist/analysis/picks.js
CHANGED
|
@@ -106,7 +106,12 @@
|
|
|
106
106
|
// Otherwise in a 1v1 (a primary of one pick, or of five or more), among the equally
|
|
107
107
|
// scored compact fallbacks found at its hop limit, the one farthest from the primary
|
|
108
108
|
// (fewest hops between the two groups, maximised) wins, so one counter-pick cannot reach
|
|
109
|
-
// both.
|
|
109
|
+
// both. #289: a first fallback tier of the primary's size that is one compact cluster
|
|
110
|
+
// and, scored alone as the primary is (nothing taken), beats it becomes the primary (the
|
|
111
|
+
// seeded greedy search missed it), once; the fallback is then built again. A fallback that
|
|
112
|
+
// still outscores the primary (its score is with the primary taken) is warned about, and the
|
|
113
|
+
// warning says why the primary stays first: an answering tier is granted whole only if every
|
|
114
|
+
// primary pick is lost, a spread one breaks the one-cluster rule. A list longer than
|
|
110
115
|
// twice the limit (war.app's client allows players × territories per player,
|
|
111
116
|
// `clientPickLimits`) runs in fallback tiers of the primary's size, each built as a group
|
|
112
117
|
// with the primary and the earlier tiers taken; the fallback group's score, bonuses
|
|
@@ -1121,7 +1126,7 @@ function planCore(input, friendlyIds = []) {
|
|
|
1121
1126
|
if (pickable.length < limit)
|
|
1122
1127
|
warnings.push(`Only ${pickable.length} pickable territor${pickable.length === 1 ? 'y' : 'ies'} for a limit of ${limit}: the list has no full fallback.`);
|
|
1123
1128
|
const primary = buildGroup(firstView, pickable, primarySize, 'primary');
|
|
1124
|
-
|
|
1129
|
+
let rest = pickable.filter((t) => !primary.includes(t));
|
|
1125
1130
|
// Commanders (#129): the first pick awarded carries the commander, so the primary's safest
|
|
1126
1131
|
// pick goes first — the fewest other pickable territories (where other players may start)
|
|
1127
1132
|
// within COMPACT_DISTANCE hops, then the fewest neighbours outside the primary, then score.
|
|
@@ -1301,6 +1306,33 @@ function planCore(input, friendlyIds = []) {
|
|
|
1301
1306
|
maxHops: Number.isFinite(far) ? far : null,
|
|
1302
1307
|
};
|
|
1303
1308
|
};
|
|
1309
|
+
// #289: the fallback is scored with the primary taken, so its group score and the primary's
|
|
1310
|
+
// are on one footing only when both are scored alone. A first tier of the primary's size
|
|
1311
|
+
// that is one compact cluster and, scored alone, beats the primary is a better group the
|
|
1312
|
+
// seeded search missed (greedy growth from its seeds reached into the primary): it becomes
|
|
1313
|
+
// the primary, and the fallback is built again for it. Once only.
|
|
1314
|
+
let promoted = null;
|
|
1315
|
+
{
|
|
1316
|
+
const tier = listed.tiers[0] ?? [];
|
|
1317
|
+
const was = round2(simScore(primary, []));
|
|
1318
|
+
const now = round2(simScore(tier, []));
|
|
1319
|
+
if (!spread && tier.length > 1 && tier.length === primary.length && spreadOf(tier).link <= COMPACT_DISTANCE && now > was) {
|
|
1320
|
+
const byFirst = (a, b) => firstView.of.get(b).score - firstView.of.get(a).score || a - b;
|
|
1321
|
+
primary.splice(0, primary.length, ...[...tier].sort(byFirst));
|
|
1322
|
+
rest = pickable.filter((t) => !primary.includes(t));
|
|
1323
|
+
if (relaxedTo.delete('primary')) {
|
|
1324
|
+
for (let i = warnings.length - 1; i >= 0; i--)
|
|
1325
|
+
if (warnings[i].startsWith('No compact primary group'))
|
|
1326
|
+
warnings.splice(i, 1);
|
|
1327
|
+
}
|
|
1328
|
+
if (s.commanders) {
|
|
1329
|
+
({ pick: commanderPick, exposure: commanderExposure } = safestOf(primary));
|
|
1330
|
+
primary.splice(0, primary.length, commanderPick, ...primary.filter((t) => t !== commanderPick));
|
|
1331
|
+
}
|
|
1332
|
+
listed = buildFallback(primary);
|
|
1333
|
+
promoted = { was, now };
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1304
1336
|
// The award order (#129): a list is judged by the sets it can actually yield. The worst
|
|
1305
1337
|
// outcome is scored with the other players holding the picks it implies they took; the
|
|
1306
1338
|
// primary's order is changed only when another order raises that worst outcome.
|
|
@@ -1464,16 +1496,33 @@ function planCore(input, friendlyIds = []) {
|
|
|
1464
1496
|
primary: groupOf(primary, NO_TAKEN),
|
|
1465
1497
|
fallback: { ...groupOf(firstTier, firstFallbackView.taken), territoryIds: fallback },
|
|
1466
1498
|
};
|
|
1467
|
-
if (
|
|
1468
|
-
|
|
1469
|
-
(
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1499
|
+
if (promoted)
|
|
1500
|
+
rationale.push(`The seeded search's primary scored ${promoted.was}; the first fallback group, one compact cluster of as many picks, ` +
|
|
1501
|
+
`scores ${promoted.now} on the same footing (each alone, nothing taken), so it is the primary now and the fallback was built again for it (#289).`);
|
|
1502
|
+
if (groups.fallback.score > groups.primary.score) {
|
|
1503
|
+
// #289: say why the primary still ranks first. The fallback's score is with the primary
|
|
1504
|
+
// taken (it is granted only then); a compact tier that beat the primary alone was promoted
|
|
1505
|
+
// above, so what is left is a fallback the primary's rules keep out of first place.
|
|
1506
|
+
const alone = round2(simScore(firstTier, []));
|
|
1507
|
+
const link = spreadOf(firstTier).link;
|
|
1508
|
+
const tierCompact = link <= COMPACT_DISTANCE;
|
|
1509
|
+
const steps = Number.isFinite(link) ? `${link} hops` : 'any distance (some are not connected)';
|
|
1510
|
+
const reason = answerSets
|
|
1511
|
+
? 'the primary is one compact cluster, so the start has one front; each fallback pick is chosen for the outcomes in which a pick above it is lost, ' +
|
|
1512
|
+
'and the fallback picks are granted together only if every primary pick is lost' +
|
|
1513
|
+
(tierCompact ? '' : ` (nor are they one cluster: they link up only in steps of up to ${steps})`) +
|
|
1514
|
+
', so its joint score is not a start this list can choose'
|
|
1515
|
+
: spread
|
|
1516
|
+
? `the primary keeps within ${SPREAD_DISTANCE} hops unless spreading scores ${SPREAD_RELAX_GAIN}× as much`
|
|
1517
|
+
: !tierCompact
|
|
1518
|
+
? `the fallback is not one compact cluster (its picks link up only in steps of up to ${steps}) and the primary keeps to one, ` +
|
|
1519
|
+
(players > 2
|
|
1520
|
+
? `since with ${players} players spread picks are likely contested`
|
|
1521
|
+
: 'so the start has one front; the fallback covers a counter-pick')
|
|
1522
|
+
: `scored alone, as the primary is, the fallback makes ${alone}, not more than the primary: the gap comes from scoring it with the primary taken`;
|
|
1523
|
+
warnings.push(`The fallback group scores more than the primary (${groups.fallback.score} vs ${groups.primary.score}; the fallback is scored with the primary taken, ` +
|
|
1524
|
+
`since it is granted only then, and makes ${alone} alone). The primary stays first: ${reason}. Weigh the trade before submitting.`);
|
|
1525
|
+
}
|
|
1477
1526
|
if (commanderPick !== null)
|
|
1478
1527
|
rationale.push(`Commanders are on: the first pick awarded carries the commander, so the primary's safest pick (${terrName(commanderPick)}: ` +
|
|
1479
1528
|
`fewest other pickable territories within ${COMPACT_DISTANCE} hops) is listed first; if another player takes it, the next pick awarded carries it.`);
|
|
@@ -1544,6 +1593,8 @@ function planCore(input, friendlyIds = []) {
|
|
|
1544
1593
|
picks,
|
|
1545
1594
|
groups,
|
|
1546
1595
|
...(award ? { award } : {}),
|
|
1596
|
+
// #305: report only, never scored.
|
|
1597
|
+
side: mapSides(g, groups.primary.territoryIds, award?.worst.opponentStarts ?? []),
|
|
1547
1598
|
coverage: primaryCoverage,
|
|
1548
1599
|
...(alternative ? { alternative } : {}),
|
|
1549
1600
|
warnings,
|
|
@@ -1789,6 +1840,34 @@ export function impliedOpponentStarts(list, granted) {
|
|
|
1789
1840
|
});
|
|
1790
1841
|
return list.slice(0, last + 1).filter((t) => !got.has(t));
|
|
1791
1842
|
}
|
|
1843
|
+
export function mapSides(g, primary, opponentStarts) {
|
|
1844
|
+
const starts = [...opponentStarts].sort((a, b) => a - b);
|
|
1845
|
+
if (!starts.length || !primary.length)
|
|
1846
|
+
return {
|
|
1847
|
+
known: false,
|
|
1848
|
+
opponentStarts: starts,
|
|
1849
|
+
note: 'No opponent start is implied by the award of this list, so the map is not split into my side and the rest.',
|
|
1850
|
+
};
|
|
1851
|
+
const fromMe = bfsDistances(g, primary);
|
|
1852
|
+
const fromThem = bfsDistances(g, starts);
|
|
1853
|
+
const mine = { income: 0, bonuses: [] };
|
|
1854
|
+
const contested = { income: 0, bonuses: [] };
|
|
1855
|
+
for (const b of [...g.map.bonuses].sort((x, y) => x.id - y.id)) {
|
|
1856
|
+
if (b.value <= 0)
|
|
1857
|
+
continue;
|
|
1858
|
+
const members = bonusTerritories(g, b.id);
|
|
1859
|
+
if (!members.length)
|
|
1860
|
+
continue;
|
|
1861
|
+
const near = members.every((t) => {
|
|
1862
|
+
const d = fromMe.get(t);
|
|
1863
|
+
return d !== undefined && d < (fromThem.get(t) ?? Infinity);
|
|
1864
|
+
});
|
|
1865
|
+
const side = near ? mine : contested;
|
|
1866
|
+
side.bonuses.push({ id: b.id, name: b.name, value: b.value });
|
|
1867
|
+
side.income += b.value;
|
|
1868
|
+
}
|
|
1869
|
+
return { known: true, opponentStarts: starts, mine, contested };
|
|
1870
|
+
}
|
|
1792
1871
|
/** Every ordering of `xs`, starting with `xs` itself (lexicographic by position). */
|
|
1793
1872
|
function permutations(xs) {
|
|
1794
1873
|
if (xs.length <= 1)
|
|
@@ -26,13 +26,16 @@ export function plainEconomy(pc, tgt, id, gain) {
|
|
|
26
26
|
/**
|
|
27
27
|
* Pass 3's eligibility (#125): not a player's under `balanced` (but #281's empty enemy territory), and
|
|
28
28
|
* 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
|
|
29
|
+
* its worth, not my bonus; and #417's land a static seat left, outside a negative bonus: the breach force
|
|
30
|
+
* takes it while it is up for taking).
|
|
30
31
|
*/
|
|
31
32
|
export function plainEligible(pc, tgt, id, enemy) {
|
|
32
33
|
return (!(pc.balanced && enemy && !tgt.emptyEnemies.has(id)) &&
|
|
33
34
|
(tgt.economicMember.has(id) ||
|
|
34
35
|
!tgt.uneconomicMember.has(id) ||
|
|
35
36
|
tgt.denials.has(id) ||
|
|
37
|
+
// #417, the breach force: land a static seat left is taken while it is up for taking.
|
|
38
|
+
(pc.vacated.has(id) && !tgt.negativeMember.has(id)) ||
|
|
36
39
|
(pc.territoryShare(1) > 0 && !tgt.negativeMember.has(id))));
|
|
37
40
|
}
|
|
38
41
|
/**
|