@chrischall/warapp-mcp 0.7.0 → 0.9.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 +5 -4
- package/dist/analysis/card-support.js +12 -4
- package/dist/analysis/coalition.js +55 -0
- package/dist/analysis/local-deploy.js +14 -0
- package/dist/analysis/opponents.js +2 -1
- package/dist/analysis/picks.js +270 -37
- package/dist/analysis/plan/after-leftover.js +26 -4
- package/dist/analysis/plan/captures.js +86 -14
- package/dist/analysis/plan/completed.js +8 -1
- package/dist/analysis/plan/conceded-out.js +16 -11
- package/dist/analysis/plan/deploy-estimates.js +544 -0
- package/dist/analysis/plan/doomed-out.js +135 -0
- package/dist/analysis/plan/estimates.js +4 -1
- package/dist/analysis/plan/free-capture.js +34 -0
- package/dist/analysis/plan/holds.js +8 -309
- package/dist/analysis/plan/horizon.js +42 -0
- package/dist/analysis/plan/leftover.js +43 -5
- package/dist/analysis/plan/observe.js +896 -0
- package/dist/analysis/plan/orders.js +35 -1
- package/dist/analysis/plan/report.js +10 -4
- package/dist/analysis/plan/shared.js +4 -1376
- package/dist/analysis/plan/spread-bind.js +49 -0
- package/dist/analysis/plan/stand-still.js +5 -3
- package/dist/analysis/plan/state.js +12 -0
- package/dist/analysis/plan/strike-stack.js +467 -0
- package/dist/analysis/plan/strike.js +3 -463
- package/dist/analysis/plan/targets.js +219 -28
- package/dist/analysis/plan/threats.js +23 -9
- package/dist/analysis/plan/transfers.js +24 -1
- package/dist/analysis/plan/two-move.js +1 -1
- package/dist/analysis/plan/withdraw.js +316 -0
- package/dist/analysis/planner.js +106 -43
- package/dist/analysis/player.js +4 -0
- package/dist/analysis/relations.js +8 -2
- package/dist/analysis/stress.js +1 -1
- package/dist/bundle.js +4578 -3405
- package/dist/cards.js +37 -0
- package/dist/my-games.js +2 -0
- package/dist/my-orders.js +134 -0
- package/dist/open-games.js +94 -10
- package/dist/team-cards.js +2 -2
- package/dist/team-orders.js +51 -23
- package/dist/tools/card-advice.js +57 -13
- package/dist/tools/card-support-advice.js +17 -1
- package/dist/tools/check-plan.js +2 -1
- package/dist/tools/commander-check.js +2 -1
- package/dist/tools/decision-capture.js +4 -2
- package/dist/tools/index.js +3 -0
- package/dist/tools/join-game.js +44 -8
- package/dist/tools/live.js +43 -5
- package/dist/tools/my-orders.js +110 -0
- package/dist/tools/open-games.js +2 -2
- package/dist/tools/picks.js +128 -51
- package/dist/tools/team-brief.js +1 -1
- package/dist/tools/team.js +25 -9
- package/dist/tools/turn.js +61 -6
- package/dist/tools/uncommit.js +27 -5
- package/dist/trend.js +36 -1
- package/dist/version.js +1 -1
- package/manifest.json +5 -1
- package/package.json +1 -1
- package/server.json +2 -2
- package/skills/warapp-mcp/SKILL.md +9 -2
|
@@ -5,6 +5,9 @@
|
|
|
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
|
+
import { noLossNeutral } from './after-leftover.js';
|
|
10
|
+
import { visibleState } from './observe.js';
|
|
8
11
|
import { captureCost } from './shared.js';
|
|
9
12
|
import { byNum } from './util.js';
|
|
10
13
|
import { denialLine, emptyEnemyLine } from './vacated.js';
|
|
@@ -17,7 +20,7 @@ export function capturesPhase(pc, ps, pass, book, threats, hd, tgt) {
|
|
|
17
20
|
}
|
|
18
21
|
/** R3: a completion must leave a frontier I can hold; No-Split (#124): a stack that must hold. */
|
|
19
22
|
export function captureRules(pc, ps, book, threats, hd) {
|
|
20
|
-
const { g, s, foe, goal, guarded, reserve, deployOf, territories: state, label, bonusName, mine, mineSet, armiesOf, unitsAt, defenceAt, bonusTs, completedBy, guard, toTake, noSplit, myCommanders, } = pc;
|
|
23
|
+
const { g, s, foe, goal, guarded, reserve, deployOf, territories: state, label, bonusName, mine, mineSet, armiesOf, unitsAt, defenceAt, bonusTs, completedBy, guard, toTake, noSplit, myCommanders, rates, } = pc;
|
|
21
24
|
const { warnings, rationale, deployed, avail, captured, survivorsAt, incoming } = ps;
|
|
22
25
|
const { guardAt, valueOf } = book;
|
|
23
26
|
const { holdArmies, nextTurnAt, exposure, borderAt } = threats;
|
|
@@ -39,8 +42,9 @@ export function captureRules(pc, ps, book, threats, hd) {
|
|
|
39
42
|
* The total need is checked, not each member alone: holding the bonus needs every
|
|
40
43
|
* exposed member held. The leftover is as of this check; a later capture this turn
|
|
41
44
|
* may still spend it (defence funds held borders first, so this is rarely material).
|
|
45
|
+
* `lost`: the attackers the capture of `t` loses (#422), for the payback exemption below.
|
|
42
46
|
*/
|
|
43
|
-
const defensible = (t, survivors) => {
|
|
47
|
+
const defensible = (t, survivors, lost) => {
|
|
44
48
|
const after = new Set([...mine, ...captured]);
|
|
45
49
|
const completes = g.map.bonuses
|
|
46
50
|
.filter((b) => {
|
|
@@ -84,6 +88,8 @@ export function captureRules(pc, ps, book, threats, hd) {
|
|
|
84
88
|
.flatMap(exposedOf))
|
|
85
89
|
earlier.set(e.id, Math.max(earlier.get(e.id) ?? 0, e.added));
|
|
86
90
|
let ok = true;
|
|
91
|
+
/** #422: the completions let through on payback, kept only when the capture is (no other bonus refuses it). */
|
|
92
|
+
const payback = [];
|
|
87
93
|
for (const b of completes) {
|
|
88
94
|
const exposed = exposedOf(b.id);
|
|
89
95
|
const total = exposed.reduce((sum, e) => sum + e.added, 0);
|
|
@@ -93,10 +99,28 @@ export function captureRules(pc, ps, book, threats, hd) {
|
|
|
93
99
|
// A completion that adds no exposure (total 0) is never refused: refusing it saves nothing,
|
|
94
100
|
// whatever the earlier completions need (it only adds income).
|
|
95
101
|
if (total === 0 || total + before <= nextIncome + Math.min(spare, held)) {
|
|
102
|
+
// #422: judged holdable now (a later try, with more income), so no longer a payback completion.
|
|
103
|
+
ps.paybackBonuses.delete(b.id);
|
|
96
104
|
if (anyway.length && guarded)
|
|
97
105
|
rationale.push(`Complete bonus ${bonusName(b.id)} though ${anyway.map((e) => label(e.id)).join(', ')} may fall next turn: ${anyway.length === 1 ? 'it is' : 'they are'} exposed whether or not it is completed, so refusing would save nothing.`);
|
|
98
106
|
continue;
|
|
99
107
|
}
|
|
108
|
+
// #422: the payback exemption. A bonus held at the end of this turn pays its value in next turn's
|
|
109
|
+
// income even if it falls straight after, so a completion whose losses — the attackers its captures
|
|
110
|
+
// lose this turn plus the armies left on the members that would fall — are at most that value
|
|
111
|
+
// repays itself in one turn: refusing it only gives the income up.
|
|
112
|
+
if (guarded) {
|
|
113
|
+
const falls = exposed.filter((e) => e.added > 0);
|
|
114
|
+
const left = falls.reduce((n, e) => n + stays(e.id), 0);
|
|
115
|
+
const killed = bonusTerritories(g, b.id)
|
|
116
|
+
.filter((m) => captured.has(m) && !mineSet.has(m))
|
|
117
|
+
.reduce((n, m) => n + (m === t && lost !== undefined ? lost : straightKills(defenceAt(m), rates.defensiveKillRate)), 0);
|
|
118
|
+
if (killed + left <= b.value) {
|
|
119
|
+
const line = `Complete bonus ${bonusName(b.id)} though its frontier cannot be held next turn (it needs ${total} more armies${before ? `, on top of the ${before} this turn's other completions need` : ''}, next income ${nextIncome}): it can lose at most ${killed + left} armies (${killed} killed taking it, ${left} left on ${falls.map((e) => label(e.id)).join(', ')}), no more than the +${b.value} it pays next turn (#422).`;
|
|
120
|
+
payback.push({ line, bonusId: b.id, falls: falls.map((e) => e.id) });
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
100
124
|
const worst = [...exposed].sort((a, b) => b.added - a.added || b.need - a.need || a.id - b.id)[0];
|
|
101
125
|
const head = `completing ${bonusName(b.id)} leaves ${label(worst.id)} indefensible (player ${worst.player} can take it for ${worst.take}; next income ${nextIncome})`;
|
|
102
126
|
if (guarded) {
|
|
@@ -114,6 +138,14 @@ export function captureRules(pc, ps, book, threats, hd) {
|
|
|
114
138
|
warnings.push(w);
|
|
115
139
|
}
|
|
116
140
|
}
|
|
141
|
+
if (ok)
|
|
142
|
+
for (const x of payback) {
|
|
143
|
+
if (!rationale.includes(x.line))
|
|
144
|
+
rationale.push(x.line);
|
|
145
|
+
for (const f of x.falls)
|
|
146
|
+
ps.paybackFalls.set(f, x.line);
|
|
147
|
+
ps.paybackBonuses.set(x.bonusId, x.line);
|
|
148
|
+
}
|
|
117
149
|
return ok;
|
|
118
150
|
};
|
|
119
151
|
// ---- No-Split: the whole stack moves (#124) ----
|
|
@@ -242,6 +274,11 @@ export function captureHelper(pc, ps, pass, book, threats, hd, tgt, prev) {
|
|
|
242
274
|
const need = b ? Math.max(0, holdArmies(b.threat) - unitsAt(x)) : 0;
|
|
243
275
|
return Math.max(need - (stayAt(x) - avail.get(x)), keepOf(x, t));
|
|
244
276
|
};
|
|
277
|
+
/**
|
|
278
|
+
* #416: under #319's bind (plan/spread-bind.ts), `x` beside the nearest bonus's missing members may not attack
|
|
279
|
+
* `t` unless `t` is a member of that bonus.
|
|
280
|
+
*/
|
|
281
|
+
const barred = (x, t) => ps.bind !== undefined && ps.bind.from.has(x) && !ps.bind.members.has(t);
|
|
245
282
|
/** Enemy commanders' territories attacked as a commander strike (rule 1s): exempt from R3. */
|
|
246
283
|
const strikes = new Set();
|
|
247
284
|
/** #272: captures out of a conceded border into a bonus (plan/conceded-out.ts), which R3 does not refuse. */
|
|
@@ -379,6 +416,9 @@ export function captureHelper(pc, ps, pass, book, threats, hd, tgt, prev) {
|
|
|
379
416
|
: movableFor(x, t);
|
|
380
417
|
if (force && orderOf(force.from))
|
|
381
418
|
return false;
|
|
419
|
+
// #416: under #319's bind, never from beside the nearest bonus's missing members (plan/spread-bind.ts).
|
|
420
|
+
if (force && barred(force.from, t))
|
|
421
|
+
return false;
|
|
382
422
|
/** No-Split: why `x` must hold instead (it would send at least the capture's cost). */
|
|
383
423
|
const held = (x) => mustHold(x, t, Math.max(avail.get(x), tg.cost));
|
|
384
424
|
if (force) {
|
|
@@ -391,7 +431,7 @@ export function captureHelper(pc, ps, pass, book, threats, hd, tgt, prev) {
|
|
|
391
431
|
}
|
|
392
432
|
const open = (x) => (!locked.has(x) || (!force && holdSource(x, t))) && (!conceded.has(x) || x === fromConceded || concededSource(x, t, tg.cost));
|
|
393
433
|
// No-Split (#124): a covered exit (#179) issues no order — it would send its whole stack.
|
|
394
|
-
const usable = (x) => open(x) && !held(x) && !(noSplit && coverOf(x) > 0);
|
|
434
|
+
const usable = (x) => open(x) && !held(x) && !(noSplit && coverOf(x) > 0) && !barred(x, t);
|
|
395
435
|
const sources = force
|
|
396
436
|
? [force.from]
|
|
397
437
|
: tg.sources.filter((x) => usable(x) && !orderOf(x)).sort((a, b) => avail.get(b) - avail.get(a) || a - b);
|
|
@@ -476,7 +516,7 @@ export function captureHelper(pc, ps, pass, book, threats, hd, tgt, prev) {
|
|
|
476
516
|
captured.add(t);
|
|
477
517
|
const survivors = sent - straightKills(defendersSeen(t), rates.defensiveKillRate);
|
|
478
518
|
// A commander strike is never refused by R3: killing the commander eliminates a player.
|
|
479
|
-
if (!strikes.has(t) && !r3Exempt.has(t) && !defensible(t, survivors)) {
|
|
519
|
+
if (!strikes.has(t) && !r3Exempt.has(t) && !defensible(t, survivors, sent - survivors)) {
|
|
480
520
|
// Undo: under a guarded goal a bonus that falls next turn is not completed.
|
|
481
521
|
avail.set(src, avail.get(src) + sent - need);
|
|
482
522
|
const left = (deployed.get(src) ?? 0) - need;
|
|
@@ -534,6 +574,7 @@ export function captureHelper(pc, ps, pass, book, threats, hd, tgt, prev) {
|
|
|
534
574
|
.filter((x) => !locked.has(x) &&
|
|
535
575
|
!conceded.has(x) &&
|
|
536
576
|
!myCommanders.has(x) &&
|
|
577
|
+
!barred(x, t) &&
|
|
537
578
|
avail.get(x) > 0 &&
|
|
538
579
|
!orderOf(x) &&
|
|
539
580
|
!(noSplit && coverOf(x) > 0) &&
|
|
@@ -631,7 +672,9 @@ export function captureHelper(pc, ps, pass, book, threats, hd, tgt, prev) {
|
|
|
631
672
|
}
|
|
632
673
|
avail.set(plan.finisher, avail.get(plan.finisher) - plan.armies);
|
|
633
674
|
captured.add(t);
|
|
634
|
-
|
|
675
|
+
// #422: what the combined capture loses — every softener's dead and the finisher's.
|
|
676
|
+
const lost = plan.softeners.reduce((n, x) => n + x.armies - x.survivors, 0) + plan.armies - plan.survivors;
|
|
677
|
+
if (!defensible(t, plan.survivors, lost)) {
|
|
635
678
|
for (const [k, v] of before.avail)
|
|
636
679
|
avail.set(k, v);
|
|
637
680
|
incoming.clear();
|
|
@@ -851,11 +894,11 @@ export function captureHelper(pc, ps, pass, book, threats, hd, tgt, prev) {
|
|
|
851
894
|
}
|
|
852
895
|
/** Pass 1 (complete a bonus, all or nothing) and pass 2 (advance one a capture at a time, rule 4c(c), 4d). */
|
|
853
896
|
export function bonusPasses(pc, ps, book, hd, tgt, prev) {
|
|
854
|
-
const { g, s, guarded, paybackTurns, territories: state, label, bonusName, mineSet, incomeGain, incomeAfter, defenceAt, bonusTs, completedBy, inFocus, } = pc;
|
|
897
|
+
const { g, s, guarded, capturePaybackTurns: paybackTurns, territories: state, label, bonusName, mineSet, incomeGain, incomeAfter, defenceAt, bonusTs, completedBy, inFocus, } = pc;
|
|
855
898
|
const { warnings, rationale, deployed, avail, captured, combined, moves, survivorsAt, captureOrder, staged, incoming, } = ps;
|
|
856
899
|
const { heldNow, gainWith } = book;
|
|
857
|
-
const { heldBorders, keptIncome, stayAt } = hd;
|
|
858
|
-
const { targets, leadSteps, leadTry, leadNote, bonusTarget, frontierDelta, targetScoreCost, frontierOf, startHold, toFinish, byCloseness, committing, denials, emptyEnemies, } = tgt;
|
|
900
|
+
const { heldBorders, keptIncome, keptHeld, stayAt } = hd;
|
|
901
|
+
const { targets, leadSteps, leadTry, leadNote, bonusTarget, frontierDelta, targetScoreCost, frontierOf, frontierNeeds, startHold, toFinish, byCloseness, committing, denials, emptyEnemies, } = tgt;
|
|
859
902
|
const { worstCase, tryCapture, siblings, fundedOnConceded, bareOn } = prev;
|
|
860
903
|
// ---- pass 1: complete a bonus this turn (all or nothing) ----
|
|
861
904
|
/** Snapshot the captures, deploys and notes so far; the result undoes everything since. */
|
|
@@ -1048,11 +1091,18 @@ export function bonusPasses(pc, ps, book, hd, tgt, prev) {
|
|
|
1048
1091
|
return null;
|
|
1049
1092
|
const f = frontierOf(held, stays);
|
|
1050
1093
|
const next = keptIncome(held);
|
|
1051
|
-
|
|
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)
|
|
1052
1099
|
return null;
|
|
1100
|
+
const byPools = pooled !== null && f.holdCost <= next;
|
|
1053
1101
|
if (!stopped.some((x) => x.t === t))
|
|
1054
|
-
stopped.push({ t, holdCost: f.holdCost, income: next });
|
|
1055
|
-
return
|
|
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).`;
|
|
1056
1106
|
};
|
|
1057
1107
|
/** #297: " facing player P" for the opponent beside `t` (in a 1v1, the one opponent), else nothing. */
|
|
1058
1108
|
const gateFoe = (t) => {
|
|
@@ -1061,6 +1111,17 @@ export function bonusPasses(pc, ps, book, hd, tgt, prev) {
|
|
|
1061
1111
|
.find((x) => x?.kind === 'player' && pc.foe(x.playerId));
|
|
1062
1112
|
return o?.kind === 'player' ? ` facing player ${o.playerId}` : '';
|
|
1063
1113
|
};
|
|
1114
|
+
/**
|
|
1115
|
+
* #426: whether only the fog faces `t` once taken: no neighbour not mine is a player's territory shown with
|
|
1116
|
+
* its armies (a stack in view). A player's territory whose armies the fog hides, or one not shown at all,
|
|
1117
|
+
* is the fog.
|
|
1118
|
+
*/
|
|
1119
|
+
const fogOnlyFaces = (t) => neighborsOf(g, t).every((n) => {
|
|
1120
|
+
if (mineSet.has(n))
|
|
1121
|
+
return true;
|
|
1122
|
+
const st = state.get(n);
|
|
1123
|
+
return !(st?.owner.kind === 'player' && pc.foe(st.owner.playerId) && visibleState(st));
|
|
1124
|
+
});
|
|
1064
1125
|
/**
|
|
1065
1126
|
* Rule 4d's frontier budget, judged with `t` just captured: under a guarded goal, a capture
|
|
1066
1127
|
* that adds a border facing an enemy without completing a bonus (and not focused) is stopped
|
|
@@ -1080,11 +1141,12 @@ export function bonusPasses(pc, ps, book, hd, tgt, prev) {
|
|
|
1080
1141
|
const f = frontierOf(held, stays);
|
|
1081
1142
|
const next = keptIncome(held);
|
|
1082
1143
|
const start = startHold();
|
|
1083
|
-
if (f.holdCost <= next)
|
|
1084
|
-
return null;
|
|
1085
1144
|
// #297: in a 1v1 the start-of-turn hold is no excuse — a capture that opens another gate the next income
|
|
1086
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.
|
|
1087
1147
|
const gate = pc.profile.format === '1v1' ? gateStop(t) : null;
|
|
1148
|
+
if (f.holdCost <= next && !gate)
|
|
1149
|
+
return null;
|
|
1088
1150
|
if (f.holdCost <= start && !gate)
|
|
1089
1151
|
return null;
|
|
1090
1152
|
// #281: land a static seat left, which a live stack beside it takes free next turn: the border
|
|
@@ -1102,8 +1164,18 @@ export function bonusPasses(pc, ps, book, hd, tgt, prev) {
|
|
|
1102
1164
|
denied.set(t, emptyEnemyLine(pc, t, e));
|
|
1103
1165
|
return null;
|
|
1104
1166
|
}
|
|
1167
|
+
// #426: a no-loss neutral whose new border faces only the fog (no player's territory beside it shown with
|
|
1168
|
+
// its armies): its hold cost prices a stack nobody has seen, and the capture risks only the armies that
|
|
1169
|
+
// land. Not in a 1v1, where #297's gate budget prices the one opponent's floating deploy wherever it is.
|
|
1170
|
+
// The owner's cap (2026-11-22): only while the hold the capture adds is at most the next income (1×);
|
|
1171
|
+
// over it, rule 4d decides as before (a golden synthetic board let one through at 85 against an income of 9).
|
|
1172
|
+
const adds = f.holdCost - frontierOf(without, stays).holdCost;
|
|
1173
|
+
if (!gate && adds <= next && noLossNeutral(pc, tgt, t) && fogOnlyFaces(t)) {
|
|
1174
|
+
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
|
+
return null;
|
|
1176
|
+
}
|
|
1105
1177
|
// Only the 1v1 gate budget stops it (rule 4d's start-of-turn escape would have let it through): its own line.
|
|
1106
|
-
if (gate && f.holdCost <= start)
|
|
1178
|
+
if (gate && (f.holdCost <= start || f.holdCost <= next))
|
|
1107
1179
|
return gate;
|
|
1108
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).` : ''}`;
|
|
1109
1181
|
if (!stopped.some((x) => x.t === t))
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
// #265: a member of a bonus this turn's captures complete that faces an enemy and is short of its
|
|
2
|
+
// hold once the captures land. Rule 1c (#18) and the #122 garrison keep and garrison such members;
|
|
3
|
+
// what neither could fund is the leftover's first call (rule 5, plan/leftover.ts), and a combined
|
|
4
|
+
// capture (#17) it is a source of is rebalanced at the same kills to leave armies on it
|
|
5
|
+
// (plan/captures.ts, `rebalanceCombined`).
|
|
6
|
+
import { paybackLive } from './state.js';
|
|
1
7
|
/**
|
|
2
8
|
* `weakMember(id)`: my open `id` in a positive bonus this turn's captures complete (one I did not
|
|
3
9
|
* hold at the start), next to a visible enemy once the captures land, whose `stays` armies (with
|
|
@@ -8,7 +14,8 @@ export function completedMembers(pc, ps, threats, open, stays) {
|
|
|
8
14
|
const { g, mine, mineSet, completedBy, bonusTs, unitsAt, toTake } = pc;
|
|
9
15
|
const before = new Set(completedBy(mineSet));
|
|
10
16
|
const now = completedBy(new Set([...mine, ...ps.captured]))
|
|
11
|
-
|
|
17
|
+
// #422: a payback completion is expected to fall next turn: its members are no weak members to fund.
|
|
18
|
+
.filter((b) => !before.has(b) && !paybackLive(ps, ps.paybackBonuses, b) && (g.bonusById.get(b)?.value ?? 0) > 0)
|
|
12
19
|
.sort((a, b) => g.bonusById.get(b).value - g.bonusById.get(a).value || a - b);
|
|
13
20
|
const weakMember = (id) => {
|
|
14
21
|
if (!now.length || !mineSet.has(id) || !open(id))
|
|
@@ -20,6 +20,21 @@ import { teamFocusLine } from './team.js';
|
|
|
20
20
|
import { byNum } from './util.js';
|
|
21
21
|
/** #272: a target holding at most this many armies is "empty or near-empty". */
|
|
22
22
|
export const CONCEDED_OUT_MAX = 2;
|
|
23
|
+
/**
|
|
24
|
+
* #286: rule 1c keeps my `x` — a positive bonus containing it is completed by this turn's captures —
|
|
25
|
+
* so its armies would not withdraw: they are its garrison, not a free step. Live, a +2 member
|
|
26
|
+
* attacked out with 3 into an uneconomic bonus, was kept, and ended 1 army short of its hold.
|
|
27
|
+
*/
|
|
28
|
+
export function keptByCompletion(pc, ps, x) {
|
|
29
|
+
const { g, mineSet } = pc;
|
|
30
|
+
const holding = (y) => mineSet.has(y) || ps.captured.has(y);
|
|
31
|
+
return g.map.bonuses.some((b) => {
|
|
32
|
+
if (b.value <= 0)
|
|
33
|
+
return false;
|
|
34
|
+
const ts = bonusTerritories(g, b.id);
|
|
35
|
+
return ts.includes(x) && ts.every(holding) && !ts.every((y) => mineSet.has(y));
|
|
36
|
+
});
|
|
37
|
+
}
|
|
23
38
|
export function attackOutOfConceded(pc, ps, book, hd, tgt, caps) {
|
|
24
39
|
const { g, goal, foe, territories: state, label, bonusName, mineSet, unitsAt, uncounted, defenceAt, costAt, myCommanders, noSplit } = pc;
|
|
25
40
|
const { avail, captured, spared, rationale } = ps;
|
|
@@ -46,17 +61,7 @@ export function attackOutOfConceded(pc, ps, book, hd, tgt, caps) {
|
|
|
46
61
|
}
|
|
47
62
|
return { completes, advances };
|
|
48
63
|
};
|
|
49
|
-
|
|
50
|
-
* #286: rule 1c keeps `x` — a positive bonus containing it is completed by this turn's captures —
|
|
51
|
-
* so its armies would not withdraw: they are its garrison, not a free step. Live, a +2 member
|
|
52
|
-
* attacked out with 3 into an uneconomic bonus, was kept, and ended 1 army short of its hold.
|
|
53
|
-
*/
|
|
54
|
-
const keptBy1c = (x) => g.map.bonuses.some((b) => {
|
|
55
|
-
if (b.value <= 0)
|
|
56
|
-
return false;
|
|
57
|
-
const ts = bonusTerritories(g, b.id);
|
|
58
|
-
return ts.includes(x) && ts.every(holding) && !ts.every((y) => mineSet.has(y));
|
|
59
|
-
});
|
|
64
|
+
const keptBy1c = (x) => keptByCompletion(pc, ps, x);
|
|
60
65
|
const tried = new Set();
|
|
61
66
|
for (;;) {
|
|
62
67
|
const cands = [];
|