@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,259 @@
|
|
|
1
|
+
// One turn of war.app, resolved from every player's orders. Pure and deterministic: no I/O,
|
|
2
|
+
// no randomness, and the board it is given is never changed.
|
|
3
|
+
//
|
|
4
|
+
// The rules are the wiki's (docs/STRATEGY.md "Turn resolution" links each page):
|
|
5
|
+
// - Deployments come before every attack and transfer, and deployed armies may move that turn.
|
|
6
|
+
// - Attack and transfer orders run interleaved in a zigzag over the turn's move order
|
|
7
|
+
// (1 2 … n, n … 2 1, 1 2 … n), each player's next order in each slot. An order that moves
|
|
8
|
+
// no armies takes no slot. An Order Priority card makes its player the first mover for the
|
|
9
|
+
// turn (its first order runs before the others' first, and nothing more); two cancel.
|
|
10
|
+
// - An order is an attack or a transfer by who holds the target WHEN IT RUNS: mine or a
|
|
11
|
+
// teammate's is a transfer, anything else an attack. Attack-only does nothing on a friendly
|
|
12
|
+
// target, transfer-only nothing on any other.
|
|
13
|
+
// - A battle is simultaneous: the attackers kill `offensive kill rate` × their number, the
|
|
14
|
+
// defenders `defensive kill rate` × theirs, each rounded to nearest. The territory is taken
|
|
15
|
+
// when every defender dies and an attacker lives, and all survivors move in; otherwise the
|
|
16
|
+
// survivors stay where they started. When both sides are wiped out the attack fails and one
|
|
17
|
+
// defender stands again.
|
|
18
|
+
// - One army stands guard on every territory unless the game turns that off; an army that
|
|
19
|
+
// arrived this turn can be that guard, a commander cannot (the developer's 2022 update note:
|
|
20
|
+
// to attack out of a commander's territory with no armies, deploy two).
|
|
21
|
+
// - Each army moves once a turn: armies that arrived (by a transfer, by a capture, or back from
|
|
22
|
+
// a failed attack) cannot be ordered on. Under Multi-Attack armies may attack any number of
|
|
23
|
+
// times, but one that transferred is done.
|
|
24
|
+
// - A commander fights as 7 armies, takes damage only after the armies with it, and dies only
|
|
25
|
+
// to 7 damage left over in one battle; its owner is then out and all it held turns neutral.
|
|
26
|
+
// It moves only when an order takes it along, and never onto a teammate's territory.
|
|
27
|
+
//
|
|
28
|
+
// What the wiki does not state is ASSUMED, and named in `assumptions` whenever a turn relies on
|
|
29
|
+
// it: an order sends what its territory can still move when that is fewer than ordered; an order
|
|
30
|
+
// from a territory captured earlier in the turn does nothing; losses on a defending territory
|
|
31
|
+
// fall first on the armies that could still move; and with the guard off, two sides wiped out
|
|
32
|
+
// in one battle still leave one defender; a percentage order (#165) takes its share of what can
|
|
33
|
+
// still move, guard excluded. Not modelled: the Limited Attacks mod.
|
|
34
|
+
//
|
|
35
|
+
// With luck or weighted-random rounding a battle is not determined: each one is resolved at its
|
|
36
|
+
// luck-free, straight-rounded expectation and `exact` is false.
|
|
37
|
+
import { COMMANDER_STRENGTH, DEFAULT_DEFENSIVE_KILL_RATE, DEFAULT_OFFENSIVE_KILL_RATE, luckFraction, straightKills, } from './combat.js';
|
|
38
|
+
import { neighborsOf } from './graph.js';
|
|
39
|
+
const ASSUME_FEWER = 'An order sent what its territory could still move when that was fewer than ordered (the wiki does not say).';
|
|
40
|
+
const ASSUME_LOSSES = 'Losses on a territory that was attacked fell first on the armies that could still move (the wiki does not say which die).';
|
|
41
|
+
const ASSUME_SOURCE_LOST = 'An order from a territory that was captured first did nothing (the wiki does not say).';
|
|
42
|
+
const ASSUME_WIPE = 'With the guard off, an attack that wiped out both sides failed and left one defender (the wiki states this rule under the guard setting).';
|
|
43
|
+
const ASSUME_PERCENT = 'A percentage order took its share of the armies its territory could still move, the guard left out (the client rounds the share; what it counts is not stated).';
|
|
44
|
+
/** `pct`% of `n`, rounded to nearest with a half rounded down, as the client works out a percentage order. */
|
|
45
|
+
export function percentOf(pct, n) {
|
|
46
|
+
const x = (pct / 100) * n;
|
|
47
|
+
const whole = Math.floor(x);
|
|
48
|
+
return x - whole > 0.5 ? whole + 1 : whole;
|
|
49
|
+
}
|
|
50
|
+
/** The board as the resolver sees it: hidden territories are `unknown` with no armies. */
|
|
51
|
+
export function simTerritories(board) {
|
|
52
|
+
const out = new Map();
|
|
53
|
+
for (const t of board.territories) {
|
|
54
|
+
// Hidden armies make a territory unknown whoever is shown to hold it: it is never a stack of none.
|
|
55
|
+
const owner = t.owner.kind === 'unknown' || t.armies === null ? 'unknown' : t.owner.kind === 'player' ? t.owner.playerId : 'neutral';
|
|
56
|
+
const commander = t.specialUnits?.find((u) => u.kind === 'commander');
|
|
57
|
+
out.set(t.territoryId, {
|
|
58
|
+
owner,
|
|
59
|
+
armies: owner === 'unknown' ? 0 : (t.armies ?? 0),
|
|
60
|
+
...(commander && owner !== 'unknown' ? { commander: commander.playerId } : {}),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
/** The turn's slots: 1 2 … n, n … 2 1, 1 2 … n, for as long as anyone has orders left. */
|
|
66
|
+
function* zigzag(players) {
|
|
67
|
+
for (let round = 0;; round++) {
|
|
68
|
+
const row = round % 2 === 0 ? players : [...players].reverse();
|
|
69
|
+
for (const p of row)
|
|
70
|
+
yield p;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export function simulateTurn(input) {
|
|
74
|
+
const s = input.settings ?? {};
|
|
75
|
+
const off = s.offensiveKillRate ?? DEFAULT_OFFENSIVE_KILL_RATE;
|
|
76
|
+
const def = s.defensiveKillRate ?? DEFAULT_DEFENSIVE_KILL_RATE;
|
|
77
|
+
const guard = s.oneArmyStandsGuard === false ? 0 : 1;
|
|
78
|
+
const exact = luckFraction(s.luckModifier) === 0 && s.roundingMode !== 'WeightedRandom';
|
|
79
|
+
const teams = input.teams;
|
|
80
|
+
const friendly = (owner, player) => owner === player ||
|
|
81
|
+
(typeof owner === 'number' && teams !== undefined && teams.get(owner) !== undefined && teams.get(owner) === teams.get(player));
|
|
82
|
+
const cells = new Map();
|
|
83
|
+
const ownerAtStart = new Map();
|
|
84
|
+
for (const [id, t] of input.start ?? simTerritories(input.board)) {
|
|
85
|
+
cells.set(id, { ...t, moved: 0 });
|
|
86
|
+
ownerAtStart.set(id, t.owner);
|
|
87
|
+
}
|
|
88
|
+
const assumptions = new Set();
|
|
89
|
+
const eliminated = [];
|
|
90
|
+
const log = [];
|
|
91
|
+
for (const d of input.deploys) {
|
|
92
|
+
const c = cells.get(d.territoryId);
|
|
93
|
+
if (c && c.owner === d.player && d.armies > 0)
|
|
94
|
+
c.armies += d.armies;
|
|
95
|
+
}
|
|
96
|
+
/** A player whose commander died: everything it holds turns neutral, and its orders stop. */
|
|
97
|
+
const eliminate = (player) => {
|
|
98
|
+
if (eliminated.includes(player))
|
|
99
|
+
return;
|
|
100
|
+
eliminated.push(player);
|
|
101
|
+
for (const c of cells.values()) {
|
|
102
|
+
if (c.owner === player) {
|
|
103
|
+
c.owner = 'neutral';
|
|
104
|
+
c.moved = 0;
|
|
105
|
+
}
|
|
106
|
+
if (c.commander === player)
|
|
107
|
+
delete c.commander;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
/** Carry out one order; `true` when armies (or a commander) actually moved. */
|
|
111
|
+
const execute = (player, index, o) => {
|
|
112
|
+
const base = { player, index, from: o.from, to: o.to, ordered: o.armies };
|
|
113
|
+
const skip = (reason) => {
|
|
114
|
+
log.push({ ...base, sent: 0, kind: 'none', result: 'skipped', reason });
|
|
115
|
+
return false;
|
|
116
|
+
};
|
|
117
|
+
const src = cells.get(o.from);
|
|
118
|
+
const dst = cells.get(o.to);
|
|
119
|
+
if (!src || src.owner !== player) {
|
|
120
|
+
if (src && ownerAtStart.get(o.from) === player)
|
|
121
|
+
assumptions.add(ASSUME_SOURCE_LOST);
|
|
122
|
+
return skip('source-lost');
|
|
123
|
+
}
|
|
124
|
+
if (!dst || !neighborsOf(input.graph, o.from).includes(o.to))
|
|
125
|
+
return skip('not-adjacent');
|
|
126
|
+
const isTransfer = o.attackTeammates ? dst.owner === player : friendly(dst.owner, player);
|
|
127
|
+
if (isTransfer && o.mode === 'attack-only')
|
|
128
|
+
return skip('attack-only');
|
|
129
|
+
if (!isTransfer && o.mode === 'transfer-only')
|
|
130
|
+
return skip('transfer-only');
|
|
131
|
+
// A commander goes along only when asked, has not moved, and is not headed for a teammate's land.
|
|
132
|
+
const takesCommander = o.withCommander === true && src.commander === player && !src.commanderMoved && !(isTransfer && dst.owner !== player);
|
|
133
|
+
// The armies that have not moved, less the guard — which an army that arrived can be.
|
|
134
|
+
const unmoved = Math.max(0, src.armies - src.moved);
|
|
135
|
+
const movable = Math.max(0, Math.min(unmoved, src.armies - guard));
|
|
136
|
+
const asked = Number.isFinite(o.armies) ? Math.max(0, Math.floor(o.armies)) : 0;
|
|
137
|
+
const want = o.byPercent ? percentOf(Math.min(asked, 100), movable) : asked;
|
|
138
|
+
if (o.byPercent)
|
|
139
|
+
assumptions.add(ASSUME_PERCENT);
|
|
140
|
+
const sent = Math.min(want, movable);
|
|
141
|
+
if (sent < want && sent > 0)
|
|
142
|
+
assumptions.add(ASSUME_FEWER);
|
|
143
|
+
if (sent <= 0 && !takesCommander)
|
|
144
|
+
return skip('no-armies');
|
|
145
|
+
if (dst.owner === 'unknown') {
|
|
146
|
+
// Its defenders are hidden: the armies leave, and what becomes of them is not known.
|
|
147
|
+
src.armies -= sent;
|
|
148
|
+
if (takesCommander)
|
|
149
|
+
delete src.commander;
|
|
150
|
+
log.push({ ...base, sent, kind: 'attack', result: 'unknown', targetOwner: 'unknown' });
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
if (isTransfer) {
|
|
154
|
+
src.armies -= sent;
|
|
155
|
+
dst.armies += sent;
|
|
156
|
+
dst.moved += sent;
|
|
157
|
+
if (takesCommander) {
|
|
158
|
+
delete src.commander;
|
|
159
|
+
dst.commander = player;
|
|
160
|
+
dst.commanderMoved = true;
|
|
161
|
+
}
|
|
162
|
+
log.push({ ...base, sent, kind: 'transfer', result: 'transferred', targetOwner: dst.owner });
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
const targetOwner = dst.owner;
|
|
166
|
+
const defCommander = dst.commander;
|
|
167
|
+
const attackPower = sent + (takesCommander ? COMMANDER_STRENGTH : 0);
|
|
168
|
+
const defencePower = dst.armies + (defCommander !== undefined ? COMMANDER_STRENGTH : 0);
|
|
169
|
+
const damageToDefence = straightKills(attackPower, off);
|
|
170
|
+
const damageToAttack = straightKills(defencePower, def);
|
|
171
|
+
const defendersKilled = Math.min(dst.armies, damageToDefence);
|
|
172
|
+
const defCommanderDies = defCommander !== undefined && damageToDefence - dst.armies >= COMMANDER_STRENGTH;
|
|
173
|
+
const defenceGone = defendersKilled === dst.armies && (defCommander === undefined || defCommanderDies);
|
|
174
|
+
const attackersKilled = Math.min(sent, damageToAttack);
|
|
175
|
+
const attCommanderDies = takesCommander && damageToAttack - sent >= COMMANDER_STRENGTH;
|
|
176
|
+
const survivors = sent - attackersKilled;
|
|
177
|
+
const attackLives = survivors > 0 || (takesCommander && !attCommanderDies);
|
|
178
|
+
const event = { ...base, sent, kind: 'attack', result: 'failed', defendersKilled, attackersKilled, survivors, targetOwner };
|
|
179
|
+
src.armies -= sent;
|
|
180
|
+
if (takesCommander)
|
|
181
|
+
delete src.commander;
|
|
182
|
+
if (defenceGone && attackLives) {
|
|
183
|
+
event.result = 'captured';
|
|
184
|
+
dst.owner = player;
|
|
185
|
+
dst.armies = survivors;
|
|
186
|
+
dst.moved = s.multiAttack ? 0 : survivors;
|
|
187
|
+
delete dst.commander;
|
|
188
|
+
delete dst.commanderMoved;
|
|
189
|
+
if (takesCommander && !attCommanderDies) {
|
|
190
|
+
dst.commander = player;
|
|
191
|
+
dst.commanderMoved = !s.multiAttack;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
// The attack failed: the survivors are back where they started, their move used
|
|
196
|
+
// (under Multi-Attack they may attack again).
|
|
197
|
+
src.armies += survivors;
|
|
198
|
+
src.moved += s.multiAttack ? 0 : survivors;
|
|
199
|
+
if (takesCommander && !attCommanderDies) {
|
|
200
|
+
src.commander = player;
|
|
201
|
+
src.commanderMoved = !s.multiAttack;
|
|
202
|
+
}
|
|
203
|
+
if (defenceGone) {
|
|
204
|
+
// Both sides wiped out: one defender stands again and the territory is kept.
|
|
205
|
+
if (guard === 0)
|
|
206
|
+
assumptions.add(ASSUME_WIPE);
|
|
207
|
+
dst.armies = 1;
|
|
208
|
+
dst.moved = Math.min(dst.moved, 1);
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
if (dst.moved > 0 && defendersKilled > 0)
|
|
212
|
+
assumptions.add(ASSUME_LOSSES);
|
|
213
|
+
dst.armies -= defendersKilled;
|
|
214
|
+
dst.moved = Math.min(dst.moved, dst.armies);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
log.push(event);
|
|
218
|
+
if (defCommanderDies && defCommander !== undefined)
|
|
219
|
+
eliminate(defCommander);
|
|
220
|
+
if (attCommanderDies)
|
|
221
|
+
eliminate(player);
|
|
222
|
+
return true;
|
|
223
|
+
};
|
|
224
|
+
const queues = new Map();
|
|
225
|
+
for (const p of input.orders)
|
|
226
|
+
if (p.orders.length)
|
|
227
|
+
queues.set(p.player, { orders: p.orders, next: 0 });
|
|
228
|
+
const unnamed = [...queues.keys()].filter((p) => !input.moveOrder.includes(p)).sort((a, b) => a - b);
|
|
229
|
+
const drawn = [...input.moveOrder.filter((p) => queues.has(p)), ...unnamed];
|
|
230
|
+
// Order Priority: its players move first this turn, in their drawn order (all playing one cancels).
|
|
231
|
+
const priority = new Set(input.orderPriority ?? []);
|
|
232
|
+
const players = [...drawn.filter((p) => priority.has(p)), ...drawn.filter((p) => !priority.has(p))];
|
|
233
|
+
/** Run that player's next order that moves armies (orders that move none take no slot). */
|
|
234
|
+
const takeSlot = (player) => {
|
|
235
|
+
const q = queues.get(player);
|
|
236
|
+
if (!q || eliminated.includes(player))
|
|
237
|
+
return;
|
|
238
|
+
while (q.next < q.orders.length) {
|
|
239
|
+
const index = q.next++;
|
|
240
|
+
if (execute(player, index, q.orders[index]))
|
|
241
|
+
return;
|
|
242
|
+
if (eliminated.includes(player))
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
const pending = () => players.some((p) => !eliminated.includes(p) && queues.get(p).next < queues.get(p).orders.length);
|
|
247
|
+
if (players.length) {
|
|
248
|
+
for (const p of zigzag(players)) {
|
|
249
|
+
if (!pending())
|
|
250
|
+
break;
|
|
251
|
+
takeSlot(p);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
const territories = new Map();
|
|
255
|
+
for (const [id, c] of cells) {
|
|
256
|
+
territories.set(id, { owner: c.owner, armies: c.armies, ...(c.commander !== undefined ? { commander: c.commander } : {}) });
|
|
257
|
+
}
|
|
258
|
+
return { territories, log, exact, assumptions: [...assumptions], eliminated };
|
|
259
|
+
}
|