@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
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { bonusTerritories } from '../bonuses.js';
|
|
2
|
+
/** #298: failed attempts on consecutive turns that end piecemeal funding. */
|
|
3
|
+
export const FAILED_ATTEMPTS = 2;
|
|
4
|
+
/** #298: an all-in push costs at most this many turns of the bonus's value (and at most my income). */
|
|
5
|
+
export const ALL_IN_VALUE_TURNS = 2;
|
|
6
|
+
/** #298: turns a dropped bonus is not funded, the turn it is dropped on included. */
|
|
7
|
+
export const DROP_TURNS = 3;
|
|
8
|
+
/** #298: attempts older than this many turns are forgotten. */
|
|
9
|
+
export const ATTEMPT_MEMORY_TURNS = 6;
|
|
10
|
+
const complete = (g, board, me, bonusId) => {
|
|
11
|
+
const ts = bonusTerritories(g, bonusId);
|
|
12
|
+
const at = new Map(board.territories.map((t) => [t.territoryId, t]));
|
|
13
|
+
return ts.length > 0 && ts.every((t) => {
|
|
14
|
+
const o = at.get(t)?.owner;
|
|
15
|
+
return o?.kind === 'player' && o.playerId === me;
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* The memory with the attempts made on `turn − 1` judged against `turn`'s board (`board`): failed when
|
|
20
|
+
* the bonus is not all mine. Idempotent: planning a turn again judges them the same way.
|
|
21
|
+
*/
|
|
22
|
+
export function judgeAttempts(memory, turn, g, board, me) {
|
|
23
|
+
return {
|
|
24
|
+
bonuses: memory.bonuses.map((r) => ({
|
|
25
|
+
...r,
|
|
26
|
+
attempts: r.attempts.map((a) => (a.turn === turn - 1 && a.failed === undefined ? { ...a, failed: !complete(g, board, me, r.bonusId) } : a)),
|
|
27
|
+
})),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** The failed attempts that end on `turn − 1`, on consecutive turns, oldest first. */
|
|
31
|
+
function failedRun(r, turn) {
|
|
32
|
+
const byTurn = new Map(r.attempts.map((a) => [a.turn, a]));
|
|
33
|
+
const run = [];
|
|
34
|
+
for (let t = turn - 1; byTurn.get(t)?.failed === true; t--)
|
|
35
|
+
run.unshift(byTurn.get(t));
|
|
36
|
+
return run;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* #298: each bonus the (judged) memory gives a verdict for on `turn`, by bonus id: still dropped (a drop
|
|
40
|
+
* made on an earlier turn running to this one); dropped now (last turn's all-in failed); or all-in (the
|
|
41
|
+
* last {@link FAILED_ATTEMPTS} turns' attempts failed, none of them all-in). A drop this turn's own
|
|
42
|
+
* earlier plan made is ignored, so planning a turn again decides it again.
|
|
43
|
+
*/
|
|
44
|
+
export function bonusVerdicts(memory, turn) {
|
|
45
|
+
const out = [];
|
|
46
|
+
for (const r of [...(memory?.bonuses ?? [])].sort((a, b) => a.bonusId - b.bonusId)) {
|
|
47
|
+
const run = failedRun(r, turn);
|
|
48
|
+
const failedTurns = run.map((a) => a.turn);
|
|
49
|
+
if (r.drop && r.drop.from < turn && r.drop.until >= turn) {
|
|
50
|
+
out.push({ bonusId: r.bonusId, kind: 'dropped', why: 'still-dropped', from: r.drop.from, until: r.drop.until, failedTurns });
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const last = run[run.length - 1];
|
|
54
|
+
if (last?.allIn) {
|
|
55
|
+
out.push({ bonusId: r.bonusId, kind: 'dropped', why: 'all-in-failed', from: turn, until: turn + DROP_TURNS - 1, failedTurns });
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (run.length >= FAILED_ATTEMPTS)
|
|
59
|
+
out.push({ bonusId: r.bonusId, kind: 'all-in', failedTurns: failedTurns.slice(-FAILED_ATTEMPTS) });
|
|
60
|
+
}
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* #298: the memory to keep after planning `turn` on `board` (the start of the turn): the attempts on
|
|
65
|
+
* `turn - 1` judged; this turn's attempts (every contested bonus the plan expects to complete,
|
|
66
|
+
* `completes`, the plan's `expected.bonusesCompleted`; all-in when `push` says so) in place of any an
|
|
67
|
+
* earlier plan of this turn recorded; this turn's drops from `push`; nothing older than
|
|
68
|
+
* {@link ATTEMPT_MEMORY_TURNS} turns. Only a completion is an attempt: a turn that only advances a bonus
|
|
69
|
+
* leaves it incomplete by design, and a capture that also steps into a larger bonus is no try at it.
|
|
70
|
+
*/
|
|
71
|
+
export function rememberBonusAttempts(memory, turn, g, board, me, completes, push = []) {
|
|
72
|
+
const judged = judgeAttempts(memory ?? { bonuses: [] }, turn, g, board, me);
|
|
73
|
+
const at = new Map(board.territories.map((t) => [t.territoryId, t]));
|
|
74
|
+
const records = new Map();
|
|
75
|
+
for (const r of judged.bonuses) {
|
|
76
|
+
const drop = r.drop && r.drop.from !== turn ? r.drop : undefined;
|
|
77
|
+
records.set(r.bonusId, { bonusId: r.bonusId, attempts: r.attempts.filter((a) => a.turn !== turn), ...(drop ? { drop } : {}) });
|
|
78
|
+
}
|
|
79
|
+
const allIn = new Set(push.filter((p) => p.kind === 'all-in').map((p) => p.bonusId));
|
|
80
|
+
for (const id of [...new Set(completes)].sort((a, b) => a - b)) {
|
|
81
|
+
const b = g.bonusById.get(id);
|
|
82
|
+
if (!b || b.value <= 0)
|
|
83
|
+
continue;
|
|
84
|
+
const contested = bonusTerritories(g, id).some((t) => {
|
|
85
|
+
const o = at.get(t)?.owner;
|
|
86
|
+
return o?.kind === 'player' && o.playerId !== me;
|
|
87
|
+
});
|
|
88
|
+
if (!contested)
|
|
89
|
+
continue;
|
|
90
|
+
const r = records.get(id) ?? { bonusId: id, attempts: [] };
|
|
91
|
+
r.attempts = [...r.attempts, { turn, allIn: allIn.has(id) }].sort((x, y) => x.turn - y.turn);
|
|
92
|
+
records.set(id, r);
|
|
93
|
+
}
|
|
94
|
+
for (const p of push)
|
|
95
|
+
if (p.kind === 'dropped' && p.from === turn) {
|
|
96
|
+
const r = records.get(p.bonusId) ?? { bonusId: p.bonusId, attempts: [] };
|
|
97
|
+
r.drop = { from: p.from, until: p.until };
|
|
98
|
+
records.set(p.bonusId, r);
|
|
99
|
+
}
|
|
100
|
+
const bonuses = [...records.values()]
|
|
101
|
+
.map((r) => ({ ...r, attempts: r.attempts.filter((a) => a.turn > turn - ATTEMPT_MEMORY_TURNS) }))
|
|
102
|
+
.filter((r) => r.attempts.length || (r.drop && r.drop.until >= turn))
|
|
103
|
+
.sort((a, b) => a.bonusId - b.bonusId);
|
|
104
|
+
return { bonuses };
|
|
105
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// #285: capture the one enemy stack a held bonus's borders face, rather than hold them against it.
|
|
2
|
+
// Rule 1h holds a contested held bonus whole from what the captures leave (#118). Live, two borders
|
|
3
|
+
// that faced only one enemy stack were held against it and its owner's deploy (41 deployed on one
|
|
4
|
+
// of them), while capturing the stack would have left both borders interior. Owner decisions of
|
|
5
|
+
// 2026-11-19: the capture is sized against the same deploy estimate the holds are sized against
|
|
6
|
+
// (#368's middle figure, through `reinforcementAt`: rule 3's #120 sizing, so it lands even if the
|
|
7
|
+
// owner deploys there first), and the hold it saves is credited for HOLD_CREDIT_TURNS turns, since
|
|
8
|
+
// a border that stops being one needs no hold on the turns after this one either.
|
|
9
|
+
// So, once the capture passes have run and before `settleContested` holds the contested units: for
|
|
10
|
+
// each enemy territory S beside a contested member still unheld, the members that border no enemy,
|
|
11
|
+
// fog or hidden territory but S (and face no threat once S falls) are its interior set. When the
|
|
12
|
+
// deploy that captures S from one of them (the one needing the least; it keeps what it still must
|
|
13
|
+
// hold, #172's two-step keep included) is at most HOLD_CREDIT_TURNS × the hold costs of that set,
|
|
14
|
+
// and the turn can fund it, S is captured from there and the set is held: rule 1h no longer deploys
|
|
15
|
+
// to it. Largest saving first, then id; repeated while one is taken. Not under No-Split (an order
|
|
16
|
+
// carries the whole stack), never from my commander's territory, never a truce's covered territory,
|
|
17
|
+
// a buffer left standing (#179), a territory with a special unit or one whose capture lowers income.
|
|
18
|
+
import { neighborsOf } from '../graph.js';
|
|
19
|
+
import { byNum } from './util.js';
|
|
20
|
+
/** #285 (owner decision of 2026-11-19): the turns a hold made unnecessary by a capture is credited for. */
|
|
21
|
+
export const HOLD_CREDIT_TURNS = 3;
|
|
22
|
+
export function captureInsteadOfHold(pc, ps, book, threats, hd, tgt, caps) {
|
|
23
|
+
const { g, foe, territories: state, label, mineSet, unitsAt, uncounted, defenceAt, costAt, myCommanders, noSplit } = pc;
|
|
24
|
+
const { avail, captured, spared, rationale } = ps;
|
|
25
|
+
const { units, heldBorders, conceded, keepFor, twoStepKeep } = hd;
|
|
26
|
+
const { borderAt, reinforcementAt } = threats;
|
|
27
|
+
const { targets } = tgt;
|
|
28
|
+
const { gainWith, spareAt, orderOf } = book;
|
|
29
|
+
if (noSplit)
|
|
30
|
+
return;
|
|
31
|
+
const tried = new Set();
|
|
32
|
+
for (;;) {
|
|
33
|
+
const members = [
|
|
34
|
+
...new Set(units
|
|
35
|
+
.filter((u) => u.contested && !u.conceded)
|
|
36
|
+
.flatMap((u) => u.members.filter((m) => !heldBorders.has(m.id) && !conceded.has(m.id) && m.holdCost > 0))),
|
|
37
|
+
].sort((a, b) => a.id - b.id);
|
|
38
|
+
if (!members.length)
|
|
39
|
+
return;
|
|
40
|
+
const foeOf = (n) => {
|
|
41
|
+
const o = state.get(n)?.owner;
|
|
42
|
+
return o?.kind === 'player' && foe(o.playerId) ? o.playerId : undefined;
|
|
43
|
+
};
|
|
44
|
+
/** Every neighbour of `x` but `s` is mine, captured, a neutral in view or a teammate's: no frontier left. */
|
|
45
|
+
const closedBut = (x, s) => neighborsOf(g, x).every((y) => {
|
|
46
|
+
if (y === s || mineSet.has(y) || captured.has(y))
|
|
47
|
+
return true;
|
|
48
|
+
const st = state.get(y);
|
|
49
|
+
if (!st || st.armies === null)
|
|
50
|
+
return false;
|
|
51
|
+
return st.owner.kind === 'neutral' || (st.owner.kind === 'player' && !foe(st.owner.playerId));
|
|
52
|
+
});
|
|
53
|
+
let best;
|
|
54
|
+
const seen = [...new Set(members.flatMap((m) => neighborsOf(g, m.id)))].sort(byNum);
|
|
55
|
+
for (const s of seen) {
|
|
56
|
+
const player = foeOf(s);
|
|
57
|
+
const st = state.get(s);
|
|
58
|
+
if (player === undefined || !st || st.armies === null)
|
|
59
|
+
continue;
|
|
60
|
+
if (tried.has(s) || captured.has(s) || spared.has(s) || pc.truce.noTarget(s) || uncounted(s) || unitsAt(s) > 0)
|
|
61
|
+
continue;
|
|
62
|
+
const gone = (n) => n === s;
|
|
63
|
+
const set = members.filter((m) => neighborsOf(g, m.id).includes(s) && closedBut(m.id, s) && !borderAt(m.id, (n) => captured.has(n) || gone(n)));
|
|
64
|
+
if (!set.length || gainWith([s]) < 0)
|
|
65
|
+
continue;
|
|
66
|
+
const d = defenceAt(s);
|
|
67
|
+
const extra = reinforcementAt(s);
|
|
68
|
+
const cost = costAt(s, d + extra);
|
|
69
|
+
if (cost === null)
|
|
70
|
+
continue;
|
|
71
|
+
const credit = HOLD_CREDIT_TURNS * set.reduce((n, m) => n + m.holdCost, 0);
|
|
72
|
+
const src = set
|
|
73
|
+
.filter((m) => !myCommanders.has(m.id) && !orderOf(m.id))
|
|
74
|
+
.map((m) => {
|
|
75
|
+
const keep = Math.max(keepFor(m.id, gone), twoStepKeep(m.id, gone));
|
|
76
|
+
return { id: m.id, keep, need: Math.max(0, cost - (avail.get(m.id) - keep)) };
|
|
77
|
+
})
|
|
78
|
+
.filter((o) => o.need <= spareAt(o.id))
|
|
79
|
+
.sort((a, b) => a.need - b.need || a.id - b.id)[0];
|
|
80
|
+
if (!src || src.need > credit)
|
|
81
|
+
continue;
|
|
82
|
+
const c = { s, src: src.id, keep: src.keep, need: src.need, cost, d, extra, set, credit };
|
|
83
|
+
if (!best || c.credit - c.need > best.credit - best.need)
|
|
84
|
+
best = c;
|
|
85
|
+
}
|
|
86
|
+
if (!best)
|
|
87
|
+
return;
|
|
88
|
+
const c = best;
|
|
89
|
+
tried.add(c.s);
|
|
90
|
+
const prev = targets.get(c.s);
|
|
91
|
+
targets.set(c.s, { id: c.s, cost: c.cost, enemy: true, sources: [c.src] });
|
|
92
|
+
const hadWorst = caps.worstCase.get(c.s);
|
|
93
|
+
caps.worstCase.set(c.s, c.d + c.extra);
|
|
94
|
+
const player = foeOf(c.s);
|
|
95
|
+
const names = c.set.map((m) => label(m.id)).join(', ');
|
|
96
|
+
const holds = c.set.reduce((n, m) => n + m.holdCost, 0);
|
|
97
|
+
const reason = `takes the one enemy stack beside ${names}, sure even if player ${player} deploys its ~${c.extra} there first (${c.d} + ${c.extra} defenders), so ${c.set.length === 1 ? 'that border needs' : 'those borders need'} no hold (#285)`;
|
|
98
|
+
if (!caps.tryCapture(c.s, reason, { from: c.src, keep: c.keep })) {
|
|
99
|
+
if (prev)
|
|
100
|
+
targets.set(c.s, prev);
|
|
101
|
+
else
|
|
102
|
+
targets.delete(c.s);
|
|
103
|
+
if (hadWorst === undefined)
|
|
104
|
+
caps.worstCase.delete(c.s);
|
|
105
|
+
else
|
|
106
|
+
caps.worstCase.set(c.s, hadWorst);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
for (const m of c.set)
|
|
110
|
+
heldBorders.add(m.id);
|
|
111
|
+
for (const u of units)
|
|
112
|
+
if (u.contested && u.members.every((m) => heldBorders.has(m.id)))
|
|
113
|
+
u.contested = false;
|
|
114
|
+
rationale.push(`Take ${label(c.s)} from ${label(c.src)} rather than hold ${names}: a deploy of ${c.need} sends ${c.cost}, sure even if player ${player} deploys its ~${c.extra} there first, against the ${holds} the ${c.set.length === 1 ? 'hold' : 'holds'} would cost this turn (${c.credit} for ${HOLD_CREDIT_TURNS} turns); once it falls ${names} ${c.set.length === 1 ? 'borders' : 'border'} no enemy (#285).`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// 4c(c), rule 4d's frontier budget). planPass runs the passes, the strikes and pass 3 with them.
|
|
5
5
|
import { bonusTerritories } from '../bonuses.js';
|
|
6
6
|
import { armiesToTake, straightKills } from '../combat.js';
|
|
7
|
+
import { neighborsOf } from '../graph.js';
|
|
7
8
|
import { captureCost } from './shared.js';
|
|
8
9
|
import { byNum } from './util.js';
|
|
9
10
|
import { denialLine, emptyEnemyLine } from './vacated.js';
|
|
@@ -515,8 +516,9 @@ export function captureHelper(pc, ps, pass, book, threats, hd, tgt, prev) {
|
|
|
515
516
|
}
|
|
516
517
|
return true;
|
|
517
518
|
};
|
|
518
|
-
|
|
519
|
-
|
|
519
|
+
// #421: the strike share is said on its own line (planner.ts), not as the caller's reserve.
|
|
520
|
+
if (reserve - pc.strikeShare)
|
|
521
|
+
rationale.push(`Hold a reserve of ${reserve - pc.strikeShare} out of captures.`);
|
|
520
522
|
// ---- 3a. combined (multi-source) captures (R4) ----
|
|
521
523
|
/**
|
|
522
524
|
* The cheapest combined capture of `t` (fewest sources) under exact 0%-luck,
|
|
@@ -1027,11 +1029,43 @@ export function bonusPasses(pc, ps, book, hd, tgt, prev) {
|
|
|
1027
1029
|
const denied = new Map();
|
|
1028
1030
|
/** The start of rule 4d's rationale line for a stopped `t` (one per attempt that differed). */
|
|
1029
1031
|
const stoppedLine = (t) => `Do not take ${label(t)}: it adds a border facing an enemy without completing a bonus,`;
|
|
1032
|
+
/**
|
|
1033
|
+
* #297: in a 1v1, the gate budget's veto: a capture of `t` that opens another border facing the opponent (a gate,
|
|
1034
|
+
* each sized for its stack plus the whole floating deploy) is stopped when the frontier would then need more next
|
|
1035
|
+
* turn than the next income, and more than it needs without that capture. Its rationale line, else `null`. Rule
|
|
1036
|
+
* 4d runs it in a 1v1 in place of its start-of-turn escape, and rule 4e's contact fallback runs it where rule 4d is
|
|
1037
|
+
* only a cost (#114): a gate the income cannot hold is lost next turn, armies and all.
|
|
1038
|
+
*/
|
|
1039
|
+
const gateStop = (t) => {
|
|
1040
|
+
if (pc.profile.format !== '1v1' || !guarded || inFocus(t))
|
|
1041
|
+
return null;
|
|
1042
|
+
const held = heldNow();
|
|
1043
|
+
if (completedBy(held).some((id) => g.bonusById.get(id).value > 0 && bonusTs.get(id).includes(t)))
|
|
1044
|
+
return null;
|
|
1045
|
+
const stays = (x) => (mineSet.has(x) ? stayAt(x) : (survivorsAt.get(x) ?? 0));
|
|
1046
|
+
const without = new Set([...held].filter((x) => x !== t));
|
|
1047
|
+
if (frontierDelta(without, [t], stays).enemy <= 0)
|
|
1048
|
+
return null;
|
|
1049
|
+
const f = frontierOf(held, stays);
|
|
1050
|
+
const next = keptIncome(held);
|
|
1051
|
+
if (f.holdCost <= next || f.holdCost <= frontierOf(without, stays).holdCost)
|
|
1052
|
+
return null;
|
|
1053
|
+
if (!stopped.some((x) => x.t === t))
|
|
1054
|
+
stopped.push({ t, holdCost: f.holdCost, income: next });
|
|
1055
|
+
return `${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
|
+
};
|
|
1057
|
+
/** #297: " facing player P" for the opponent beside `t` (in a 1v1, the one opponent), else nothing. */
|
|
1058
|
+
const gateFoe = (t) => {
|
|
1059
|
+
const o = neighborsOf(g, t)
|
|
1060
|
+
.map((n) => state.get(n)?.owner)
|
|
1061
|
+
.find((x) => x?.kind === 'player' && pc.foe(x.playerId));
|
|
1062
|
+
return o?.kind === 'player' ? ` facing player ${o.playerId}` : '';
|
|
1063
|
+
};
|
|
1030
1064
|
/**
|
|
1031
1065
|
* Rule 4d's frontier budget, judged with `t` just captured: under a guarded goal, a capture
|
|
1032
1066
|
* that adds a border facing an enemy without completing a bonus (and not focused) is stopped
|
|
1033
1067
|
* when holding the frontier next turn would then need more than the next income, and more than
|
|
1034
|
-
* it needed at the start of the turn. Returns the rationale line when stopped, else `null`.
|
|
1068
|
+
* it needed at the start of the turn (in a 1v1, more than without it: {@link gateStop}, #297). Returns the rationale line when stopped, else `null`.
|
|
1035
1069
|
*/
|
|
1036
1070
|
const outgrows = (t) => {
|
|
1037
1071
|
if (!guarded || inFocus(t))
|
|
@@ -1046,7 +1080,12 @@ export function bonusPasses(pc, ps, book, hd, tgt, prev) {
|
|
|
1046
1080
|
const f = frontierOf(held, stays);
|
|
1047
1081
|
const next = keptIncome(held);
|
|
1048
1082
|
const start = startHold();
|
|
1049
|
-
if (f.holdCost <= next
|
|
1083
|
+
if (f.holdCost <= next)
|
|
1084
|
+
return null;
|
|
1085
|
+
// #297: in a 1v1 the start-of-turn hold is no excuse — a capture that opens another gate the next income
|
|
1086
|
+
// cannot hold is stopped even when this turn's other orders bring the total back under where it started.
|
|
1087
|
+
const gate = pc.profile.format === '1v1' ? gateStop(t) : null;
|
|
1088
|
+
if (f.holdCost <= start && !gate)
|
|
1050
1089
|
return null;
|
|
1051
1090
|
// #281: land a static seat left, which a live stack beside it takes free next turn: the border
|
|
1052
1091
|
// comes either way, so the hold cost alone never refuses it (the capture still spends only what
|
|
@@ -1063,7 +1102,10 @@ export function bonusPasses(pc, ps, book, hd, tgt, prev) {
|
|
|
1063
1102
|
denied.set(t, emptyEnemyLine(pc, t, e));
|
|
1064
1103
|
return null;
|
|
1065
1104
|
}
|
|
1066
|
-
|
|
1105
|
+
// 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)
|
|
1107
|
+
return gate;
|
|
1108
|
+
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).` : ''}`;
|
|
1067
1109
|
if (!stopped.some((x) => x.t === t))
|
|
1068
1110
|
stopped.push({ t, holdCost: f.holdCost, income: next });
|
|
1069
1111
|
return why;
|
|
@@ -1152,7 +1194,7 @@ export function bonusPasses(pc, ps, book, hd, tgt, prev) {
|
|
|
1152
1194
|
if (stepping === null)
|
|
1153
1195
|
continue;
|
|
1154
1196
|
const worth = p.net === p.value ? `+${p.value}` : `+${p.value}, net +${p.net}`;
|
|
1155
|
-
const reason = (stepping?.reason ?? `advances bonus ${bonusName(p.bonusId)} (${worth}, ${toFinish(p.cost, p
|
|
1197
|
+
const reason = (stepping?.reason ?? `advances bonus ${bonusName(p.bonusId)} (${worth}, ${toFinish(p.cost, p)})`) + leadNote(t);
|
|
1156
1198
|
// Only a lead step (#203) can be funded on a conceded source.
|
|
1157
1199
|
const before = whole || !lead ? undefined : snapshot();
|
|
1158
1200
|
const tried = before && new Map(leadTry);
|
|
@@ -1191,5 +1233,5 @@ export function bonusPasses(pc, ps, book, hd, tgt, prev) {
|
|
|
1191
1233
|
if (closest)
|
|
1192
1234
|
run(todo.filter((t) => leadSteps.has(t) && !captured.has(t)), true);
|
|
1193
1235
|
};
|
|
1194
|
-
return { snapshot, complete, unstaged, stage, stopped, stoppedLine, denied, outgrows, tryExpand, advance };
|
|
1236
|
+
return { snapshot, complete, unstaged, stage, stopped, stoppedLine, denied, outgrows, gateStop, tryExpand, advance };
|
|
1195
1237
|
}
|
|
@@ -46,11 +46,22 @@ export function attackOutOfConceded(pc, ps, book, hd, tgt, caps) {
|
|
|
46
46
|
}
|
|
47
47
|
return { completes, advances };
|
|
48
48
|
};
|
|
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
|
+
});
|
|
49
60
|
const tried = new Set();
|
|
50
61
|
for (;;) {
|
|
51
62
|
const cands = [];
|
|
52
63
|
for (const x of [...conceded].sort(byNum)) {
|
|
53
|
-
if (!mineSet.has(x) || myCommanders.has(x))
|
|
64
|
+
if (!mineSet.has(x) || myCommanders.has(x) || keptBy1c(x))
|
|
54
65
|
continue;
|
|
55
66
|
// #272 review: what tryCapture's forced source may spend: a covered exit (#179) keeps its cover
|
|
56
67
|
// (No-Split sends the whole stack).
|
|
@@ -58,7 +69,7 @@ export function attackOutOfConceded(pc, ps, book, hd, tgt, caps) {
|
|
|
58
69
|
if (n <= 0)
|
|
59
70
|
continue;
|
|
60
71
|
for (const t of neighborsOf(g, x)) {
|
|
61
|
-
if (mineSet.has(t) || captured.has(t) || spared.has(t) || tried.has(t) || pc.truce.noTarget(t))
|
|
72
|
+
if (mineSet.has(t) || captured.has(t) || spared.has(t) || tried.has(t) || pc.truce.noTarget(t) || tgt.droppedMembers.has(t))
|
|
62
73
|
continue;
|
|
63
74
|
const st = state.get(t);
|
|
64
75
|
if (!st || st.armies === null || uncounted(t) || unitsAt(t) > 0)
|