@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,347 @@
|
|
|
1
|
+
// Game profile: what kind of game this is, from one player's view — the format, the
|
|
2
|
+
// settings that shape strategy, the phase and whether I am ahead. In a free-for-all the
|
|
3
|
+
// contact phase needs a real front (#132): an enemy stack that can take a territory of mine
|
|
4
|
+
// as the board stands, or most of my borders facing enemies — not one enemy territory beside me. Pure and deterministic;
|
|
5
|
+
// no I/O. The planner (rule 0p in planner.ts) reads it to pick a default goal and to tune
|
|
6
|
+
// its scoring; the plan echoes it. #178: it counts the humans still playing and the AI opponents, and names who
|
|
7
|
+
// the game ends with when the AIs surrender to the last human (`endsWith`).
|
|
8
|
+
import { holdsSeat } from '../player-states.js';
|
|
9
|
+
import { carriesTeam, isTeamGame } from '../teams.js';
|
|
10
|
+
import { armiesToTake } from './combat.js';
|
|
11
|
+
import { neighborsOf } from './graph.js';
|
|
12
|
+
/** Ahead when my income is at least this many times the strongest opponent's estimated income. */
|
|
13
|
+
export const AHEAD_RATIO = 1.25;
|
|
14
|
+
/** Behind when my income is at most this many times the strongest opponent's estimated income. */
|
|
15
|
+
export const BEHIND_RATIO = 0.8;
|
|
16
|
+
/**
|
|
17
|
+
* A player's strength in a free-for-all ranking (#167): its visible armies plus this many turns of
|
|
18
|
+
* its income — what it can field over the next few turns.
|
|
19
|
+
*/
|
|
20
|
+
export const STRENGTH_INCOME_TURNS = 3;
|
|
21
|
+
/** #276: the guard case of a game's settings (see {@link GuardCase}). Pure. */
|
|
22
|
+
export function guardCase(s) {
|
|
23
|
+
const stated = s?.oneArmyStandsGuard !== undefined;
|
|
24
|
+
if (s?.oneArmyStandsGuard === false)
|
|
25
|
+
return {
|
|
26
|
+
case: 'off',
|
|
27
|
+
stated,
|
|
28
|
+
interiorDefence: 'every army may move, so any territory can stand at 0 and an advancing stack loses nothing per step. ' +
|
|
29
|
+
'Behind a breached border the interior is hollow: one large stack within two moves can split into single armies ' +
|
|
30
|
+
'that each take an empty territory. The plan keeps one army on each territory beside an enemy (#165), counts ' +
|
|
31
|
+
'a stack two steps away whole, keeps a second line inside a held bonus within two moves of a big stack, raids ' +
|
|
32
|
+
'an emptied hinterland one step deep and retakes an emptied territory of mine with one army (#276).',
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
case: 'on',
|
|
36
|
+
stated,
|
|
37
|
+
interiorDefence: `${stated ? '' : 'not stated, so the default: '}every territory keeps an army and every capture leaves one behind, ` +
|
|
38
|
+
'so an interior is one army deep and a breaching stack thins by an army per step; the guard-off risks (a hollow ' +
|
|
39
|
+
'interior, raids on an emptied hinterland) do not apply.',
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const playing = (p) => (p.state ?? 'Playing') === 'Playing';
|
|
43
|
+
function luckPercent(v) {
|
|
44
|
+
if (!v || v <= 0)
|
|
45
|
+
return 0;
|
|
46
|
+
return Math.round((v > 1 ? v : v * 100) * 100) / 100;
|
|
47
|
+
}
|
|
48
|
+
export function gameProfile(input) {
|
|
49
|
+
const { graph: g, board, me } = input;
|
|
50
|
+
const notes = [];
|
|
51
|
+
const s = input.settings ?? {};
|
|
52
|
+
// ---- who is playing, and on which side ----
|
|
53
|
+
const owners = new Map();
|
|
54
|
+
for (const t of board.territories)
|
|
55
|
+
if (g.territoryById.has(t.territoryId) && t.owner.kind === 'player' && t.armies !== null)
|
|
56
|
+
owners.set(t.territoryId, t.owner.playerId);
|
|
57
|
+
let players = input.players;
|
|
58
|
+
if (!players.length) {
|
|
59
|
+
players = [{ id: me }, ...[...new Set(owners.values())].filter((p) => p !== me).sort((a, b) => a - b).map((id) => ({ id }))];
|
|
60
|
+
notes.push('No player list: the opponents are the players in sight on the board.');
|
|
61
|
+
}
|
|
62
|
+
const teams = isTeamGame(players);
|
|
63
|
+
const myTeam = players.find((p) => p.id === me)?.team;
|
|
64
|
+
/** Players on my side (me, and my teammates in a team game). */
|
|
65
|
+
const ally = (id) => id === me || (teams && carriesTeam(myTeam) && players.find((p) => p.id === id)?.team === myTeam);
|
|
66
|
+
const opponents = players.filter((p) => !ally(p.id) && playing(p)).length;
|
|
67
|
+
const started = players.filter((p) => holdsSeat(p.state)).length;
|
|
68
|
+
const format = teams ? 'teams' : opponents <= 1 ? '1v1' : 'ffa';
|
|
69
|
+
// #178: who is human, and who the game ends with when the AIs surrender to the last human.
|
|
70
|
+
const machine = (p) => p.isAI === true || p.humanTurnedIntoAI === true;
|
|
71
|
+
const humans = players.filter((p) => playing(p) && !machine(p));
|
|
72
|
+
const humansAlive = humans.length;
|
|
73
|
+
const aiOpponents = players.filter((p) => playing(p) && machine(p) && !ally(p.id)).map((p) => p.id).sort((a, b) => a - b);
|
|
74
|
+
const otherHumans = humans.filter((p) => p.id !== me);
|
|
75
|
+
let endsWith = null;
|
|
76
|
+
if (input.endRules?.aisSurrenderWhenOneHumanRemains === true && aiOpponents.length && otherHumans.length === 1 && !ally(otherHumans[0].id)) {
|
|
77
|
+
endsWith = otherHumans[0].id;
|
|
78
|
+
notes.push(`AIs surrender once one human remains: the game ends with player ${endsWith} or me, whatever the AIs hold.`);
|
|
79
|
+
}
|
|
80
|
+
// ---- phase ----
|
|
81
|
+
const mine = [...owners].filter(([, p]) => p === me).map(([t]) => t);
|
|
82
|
+
const enemyAt = (t) => {
|
|
83
|
+
const p = owners.get(t);
|
|
84
|
+
return p !== undefined && !ally(p);
|
|
85
|
+
};
|
|
86
|
+
const touches = mine.some((t) => neighborsOf(g, t).some(enemyAt));
|
|
87
|
+
// #132: in a free-for-all one enemy territory beside me is not contact — it switched the opening
|
|
88
|
+
// rules off from turn 3 in most saved FFA plans. Contact there is an enemy stack that can take a
|
|
89
|
+
// territory of mine as the board stands (its movable armies beside it, one player at a time,
|
|
90
|
+
// against what taking it needs at the game's kill rates), or most of my borders facing enemies.
|
|
91
|
+
// Short of that the phase stays expansion, so rule 4f keeps committing while neutrals are in reach.
|
|
92
|
+
let contact = touches;
|
|
93
|
+
if (touches && format === 'ffa') {
|
|
94
|
+
const guard = s.oneArmyStandsGuard === false ? 0 : 1;
|
|
95
|
+
const rates = {
|
|
96
|
+
...(s.offensiveKillRate !== undefined ? { offensiveKillRate: s.offensiveKillRate } : {}),
|
|
97
|
+
...(s.defensiveKillRate !== undefined ? { defensiveKillRate: s.defensiveKillRate } : {}),
|
|
98
|
+
};
|
|
99
|
+
const armies = new Map(board.territories.filter((t) => g.territoryById.has(t.territoryId)).map((t) => [t.territoryId, t.armies]));
|
|
100
|
+
const mineSet = new Set(mine);
|
|
101
|
+
const threatened = mine.some((t) => {
|
|
102
|
+
const take = armiesToTake(armies.get(t) ?? 0, rates);
|
|
103
|
+
if (take === null)
|
|
104
|
+
return false;
|
|
105
|
+
const movable = new Map();
|
|
106
|
+
for (const n of neighborsOf(g, t)) {
|
|
107
|
+
const p = owners.get(n);
|
|
108
|
+
const a = armies.get(n);
|
|
109
|
+
if (p === undefined || ally(p) || a === null || a === undefined)
|
|
110
|
+
continue;
|
|
111
|
+
movable.set(p, (movable.get(p) ?? 0) + Math.max(0, a - guard));
|
|
112
|
+
}
|
|
113
|
+
return [...movable.values()].some((m) => m >= take);
|
|
114
|
+
});
|
|
115
|
+
const borders = mine.filter((t) => neighborsOf(g, t).some((n) => !mineSet.has(n)));
|
|
116
|
+
const facing = borders.filter((t) => neighborsOf(g, t).some(enemyAt)).length;
|
|
117
|
+
contact = threatened || facing * 2 > borders.length;
|
|
118
|
+
}
|
|
119
|
+
const side = (p) => (teams ? (players.find((x) => x.id === p)?.team ?? p) : p);
|
|
120
|
+
const bySide = new Map();
|
|
121
|
+
for (const p of owners.values()) {
|
|
122
|
+
const key = teams && carriesTeam(players.find((x) => x.id === p)?.team) ? `team ${side(p)}` : `player ${p}`;
|
|
123
|
+
bySide.set(key, (bySide.get(key) ?? 0) + 1);
|
|
124
|
+
}
|
|
125
|
+
const total = g.territoryById.size;
|
|
126
|
+
const dominant = [...bySide].find(([, n]) => n > total / 2);
|
|
127
|
+
let phase;
|
|
128
|
+
if (input.picking || (input.turn !== null && input.turn !== undefined && input.turn <= 2))
|
|
129
|
+
phase = 'opening';
|
|
130
|
+
else if (started >= 3 && opponents === 1) {
|
|
131
|
+
phase = 'late';
|
|
132
|
+
notes.push(`Late game: one opponent is left of the ${started} players who started.`);
|
|
133
|
+
}
|
|
134
|
+
else if (dominant) {
|
|
135
|
+
phase = 'late';
|
|
136
|
+
notes.push(`Late game: ${dominant[0]} holds ${dominant[1]} of the map's ${total} territories, over half.`);
|
|
137
|
+
}
|
|
138
|
+
else
|
|
139
|
+
phase = contact ? 'contact' : 'expansion';
|
|
140
|
+
// ---- standing ----
|
|
141
|
+
let standing;
|
|
142
|
+
// #275 (b): an untrusted opponent is compared at the larger of its estimate and the figure it is sized for.
|
|
143
|
+
const untrustedFigure = new Map((input.untrusted ?? []).filter((u) => !ally(u.playerId)).map((u) => [u.playerId, Math.max(0, Math.floor(u.deploy))]));
|
|
144
|
+
const enemies = input.estimates
|
|
145
|
+
.filter((e) => !ally(e.playerId))
|
|
146
|
+
.map((e) => {
|
|
147
|
+
const f = untrustedFigure.get(e.playerId);
|
|
148
|
+
return f !== undefined && f > e.estimate ? { ...e, estimate: f, untrustedFrom: e.estimate } : e;
|
|
149
|
+
})
|
|
150
|
+
.sort((a, b) => b.estimate - a.estimate || a.playerId - b.playerId);
|
|
151
|
+
const visible = new Map(board.territories.filter((t) => g.territoryById.has(t.territoryId)).map((t) => [t.territoryId, t]));
|
|
152
|
+
const mineSet = new Set(mine);
|
|
153
|
+
const notMine = [...g.territoryById.keys()].filter((t) => !mineSet.has(t));
|
|
154
|
+
const foggedCount = notMine.filter((t) => {
|
|
155
|
+
const st = visible.get(t);
|
|
156
|
+
return !st || st.owner.kind === 'unknown' || st.armies === null;
|
|
157
|
+
}).length;
|
|
158
|
+
const strongest = enemies[0];
|
|
159
|
+
// #94: an opponent out of sight is the most dangerous case; the 'unknown' note says what it has received.
|
|
160
|
+
const unseen = (input.unseen ?? [])
|
|
161
|
+
.filter((u) => !ally(u.playerId))
|
|
162
|
+
.sort((a, b) => a.playerId - b.playerId)
|
|
163
|
+
.map((u) => ` Player ${u.playerId} has been out of sight for ${u.turnsUnseenAtLeast ? 'at least ' : ''}${u.turnsUnseen} turn${u.turnsUnseen === 1 ? '' : 's'} and has received at least ${u.earnedAtLeast} armies: it could be banking up to roughly that, minus what its expansion cost.`)
|
|
164
|
+
.join('');
|
|
165
|
+
let standingSource = null;
|
|
166
|
+
/** How the strongest estimate is described: the fog prior is a floor of my own income (#119). */
|
|
167
|
+
const priorNote = `, a fog prior: assumed to earn at least my own income, so "ahead" is out of reach unless what it could earn on this board caps it`;
|
|
168
|
+
// PLAN-TEAMS C3: in a team game the standing compares sides — my team's summed income (mine and
|
|
169
|
+
// each teammate's still playing that has an estimate) against each enemy team's summed estimate.
|
|
170
|
+
// Elsewhere a side is one player and every figure and note is what it was.
|
|
171
|
+
const sideKey = (p) => {
|
|
172
|
+
const team = players.find((x) => x.id === p)?.team;
|
|
173
|
+
return teams && carriesTeam(team) ? `team ${team}` : `player ${p}`;
|
|
174
|
+
};
|
|
175
|
+
const mateEstimates = teams
|
|
176
|
+
? input.estimates.filter((e) => e.playerId !== me && ally(e.playerId)).sort((a, b) => a.playerId - b.playerId)
|
|
177
|
+
: [];
|
|
178
|
+
const matesPlaying = teams ? players.filter((p) => p.id !== me && ally(p.id) && playing(p)).sort((a, b) => a.id - b.id) : [];
|
|
179
|
+
const counted = mateEstimates.filter((e) => matesPlaying.some((p) => p.id === e.playerId));
|
|
180
|
+
const myIncome = input.income + counted.reduce((n, e) => n + e.estimate, 0);
|
|
181
|
+
const missing = matesPlaying.filter((p) => !counted.some((e) => e.playerId === p.id));
|
|
182
|
+
if (missing.length)
|
|
183
|
+
notes.push(`${missing.map((p) => `Player ${p.id}`).join(', ')}, on my team, ${missing.length === 1 ? 'has' : 'have'} no income estimate and ${missing.length === 1 ? 'is' : 'are'} not counted in my team's income: the team standing is a lower bound for my side.`);
|
|
184
|
+
const sides = new Map();
|
|
185
|
+
for (const e of enemies) {
|
|
186
|
+
const k = sideKey(e.playerId);
|
|
187
|
+
const side = sides.get(k) ?? { members: [], estimate: 0 };
|
|
188
|
+
side.members.push(e);
|
|
189
|
+
side.estimate += e.estimate;
|
|
190
|
+
sides.set(k, side);
|
|
191
|
+
}
|
|
192
|
+
const strongestSide = [...sides]
|
|
193
|
+
.map(([key, v]) => ({ key, ...v, members: [...v.members].sort((a, b) => a.playerId - b.playerId) }))
|
|
194
|
+
.sort((a, b) => b.estimate - a.estimate || a.members[0].playerId - b.members[0].playerId)[0];
|
|
195
|
+
const theirEstimate = teams ? (strongestSide?.estimate ?? 0) : (strongest?.estimate ?? 0);
|
|
196
|
+
const fromPrior = teams ? !!strongestSide?.members.some((e) => e.source === 'prior') : strongest?.source === 'prior';
|
|
197
|
+
/** The comparison a standing note states: mine (or my team's) against the strongest opponent (or enemy team). */
|
|
198
|
+
const against = (basis) => {
|
|
199
|
+
const broke = (e) => 'untrustedFrom' in e ? `, untrusted (#275): an observation broke its estimate of ${e.untrustedFrom}` : undefined;
|
|
200
|
+
if (!teams)
|
|
201
|
+
return `my income ${input.income} against the strongest opponent, player ${strongest.playerId} (~${strongest.estimate}${broke(strongest) ?? (fromPrior ? priorNote : ` ${basis}`)})`;
|
|
202
|
+
const mineText = `my team's income ${myIncome} (${[`mine ${input.income}`, ...counted.map((e) => `player ${e.playerId} ~${e.estimate}`)].join(', ')})`;
|
|
203
|
+
const side = strongestSide;
|
|
204
|
+
const rest = fromPrior ? priorNote : `, ${basis}`;
|
|
205
|
+
return side.key.startsWith('team ')
|
|
206
|
+
? `${mineText} against the strongest enemy team, ${side.key} (~${side.estimate}: ${side.members.map((e) => `player ${e.playerId} ~${e.estimate}`).join(', ')}${rest})`
|
|
207
|
+
: `${mineText} against the strongest enemy, ${side.key} (~${side.estimate}${rest})`;
|
|
208
|
+
};
|
|
209
|
+
// #97: under fog, a standing from tracked income needs every opponent still playing to be in
|
|
210
|
+
// sight with a trusted track (an unseen one could be anything).
|
|
211
|
+
const unseenEnemies = (input.unseen ?? []).filter((u) => !ally(u.playerId));
|
|
212
|
+
const trackedAll = enemies.length > 0 && enemies.length >= opponents && !unseenEnemies.length && enemies.every((e) => e.tracked !== undefined && e.tracked !== null);
|
|
213
|
+
if (!strongest) {
|
|
214
|
+
standing = 'unknown';
|
|
215
|
+
notes.push(`Standing unknown: no opponent is in sight, so its income cannot be estimated.${unseen}`);
|
|
216
|
+
}
|
|
217
|
+
else if (notMine.length && foggedCount > notMine.length / 2 && trackedAll) {
|
|
218
|
+
// #97: the fog hides most of the board, but every opponent in the game is in sight with an
|
|
219
|
+
// income tracked over several turns — compare against that, and say it is a tracked figure.
|
|
220
|
+
const ratio = theirEstimate > 0 ? myIncome / theirEstimate : Infinity;
|
|
221
|
+
standing = ratio >= AHEAD_RATIO ? 'ahead' : ratio <= BEHIND_RATIO ? 'behind' : 'even';
|
|
222
|
+
standingSource = 'tracked';
|
|
223
|
+
notes.push(`Standing ${standing} (tracked): ${against('tracked over several turns')}${standing === 'ahead' ? `, at least ${AHEAD_RATIO}×` : standing === 'behind' ? `, at most ${BEHIND_RATIO}×` : ''}. ${foggedCount} of the ${notMine.length} territories I do not hold are in the fog, so income it hides from its observed deploys is not counted.`);
|
|
224
|
+
}
|
|
225
|
+
else if (notMine.length && foggedCount > notMine.length / 2) {
|
|
226
|
+
standing = 'unknown';
|
|
227
|
+
notes.push(`Standing unknown: ${foggedCount} of the ${notMine.length} territories I do not hold are in the fog, so the opponents' income is mostly unseen.${unseen}`);
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
const ratio = theirEstimate > 0 ? myIncome / theirEstimate : Infinity;
|
|
231
|
+
standing = ratio >= AHEAD_RATIO ? 'ahead' : ratio <= BEHIND_RATIO ? 'behind' : 'even';
|
|
232
|
+
standingSource = 'visible';
|
|
233
|
+
notes.push(`Standing ${standing}: ${against('estimated')}${standing === 'ahead' ? `, at least ${AHEAD_RATIO}×` : standing === 'behind' ? `, at most ${BEHIND_RATIO}×` : ''}.`);
|
|
234
|
+
}
|
|
235
|
+
// PLAN-TEAMS C3 (absent means unknown): an enemy-team member still playing with no estimate (out
|
|
236
|
+
// of view) is no part of its side's sum, so the enemy figure is a lower bound. Behind and even
|
|
237
|
+
// stand as lower bounds of the gap; ahead is unproven and reads unknown.
|
|
238
|
+
if (teams) {
|
|
239
|
+
const unestimated = players
|
|
240
|
+
.filter((p) => !ally(p.id) && playing(p) && !enemies.some((e) => e.playerId === p.id))
|
|
241
|
+
.sort((a, b) => a.id - b.id);
|
|
242
|
+
if (unestimated.length) {
|
|
243
|
+
const named = unestimated.map((p) => (sideKey(p.id) === `player ${p.id}` ? `Player ${p.id}` : `Player ${p.id}, on ${sideKey(p.id)},`)).join('; ');
|
|
244
|
+
const one = unestimated.length === 1;
|
|
245
|
+
notes.push(`${named} ${one ? 'has' : 'have'} no income estimate and ${one ? 'is' : 'are'} not counted in the enemy side: its income is a lower bound.`);
|
|
246
|
+
if (standing === 'ahead') {
|
|
247
|
+
notes.push(`Standing unknown, not ahead: the income comparison says ahead, but an enemy still playing is not counted.${unseen}`);
|
|
248
|
+
standing = 'unknown';
|
|
249
|
+
standingSource = null;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
// ---- the armies on the board overrule an income comparison ----
|
|
254
|
+
// An opponent's visible armies are a lower bound on what it has, and mine are exact, so being
|
|
255
|
+
// outnumbered in view is certain where an income estimate is not. Live, the standing read
|
|
256
|
+
// "ahead (23 against ~12 tracked)" while I held 65 armies against 138 in view, and "unknown"
|
|
257
|
+
// against 893. PLAN-TEAMS C3: in a team game both sides are summed by team.
|
|
258
|
+
const armiesBy = new Map();
|
|
259
|
+
for (const t of board.territories)
|
|
260
|
+
if (g.territoryById.has(t.territoryId) && t.owner.kind === 'player' && t.armies !== null)
|
|
261
|
+
armiesBy.set(t.owner.playerId, (armiesBy.get(t.owner.playerId) ?? 0) + t.armies);
|
|
262
|
+
const myArmies = armiesBy.get(me) ?? 0;
|
|
263
|
+
// Only teammates still playing: one who surrendered or was booted issues no orders with what it left.
|
|
264
|
+
const sideArmies = teams
|
|
265
|
+
? myArmies + matesPlaying.reduce((n, p) => n + (armiesBy.get(p.id) ?? 0), 0)
|
|
266
|
+
: myArmies;
|
|
267
|
+
const armiesBySide = new Map();
|
|
268
|
+
for (const [p, a] of armiesBy) {
|
|
269
|
+
if (ally(p))
|
|
270
|
+
continue;
|
|
271
|
+
const k = teams ? sideKey(p) : `player ${p}`;
|
|
272
|
+
const side = armiesBySide.get(k) ?? { armies: 0, first: p };
|
|
273
|
+
side.armies += a;
|
|
274
|
+
side.first = Math.min(side.first, p);
|
|
275
|
+
armiesBySide.set(k, side);
|
|
276
|
+
}
|
|
277
|
+
const rival = [...armiesBySide].sort((a, b) => b[1].armies - a[1].armies || a[1].first - b[1].first)[0];
|
|
278
|
+
if (rival && rival[1].armies > 0 && mine.length) {
|
|
279
|
+
const theirArmies = rival[1].armies;
|
|
280
|
+
const mineText = teams ? `my team's ${sideArmies}` : `my ${sideArmies}`;
|
|
281
|
+
const theirsText = `${rival[0]}'s ${theirArmies}`;
|
|
282
|
+
if (sideArmies * 2 < theirArmies && standing !== 'behind') {
|
|
283
|
+
notes.push(`Standing behind, whatever the incomes (it read ${standing}): ${mineText} visible armies are less than half of ${theirsText} in view, and what it shows is the least it has.`);
|
|
284
|
+
standing = 'behind';
|
|
285
|
+
standingSource ??= 'visible';
|
|
286
|
+
}
|
|
287
|
+
else if (standing === 'ahead' && sideArmies < BEHIND_RATIO * theirArmies) {
|
|
288
|
+
notes.push(`Not ahead: the income comparison says so, but ${mineText} visible armies are below ${BEHIND_RATIO}× ${theirsText} in view. Standing even.`);
|
|
289
|
+
standing = 'even';
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
// #275 (b): an observation broke an opponent's estimate: what it really earns is unknown and above it,
|
|
293
|
+
// so the game is not even. Only a running tripwire does this: reading `behind` on armies in view alone
|
|
294
|
+
// (an opponent's ≥ 1.25 × mine, no tripwire) is not part of #275 — it is deferred to #287.
|
|
295
|
+
if (standing === 'even') {
|
|
296
|
+
const running = enemies.filter((e) => untrustedFigure.has(e.playerId)).map((e) => e.playerId).sort((a, b) => a - b);
|
|
297
|
+
if (running.length) {
|
|
298
|
+
notes.push(`Standing behind, not even: ${running.map((p) => `player ${p}'s`).join(', ')} estimate is untrusted (#275): an observation broke it, so what ${running.length === 1 ? 'it earns' : 'they earn'} is above the figure compared.`);
|
|
299
|
+
standing = 'behind';
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
// ---- #167: who leads a free-for-all ----
|
|
303
|
+
let ranking;
|
|
304
|
+
if (format === 'ffa' && mine.length) {
|
|
305
|
+
const incomeOf = new Map(input.estimates.filter((e) => !ally(e.playerId)).map((e) => [e.playerId, e.estimate]));
|
|
306
|
+
const rows = [
|
|
307
|
+
{ playerId: me, armies: myArmies, income: input.income },
|
|
308
|
+
...[...armiesBy]
|
|
309
|
+
.filter(([p]) => !ally(p))
|
|
310
|
+
.map(([p, armies]) => ({ playerId: p, armies, income: incomeOf.get(p) ?? 0 })),
|
|
311
|
+
]
|
|
312
|
+
.map((r) => ({ ...r, strength: r.armies + STRENGTH_INCOME_TURNS * r.income }))
|
|
313
|
+
.sort((a, b) => b.strength - a.strength || a.playerId - b.playerId);
|
|
314
|
+
const leader = rows[0].playerId;
|
|
315
|
+
const myRank = rows.findIndex((r) => r.playerId === me) + 1;
|
|
316
|
+
ranking = { leader, myRank, of: rows.length, commonThreat: leader === me ? null : leader, players: rows };
|
|
317
|
+
notes.push(leader === me
|
|
318
|
+
? `FFA ranking: I lead ${rows.length} players in sight on strength (armies + ${STRENGTH_INCOME_TURNS} × income: ${rows[0].strength}${rows[1] ? ` against player ${rows[1].playerId}'s ${rows[1].strength}` : ''}); the others may combine against me.`
|
|
319
|
+
: `FFA ranking: player ${leader} leads on strength (armies + ${STRENGTH_INCOME_TURNS} × income: ${rows[0].strength}); I am ${myRank} of ${rows.length} in sight (${rows[myRank - 1].strength}). Opponents' figures are lower bounds under fog.`);
|
|
320
|
+
}
|
|
321
|
+
// #276: a guard-off game names the case at the top of the profile.
|
|
322
|
+
const guard = s.oneArmyStandsGuard === false ? guardCase(s) : undefined;
|
|
323
|
+
if (guard)
|
|
324
|
+
notes.unshift(`One Army Must Stand Guard is off: ${guard.interiorDefence}`);
|
|
325
|
+
return {
|
|
326
|
+
...(guard ? { guard } : {}),
|
|
327
|
+
format,
|
|
328
|
+
opponents,
|
|
329
|
+
settings: {
|
|
330
|
+
luck: luckPercent(s.luckModifier),
|
|
331
|
+
rounding: s.roundingMode ?? null,
|
|
332
|
+
cards: s.cards === true,
|
|
333
|
+
localDeployments: s.localDeployments === true,
|
|
334
|
+
noSplit: s.noSplit === true,
|
|
335
|
+
commanders: s.commanders === true,
|
|
336
|
+
fog: s.fog ?? null,
|
|
337
|
+
},
|
|
338
|
+
phase,
|
|
339
|
+
standing,
|
|
340
|
+
standingSource,
|
|
341
|
+
...(ranking ? { ranking } : {}),
|
|
342
|
+
humansAlive,
|
|
343
|
+
aiOpponents,
|
|
344
|
+
endsWith,
|
|
345
|
+
notes,
|
|
346
|
+
};
|
|
347
|
+
}
|