@chrischall/warapp-mcp 0.0.0 → 0.2.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 +4 -4
- package/.claude-plugin/plugin.json +2 -2
- package/README.md +211 -9
- package/dist/analysis/accept-surrender.js +56 -0
- package/dist/analysis/award.js +159 -0
- package/dist/analysis/bonuses.js +98 -0
- package/dist/analysis/breach.js +62 -0
- package/dist/analysis/calibrate.js +239 -0
- package/dist/analysis/card-support.js +329 -0
- package/dist/analysis/card-threats.js +234 -0
- package/dist/analysis/cards-in-effect.js +130 -0
- package/dist/analysis/chains.js +59 -0
- package/dist/analysis/chokepoints.js +140 -0
- package/dist/analysis/combat.js +231 -0
- package/dist/analysis/commander-safety.js +149 -0
- package/dist/analysis/commitments.js +338 -0
- package/dist/analysis/exchange.js +155 -0
- package/dist/analysis/finished-game.js +136 -0
- package/dist/analysis/game-lessons.js +217 -0
- package/dist/analysis/graph.js +82 -0
- package/dist/analysis/guard-off.js +54 -0
- package/dist/analysis/guess.js +351 -0
- package/dist/analysis/headroom.js +241 -0
- package/dist/analysis/hold-diff.js +64 -0
- package/dist/analysis/how-lost.js +130 -0
- package/dist/analysis/index.js +14 -0
- package/dist/analysis/local-deploy.js +179 -0
- package/dist/analysis/lookahead.js +108 -0
- package/dist/analysis/opponent-profile.js +552 -0
- package/dist/analysis/opponents.js +1253 -0
- package/dist/analysis/outlook.js +695 -0
- package/dist/analysis/overrides.js +60 -0
- package/dist/analysis/picks.js +1879 -0
- package/dist/analysis/plan/after-leftover.js +140 -0
- package/dist/analysis/plan/cap-spend.js +242 -0
- package/dist/analysis/plan/captures.js +1195 -0
- package/dist/analysis/plan/commander.js +236 -0
- package/dist/analysis/plan/completed.js +29 -0
- package/dist/analysis/plan/conceded-out.js +131 -0
- package/dist/analysis/plan/estimates.js +715 -0
- package/dist/analysis/plan/guard-off.js +232 -0
- package/dist/analysis/plan/holds.js +1631 -0
- package/dist/analysis/plan/leftover.js +760 -0
- package/dist/analysis/plan/move-order.js +319 -0
- package/dist/analysis/plan/orders.js +317 -0
- package/dist/analysis/plan/relations.js +702 -0
- package/dist/analysis/plan/report.js +672 -0
- package/dist/analysis/plan/shared.js +1405 -0
- package/dist/analysis/plan/stand-still.js +823 -0
- package/dist/analysis/plan/state.js +44 -0
- package/dist/analysis/plan/strike.js +1416 -0
- package/dist/analysis/plan/targets.js +651 -0
- package/dist/analysis/plan/team.js +299 -0
- package/dist/analysis/plan/threats.js +1001 -0
- package/dist/analysis/plan/transfers.js +328 -0
- package/dist/analysis/plan/util.js +5 -0
- package/dist/analysis/plan/vacated.js +285 -0
- package/dist/analysis/planner.js +2927 -0
- package/dist/analysis/player-record.js +144 -0
- package/dist/analysis/player.js +268 -0
- package/dist/analysis/profile.js +347 -0
- package/dist/analysis/relations.js +1030 -0
- package/dist/analysis/schedule.js +88 -0
- package/dist/analysis/since-last.js +50 -0
- package/dist/analysis/static-seats.js +71 -0
- package/dist/analysis/stress.js +584 -0
- package/dist/analysis/team-brief.js +151 -0
- package/dist/analysis/tripwire.js +644 -0
- package/dist/analysis/turn-sim.js +259 -0
- package/dist/analysis/whereabouts.js +1112 -0
- package/dist/board.js +105 -0
- package/dist/bundle.js +121082 -36148
- package/dist/calibration-source.js +75 -0
- package/dist/cards.js +435 -0
- package/dist/chat-cursor.js +135 -0
- package/dist/chat.js +265 -0
- package/dist/client.js +439 -0
- package/dist/config.js +62 -0
- package/dist/direct/link.js +102 -0
- package/dist/direct/session.js +267 -0
- package/dist/direct/transport.js +424 -0
- package/dist/finished-store.js +357 -0
- package/dist/guess-salt.js +65 -0
- package/dist/hosted.js +24 -0
- package/dist/index.js +33 -0
- package/dist/join-color.js +140 -0
- package/dist/lessons-store.js +356 -0
- package/dist/live.js +287 -0
- package/dist/map-details.js +127 -0
- package/dist/map-stats.js +160 -0
- package/dist/map-store.js +242 -0
- package/dist/move-order.js +141 -0
- package/dist/my-games.js +218 -0
- package/dist/normalize.js +443 -0
- package/dist/notifications.js +143 -0
- package/dist/open-games.js +537 -0
- package/dist/outlook-log.js +165 -0
- package/dist/path-lock.js +22 -0
- package/dist/pick-list.js +193 -0
- package/dist/player-record-store.js +231 -0
- package/dist/player-states.js +31 -0
- package/dist/profile-store.js +727 -0
- package/dist/protocol/bundle.js +375 -0
- package/dist/protocol/codec.js +556 -0
- package/dist/protocol/decoded.js +12 -0
- package/dist/protocol/interp.js +1904 -0
- package/dist/protocol/methods.js +615 -0
- package/dist/protocol/rpc.js +202 -0
- package/dist/push/listener.js +393 -0
- package/dist/push/packets.js +66 -0
- package/dist/push/socketio.js +333 -0
- package/dist/push/websocket.js +179 -0
- package/dist/redact.js +62 -0
- package/dist/relations-store.js +242 -0
- package/dist/replay.js +227 -0
- package/dist/scalars.js +28 -0
- package/dist/scout.js +346 -0
- package/dist/stats.js +291 -0
- package/dist/strategy/card-clock.js +185 -0
- package/dist/strategy/map-notes.js +128 -0
- package/dist/strategy/notes.js +2223 -0
- package/dist/surrender-pending.js +126 -0
- package/dist/team-cards.js +84 -0
- package/dist/team-orders.js +150 -0
- package/dist/teams.js +19 -0
- package/dist/tools/accept-surrender.js +311 -0
- package/dist/tools/award.js +206 -0
- package/dist/tools/begin-turn.js +162 -0
- package/dist/tools/board.js +77 -0
- package/dist/tools/card-advice.js +256 -0
- package/dist/tools/card-effects.js +49 -0
- package/dist/tools/card-plays.js +434 -0
- package/dist/tools/card-support-advice.js +140 -0
- package/dist/tools/chat-inbox.js +158 -0
- package/dist/tools/chat-read-mark.js +179 -0
- package/dist/tools/chat.js +525 -0
- package/dist/tools/check-plan.js +689 -0
- package/dist/tools/commander-check.js +103 -0
- package/dist/tools/commitments.js +216 -0
- package/dist/tools/common.js +143 -0
- package/dist/tools/diplomacy.js +342 -0
- package/dist/tools/end-of-game.js +384 -0
- package/dist/tools/game.js +151 -0
- package/dist/tools/guess-view.js +56 -0
- package/dist/tools/healthcheck.js +90 -0
- package/dist/tools/hints.js +34 -0
- package/dist/tools/how-lost.js +154 -0
- package/dist/tools/index.js +152 -0
- package/dist/tools/join-game.js +327 -0
- package/dist/tools/leave-game.js +181 -0
- package/dist/tools/live-context.js +339 -0
- package/dist/tools/live.js +404 -0
- package/dist/tools/map-details.js +88 -0
- package/dist/tools/map-stats.js +130 -0
- package/dist/tools/map.js +141 -0
- package/dist/tools/my-games.js +193 -0
- package/dist/tools/notifications.js +484 -0
- package/dist/tools/open-games.js +104 -0
- package/dist/tools/opponents.js +163 -0
- package/dist/tools/order-options.js +135 -0
- package/dist/tools/past-games.js +94 -0
- package/dist/tools/picks.js +305 -0
- package/dist/tools/profile-hook.js +156 -0
- package/dist/tools/profile-opponents.js +121 -0
- package/dist/tools/profile-reads.js +99 -0
- package/dist/tools/push.js +445 -0
- package/dist/tools/relations.js +611 -0
- package/dist/tools/resolve.js +45 -0
- package/dist/tools/route.js +36 -0
- package/dist/tools/scout.js +87 -0
- package/dist/tools/session.js +163 -0
- package/dist/tools/strategy.js +257 -0
- package/dist/tools/stress-opponents.js +83 -0
- package/dist/tools/surrender-pending.js +74 -0
- package/dist/tools/surrender.js +247 -0
- package/dist/tools/survival.js +189 -0
- package/dist/tools/team-brief.js +266 -0
- package/dist/tools/team-source.js +222 -0
- package/dist/tools/team.js +178 -0
- package/dist/tools/turn.js +2825 -0
- package/dist/tools/uncommit.js +160 -0
- package/dist/tools/where.js +300 -0
- package/dist/tools/write-kit.js +164 -0
- package/dist/transport-bridge.js +33 -0
- package/dist/trend.js +577 -0
- package/dist/version.js +4 -0
- package/manifest.json +194 -4
- package/mint.yaml +106 -14
- package/package.json +11 -6
- package/server.json +40 -3
- package/skills/warapp-api/SKILL.md +95 -4
- package/skills/warapp-api/references/scout.mjs +348 -0
- package/skills/warapp-api/scripts/warapp.sh +69 -8
- package/skills/warapp-mcp/SKILL.md +1096 -21
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
// The card clock: when each card can first be in a hand, from the game's card settings alone.
|
|
2
|
+
// Pure and deterministic; no I/O.
|
|
3
|
+
//
|
|
4
|
+
// The rules are the wiki's (docs/STRATEGY.md links the pages): a player who captures at least one
|
|
5
|
+
// territory in a turn receives the game's "pieces per turn" at the end of it; each card's minimum
|
|
6
|
+
// is always part of that hand-out and the rest is drawn at random by card weight (a weight of 0
|
|
7
|
+
// is never drawn); a card is playable once all its pieces are held, so from the turn after its
|
|
8
|
+
// last piece arrives; and when the minimums add up to more than the pieces per turn the game
|
|
9
|
+
// raises the pieces per turn to match. When the minimums use up every piece (or only one card can
|
|
10
|
+
// be drawn at random), every player who captures each turn holds the same cards on the same turns.
|
|
11
|
+
// Pieces left over when a card completes count toward the next one.
|
|
12
|
+
//
|
|
13
|
+
// The clock is per player. A team shares one hand, and players report that each teammate who
|
|
14
|
+
// captures adds pieces (the wiki does not say), so a team's cards can come sooner than this.
|
|
15
|
+
import { cardTypeByName, cardTypeName } from '../cards.js';
|
|
16
|
+
import { asInt } from '../scalars.js';
|
|
17
|
+
const isRec = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
18
|
+
const bool = (v) => (v === true || v === 'true' || v === 'True' ? true : v === false || v === 'false' || v === 'False' ? false : null);
|
|
19
|
+
const perTurn = (need, rate) => (need <= 0 ? 0 : rate > 0 ? Math.ceil(need / rate) : null);
|
|
20
|
+
/** Capturing turns for the first three cards at `rate` pieces a turn. */
|
|
21
|
+
const firstThree = (pieces, initial, rate) => rate > 0 ? [1, 2, 3].map((k) => Math.max(0, Math.ceil((k * pieces - initial) / rate))) : null;
|
|
22
|
+
const CARD_CLOCK_PER_PLAYER = 'Per player. A team shares one hand, and each teammate who captures is reported to add pieces (not on the wiki), so a team can hold a card sooner.';
|
|
23
|
+
const round2 = (n) => Math.round(n * 100) / 100;
|
|
24
|
+
/** The game's card clock; `undefined` when no card is in play. */
|
|
25
|
+
export function cardClock(settings) {
|
|
26
|
+
if (!settings || settings.cards.length === 0)
|
|
27
|
+
return undefined;
|
|
28
|
+
const raw = settings.raw;
|
|
29
|
+
const read = settings.cards.flatMap((key) => {
|
|
30
|
+
const r = raw[`${key}Card`];
|
|
31
|
+
if (!isRec(r))
|
|
32
|
+
return [];
|
|
33
|
+
const type = cardTypeByName(key);
|
|
34
|
+
return [
|
|
35
|
+
{
|
|
36
|
+
card: type !== undefined ? cardTypeName(type) : key,
|
|
37
|
+
pieces: Math.max(1, asInt(r.NumPieces) ?? 1),
|
|
38
|
+
initialPieces: Math.max(0, asInt(r.InitialPieces) ?? 0),
|
|
39
|
+
minimumPerTurn: Math.max(0, asInt(r.MinimumPiecesPerTurn) ?? 0),
|
|
40
|
+
weight: Math.max(0, Number(r.Weight ?? 1) || 0),
|
|
41
|
+
fixedArmies: asInt(r.FixedArmies),
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
});
|
|
45
|
+
if (read.length === 0)
|
|
46
|
+
return undefined;
|
|
47
|
+
const minimums = read.reduce((n, c) => n + c.minimumPerTurn, 0);
|
|
48
|
+
const stated = asInt(raw.NumberOfCardsToReceiveEachTurn);
|
|
49
|
+
const piecesPerTurn = Math.max(stated ?? minimums, minimums);
|
|
50
|
+
const randomPerTurn = piecesPerTurn - minimums;
|
|
51
|
+
// When only one card can be drawn at random, every random piece is that card's for certain.
|
|
52
|
+
const drawable = read.filter((c) => c.weight > 0);
|
|
53
|
+
const cards = read.map(({ fixedArmies, ...c }) => {
|
|
54
|
+
const need = c.pieces - c.initialPieces;
|
|
55
|
+
const fastestRate = c.minimumPerTurn + (c.weight > 0 ? randomPerTurn : 0);
|
|
56
|
+
const guaranteedRate = c.minimumPerTurn + (c.weight > 0 && drawable.length === 1 ? randomPerTurn : 0);
|
|
57
|
+
const turns = { fastest: perTurn(need, fastestRate), guaranteed: perTurn(need, guaranteedRate) };
|
|
58
|
+
return {
|
|
59
|
+
...c,
|
|
60
|
+
capturingTurns: turns,
|
|
61
|
+
// Pieces arrive at the end of a turn, so the card is playable on the next one.
|
|
62
|
+
firstPlayableTurn: { fastest: turns.fastest === null ? null : turns.fastest + 1, guaranteed: turns.guaranteed === null ? null : turns.guaranteed + 1 },
|
|
63
|
+
cardsAfter: { fastest: firstThree(c.pieces, c.initialPieces, fastestRate), guaranteed: firstThree(c.pieces, c.initialPieces, guaranteedRate) },
|
|
64
|
+
...(c.card === 'Reinforcement' && fixedArmies !== undefined && fixedArmies > 0 ? { pieceValue: round2(fixedArmies / c.pieces) } : {}),
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
return {
|
|
68
|
+
piecesPerTurn,
|
|
69
|
+
randomPerTurn,
|
|
70
|
+
piecesPerTurnKnown: stated !== undefined,
|
|
71
|
+
// Exact only when the setting was read and no piece is left to chance.
|
|
72
|
+
fixed: stated !== undefined && (randomPerTurn === 0 || drawable.length === 1),
|
|
73
|
+
perPlayer: CARD_CLOCK_PER_PLAYER,
|
|
74
|
+
maxCardsHold: asInt(raw.MaxCardsHold) ?? null,
|
|
75
|
+
handsHidden: bool(raw.CardsHoldingAndReceivingFogged ?? raw.CardHoldingsAndReceivesFogged),
|
|
76
|
+
playsHidden: bool(raw.CardPlayingsFogged),
|
|
77
|
+
cards,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The armies one turn with a capture earns in card pieces (#127): the Reinforcement pieces it brings
|
|
82
|
+
* — the card's minimum per turn plus its weighted share of the random pieces — times the armies a
|
|
83
|
+
* Reinforcement card adds over the pieces it takes. Those armies are the game's `FixedArmies`; when
|
|
84
|
+
* the card is not fixed (progressive), the armies of a Reinforcement card in my hand stand in
|
|
85
|
+
* (`handArmies`: the card as it is worth now). The other cards have no army value here: `null` when
|
|
86
|
+
* no Reinforcement card is in play or its armies are unknown, with the reason.
|
|
87
|
+
*/
|
|
88
|
+
export function capturePieceValue(settings, handArmies) {
|
|
89
|
+
const clock = cardClock(settings);
|
|
90
|
+
if (!clock)
|
|
91
|
+
return { armies: null, why: 'no card is in play' };
|
|
92
|
+
const r = clock.cards.find((c) => c.card === 'Reinforcement');
|
|
93
|
+
if (!r)
|
|
94
|
+
return { armies: null, why: 'no Reinforcement card is in play, and the other cards have no army value here' };
|
|
95
|
+
const drawWeight = clock.cards.reduce((n, c) => n + c.weight, 0);
|
|
96
|
+
const pieces = r.minimumPerTurn + (r.weight > 0 && drawWeight > 0 ? (clock.randomPerTurn * r.weight) / drawWeight : 0);
|
|
97
|
+
const reinforcementPieces = round2(pieces);
|
|
98
|
+
const raw = settings.raw.ReinforcementCard;
|
|
99
|
+
const fixed = isRec(raw) ? asInt(raw.FixedArmies) : undefined;
|
|
100
|
+
const per = fixed !== undefined && fixed > 0 ? fixed : handArmies !== undefined && handArmies > 0 ? handArmies : undefined;
|
|
101
|
+
if (per === undefined)
|
|
102
|
+
return {
|
|
103
|
+
armies: null,
|
|
104
|
+
reinforcementPieces,
|
|
105
|
+
pieces: r.pieces,
|
|
106
|
+
why: 'the Reinforcement card is not a fixed number of armies here, and no Reinforcement card in hand shows what one is worth now',
|
|
107
|
+
};
|
|
108
|
+
const armies = round2((pieces * per) / r.pieces);
|
|
109
|
+
const source = fixed !== undefined && fixed > 0 ? `${per} armies a card` : `the Reinforcement card in hand (${per} armies)`;
|
|
110
|
+
return {
|
|
111
|
+
armies,
|
|
112
|
+
reinforcementPieces,
|
|
113
|
+
armiesPerCard: per,
|
|
114
|
+
pieces: r.pieces,
|
|
115
|
+
why: `a capturing turn brings ~${reinforcementPieces} Reinforcement pieces of the ${r.pieces} a card takes, at ${source}: ~${armies} armies (the other cards are not valued)`,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/** Cards that never add armies to their holder. */
|
|
119
|
+
const NO_ARMY_CARDS = new Set([
|
|
120
|
+
'Spy',
|
|
121
|
+
'Emergency Blockade',
|
|
122
|
+
'Order Priority',
|
|
123
|
+
'Order Delay',
|
|
124
|
+
'Airlift',
|
|
125
|
+
'Diplomacy',
|
|
126
|
+
'Sanctions',
|
|
127
|
+
'Reconnaissance',
|
|
128
|
+
'Surveillance',
|
|
129
|
+
'Blockade',
|
|
130
|
+
'Bomb',
|
|
131
|
+
]);
|
|
132
|
+
const FIXED_MODES = new Set(['0', 'fixed']);
|
|
133
|
+
/** {@link CardArmyCeiling} from the game's card settings; `undefined` when cards are not bounded (or none is in play, or the cards a turn are not stated). */
|
|
134
|
+
export function cardArmyCeiling(settings) {
|
|
135
|
+
const clock = cardClock(settings);
|
|
136
|
+
if (!clock)
|
|
137
|
+
return undefined;
|
|
138
|
+
const r = clock.cards.find((c) => c.card === 'Reinforcement');
|
|
139
|
+
if (clock.cards.some((c) => c.card !== 'Reinforcement' && !NO_ARMY_CARDS.has(c.card)))
|
|
140
|
+
return undefined;
|
|
141
|
+
if (!r)
|
|
142
|
+
return { armiesPerCard: 0, pieces: 1, initialPieces: 0, piecesPerTurn: 0 };
|
|
143
|
+
// Without NumberOfCardsToReceiveEachTurn the random pieces a turn are unknown, so no ceiling.
|
|
144
|
+
if (!clock.piecesPerTurnKnown)
|
|
145
|
+
return undefined;
|
|
146
|
+
const raw = settings.raw.ReinforcementCard;
|
|
147
|
+
const fixed = asInt(raw.FixedArmies);
|
|
148
|
+
if (fixed === undefined || fixed <= 0)
|
|
149
|
+
return undefined;
|
|
150
|
+
if (raw.Mode !== undefined && !FIXED_MODES.has(String(raw.Mode).toLowerCase()))
|
|
151
|
+
return undefined;
|
|
152
|
+
return {
|
|
153
|
+
armiesPerCard: fixed,
|
|
154
|
+
pieces: r.pieces,
|
|
155
|
+
initialPieces: r.initialPieces,
|
|
156
|
+
piecesPerTurn: r.minimumPerTurn + (r.weight > 0 ? clock.randomPerTurn : 0),
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/** The most armies cards can have added by `turn` (pieces arrive at the end of a turn, so turn `t` plays those of turns 1 to t − 1). */
|
|
160
|
+
export function cardArmiesBy(c, turn) {
|
|
161
|
+
if (c.armiesPerCard <= 0)
|
|
162
|
+
return 0;
|
|
163
|
+
const pieces = c.initialPieces + c.piecesPerTurn * Math.max(0, turn - 1);
|
|
164
|
+
return Math.floor(pieces / c.pieces) * c.armiesPerCard;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* The Reinforcement cards one player can hold when it plays on `turn` (every capturing turn from turn 1,
|
|
168
|
+
* every random piece its own, at most `MaxCardsHold`) and one card's armies: `cards` null when the
|
|
169
|
+
* pieces a turn are not stated, `armiesPerCard` null when its armies are not a fixed number. `undefined`
|
|
170
|
+
* when no Reinforcement card is in play.
|
|
171
|
+
*/
|
|
172
|
+
export function reinforcementHand(settings, turn) {
|
|
173
|
+
const clock = cardClock(settings);
|
|
174
|
+
const r = clock?.cards.find((c) => c.card === 'Reinforcement');
|
|
175
|
+
if (!clock || !r)
|
|
176
|
+
return undefined;
|
|
177
|
+
const raw = settings.raw.ReinforcementCard;
|
|
178
|
+
const fixed = asInt(raw.FixedArmies);
|
|
179
|
+
const armiesPerCard = fixed !== undefined && fixed > 0 && (raw.Mode === undefined || FIXED_MODES.has(String(raw.Mode).toLowerCase())) ? fixed : null;
|
|
180
|
+
if (!clock.piecesPerTurnKnown)
|
|
181
|
+
return { cards: null, armiesPerCard };
|
|
182
|
+
const rate = r.minimumPerTurn + (r.weight > 0 ? clock.randomPerTurn : 0);
|
|
183
|
+
const earned = Math.floor((r.initialPieces + rate * Math.max(0, turn - 1)) / r.pieces);
|
|
184
|
+
return { cards: clock.maxCardsHold === null ? earned : Math.min(earned, Math.max(0, clock.maxCardsHold)), armiesPerCard };
|
|
185
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// Map notes: what the map itself says about strategy, computed with no extra traffic —
|
|
2
|
+
// bonuses ranked by value per army to take at the game's settings, their entry points (and
|
|
3
|
+
// which of those are double borders, #166), the chokepoints, and (before the opening) income targets by turn from the pick
|
|
4
|
+
// advisor's opening simulation over the territories the game lists as pickable (never a
|
|
5
|
+
// start nobody can pick, #132). Pure and deterministic.
|
|
6
|
+
import { analyzeBonuses, entryTouches } from '../analysis/bonuses.js';
|
|
7
|
+
import { findChokepoints } from '../analysis/chokepoints.js';
|
|
8
|
+
import { DEFAULT_NON_DISTRIBUTION_ARMIES, PICK_HORIZON, planPicks, } from '../analysis/picks.js';
|
|
9
|
+
import { OVERRIDES_UNPARSED } from '../analysis/overrides.js';
|
|
10
|
+
import { captureCost } from '../analysis/planner.js';
|
|
11
|
+
import { DEFAULT_BASE_INCOME } from '../analysis/player.js';
|
|
12
|
+
import { DEFAULT_DEFENSIVE_KILL_RATE, DEFAULT_OFFENSIVE_KILL_RATE } from '../analysis/combat.js';
|
|
13
|
+
/** Bonus rows by default. */
|
|
14
|
+
const MAP_NOTES_LIMIT = 10;
|
|
15
|
+
/** Chokepoint rows by default. */
|
|
16
|
+
const MAP_CHOKEPOINTS_LIMIT = 10;
|
|
17
|
+
const round2 = (x) => Math.round(x * 100) / 100;
|
|
18
|
+
export function mapNotes(input) {
|
|
19
|
+
const { graph: g } = input;
|
|
20
|
+
const s = input.settings ?? {};
|
|
21
|
+
const limit = input.limit ?? MAP_NOTES_LIMIT;
|
|
22
|
+
const assumptions = [];
|
|
23
|
+
if (input.overridesUnparsed)
|
|
24
|
+
assumptions.push(OVERRIDES_UNPARSED);
|
|
25
|
+
const name = (id) => ({ id, name: g.territoryById.get(id)?.name ?? String(id) });
|
|
26
|
+
const bonusName = (id) => (id === null ? null : (g.bonusById.get(id)?.name ?? String(id)));
|
|
27
|
+
// ---- bonuses by value per army ----
|
|
28
|
+
const neutral = s.initialNonDistributionArmies ?? DEFAULT_NON_DISTRIBUTION_ARMIES;
|
|
29
|
+
assumptions.push(`Every territory is costed as a neutral of ${neutral}${s.initialNonDistributionArmies === undefined ? ' (the usual default; the settings did not say)' : ''}; wastelands and picked territories are not known from the map.`);
|
|
30
|
+
if (s.offensiveKillRate === undefined || s.defensiveKillRate === undefined)
|
|
31
|
+
assumptions.push(`Kill rates assumed ${DEFAULT_OFFENSIVE_KILL_RATE}/${DEFAULT_DEFENSIVE_KILL_RATE} (offence/defence).`);
|
|
32
|
+
const cost = captureCost(neutral, {
|
|
33
|
+
...(s.offensiveKillRate !== undefined ? { offensiveKillRate: s.offensiveKillRate } : {}),
|
|
34
|
+
...(s.defensiveKillRate !== undefined ? { defensiveKillRate: s.defensiveKillRate } : {}),
|
|
35
|
+
...(s.luckModifier !== undefined ? { luckModifier: s.luckModifier } : {}),
|
|
36
|
+
});
|
|
37
|
+
const ranked = [];
|
|
38
|
+
if (cost === null)
|
|
39
|
+
assumptions.push('At these kill rates attackers cannot kill: no bonus can be taken.');
|
|
40
|
+
else {
|
|
41
|
+
for (const b of analyzeBonuses(g)) {
|
|
42
|
+
if (b.value < 1 || !b.territoryIds.length)
|
|
43
|
+
continue;
|
|
44
|
+
const armies = b.territoryIds.length * cost;
|
|
45
|
+
ranked.push({
|
|
46
|
+
bonusId: b.bonusId,
|
|
47
|
+
name: b.name,
|
|
48
|
+
value: b.value,
|
|
49
|
+
territories: b.territoryIds.length,
|
|
50
|
+
armiesToTake: armies,
|
|
51
|
+
valuePerArmy: round2(b.value / armies),
|
|
52
|
+
entryPoints: b.entryPointIds.map(name),
|
|
53
|
+
doubleBorders: [...entryTouches(g, b.bonusId)].filter(([, k]) => k > 1).map(([id, k]) => ({ ...name(id), touches: k })),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
ranked.sort((a, b) => b.value / b.armiesToTake - a.value / a.armiesToTake ||
|
|
57
|
+
a.entryPoints.length - b.entryPoints.length ||
|
|
58
|
+
b.value - a.value ||
|
|
59
|
+
a.bonusId - b.bonusId);
|
|
60
|
+
}
|
|
61
|
+
// ---- chokepoints ----
|
|
62
|
+
const chokepoints = findChokepoints(g)
|
|
63
|
+
.slice(0, input.limit ?? MAP_CHOKEPOINTS_LIMIT)
|
|
64
|
+
.map((c) => ({
|
|
65
|
+
territoryId: c.territoryId,
|
|
66
|
+
name: c.name,
|
|
67
|
+
reasons: [...c.reasons],
|
|
68
|
+
bonus: bonusName(c.bonusId),
|
|
69
|
+
connects: c.connectsBonusIds.map((id) => bonusName(id)),
|
|
70
|
+
}));
|
|
71
|
+
const out = { bonuses: ranked.slice(0, limit), bonusesRanked: ranked.length, chokepoints, assumptions };
|
|
72
|
+
// ---- income targets from the opening simulation ----
|
|
73
|
+
if (input.opening && input.opening.territoryLimit > 0) {
|
|
74
|
+
const { players, territoryLimit } = input.opening;
|
|
75
|
+
const pickable = (input.opening.pickable ?? []).filter((t) => g.territoryById.has(t));
|
|
76
|
+
if (!pickable.length) {
|
|
77
|
+
assumptions.push('No income targets: the game did not list its pickable territories here, and a simulation over every ' +
|
|
78
|
+
'territory would pace a start nobody can pick. warapp_plan_picks reads them from the live board.');
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
// Only the primary group sets the pace, so only it is searched (maxPicks = the limit): the
|
|
82
|
+
// fallback search behind it took ~10 s in a 1v1 on a 761-territory map, on the server's thread (#129, #132).
|
|
83
|
+
const plan = planPicks({
|
|
84
|
+
graph: g,
|
|
85
|
+
pickable,
|
|
86
|
+
settings: s,
|
|
87
|
+
players: Math.max(2, players),
|
|
88
|
+
territoryLimit,
|
|
89
|
+
maxPicks: territoryLimit,
|
|
90
|
+
...(input.opening.neutralArmies ? { neutralArmies: input.opening.neutralArmies } : {}),
|
|
91
|
+
});
|
|
92
|
+
const base = s.minimumArmyBonus ?? DEFAULT_BASE_INCOME;
|
|
93
|
+
const done = plan.groups.primary.bonuses;
|
|
94
|
+
out.incomeTargets = Array.from({ length: PICK_HORIZON + 1 }, (_, i) => {
|
|
95
|
+
const turn = i + 1;
|
|
96
|
+
// A bonus completed during turn k (0: held by the picks) pays from turn k + 1.
|
|
97
|
+
const held = done.filter((b) => b.turn < turn);
|
|
98
|
+
return { turn, income: base + held.reduce((n, b) => n + b.value, 0), bonuses: held.map((b) => b.name) };
|
|
99
|
+
});
|
|
100
|
+
assumptions.push(`Income targets come from the pick advisor's best opening over the ${pickable.length} territor${pickable.length === 1 ? 'y' : 'ies'} the game lists as pickable, with nobody in the way: a pace to aim for, not a promise ` +
|
|
101
|
+
'(warapp_plan_picks gives the picks and a fallback group).');
|
|
102
|
+
if (s.bonusArmyPer)
|
|
103
|
+
assumptions.push('Income targets leave out per-territory income.');
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
/** Map notes as markdown. Bonus and territory names are the map designer's text. */
|
|
109
|
+
export function mapNotesMarkdown(mapName, n) {
|
|
110
|
+
const lines = [`# Strategy notes for the map ${mapName}`, ''];
|
|
111
|
+
lines.push(`## Bonuses by value per army to take (${n.bonuses.length} of ${n.bonusesRanked})`, '');
|
|
112
|
+
for (const b of n.bonuses) {
|
|
113
|
+
const double = new Map(b.doubleBorders.map((d) => [d.id, d.touches]));
|
|
114
|
+
const entry = (e) => double.has(e.id) ? `${e.name} (a double border: next to ${double.get(e.id)} of its territories)` : e.name;
|
|
115
|
+
lines.push(`- ${b.name} (+${b.value}): ${b.territories} territories, ${b.armiesToTake} armies to take, ` +
|
|
116
|
+
`${b.valuePerArmy} per army; entry points: ${b.entryPoints.map(entry).join(', ') || 'none'}`);
|
|
117
|
+
}
|
|
118
|
+
lines.push('', '## Chokepoints', '');
|
|
119
|
+
for (const c of n.chokepoints)
|
|
120
|
+
lines.push(`- ${c.name} (${c.reasons.join(', ')})${c.connects.length ? `: joins ${[c.bonus, ...c.connects].filter(Boolean).join(', ')}` : ''}`);
|
|
121
|
+
if (n.incomeTargets) {
|
|
122
|
+
lines.push('', '## Income targets by turn', '');
|
|
123
|
+
for (const t of n.incomeTargets)
|
|
124
|
+
lines.push(`- Turn ${t.turn}: ${t.income}${t.bonuses.length ? ` (${t.bonuses.join(', ')})` : ''}`);
|
|
125
|
+
}
|
|
126
|
+
lines.push('', '## Assumptions', '', ...n.assumptions.map((a) => `- ${a}`), '');
|
|
127
|
+
return lines.join('\n');
|
|
128
|
+
}
|