@chrischall/warapp-mcp 0.0.0 → 0.1.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.
Files changed (177) hide show
  1. package/.claude-plugin/marketplace.json +4 -4
  2. package/.claude-plugin/plugin.json +2 -2
  3. package/README.md +199 -8
  4. package/dist/analysis/award.js +159 -0
  5. package/dist/analysis/bonuses.js +98 -0
  6. package/dist/analysis/breach.js +62 -0
  7. package/dist/analysis/card-support.js +329 -0
  8. package/dist/analysis/card-threats.js +234 -0
  9. package/dist/analysis/cards-in-effect.js +130 -0
  10. package/dist/analysis/chains.js +59 -0
  11. package/dist/analysis/chokepoints.js +140 -0
  12. package/dist/analysis/combat.js +231 -0
  13. package/dist/analysis/commander-safety.js +149 -0
  14. package/dist/analysis/commitments.js +338 -0
  15. package/dist/analysis/exchange.js +155 -0
  16. package/dist/analysis/graph.js +82 -0
  17. package/dist/analysis/guard-off.js +54 -0
  18. package/dist/analysis/guess.js +351 -0
  19. package/dist/analysis/headroom.js +241 -0
  20. package/dist/analysis/hold-diff.js +64 -0
  21. package/dist/analysis/how-lost.js +130 -0
  22. package/dist/analysis/index.js +14 -0
  23. package/dist/analysis/local-deploy.js +159 -0
  24. package/dist/analysis/lookahead.js +108 -0
  25. package/dist/analysis/opponent-profile.js +551 -0
  26. package/dist/analysis/opponents.js +1245 -0
  27. package/dist/analysis/outlook.js +633 -0
  28. package/dist/analysis/overrides.js +60 -0
  29. package/dist/analysis/picks.js +1879 -0
  30. package/dist/analysis/plan/after-leftover.js +140 -0
  31. package/dist/analysis/plan/cap-spend.js +242 -0
  32. package/dist/analysis/plan/captures.js +1195 -0
  33. package/dist/analysis/plan/commander.js +236 -0
  34. package/dist/analysis/plan/completed.js +29 -0
  35. package/dist/analysis/plan/conceded-out.js +131 -0
  36. package/dist/analysis/plan/estimates.js +715 -0
  37. package/dist/analysis/plan/guard-off.js +232 -0
  38. package/dist/analysis/plan/holds.js +1631 -0
  39. package/dist/analysis/plan/leftover.js +760 -0
  40. package/dist/analysis/plan/move-order.js +319 -0
  41. package/dist/analysis/plan/orders.js +317 -0
  42. package/dist/analysis/plan/relations.js +702 -0
  43. package/dist/analysis/plan/report.js +672 -0
  44. package/dist/analysis/plan/shared.js +1218 -0
  45. package/dist/analysis/plan/stand-still.js +823 -0
  46. package/dist/analysis/plan/state.js +44 -0
  47. package/dist/analysis/plan/strike.js +1416 -0
  48. package/dist/analysis/plan/targets.js +651 -0
  49. package/dist/analysis/plan/team.js +299 -0
  50. package/dist/analysis/plan/threats.js +927 -0
  51. package/dist/analysis/plan/transfers.js +328 -0
  52. package/dist/analysis/plan/util.js +5 -0
  53. package/dist/analysis/plan/vacated.js +285 -0
  54. package/dist/analysis/planner.js +2922 -0
  55. package/dist/analysis/player-record.js +144 -0
  56. package/dist/analysis/player.js +268 -0
  57. package/dist/analysis/profile.js +347 -0
  58. package/dist/analysis/relations.js +1030 -0
  59. package/dist/analysis/schedule.js +88 -0
  60. package/dist/analysis/since-last.js +50 -0
  61. package/dist/analysis/static-seats.js +71 -0
  62. package/dist/analysis/stress.js +577 -0
  63. package/dist/analysis/team-brief.js +151 -0
  64. package/dist/analysis/tripwire.js +644 -0
  65. package/dist/analysis/turn-sim.js +259 -0
  66. package/dist/analysis/whereabouts.js +1109 -0
  67. package/dist/board.js +105 -0
  68. package/dist/bundle.js +117959 -36172
  69. package/dist/cards.js +435 -0
  70. package/dist/chat-cursor.js +135 -0
  71. package/dist/chat.js +192 -0
  72. package/dist/client.js +361 -0
  73. package/dist/config.js +62 -0
  74. package/dist/direct/link.js +102 -0
  75. package/dist/direct/session.js +267 -0
  76. package/dist/direct/transport.js +424 -0
  77. package/dist/guess-salt.js +65 -0
  78. package/dist/hosted.js +24 -0
  79. package/dist/index.js +33 -0
  80. package/dist/join-color.js +140 -0
  81. package/dist/live.js +278 -0
  82. package/dist/map-stats.js +152 -0
  83. package/dist/map-store.js +204 -0
  84. package/dist/move-order.js +141 -0
  85. package/dist/my-games.js +180 -0
  86. package/dist/normalize.js +411 -0
  87. package/dist/open-games.js +537 -0
  88. package/dist/outlook-log.js +138 -0
  89. package/dist/path-lock.js +22 -0
  90. package/dist/pick-list.js +193 -0
  91. package/dist/player-record-store.js +229 -0
  92. package/dist/player-states.js +31 -0
  93. package/dist/profile-store.js +677 -0
  94. package/dist/protocol/bundle.js +375 -0
  95. package/dist/protocol/codec.js +556 -0
  96. package/dist/protocol/decoded.js +12 -0
  97. package/dist/protocol/interp.js +1904 -0
  98. package/dist/protocol/methods.js +531 -0
  99. package/dist/protocol/rpc.js +202 -0
  100. package/dist/push/listener.js +393 -0
  101. package/dist/push/packets.js +66 -0
  102. package/dist/push/socketio.js +333 -0
  103. package/dist/push/websocket.js +179 -0
  104. package/dist/redact.js +62 -0
  105. package/dist/relations-store.js +242 -0
  106. package/dist/replay.js +215 -0
  107. package/dist/scalars.js +28 -0
  108. package/dist/scout.js +346 -0
  109. package/dist/stats.js +269 -0
  110. package/dist/strategy/card-clock.js +185 -0
  111. package/dist/strategy/map-notes.js +128 -0
  112. package/dist/strategy/notes.js +2168 -0
  113. package/dist/team-cards.js +84 -0
  114. package/dist/team-orders.js +150 -0
  115. package/dist/teams.js +19 -0
  116. package/dist/tools/award.js +206 -0
  117. package/dist/tools/begin-turn.js +162 -0
  118. package/dist/tools/board.js +77 -0
  119. package/dist/tools/card-advice.js +256 -0
  120. package/dist/tools/card-effects.js +49 -0
  121. package/dist/tools/card-plays.js +434 -0
  122. package/dist/tools/card-support-advice.js +140 -0
  123. package/dist/tools/chat-inbox.js +146 -0
  124. package/dist/tools/chat.js +483 -0
  125. package/dist/tools/check-plan.js +688 -0
  126. package/dist/tools/commander-check.js +102 -0
  127. package/dist/tools/commitments.js +216 -0
  128. package/dist/tools/common.js +143 -0
  129. package/dist/tools/diplomacy.js +342 -0
  130. package/dist/tools/game.js +126 -0
  131. package/dist/tools/guess-view.js +56 -0
  132. package/dist/tools/healthcheck.js +90 -0
  133. package/dist/tools/hints.js +34 -0
  134. package/dist/tools/how-lost.js +154 -0
  135. package/dist/tools/index.js +142 -0
  136. package/dist/tools/join-game.js +327 -0
  137. package/dist/tools/leave-game.js +181 -0
  138. package/dist/tools/live-context.js +339 -0
  139. package/dist/tools/live.js +404 -0
  140. package/dist/tools/map-stats.js +117 -0
  141. package/dist/tools/map.js +133 -0
  142. package/dist/tools/my-games.js +123 -0
  143. package/dist/tools/open-games.js +104 -0
  144. package/dist/tools/opponents.js +151 -0
  145. package/dist/tools/order-options.js +135 -0
  146. package/dist/tools/picks.js +292 -0
  147. package/dist/tools/profile-hook.js +156 -0
  148. package/dist/tools/profile-opponents.js +121 -0
  149. package/dist/tools/profile-reads.js +99 -0
  150. package/dist/tools/push.js +385 -0
  151. package/dist/tools/relations.js +611 -0
  152. package/dist/tools/resolve.js +45 -0
  153. package/dist/tools/route.js +36 -0
  154. package/dist/tools/scout.js +87 -0
  155. package/dist/tools/session.js +163 -0
  156. package/dist/tools/strategy.js +200 -0
  157. package/dist/tools/stress-opponents.js +83 -0
  158. package/dist/tools/surrender.js +240 -0
  159. package/dist/tools/survival.js +189 -0
  160. package/dist/tools/team-brief.js +266 -0
  161. package/dist/tools/team-source.js +222 -0
  162. package/dist/tools/team.js +182 -0
  163. package/dist/tools/turn.js +2761 -0
  164. package/dist/tools/uncommit.js +160 -0
  165. package/dist/tools/where.js +275 -0
  166. package/dist/tools/write-kit.js +158 -0
  167. package/dist/transport-bridge.js +33 -0
  168. package/dist/trend.js +452 -0
  169. package/dist/version.js +4 -0
  170. package/manifest.json +174 -4
  171. package/mint.yaml +101 -14
  172. package/package.json +11 -6
  173. package/server.json +40 -3
  174. package/skills/warapp-api/SKILL.md +95 -4
  175. package/skills/warapp-api/references/scout.mjs +348 -0
  176. package/skills/warapp-api/scripts/warapp.sh +69 -8
  177. package/skills/warapp-mcp/SKILL.md +969 -21
@@ -0,0 +1,319 @@
1
+ // The move order of a planning pass (#127, #179; rule 1s; #133): Order Priority for a commander
2
+ // strike, the schedule of the moves (the protected first order, early, sure, filler and last
3
+ // slots), the first-mover warnings on finishing a player off, the exits of an opponent down to a few
4
+ // territories, the Order Priority advice and the move-position lines. planPass runs them where they
5
+ // ran before: Order Priority for a strike after the transfers (rule 6), before the expected outcome;
6
+ // the schedule after the "Not attacking" line, before the offence list is built.
7
+ import { neighborsOf } from '../graph.js';
8
+ import { captureCost, FEW_TERRITORIES, ORDER_PRIORITY_MIN_ARMIES, } from './shared.js';
9
+ import { straightKills } from '../combat.js';
10
+ import { indexAfterAll, MoveSlot, opponentOrdersBefore, scheduleMoves } from '../schedule.js';
11
+ import { byNum } from './util.js';
12
+ /** Order Priority for a strike (rule 1s): `strikeCard` when the threat to my commander advised the card. */
13
+ export function strikeOrderPriority(pc, ps, threats, hd, struck) {
14
+ const { opts, territories: state, label, unitsAt, toTake, myCommanders } = pc;
15
+ const { warnings, rationale } = ps;
16
+ const { borderAt } = threats;
17
+ const { stayAt } = hd;
18
+ // ---- Order Priority for a strike (rule 1s) ----
19
+ // war.app interleaves both players' attacks, so a struck player's stacks next to my commander
20
+ // may attack before the strike lands. Judged on what stays on my commander's territory once
21
+ // every planned deploy and move is in (a strike from it thins it), against the STRUCK players'
22
+ // visible stacks only: moving first kills their commander before they attack, but does nothing
23
+ // against a third player, so a threat from someone else is no reason to spend the card.
24
+ const commanderThreatened = [...myCommanders].some((c) => {
25
+ const b = borderAt(c, (n) => {
26
+ const st = state.get(n);
27
+ return !(st?.owner.kind === 'player' && struck.has(st.owner.playerId));
28
+ });
29
+ return b !== null && (toTake(stayAt(c) + unitsAt(c)) ?? Infinity) <= b.threat;
30
+ });
31
+ /** The threat to my commander, not a withdrawal, advised Order Priority for the strike (rule 1s). */
32
+ let strikeCard = false;
33
+ const strikeWho = [...struck].sort(byNum).map((p) => `player ${p}`).join(' and ');
34
+ if (struck.size && commanderThreatened) {
35
+ const where = [...myCommanders].map(label).join(', ');
36
+ const who = strikeWho;
37
+ if (opts.holdsOrderPriority) {
38
+ strikeCard = true;
39
+ rationale.push(`Play Order Priority: my commander's territory ${where} is threatened this turn by what is left on it after this turn's orders, and with the card my attacks resolve first, so the strike on ${who}'s commander lands before its attacks.`);
40
+ }
41
+ else
42
+ warnings.push(`My attacks and ${who}'s interleave this turn, so its stacks may attack my commander's territory ${where} before the strike lands, and what is left on it after this turn's orders would fall; I hold no Order Priority card to make my attacks resolve first.`);
43
+ }
44
+ return { strikeCard, strikeWho };
45
+ }
46
+ /** The schedule of the moves (#127), the Order Priority advice, and the exits of an opponent down to a few (#179). */
47
+ export function scheduleOrders(pc, ps, threats, hd, caps, struck, strikeCard, strikeWho) {
48
+ const { g, s, opts, foe, deployOf, territories: state, label, mine, mineSet, armiesOf, unitsAt, defenceAt, guard, rates, toTake, } = pc;
49
+ const { warnings, rationale, captured, combined, moves } = ps;
50
+ const { deployReaching, ownedBy, fogEdge } = threats;
51
+ const { conceded, stayAt } = hd;
52
+ const { strikes, worstCase, finishedOff } = caps;
53
+ // ---- 7. schedule the moves (#127) ----
54
+ // Orders zigzag (the first mover's 1st, the other's 1st and 2nd, …), so the place of a move in
55
+ // the list decides what it meets. One order is protected when Order Priority is advised.
56
+ const CONCEDED_ORDER = /; play Order Priority so it goes first\.$/;
57
+ /** The strike Order Priority protects (rule 1s), when the threat to my commander advised the card. */
58
+ const strikeOrder = strikeCard ? moves.find((m) => m.kind === 'attack' && strikes.has(m.to)) : undefined;
59
+ /**
60
+ * #179: the strike that eliminates a player finished off (rule 1e) — the attack on its largest
61
+ * stack (most armies plus special units, then lowest id): the one that can flee or strike first.
62
+ * Else a commander strike (rule 1s) the threat to my commander did not already protect
63
+ * (`commander`): it ends a player too, and the commander can walk away before it lands.
64
+ * A combined capture there (rule 3a) has no such strike: its first attack only wears the stack
65
+ * down, and Order Priority moves only my first order ahead, so the card cannot secure it.
66
+ */
67
+ const kill = (() => {
68
+ for (const p of [...finishedOff].sort(byNum)) {
69
+ const target = [...(ownedBy.get(p) ?? [])]
70
+ .filter((t) => moves.some((m) => m.kind === 'attack' && m.to === t))
71
+ .sort((a, b) => armiesOf(b) + unitsAt(b) - (armiesOf(a) + unitsAt(a)) || a - b)[0];
72
+ const order = target === undefined ? undefined : moves.find((m) => m.kind === 'attack' && m.to === target);
73
+ if (order)
74
+ return { p, order, attacks: moves.filter((m) => m.kind === 'attack' && m.to === target).length, commander: false };
75
+ }
76
+ // Else a strike on a commander (rule 1s) that no threat to mine advised the card for: it too
77
+ // ends a player, and the commander can walk away before it lands.
78
+ if (strikeOrder)
79
+ return undefined;
80
+ for (const t of [...strikes].sort(byNum)) {
81
+ const st = state.get(t);
82
+ if (st?.owner.kind !== 'player' || !struck.has(st.owner.playerId))
83
+ continue;
84
+ const order = moves.find((m) => m.kind === 'attack' && m.to === t);
85
+ if (order)
86
+ return { p: st.owner.playerId, order, attacks: moves.filter((m) => m.kind === 'attack' && m.to === t).length, commander: true };
87
+ }
88
+ return undefined;
89
+ })();
90
+ if (!strikeOrder && kill && combined.has(kill.order.to))
91
+ warnings.push(`The strike that eliminates player ${kill.p} is a combined capture of ${label(kill.order.to)} (${kill.attacks} attacks that must run in order): Order Priority moves only my first order ahead, so it cannot secure the kill; its stack can still flee or strike before the capture lands.`);
92
+ const killOrder = strikeOrder || (kill && combined.has(kill.order.to)) ? undefined : kill?.order;
93
+ /** #274: my commander's walk toward safety: my early order whatever happens. */
94
+ const commanderOrder = moves.find((m) => m.commander === true);
95
+ /**
96
+ * #274 review: the walk is my first order (after a strike or kill, before any withdrawal) only when
97
+ * the opponent's first attack may catch my commander before it runs (`ps.commanderCaught`: the
98
+ * transit hold falls short, or the fog beside it), or when that hold covers only what lands before
99
+ * my first order (`ps.commanderWalkFirst`, #274 review 2: no card advised for it then); otherwise
100
+ * the first order is chosen as before.
101
+ */
102
+ const caughtOrder = ps.commanderCaught || ps.commanderWalkFirst ? commanderOrder : undefined;
103
+ const outOfConceded = moves.filter((m) => conceded.has(m.from) && m !== strikeOrder && m !== killOrder && m !== caughtOrder);
104
+ /** My first order: the one Order Priority would protect. Checked against the schedule below. */
105
+ let firstOrder = strikeOrder ?? killOrder ?? caughtOrder ?? [...outOfConceded].sort((a, b) => b.armies - a.armies || a.from - b.from || a.to - b.to)[0];
106
+ /** The visible stacks of one player next to `t` plus its deploy: what can reach `t` this turn. */
107
+ const reachOf = (t) => {
108
+ const byPlayer = new Map();
109
+ for (const n of neighborsOf(g, t)) {
110
+ const st = state.get(n);
111
+ if (st?.owner.kind !== 'player' || !foe(st.owner.playerId) || st.armies === null)
112
+ continue;
113
+ const p = st.owner.playerId;
114
+ byPlayer.set(p, (byPlayer.get(p) ?? deployOf(p)) + Math.max(0, st.armies - guard) + unitsAt(n));
115
+ }
116
+ return byPlayer.size ? Math.max(...byPlayer.values()) : null;
117
+ };
118
+ const facesEnemy = (t) => neighborsOf(g, t).some((n) => {
119
+ const st = state.get(n);
120
+ return st?.owner.kind === 'player' && foe(st.owner.playerId);
121
+ });
122
+ const lastWhy = new Map();
123
+ const slotOf = (m) => {
124
+ if (m === firstOrder)
125
+ return MoveSlot.Protected;
126
+ // #274: my commander's walk goes as early as it can.
127
+ if (m === commanderOrder)
128
+ return MoveSlot.Early;
129
+ if (m.kind === 'transfer')
130
+ return conceded.has(m.from) || facesEnemy(m.to) ? MoveSlot.Early : MoveSlot.Filler;
131
+ if (conceded.has(m.from))
132
+ return MoveSlot.Early;
133
+ const st = state.get(m.to);
134
+ if (st?.owner.kind === 'player') {
135
+ if (worstCase.has(m.to) || strikes.has(m.to))
136
+ return MoveSlot.Sure;
137
+ lastWhy.set(m, `${label(m.to)} (player ${st.owner.playerId}'s stack can attack first; attacking second fights its survivors)`);
138
+ return MoveSlot.Last;
139
+ }
140
+ // A neutral another player can reach: early only when my survivors hold against its capture
141
+ // of that neutral (sized as mine are), at most what its stacks next to it plus its deploy send.
142
+ const near = reachOf(m.to);
143
+ if (near === null)
144
+ return MoveSlot.Filler;
145
+ const reach = Math.min(near, captureCost(defenceAt(m.to), s) ?? near);
146
+ const survivors = m.armies - Math.min(m.armies, straightKills(defenceAt(m.to), rates.defensiveKillRate));
147
+ if ((toTake(survivors) ?? Infinity) > reach)
148
+ return MoveSlot.Sure;
149
+ lastWhy.set(m, `${label(m.to)} (another player can send ~${reach} at it, which would take my ${survivors} survivors: taken last, mine is the capture that stands)`);
150
+ return MoveSlot.Last;
151
+ };
152
+ // "Eliminated even if it reinforces" holds only if my attacks land before its own orders: moving
153
+ // first, it can move between its territories or take a thin border of mine, and survive.
154
+ for (const p of opts.movesFirst ? [] : [...finishedOff].sort(byNum)) {
155
+ const theirs = ownedBy.get(p) ?? [];
156
+ /** Its stacks next to my `b` plus the deploy that can reach them (as the cover sizes it, #179). */
157
+ const reach = (b) => {
158
+ const adj = neighborsOf(g, b).filter((n) => theirs.includes(n));
159
+ return deployReaching(p, adj) + adj.reduce((a, n) => a + Math.max(0, armiesOf(n) - guard) + unitsAt(n), 0);
160
+ };
161
+ const exposed = mine.filter((b) => neighborsOf(g, b).some((n) => theirs.includes(n)) && (toTake(stayAt(b) + unitsAt(b)) ?? Infinity) <= reach(b));
162
+ const most = Math.max(0, ...exposed.map(reach));
163
+ warnings.push(`Eliminating player ${p} assumes my attacks land before its own orders: they interleave, so if it moves first it can move between its territories${exposed.length ? `, or take ${exposed.map(label).join(' or ')} (what this plan leaves there falls to its ~${most})` : ''}, and survive.`);
164
+ }
165
+ // ---- #179: the exits of an opponent down to a few territories ----
166
+ // Each of its stacks can move to its own neighbours, take a neutral its movable armies plus the
167
+ // deploy that can reach it take, or take a territory of mine that falls to that (what this plan
168
+ // leaves there).
169
+ const exits = [];
170
+ for (const [p, theirs] of [...ownedBy].sort((a, b) => a[0] - b[0])) {
171
+ // Its land bordering the fog, it may hold more there: not known to be down to a few.
172
+ if (theirs.length > FEW_TERRITORIES || (fogEdge(p).length && !finishedOff.has(p)))
173
+ continue;
174
+ const stacks = theirs.map((t) => {
175
+ const movable = Math.max(0, armiesOf(t) - guard) + unitsAt(t);
176
+ const reach = movable + deployReaching(p, [t]);
177
+ const next = [...neighborsOf(g, t)].sort(byNum);
178
+ return {
179
+ territory: t,
180
+ movable,
181
+ own: next.filter((n) => theirs.includes(n)),
182
+ neutrals: next.filter((n) => {
183
+ const st = state.get(n);
184
+ return st?.owner.kind === 'neutral' && st.armies !== null && !captured.has(n) && (captureCost(defenceAt(n), s) ?? Infinity) <= reach;
185
+ }),
186
+ mine: next.filter((n) => mineSet.has(n) && (toTake(stayAt(n) + unitsAt(n)) ?? Infinity) <= reach),
187
+ };
188
+ });
189
+ exits.push({ player: p, stacks });
190
+ if (!finishedOff.has(p) || opts.movesFirst)
191
+ continue;
192
+ for (const x of stacks)
193
+ for (const n of x.neutrals) {
194
+ const by = neighborsOf(g, n).filter((y) => mineSet.has(y) || captured.has(y)).sort(byNum);
195
+ warnings.push(`player ${p}'s stack on ${label(x.territory)} can flee onto ${label(n)} before my attack lands and survive there; ${by.length ? `${by.map(label).join(' or ')} borders it: retake it next turn` : 'nothing of mine borders it'}.`);
196
+ }
197
+ }
198
+ const decided = [...moves];
199
+ /** Within a slot, a larger early move first: one grouped early transfer beats several small ones. */
200
+ const rankOf = (m) => (m === commanderOrder ? Infinity : slotOf(m) === MoveSlot.Early ? m.armies : 0);
201
+ /** #274 review 2: a strike that ends a player may leave my commander's territory before the walk; nothing else may. */
202
+ const beforeWalk = (m) => m === strikeOrder || m === killOrder;
203
+ let scheduled = scheduleMoves(decided, slotOf, rankOf, beforeWalk);
204
+ if (firstOrder && scheduled[0] !== firstOrder) {
205
+ // A move it depends on (one into its source, say) must run before it, so it is not my first
206
+ // order, and the card protects only that one: my first order is whatever the schedule puts first.
207
+ const head = scheduled[0];
208
+ if (firstOrder === killOrder)
209
+ warnings.push(`The strike that eliminates player ${kill.p} cannot be my first order: ${label(head.from)} → ${label(head.to)} must run before it.`);
210
+ if (firstOrder === strikeOrder) {
211
+ const r = rationale.findIndex((l) => l.startsWith("Play Order Priority: my commander's territory"));
212
+ if (r >= 0)
213
+ rationale.splice(r, 1);
214
+ warnings.push(`The strike on ${strikeWho}'s commander cannot be my first order: ${label(head.from)} → ${label(head.to)} must run before it, so Order Priority would not make it land before ${strikeWho}'s attacks on my commander's territory.`);
215
+ }
216
+ firstOrder = outOfConceded.includes(head) || (caughtOrder !== undefined && head === caughtOrder) ? head : undefined;
217
+ lastWhy.clear();
218
+ scheduled = scheduleMoves(decided, slotOf, rankOf, beforeWalk);
219
+ }
220
+ moves.splice(0, moves.length, ...scheduled);
221
+ // #274 review 2: a walk whose transit hold covers only the first attacks must be my first order.
222
+ if (ps.commanderWalkFirst && commanderOrder && scheduled[0] !== commanderOrder) {
223
+ const head = scheduled[0];
224
+ warnings.push(`My commander's walk from ${label(commanderOrder.from)} cannot be my first order (${label(head.from)} → ${label(head.to)} is): what is deployed there holds only against the first attacks, and moving first, two of the opponent's may land on it before the walk runs (#274).`);
225
+ }
226
+ // Order Priority moves only my first order ahead of the opponent's first: spend the card only
227
+ // for that order — the strike rule 1s advised it for, else a move out of a conceded border that
228
+ // saves enough — when I hold one, and when I do not move first anyway.
229
+ /** Why Order Priority is not advised for the protected first order, if not. */
230
+ let why;
231
+ if (!firstOrder)
232
+ ps.cardAdvice = null;
233
+ else {
234
+ const n = firstOrder.armies;
235
+ /** #179: a strike that ends a player is protected even moving first when the opponent may hold the card too. */
236
+ const decisive = firstOrder === strikeOrder || firstOrder === killOrder;
237
+ const contested = decisive && opts.movesFirst === true && opts.opponentsMayHoldOrderPriority === true;
238
+ why = opts.movesFirst && !contested
239
+ ? "I move first this turn, so my first order already runs before any of the opponent's"
240
+ : firstOrder === strikeOrder
241
+ ? undefined
242
+ : !opts.holdsOrderPriority
243
+ ? 'I hold no Order Priority card to play'
244
+ : firstOrder === caughtOrder && !ps.commanderCaught
245
+ ? "my commander's walk is my first order, and the territory it leaves already holds against what lands before it"
246
+ : n < ORDER_PRIORITY_MIN_ARMIES && !opts.orderPriorityForced && firstOrder !== killOrder && firstOrder !== caughtOrder
247
+ ? `it saves only ${n} ${n === 1 ? 'army' : 'armies'}, under the ${ORDER_PRIORITY_MIN_ARMIES} a card is worth`
248
+ : undefined;
249
+ ps.cardAdvice = why === undefined ? 'order-priority' : null;
250
+ const mayHold = (who) => `I move first this turn, but ${who} may hold an Order Priority card: two cancel, so mine keeps this order first`;
251
+ if (firstOrder === killOrder && ps.cardAdvice) {
252
+ const units = unitsAt(firstOrder.to);
253
+ const stack = `${armiesOf(firstOrder.to)}${units ? ` armies and special units worth ${units}` : ''}`;
254
+ const what = kill.commander
255
+ ? `the strike on player ${kill.p}'s commander, which eliminates it (${stack} there), before the commander can move away`
256
+ : `the strike that eliminates player ${kill.p}, on its largest stack (${stack}), the one that could flee or strike first`;
257
+ rationale.push(`Play Order Priority: ${label(firstOrder.from)} → ${label(firstOrder.to)} is ${what}; ${contested ? mayHold(`player ${kill.p}`) : `with the card it is my first order and runs before player ${kill.p}'s first`}.`);
258
+ }
259
+ if (caughtOrder !== undefined && firstOrder === caughtOrder && ps.cardAdvice)
260
+ rationale.push(`Play Order Priority: ${label(firstOrder.from)} → ${label(firstOrder.to)} walks my commander away (#274); with the card it is my first order and runs before the opponent's first.`);
261
+ if (firstOrder === strikeOrder && contested) {
262
+ const r = rationale.findIndex((l) => l.startsWith("Play Order Priority: my commander's territory"));
263
+ if (r >= 0)
264
+ rationale[r] = `${rationale[r]} ${mayHold(strikeWho)}.`;
265
+ }
266
+ else if (firstOrder === strikeOrder && opts.movesFirst) {
267
+ // Rule 1s advised the card before it knew I move first: take that line back.
268
+ const r = rationale.findIndex((l) => l.startsWith("Play Order Priority: my commander's territory"));
269
+ if (r >= 0)
270
+ rationale.splice(r, 1);
271
+ rationale.push("Order Priority is not needed for the strike: I move first this turn, so my first order already runs before any of the opponent's.");
272
+ }
273
+ }
274
+ // Each move out of a conceded border says where it stands: the protected first order, or early
275
+ // but possibly too late (the card protects one order only).
276
+ const top = firstOrder && conceded.has(firstOrder.from) ? label(firstOrder.from) : undefined;
277
+ for (let i = 0; i < warnings.length; i++) {
278
+ if (!CONCEDED_ORDER.test(warnings[i]))
279
+ continue;
280
+ const head = warnings[i].replace(CONCEDED_ORDER, '');
281
+ const isTop = top !== undefined && (head.startsWith(`The withdrawal from ${top} only`) || head.startsWith(`The attack out of ${top} only`));
282
+ warnings[i] = !isTop
283
+ ? `${head}; it is listed early, but only my first order can run before the opponent's first, so it may come too late.`
284
+ : why === undefined
285
+ ? `${head}; play Order Priority: it is my first order, and the card runs it before the opponent's first.`
286
+ : `${head}; it is my first order (Order Priority not advised: ${why}).`;
287
+ }
288
+ const lasts = scheduled.filter((m) => lastWhy.has(m)).map((m) => lastWhy.get(m));
289
+ if (lasts.length || scheduled.some((m, i) => m !== decided[i])) {
290
+ rationale.push(`Move order (#127): ${firstOrder ? `${label(firstOrder.from)} → ${label(firstOrder.to)} first; ` : ''}withdrawals and transfers into borders the enemy can break early, attacks that land even if the owner deploys there first next, uncontested captures and interior transfers as filler${lasts.length ? `, and last ${lasts.join('; ')}` : ''}.`);
291
+ }
292
+ // Where each move put last lands among the opponent's orders (two players only: with more,
293
+ // the interleave runs through every player). An Order Priority played (and not matched) makes me
294
+ // the first mover for the turn, whichever I was.
295
+ const foes = [
296
+ ...new Set([...state.values()].flatMap((st) => (st.owner.kind === 'player' && foe(st.owner.playerId) ? [st.owner.playerId] : []))),
297
+ ];
298
+ const lastMoves = scheduled.filter((m) => lastWhy.has(m));
299
+ if (foes.length === 1 && lastMoves.length) {
300
+ const p = foes[0];
301
+ const mover = opts.movesFirst === true || ps.cardAdvice === 'order-priority'
302
+ ? 'first'
303
+ : opts.movesFirst === false
304
+ ? 'second'
305
+ : 'unknown';
306
+ const orders = (ownedBy.get(p) ?? []).filter((t) => Math.max(0, armiesOf(t) - guard) + unitsAt(t) > 0).length;
307
+ const need = indexAfterAll(orders, mover);
308
+ const items = lastMoves.map((m) => {
309
+ const k = scheduled.indexOf(m) + 1;
310
+ const before = mover === 'unknown'
311
+ ? `after ${opponentOrdersBefore(k, 'first')} of player ${p}'s orders if I move first, ${opponentOrdersBefore(k, 'second')} if it does`
312
+ : `after ${opponentOrdersBefore(k, mover)} of player ${p}'s orders (${mover === 'first' ? 'I move' : 'it moves'} first)`;
313
+ const short = need - k;
314
+ return `${label(m.to)} is my order ${k}: ${before}; player ${p} has ${orders} ${orders === 1 ? 'territory' : 'territories'} in view with armies to move, so it runs after them all${short > 0 ? ` from order ${need} (${short} more ${short === 1 ? 'order' : 'orders'} above it)` : ''}.`;
315
+ });
316
+ rationale.push(`Move position (#127): ${items.join(' ')}`);
317
+ }
318
+ return { slotOf, facesEnemy, exits };
319
+ }
@@ -0,0 +1,317 @@
1
+ // The deploy book of a planning pass (#133): what every later phase deploys and moves through —
2
+ // the budget (`ps.budget`), the guard and #165's sentinels, deploy / undeploy, Local Deployment's
3
+ // pools and the room they leave, the income change of a capture (#70), and the protected value of
4
+ // a territory of mine (R2, #122, #128) judged against `ps.holdings`. Run once, right after the
5
+ // estimates: it sets the starting `avail`, pays the sentinels, and states both in the rationale.
6
+ import { bonusTerritories } from '../bonuses.js';
7
+ import { breachBehind } from '../breach.js';
8
+ import { neighborsOf } from '../graph.js';
9
+ import { chargeDeploys, deployPools } from '../local-deploy.js';
10
+ import { territoryIncome } from '../player.js';
11
+ import { BREACH_WEIGHT, WASTELAND_FACTOR } from './shared.js';
12
+ import { byNum } from './util.js';
13
+ import { secondLineOf } from './guard-off.js';
14
+ /** Open the deploy book of one pass: sets `ps.budget`, `ps.holdings` and the starting `avail`. */
15
+ export function deployBook(ctx, ps) {
16
+ const { g, territories: state, s, mine, mineSet, myCommanders, foe, guard, noSplit, armiesOf, incomeGain, label, income, reserve, econCostAt, paybackTurns, baseIncome, unitsAt, deployOf, untrustedAt, } = ctx;
17
+ const { warnings, rationale, deployed, avail, coverKeep, captured, moves } = ps;
18
+ // ---- mutable plan state ----
19
+ ps.budget = income;
20
+ // #165: with the guard off, a territory of mine next to a visible enemy at the start of the turn
21
+ // keeps one army all the same (an empty territory falls to any single army) — never my commander's
22
+ // (it is not empty), and not under No-Split (an order sends the whole stack).
23
+ const sentinel = new Set(guard || noSplit
24
+ ? []
25
+ : mine.filter((id) => !myCommanders.has(id) &&
26
+ neighborsOf(g, id).some((n) => {
27
+ const o = state.get(n)?.owner;
28
+ return o?.kind === 'player' && foe(o.playerId);
29
+ })));
30
+ // #276: with the guard off, an interior member of a held bonus within two moves of a big enemy
31
+ // stack keeps a garrison one army cannot take (plan/guard-off.ts): what stands there now, up to it;
32
+ // `fillSecondLine` deploys the rest before the leftover.
33
+ const secondLine = secondLineOf(ctx);
34
+ const secondLineKept = new Map([...secondLine].map(([id, e]) => [id, Math.min(e.size, Math.max(0, armiesOf(id)))]));
35
+ /**
36
+ * Armies that stay on my `id` whatever its orders: the guard, or (#165) the army kept next to an
37
+ * enemy, or (#276) a second-line garrison.
38
+ */
39
+ const guardAt = (id) => (guard || sentinel.has(id) ? 1 : (secondLineKept.get(id) ?? 0));
40
+ // May start at −1 (a 0-army territory still owes its guard): deploys there pay for it first.
41
+ for (const id of mine)
42
+ avail.set(id, armiesOf(id) - guardAt(id));
43
+ /** #179: what my `x` keeps to cover a finished-off player's exit, in `avail` terms (0 when none). */
44
+ const coverOf = (x) => coverKeep.get(x) ?? 0;
45
+ // ---- income change (#70): the one computation nextIncome, R3 and the negative-bonus rules use ----
46
+ const heldNow = () => new Set([...mine, ...captured]);
47
+ /** The income change of also capturing `ts`, on top of this turn's captures so far. */
48
+ const gainWith = (ts) => {
49
+ const now = heldNow();
50
+ return incomeGain(new Set([...now, ...ts])) - incomeGain(now);
51
+ };
52
+ /** Under No-Split, the order `x` already issues (its only one); otherwise always `undefined`. */
53
+ const orderOf = (x) => (noSplit ? moves.find((m) => m.from === x) : undefined);
54
+ const describeOrder = (m) => m.kind === 'attack' ? `attacks ${label(m.to)}` : `transfers to ${label(m.to)}`;
55
+ /** A No-Split warning: `x` already issues an order, so `what` is not planned. Never repeated. */
56
+ const warnSplit = (x, what) => {
57
+ const w = `No-Split: ${label(x)} already ${describeOrder(orderOf(x))}, so ${what} (one attack or transfer per territory).`;
58
+ if (!warnings.includes(w))
59
+ warnings.push(w);
60
+ };
61
+ const deploy = (id, n) => {
62
+ if (n <= 0)
63
+ return;
64
+ deployed.set(id, (deployed.get(id) ?? 0) + n);
65
+ avail.set(id, avail.get(id) + n);
66
+ ps.budget -= n;
67
+ };
68
+ const undeploy = (id, n) => {
69
+ const d = (deployed.get(id) ?? 0) - n;
70
+ if (d > 0)
71
+ deployed.set(id, d);
72
+ else
73
+ deployed.delete(id);
74
+ avail.set(id, avail.get(id) - n);
75
+ ps.budget += n;
76
+ };
77
+ // ---- Local Deployment pools ----
78
+ const pools = s.localDeployments ? deployPools(g, mineSet, income) : null;
79
+ const local = pools !== null && pools.bonuses.length > 0;
80
+ /** Armies that may still be deployed on `id` (pools respected; with Local Deployment off, the budget). */
81
+ const roomAt = (id) => {
82
+ if (!local || ps.budget <= 0)
83
+ return ps.budget;
84
+ const fits = (n) => {
85
+ const next = new Map(deployed);
86
+ next.set(id, (next.get(id) ?? 0) + n);
87
+ return chargeDeploys(pools, next).anywhereUsed <= pools.anywhere;
88
+ };
89
+ let lo = 0;
90
+ let hi = ps.budget;
91
+ while (lo < hi) {
92
+ const mid = Math.ceil((lo + hi) / 2);
93
+ if (fits(mid))
94
+ lo = mid;
95
+ else
96
+ hi = mid - 1;
97
+ }
98
+ return lo;
99
+ };
100
+ /** Armies a capture may still deploy on `id`: its room, less the reserve. */
101
+ const spareAt = (id) => Math.min(ps.budget - reserve, roomAt(id));
102
+ // #165: a sentinel that starts the turn at 0 owes its army: paid from the income before any other
103
+ // deploy, holds included (the reserve holds back captures only). When income is scarce one army
104
+ // may go to a border later conceded ahead of a high-value hold: a cheap price, said in the rationale. One the income (or its pool) cannot pay stays at
105
+ // 0, and the rationale does not claim it keeps one army.
106
+ for (const id of [...sentinel].sort(byNum)) {
107
+ const owed = -avail.get(id);
108
+ if (owed > 0)
109
+ deploy(id, Math.min(owed, roomAt(id)));
110
+ }
111
+ const sentinelHeld = [...sentinel].filter((id) => avail.get(id) >= 0).sort(byNum);
112
+ const paid = sentinelHeld.filter((id) => armiesOf(id) === 0);
113
+ if (sentinelHeld.length)
114
+ rationale.push(`One Army Must Stand Guard is off: every army may move, but an empty territory falls to any single army, so ${sentinelHeld.map(label).join(', ')} ${sentinelHeld.length === 1 ? 'keeps' : 'each keep'} one army (next to an enemy)${paid.length ? `; ${paid.map(label).join(', ')} ${paid.length === 1 ? 'starts at 0, so its army is' : 'start at 0, so their armies are'} deployed first, before any hold (one army each, spent even where a border is later conceded)` : ''}.`);
115
+ if (local) {
116
+ rationale.push(`Local Deployment: ${pools.anywhere} of the ${income} income may be deployed anywhere; each held bonus's armies stay inside it.`);
117
+ for (const p of pools.bonuses)
118
+ rationale.push(`Local Deployment: bonus ${p.name} (#${p.bonusId})'s +${p.value} may only be deployed on its territories (${p.territoryIds.map(label).join(', ')}).`);
119
+ if (pools.trimmed)
120
+ warnings.push(`Local Deployment: the income of ${income} is less than the held bonuses are worth; ${pools.trimmed} pooled armies were dropped from the plan's pools.`);
121
+ }
122
+ // ---- protected value ----
123
+ // Judged against my holdings at the start of the turn until the capture passes
124
+ // have run; then against those holdings plus this turn's captures (R2).
125
+ ps.holdings = mineSet;
126
+ /** #122: bonus `ts` is being built — its missing members all visible neutrals, finishing it economic (rule 4). */
127
+ const building = (ts, value) => {
128
+ let cost = 0;
129
+ let worst = 0;
130
+ for (const x of ts) {
131
+ if (ps.holdings.has(x))
132
+ continue;
133
+ const st = state.get(x);
134
+ if (st?.owner.kind !== 'neutral' || st.armies === null)
135
+ return false;
136
+ const c = econCostAt(x);
137
+ cost += c;
138
+ worst = Math.max(worst, c);
139
+ }
140
+ return cost <= paybackTurns * value && worst <= WASTELAND_FACTOR * value;
141
+ };
142
+ /**
143
+ * #235: what losing my `t` cuts off from the rest of my holdings (`ps.holdings` without `t`): when
144
+ * its neighbours of mine fall into two or more parts, every part but the largest (most territories,
145
+ * then most armies, then lowest id) is cut off — its territories, the armies on them (my start-of-turn
146
+ * armies), and the income they make: the positive bonuses held in full inside them, plus their
147
+ * per-territory income. `null` when nothing is cut off.
148
+ */
149
+ const cutOff = (t) => {
150
+ if (cutCache.has(t))
151
+ return cutCache.get(t);
152
+ const has = (x) => x !== t && ps.holdings.has(x);
153
+ const parts = [];
154
+ const seen = new Set();
155
+ for (const start of neighborsOf(g, t).filter(has).sort(byNum)) {
156
+ if (seen.has(start))
157
+ continue;
158
+ const part = [];
159
+ const queue = [start];
160
+ seen.add(start);
161
+ while (queue.length) {
162
+ const x = queue.shift();
163
+ part.push(x);
164
+ for (const n of neighborsOf(g, x))
165
+ if (has(n) && !seen.has(n)) {
166
+ seen.add(n);
167
+ queue.push(n);
168
+ }
169
+ }
170
+ parts.push(part.sort(byNum));
171
+ }
172
+ let cut = null;
173
+ if (parts.length >= 2) {
174
+ const armies = (part) => part.reduce((n, x) => n + (mineSet.has(x) ? armiesOf(x) : 0), 0);
175
+ const main = [...parts].sort((a, b) => b.length - a.length || armies(b) - armies(a) || a[0] - b[0])[0];
176
+ const ids = parts.filter((p) => p !== main).flat().sort(byNum);
177
+ const off = new Set(ids);
178
+ let inc = 0;
179
+ for (const b of g.map.bonuses) {
180
+ const ts = bonusTerritories(g, b.id);
181
+ if (b.value > 0 && ts.length && ts.every((x) => off.has(x)))
182
+ inc += b.value;
183
+ }
184
+ // On the holdings the cut is taken from (#235 review 2): my start-of-turn count until the
185
+ // captures are known, then with this turn's captures, which the cut-off part may include.
186
+ const per = s.bonusArmyPer ?? 0;
187
+ const n = ps.holdings.size;
188
+ if (per > 0)
189
+ inc += territoryIncome(n, baseIncome, per) - territoryIncome(n - ids.length, baseIncome, per);
190
+ cut = { ids, armies: armies(ids), income: inc };
191
+ }
192
+ cutCache.set(t, cut);
193
+ return cut;
194
+ };
195
+ const cutCache = new Map();
196
+ /** #275: my `x` faces a visible enemy or the fog (a territory whose owner the board does not show). */
197
+ const front = (x) => neighborsOf(g, x).some((n) => {
198
+ const o = state.get(n)?.owner;
199
+ return o === undefined || o.kind === 'unknown' || (o.kind === 'player' && foe(o.playerId));
200
+ });
201
+ /**
202
+ * #275 (pattern 2): with the guard off, what a breach of my border `t` opens — the territories
203
+ * within two steps behind it that only it shields ({@link breachBehind}), what losing it cuts off
204
+ * left out (#235 counts that whole), and the income they make: the bonuses held in full with a
205
+ * member among them (not `t`'s own), plus their per-territory income. `null` with the guard on,
206
+ * or when it opens nothing that earns.
207
+ */
208
+ const breachAt = (t) => {
209
+ if (guard)
210
+ return null;
211
+ if (breachCache.has(t))
212
+ return breachCache.get(t);
213
+ // The stack that would come through: the largest visible foe stack beside `t` with its owner's
214
+ // deploy — the untrusted figure when larger (#275 b), as the hold at `t` is sized. A territory
215
+ // behind is hollow when none of mine beside it (itself included, `t` left out) holds as many: a
216
+ // stack that can answer the breach is no hollow interior.
217
+ const through = Math.max(0, ...neighborsOf(g, t).map((n) => {
218
+ const st = state.get(n);
219
+ const o = st?.owner;
220
+ if (o?.kind !== 'player' || !foe(o.playerId) || st.armies === null)
221
+ return 0;
222
+ return st.armies + unitsAt(n) + Math.max(deployOf(o.playerId), untrustedAt(o.playerId, t));
223
+ }));
224
+ const hollow = (x) => [x, ...neighborsOf(g, x)].every((y) => y === t || !mineSet.has(y) || armiesOf(y) + unitsAt(y) < through);
225
+ const b = through > 0 ? breachBehind(g, ps.holdings, front, t, new Set(cutOff(t)?.ids ?? []), hollow) : { ids: [], bonuses: [], income: 0 };
226
+ let income = b.income;
227
+ const per = s.bonusArmyPer ?? 0;
228
+ const n = ps.holdings.size;
229
+ if (per > 0 && b.ids.length)
230
+ income += territoryIncome(n, baseIncome, per) - territoryIncome(n - b.ids.length, baseIncome, per);
231
+ const out = income > 0 ? { ...b, income, worth: Math.round(BREACH_WEIGHT * income * 10) / 10 } : null;
232
+ breachCache.set(t, out);
233
+ return out;
234
+ };
235
+ const breachCache = new Map();
236
+ const protectedValue = (t) => {
237
+ // Each bonus is visited once, so it counts once however many of its borders are threatened.
238
+ // #235: plus the income of what losing it cuts off from the rest of my holdings.
239
+ // #275: plus, with the guard off, BREACH_WEIGHT × what a breach of it opens behind it.
240
+ let v = (cutOff(t)?.income ?? 0) + (breachAt(t)?.worth ?? 0);
241
+ const mineWithout = (x) => x !== t && ps.holdings.has(x);
242
+ for (const b of g.map.bonuses) {
243
+ const ts = bonusTerritories(g, b.id);
244
+ if (!ts.includes(t))
245
+ continue;
246
+ // #128: a negative bonus I hold in full that contains T is lifted when T falls.
247
+ if (b.value < 0) {
248
+ if (ts.every((x) => ps.holdings.has(x)))
249
+ v += b.value;
250
+ continue;
251
+ }
252
+ if (b.value === 0)
253
+ continue;
254
+ if (ts.every((x) => ps.holdings.has(x))) {
255
+ v += b.value;
256
+ continue;
257
+ }
258
+ // An incomplete bonus I am working on (T is in it): lost access if T is my only way in.
259
+ const access = (has) => ts.some((x) => has(x) || neighborsOf(g, x).some(has));
260
+ if (!access(mineWithout)) {
261
+ v += b.value;
262
+ continue;
263
+ }
264
+ // #122: a member of a bonus I am building carries its share of the bonus — value × the
265
+ // members I hold ÷ its size — so a second member is not worth +0 when the first (my only
266
+ // foothold) was worth the whole bonus. Being built: every missing member is a visible
267
+ // neutral, and finishing it passes rule 4's economy tests (a bonus behind an enemy, the
268
+ // fog or a wasteland is not being built).
269
+ if (building(ts, b.value)) {
270
+ const held = ts.filter((x) => ps.holdings.has(x) || x === t).length;
271
+ v += Math.round(((b.value * held) / ts.length) * 10) / 10;
272
+ }
273
+ }
274
+ // Per-territory income replaces the base only when larger, so losing T
275
+ // costs an army only above it.
276
+ const per = s.bonusArmyPer ?? 0;
277
+ if (per > 0)
278
+ v += territoryIncome(mine.length, baseIncome, per) - territoryIncome(mine.length - 1, baseIncome, per);
279
+ // Floored at 0 only (#128): a negative bonus can outweigh the rest, never below nothing.
280
+ return Math.max(0, v);
281
+ };
282
+ /** #235: the armies a hold of my `t` also saves, as worth: those on what losing it cuts off. */
283
+ const stakeAt = (t) => cutOff(t)?.armies ?? 0;
284
+ const valueCache = new Map();
285
+ const valueOf = (t) => {
286
+ if (!valueCache.has(t))
287
+ valueCache.set(t, protectedValue(t));
288
+ return valueCache.get(t);
289
+ };
290
+ return {
291
+ sentinel,
292
+ secondLine,
293
+ secondLineKept,
294
+ guardAt,
295
+ coverOf,
296
+ heldNow,
297
+ gainWith,
298
+ orderOf,
299
+ describeOrder,
300
+ warnSplit,
301
+ deploy,
302
+ undeploy,
303
+ pools,
304
+ local,
305
+ roomAt,
306
+ spareAt,
307
+ building,
308
+ protectedValue,
309
+ valueCache,
310
+ valueOf,
311
+ cutOff,
312
+ cutCache,
313
+ breachAt,
314
+ breachCache,
315
+ stakeAt,
316
+ };
317
+ }