@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.
- package/.claude-plugin/marketplace.json +4 -4
- package/.claude-plugin/plugin.json +2 -2
- package/README.md +199 -8
- package/dist/analysis/award.js +159 -0
- package/dist/analysis/bonuses.js +98 -0
- package/dist/analysis/breach.js +62 -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/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 +159 -0
- package/dist/analysis/lookahead.js +108 -0
- package/dist/analysis/opponent-profile.js +551 -0
- package/dist/analysis/opponents.js +1245 -0
- package/dist/analysis/outlook.js +633 -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 +1218 -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 +927 -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 +2922 -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 +577 -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 +1109 -0
- package/dist/board.js +105 -0
- package/dist/bundle.js +117959 -36172
- package/dist/cards.js +435 -0
- package/dist/chat-cursor.js +135 -0
- package/dist/chat.js +192 -0
- package/dist/client.js +361 -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/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/live.js +278 -0
- package/dist/map-stats.js +152 -0
- package/dist/map-store.js +204 -0
- package/dist/move-order.js +141 -0
- package/dist/my-games.js +180 -0
- package/dist/normalize.js +411 -0
- package/dist/open-games.js +537 -0
- package/dist/outlook-log.js +138 -0
- package/dist/path-lock.js +22 -0
- package/dist/pick-list.js +193 -0
- package/dist/player-record-store.js +229 -0
- package/dist/player-states.js +31 -0
- package/dist/profile-store.js +677 -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 +531 -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 +215 -0
- package/dist/scalars.js +28 -0
- package/dist/scout.js +346 -0
- package/dist/stats.js +269 -0
- package/dist/strategy/card-clock.js +185 -0
- package/dist/strategy/map-notes.js +128 -0
- package/dist/strategy/notes.js +2168 -0
- package/dist/team-cards.js +84 -0
- package/dist/team-orders.js +150 -0
- package/dist/teams.js +19 -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 +146 -0
- package/dist/tools/chat.js +483 -0
- package/dist/tools/check-plan.js +688 -0
- package/dist/tools/commander-check.js +102 -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/game.js +126 -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 +142 -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-stats.js +117 -0
- package/dist/tools/map.js +133 -0
- package/dist/tools/my-games.js +123 -0
- package/dist/tools/open-games.js +104 -0
- package/dist/tools/opponents.js +151 -0
- package/dist/tools/order-options.js +135 -0
- package/dist/tools/picks.js +292 -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 +385 -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 +200 -0
- package/dist/tools/stress-opponents.js +83 -0
- package/dist/tools/surrender.js +240 -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 +182 -0
- package/dist/tools/turn.js +2761 -0
- package/dist/tools/uncommit.js +160 -0
- package/dist/tools/where.js +275 -0
- package/dist/tools/write-kit.js +158 -0
- package/dist/transport-bridge.js +33 -0
- package/dist/trend.js +452 -0
- package/dist/version.js +4 -0
- package/manifest.json +174 -4
- package/mint.yaml +101 -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 +969 -21
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
// warapp_surrender: surrender a game (or take back a pending surrender) with
|
|
2
|
+
// the web client's Surrender (method 67), gated on the user's confirmation.
|
|
3
|
+
// The game is read from GameFeed first, so finished games and games the
|
|
4
|
+
// signed-in account is not playing are refused before anything is sent, and
|
|
5
|
+
// the outcome is read back from GameFeed afterwards — never from the reply,
|
|
6
|
+
// which carries no result.
|
|
7
|
+
import { CONFIRM_INJECTION_RULE, toolAnnotations } from '@chrischall/mcp-utils';
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
import { parseGameId } from '../client.js';
|
|
10
|
+
import { leavers } from '../normalize.js';
|
|
11
|
+
import { readOutlookLog } from '../outlook-log.js';
|
|
12
|
+
import { Method, writeSurrenderParams } from '../protocol/methods.js';
|
|
13
|
+
import { gameIdArg, shownAccount, UNTRUSTED_PREVIEW_NOTE, untrustedText } from './common.js';
|
|
14
|
+
import { noBrowserNote } from './session.js';
|
|
15
|
+
import { mintMeta } from './hints.js';
|
|
16
|
+
import { requireApprovedAccount, writeAccount } from './live-context.js';
|
|
17
|
+
import { defineGatedWrite, mySeat, refuse, requireMe, requirePlaying, sendAndVerify, worded } from './write-kit.js';
|
|
18
|
+
const PLAYING = 'Playing';
|
|
19
|
+
const SURRENDERED = 'SurrenderAccepted';
|
|
20
|
+
const FINISHED = 'Finished';
|
|
21
|
+
const DISTRIBUTING = 'DistributingTerritories';
|
|
22
|
+
/** The Surrender refusals war.app answers with (verified live, issue #30). */
|
|
23
|
+
const SURRENDER_ERRORS = {
|
|
24
|
+
4: 'The game is over, so there is nothing to surrender.',
|
|
25
|
+
7: 'You are no longer in the game.',
|
|
26
|
+
230: 'You are no longer in the game.',
|
|
27
|
+
};
|
|
28
|
+
/** #178: opponents close to a boot are listed when the nearest boot is this close (a day). */
|
|
29
|
+
const LEAVER_WINDOW_MINUTES = 24 * 60;
|
|
30
|
+
/**
|
|
31
|
+
* #178: whether the others must accept a surrender — from `InstantSurrender` when it reads (#228:
|
|
32
|
+
* the game is read with its settings, which carry it). Unread, two players: no (a surrender ends a
|
|
33
|
+
* 1v1 at once); more than two: `null` — it MAY be needed (#228: two of two such surrenders went
|
|
34
|
+
* through at once, so the player count no longer states it is).
|
|
35
|
+
*/
|
|
36
|
+
function acceptanceOf(game, players) {
|
|
37
|
+
const instant = game.endRules?.instantSurrender;
|
|
38
|
+
if (instant === true)
|
|
39
|
+
return { needed: false, from: 'setting', note: 'Surrender is instant in this game: it takes effect at once, without the others accepting it.' };
|
|
40
|
+
if (instant === false)
|
|
41
|
+
return {
|
|
42
|
+
needed: true,
|
|
43
|
+
from: 'setting',
|
|
44
|
+
note: 'Surrender is not instant in this game: the others must accept it before it ends your game, and until then ' +
|
|
45
|
+
'it can be taken back (undo).' +
|
|
46
|
+
(players <= 2 ? ' UNVERIFIED: whether a two-player game really waits for the opponent to accept.' : ''),
|
|
47
|
+
};
|
|
48
|
+
const raw = game.endRules?.instantSurrenderRaw;
|
|
49
|
+
return {
|
|
50
|
+
needed: players > 2 ? null : false,
|
|
51
|
+
from: 'player count',
|
|
52
|
+
note: `The InstantSurrender setting could not be read${raw !== undefined ? ` (${JSON.stringify(raw)})` : ' (not sent)'}, so this goes by the player count: ` +
|
|
53
|
+
(players > 2
|
|
54
|
+
? 'with more than two players the others MAY have to accept the surrender (unknown: such surrenders have also gone through at once), so it may end your game now.'
|
|
55
|
+
: 'with two players, a surrender ends the game at once.'),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const gameLabel = (game) => game.name ?? `game ${game.id}`;
|
|
59
|
+
/** Players still in the game (a surrender in a game of more than two needs the others' acceptance). */
|
|
60
|
+
const activePlayers = (game) => game.players.filter((p) => p.state === PLAYING);
|
|
61
|
+
/** The signed-in account's seat in `game`, refused when it cannot (or should not) be surrendered. */
|
|
62
|
+
function surrenderable(game, me, undo) {
|
|
63
|
+
if (game.state === FINISHED) {
|
|
64
|
+
refuse(`Game ${game.id} is already over, so there is nothing to surrender.`, 'Check warapp_get_game.');
|
|
65
|
+
}
|
|
66
|
+
if (game.state !== PLAYING && game.state !== DISTRIBUTING) {
|
|
67
|
+
refuse(`Game ${game.id} has not started (game state: ${game.state}), so there is nothing to surrender.`, 'A lobby is left with warapp_leave_game, not surrendered.');
|
|
68
|
+
}
|
|
69
|
+
const seat = mySeat(game, me);
|
|
70
|
+
if (undo && seat.state === SURRENDERED) {
|
|
71
|
+
refuse(`Your surrender in game ${game.id} was already accepted, so it cannot be taken back.`, 'Check warapp_get_game.');
|
|
72
|
+
}
|
|
73
|
+
requirePlaying(game, seat);
|
|
74
|
+
// GameFeed exposes no pending-surrender flag, so this can only refuse where a surrender is never
|
|
75
|
+
// pending: an instant surrender (#178: from the setting), else the two-player case.
|
|
76
|
+
if (undo && acceptanceOf(game, activePlayers(game).length).needed === false) {
|
|
77
|
+
refuse(game.endRules?.instantSurrender === true
|
|
78
|
+
? `There is no pending surrender to take back in game ${game.id}: surrender is instant in this game, so it is never pending.`
|
|
79
|
+
: `There is no pending surrender to take back in game ${game.id}: with two players a surrender ends the game at once.`, 'Check warapp_get_game.');
|
|
80
|
+
}
|
|
81
|
+
return seat;
|
|
82
|
+
}
|
|
83
|
+
export function registerSurrenderTool(server, ctx) {
|
|
84
|
+
defineGatedWrite(server, {
|
|
85
|
+
title: 'Surrender a war.app game',
|
|
86
|
+
_meta: mintMeta('change', ['surrender game', 'resign warzone game', 'give up game']),
|
|
87
|
+
}, {
|
|
88
|
+
name: 'warapp_surrender',
|
|
89
|
+
description: 'Surrender a war.app (Warzone) game as the signed-in account: you lose it and cannot rejoin. When the ' +
|
|
90
|
+
"game's InstantSurrender setting asks for acceptance (unread with more than two players: it may) the surrender " +
|
|
91
|
+
'waits for the others to accept it (reported `pending`); `undo: true` takes back such a pending ' +
|
|
92
|
+
'surrender. The preview shows what bears on the decision: the outlook warapp_plan_turn last logged and ' +
|
|
93
|
+
'its basis, AI opponents, whether acceptance is needed (`acceptance.needed`: true, false, or null when the setting is unread and it may be), what your land becomes (AI or neutral) and ' +
|
|
94
|
+
'opponents close to a boot. The game is read from GameFeed first (finished games and games you are not ' +
|
|
95
|
+
'playing are refused) and the outcome is read back from GameFeed.' +
|
|
96
|
+
`${noBrowserNote(ctx.hosted)} ${CONFIRM_INJECTION_RULE}`,
|
|
97
|
+
annotations: toolAnnotations({
|
|
98
|
+
title: 'Surrender a war.app game',
|
|
99
|
+
readOnly: false,
|
|
100
|
+
destructive: true,
|
|
101
|
+
idempotent: false,
|
|
102
|
+
openWorld: true,
|
|
103
|
+
}),
|
|
104
|
+
inputSchema: z.object({
|
|
105
|
+
game_id: gameIdArg,
|
|
106
|
+
undo: z
|
|
107
|
+
.boolean()
|
|
108
|
+
.optional()
|
|
109
|
+
.describe('Take back your pending surrender instead of surrendering (default false).'),
|
|
110
|
+
}),
|
|
111
|
+
async plan({ game_id, undo }) {
|
|
112
|
+
const gameId = parseGameId(game_id);
|
|
113
|
+
const takeBack = undo ?? false;
|
|
114
|
+
const me = await requireMe(ctx);
|
|
115
|
+
// #228: with its settings — InstantSurrender is one; without them the preview always fell
|
|
116
|
+
// back to the player count.
|
|
117
|
+
const game = await ctx.client.getGame(gameId, { map: false, settings: true });
|
|
118
|
+
const seat = surrenderable(game, me, takeBack);
|
|
119
|
+
const name = gameLabel(game);
|
|
120
|
+
const players = activePlayers(game).length;
|
|
121
|
+
const acceptance = acceptanceOf(game, players);
|
|
122
|
+
// #178: what bears on the decision — the outlook warapp_plan_turn last logged, the AI
|
|
123
|
+
// opponents, what my land becomes, and opponents close to a boot.
|
|
124
|
+
const log = ctx.dataDir ? await readOutlookLog(ctx.dataDir, gameId, me) : undefined;
|
|
125
|
+
const outlook = log?.latest
|
|
126
|
+
? { turn: log.latest.turn, state: log.latest.state, heldTurns: log.latest.heldTurns, basis: log.latest.basis }
|
|
127
|
+
: { state: null, note: 'No outlook logged for this game: warapp_plan_turn records one each turn it plans.' };
|
|
128
|
+
const aiOpponents = game.players
|
|
129
|
+
.filter((p) => p.id !== me && p.state === PLAYING && (p.isAI || p.humanTurnedIntoAI))
|
|
130
|
+
.map((p) => ({ id: p.id, name: untrustedText(p.name) }));
|
|
131
|
+
const surrenderedToAI = game.endRules?.surrenderedTurnIntoAI;
|
|
132
|
+
const soon = leavers(game, Date.now(), { withinMinutes: LEAVER_WINDOW_MINUTES });
|
|
133
|
+
const nameOf = (id) => untrustedText(game.players.find((p) => p.id === id)?.name ?? '');
|
|
134
|
+
const leaving = soon.players
|
|
135
|
+
.filter((l) => l.playerId !== me)
|
|
136
|
+
.map(({ playerId, ...rest }) => ({ id: playerId, name: nameOf(playerId), ...rest }));
|
|
137
|
+
// The sentences name the game by id only: its name is its creator's words and
|
|
138
|
+
// goes, delimited, in `game.name` (the preview sits beside the confirmToken).
|
|
139
|
+
const summary = takeBack
|
|
140
|
+
? `Take back your pending surrender in war.app game ${gameId}`
|
|
141
|
+
: `This ENDS your war.app game ${gameId} — you lose it and cannot rejoin`;
|
|
142
|
+
return {
|
|
143
|
+
gate: {
|
|
144
|
+
action: takeBack ? 'warapp.take_back_surrender' : 'warapp.surrender',
|
|
145
|
+
summary,
|
|
146
|
+
account: writeAccount(me),
|
|
147
|
+
target: gameId,
|
|
148
|
+
payload: { method: 'Surrender', gameId, surrender: !takeBack },
|
|
149
|
+
willSend: { game: gameId, surrender: !takeBack },
|
|
150
|
+
preview: {
|
|
151
|
+
warning: takeBack
|
|
152
|
+
? `This will take back your pending surrender in game ${gameId}.`
|
|
153
|
+
: `This ENDS your game ${gameId} — you lose it and cannot rejoin.`,
|
|
154
|
+
account: shownAccount(seat.name, me),
|
|
155
|
+
game: { id: gameId, name: game.name === undefined ? null : untrustedText(game.name), state: game.state, playersStillIn: players },
|
|
156
|
+
...(takeBack ? {} : { acceptance }),
|
|
157
|
+
...(takeBack || acceptance.needed === false
|
|
158
|
+
? {}
|
|
159
|
+
: {
|
|
160
|
+
note: acceptance.needed === true
|
|
161
|
+
? 'The others must accept the surrender before it ends your game.'
|
|
162
|
+
: 'The others may have to accept the surrender before it ends your game, or it may end it at once (unknown).',
|
|
163
|
+
}),
|
|
164
|
+
outlook,
|
|
165
|
+
aiOpponents,
|
|
166
|
+
yourLandBecomes: surrenderedToAI === undefined ? null : surrenderedToAI ? 'AI' : 'neutral',
|
|
167
|
+
...(leaving.length ? { leavers: { players: leaving, unverified: soon.unverified } } : {}),
|
|
168
|
+
untrusted: UNTRUSTED_PREVIEW_NOTE,
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
state: { gameId, name, me, undo: takeBack, acceptanceNeeded: acceptance.needed },
|
|
172
|
+
};
|
|
173
|
+
},
|
|
174
|
+
async execute({ gameId, name, me, undo, acceptanceNeeded }) {
|
|
175
|
+
await requireApprovedAccount(ctx, writeAccount(me));
|
|
176
|
+
const game = { id: gameId, name };
|
|
177
|
+
return sendAndVerify({
|
|
178
|
+
send: async () => {
|
|
179
|
+
await ctx.rpc.call('Surrender', Method.Surrender, (w) => writeSurrenderParams(w, { gameId, surrender: !undo }));
|
|
180
|
+
},
|
|
181
|
+
refused: worded(SURRENDER_ERRORS),
|
|
182
|
+
unanswered: (failure) => ({
|
|
183
|
+
status: 'unknown',
|
|
184
|
+
outcome: 'unknown',
|
|
185
|
+
game,
|
|
186
|
+
warning: `war.app did not confirm the ${undo ? 'take-back' : 'surrender'} ` +
|
|
187
|
+
`(${failure}), so it may already have gone through. ` +
|
|
188
|
+
'Check warapp_get_game to see your state in the game.',
|
|
189
|
+
}),
|
|
190
|
+
readBack: () => ctx.client.getGame(gameId, { map: false }),
|
|
191
|
+
unreadable: (failure) => ({
|
|
192
|
+
status: 'unconfirmed',
|
|
193
|
+
outcome: 'unconfirmed',
|
|
194
|
+
game,
|
|
195
|
+
warning: `war.app accepted the request, but GameFeed could not be read back (${failure}). Check warapp_get_game.`,
|
|
196
|
+
}),
|
|
197
|
+
classify: (after) => {
|
|
198
|
+
const seat = after.players.find((p) => p.id === me);
|
|
199
|
+
const state = { yourState: seat?.state ?? null, gameState: after.state };
|
|
200
|
+
if (seat?.state === SURRENDERED)
|
|
201
|
+
return { status: 'surrendered', outcome: 'confirmed', game, ...state };
|
|
202
|
+
if (undo) {
|
|
203
|
+
// GameFeed shows no pending surrender, so "still playing" is all that can be read (#130).
|
|
204
|
+
if (seat?.state === PLAYING) {
|
|
205
|
+
return {
|
|
206
|
+
status: 'still_playing',
|
|
207
|
+
outcome: 'accepted',
|
|
208
|
+
game,
|
|
209
|
+
...state,
|
|
210
|
+
message: 'You are still playing. GameFeed has no pending-surrender state, so whether a surrender was ' +
|
|
211
|
+
'pending (and is now taken back) cannot be read; if none was, nothing changed.',
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
else if (seat?.state === PLAYING && acceptanceNeeded !== false) {
|
|
216
|
+
return {
|
|
217
|
+
status: 'pending',
|
|
218
|
+
outcome: 'accepted',
|
|
219
|
+
game,
|
|
220
|
+
...state,
|
|
221
|
+
// GameFeed has no pending-surrender state: war.app accepted the request
|
|
222
|
+
// and the seat is still Playing, which is what a pending surrender looks like.
|
|
223
|
+
message: 'war.app accepted the surrender and you are still playing, so it should be pending: the other ' +
|
|
224
|
+
`players must accept it before it ends your game (${acceptanceNeeded ? 'the game asks for acceptance' : 'the game may ask for acceptance: its setting was not read'}). (GameFeed shows no pending state, so this is ` +
|
|
225
|
+
'inferred, not read.)',
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
return {
|
|
229
|
+
status: 'unchanged',
|
|
230
|
+
outcome: 'unconfirmed',
|
|
231
|
+
game,
|
|
232
|
+
...state,
|
|
233
|
+
warning: 'war.app accepted the request, but GameFeed does not show your state changing yet. Check ' +
|
|
234
|
+
'warapp_get_game shortly.',
|
|
235
|
+
};
|
|
236
|
+
},
|
|
237
|
+
});
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// Surviving a wrong estimate (#275, pattern 1), as the tools show it: the broken-estimate tripwire
|
|
2
|
+
// (src/analysis/tripwire.ts) read over my board history and the survival side store (src/trend.ts), and
|
|
3
|
+
// the headroom table (src/analysis/headroom.ts) in a view. warapp_plan_turn writes the store;
|
|
4
|
+
// warapp_check_plan and warapp_submit_turn only read.
|
|
5
|
+
import { headroomTable } from '../analysis/headroom.js';
|
|
6
|
+
import { symmetricStart, trackGame } from '../analysis/opponents.js';
|
|
7
|
+
import { activeTripwires, brokenEstimates } from '../analysis/tripwire.js';
|
|
8
|
+
import { reinforcementHand } from '../strategy/card-clock.js';
|
|
9
|
+
import { readSurvival, writeSurvival } from '../trend.js';
|
|
10
|
+
import { carriesTeam } from '../teams.js';
|
|
11
|
+
import { opponentCanHold } from './card-advice.js';
|
|
12
|
+
import { namer } from './common.js';
|
|
13
|
+
/** Headroom rows the compact view lists (the weakest first); the full view lists them all. */
|
|
14
|
+
export const HEADROOM_COMPACT = 10;
|
|
15
|
+
/**
|
|
16
|
+
* #275 review: the Reinforcement armies an opponent may have banked and played at once on the turn before
|
|
17
|
+
* `turn` (the one my latest board shows the result of), which its estimate (one card at most) leaves out:
|
|
18
|
+
* every card the clock says it can hold then (at most MaxCardsHold) when that is more than one, else 0; `Infinity`
|
|
19
|
+
* when Reinforcement is in play and the cards or their armies cannot be counted.
|
|
20
|
+
*/
|
|
21
|
+
export function bankedReinforcement(settings, turn) {
|
|
22
|
+
const hand = reinforcementHand(settings, turn - 1);
|
|
23
|
+
if (!hand)
|
|
24
|
+
return 0;
|
|
25
|
+
if (hand.cards === null)
|
|
26
|
+
return Infinity;
|
|
27
|
+
if (hand.cards <= 1)
|
|
28
|
+
return 0;
|
|
29
|
+
return hand.armiesPerCard === null ? Infinity : hand.cards * hand.armiesPerCard;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The tripwires running on `turn`: the marks kept, and one from each observation on my latest two
|
|
33
|
+
* boards that this turn's estimates (or the ones kept for the turns it reads) cannot explain. None while
|
|
34
|
+
* the teams are unknown (`teamsKnown: false`: a game of 3+ seats whose teams could not be read, where an
|
|
35
|
+
* opponent may be a teammate), and no observation once an opponent may hold an Airlift card (the card
|
|
36
|
+
* clock); no capture or held attack once one may hold a Bomb, no held attack once anyone may have held a
|
|
37
|
+
* Diplomacy card on the previous turn, and each allows the Reinforcement cards one
|
|
38
|
+
* may have banked (`bankedReinforcement`). A static seat (#270) and a player with no
|
|
39
|
+
* estimate this turn or kept are never read. While the teams are unknown the stored marks are kept unchanged (`keep`), never applied. Never throws.
|
|
40
|
+
*/
|
|
41
|
+
export async function readTripwires(a) {
|
|
42
|
+
const estimatesNow = new Map(a.estimates.map((e) => [e.playerId, e.estimate]));
|
|
43
|
+
const survival = a.dataDir ? await readSurvival(a.dataDir, a.gameId, a.me) : { estimates: new Map(), tripwires: [] };
|
|
44
|
+
if (a.teamsKnown === false)
|
|
45
|
+
return { tripwires: [], estimatesNow, survival, keep: [...survival.tripwires] };
|
|
46
|
+
if (a.turn === null)
|
|
47
|
+
return { tripwires: [], estimatesNow, survival, keep: [] };
|
|
48
|
+
let fresh = [];
|
|
49
|
+
try {
|
|
50
|
+
// A start only when every player began alike (#275 review): a custom scenario sets each start by
|
|
51
|
+
// hand, and unread distribution may be one, so the settings' territory limit × armies says nothing
|
|
52
|
+
// of what a stack never seen began with — no start, and such a stack is not read.
|
|
53
|
+
const banked = bankedReinforcement(a.gameSettings, a.turn);
|
|
54
|
+
const start = symmetricStart(a.gameSettings) ? trackGame([], a.gameSettings, a.map).start : undefined;
|
|
55
|
+
// Who else may play a card (a Gift of a territory with its stack): every player with an estimate, on a
|
|
56
|
+
// team or owning a territory on a board, me included, a static seat (#270) aside.
|
|
57
|
+
const players = new Set([a.me, ...estimatesNow.keys(), ...(a.teams?.keys() ?? [])]);
|
|
58
|
+
for (const b of a.boards)
|
|
59
|
+
for (const t of b.board.territories)
|
|
60
|
+
if (t.owner.kind === 'player')
|
|
61
|
+
players.add(t.owner.playerId);
|
|
62
|
+
for (const q of a.staticSeats?.keys() ?? [])
|
|
63
|
+
players.delete(q);
|
|
64
|
+
fresh = brokenEstimates({
|
|
65
|
+
...(start ? { start } : {}),
|
|
66
|
+
graph: a.graph,
|
|
67
|
+
boards: a.boards,
|
|
68
|
+
me: a.me,
|
|
69
|
+
settings: a.settings,
|
|
70
|
+
...(a.teams ? { teams: a.teams } : {}),
|
|
71
|
+
...(a.peace ? { peace: new Set(a.peace) } : {}),
|
|
72
|
+
...(opponentCanHold(a.gameSettings, 'Airlift', a.turn) ? { airlift: true } : {}),
|
|
73
|
+
...(opponentCanHold(a.gameSettings, 'Bomb', a.turn) ? { bomb: true } : {}),
|
|
74
|
+
// A Diplomacy card in force on the turn my attack ran may have worn off since: the cards in effect
|
|
75
|
+
// now (`peace`) do not say. Any player may hold one by then: no held attack is read.
|
|
76
|
+
...(opponentCanHold(a.gameSettings, 'Diplomacy', a.turn - 1) ? { diplomacy: true } : {}),
|
|
77
|
+
...(banked > 0 ? { banked } : {}),
|
|
78
|
+
...(a.staticSeats?.size ? { staticSeats: a.staticSeats } : {}),
|
|
79
|
+
// The estimate the plan of that turn used when kept, else a stand-in: the most it was kept at or is
|
|
80
|
+
// now (#275 review: today's figure alone under-counts an opponent whose estimate a bonus break has
|
|
81
|
+
// lowered since). None for a player with no estimate now (a static seat is neutralized, #270): it is
|
|
82
|
+
// not read. The stock bound reads only kept figures (`estimateKept`).
|
|
83
|
+
estimateAt: (p, t) => {
|
|
84
|
+
const now = estimatesNow.get(p);
|
|
85
|
+
if (now === undefined)
|
|
86
|
+
return undefined;
|
|
87
|
+
const kept = survival.estimates.get(t)?.get(p);
|
|
88
|
+
if (kept !== undefined)
|
|
89
|
+
return kept;
|
|
90
|
+
let most = now;
|
|
91
|
+
for (const row of survival.estimates.values())
|
|
92
|
+
most = Math.max(most, row.get(p) ?? 0);
|
|
93
|
+
return most;
|
|
94
|
+
},
|
|
95
|
+
estimateKept: (p, t) => survival.estimates.get(t)?.has(p) === true,
|
|
96
|
+
// My Gift of a territory is no capture; with my card plays unrecorded, captures of mine are unknown.
|
|
97
|
+
...(!a.gameSettings || a.gameSettings.cards.includes('Gift') ? { gift: true, players: [...players].sort((x, y) => x - y) } : {}),
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
// A board this reader cannot follow: no observation.
|
|
102
|
+
}
|
|
103
|
+
const tripwires = activeTripwires(survival.tripwires, fresh, a.turn);
|
|
104
|
+
return { tripwires, estimatesNow, survival, keep: tripwires };
|
|
105
|
+
}
|
|
106
|
+
/** Keep this turn's estimates and the marks `read.keep` names (warapp_plan_turn only). Never throws. */
|
|
107
|
+
export async function keepTripwires(dataDir, gameId, me, turn, read) {
|
|
108
|
+
if (!dataDir || turn === null)
|
|
109
|
+
return;
|
|
110
|
+
await writeSurvival(dataDir, gameId, me, turn, { estimates: read.estimatesNow, tripwires: read.keep });
|
|
111
|
+
}
|
|
112
|
+
/** What an untrusted opponent is sized for: the larger of what tripped it and my own income. */
|
|
113
|
+
export const untrustedDeploy = (w, myIncome) => Math.max(w.implied, Math.max(0, Math.floor(myIncome)));
|
|
114
|
+
const KIND_TEXT = {
|
|
115
|
+
'fog-stack': 'a stack out of the fog',
|
|
116
|
+
capture: 'a capture',
|
|
117
|
+
'held-attack': 'an attack of yours it held',
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* One warning per untrusted opponent, by id (the first warning of the answer). `sizedFor` is the figure
|
|
121
|
+
* the plan or the stress test used for it (`untrustedDeploy` on the income they used), so the warning
|
|
122
|
+
* never names another. `whatIf` is the caller's `enemy_deploy`: the planner then ignores the mark, and
|
|
123
|
+
* the warning names that figure instead.
|
|
124
|
+
*/
|
|
125
|
+
export function tripwireWarnings(tripwires, sizedFor, estimateOf, whatIf) {
|
|
126
|
+
return tripwires.map((w) => {
|
|
127
|
+
const est = estimateOf(w.player);
|
|
128
|
+
return (`Player ${w.player}'s deploy estimate${est !== undefined ? ` (${est})` : ''} is untrusted until turn ${w.until} (#275): on turn ${w.since} ` +
|
|
129
|
+
`${KIND_TEXT[w.kind]} on territory ${w.territory} needed ${w.observed} armies where the estimate allowed ${w.allowed}, ` +
|
|
130
|
+
`about ${w.implied} a turn. ` +
|
|
131
|
+
(whatIf !== undefined
|
|
132
|
+
? `This what-if plan sizes every border for enemy_deploy ${whatIf} instead; without it, borders of your held ` +
|
|
133
|
+
`bonuses facing it would be sized for ${sizedFor(w)} (the larger of that and your own income).`
|
|
134
|
+
: `Borders of your held bonuses facing it are sized for ${sizedFor(w)} ` +
|
|
135
|
+
'(the larger of that and your own income), and warapp_check_plan tries that deploy by default.'));
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
/** The headroom table on these orders, never throwing (an empty table when the board cannot be carried out). */
|
|
139
|
+
export function safeHeadroom(input) {
|
|
140
|
+
try {
|
|
141
|
+
return headroomTable(input);
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return [];
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* The headroom table as the tools show it: names beside ids, each row with whether it is below my income.
|
|
149
|
+
* `mayBeTeammate` (the teams unknown, `resolveTeams`' `known: false`): every row says its opponent may be a teammate.
|
|
150
|
+
*/
|
|
151
|
+
export function headroomView(rows, map, myIncome, full, mayBeTeammate = false) {
|
|
152
|
+
const name = namer(map);
|
|
153
|
+
const bonusName = new Map(map.bonuses.map((b) => [b.id, b.name]));
|
|
154
|
+
return rows.slice(0, full ? rows.length : HEADROOM_COMPACT).map((r) => ({
|
|
155
|
+
territory: name(r.territory),
|
|
156
|
+
armies: r.armies,
|
|
157
|
+
deploy: r.deploy,
|
|
158
|
+
opponent: r.opponent,
|
|
159
|
+
from: name(r.from),
|
|
160
|
+
...(r.firstMover ? { needsFirstMove: r.firstMover === 'me' ? 'you' : 'opponent' } : {}),
|
|
161
|
+
belowMyIncome: r.deploy !== null && r.deploy < myIncome,
|
|
162
|
+
bonuses: r.bonuses.map((b) => ({ id: b.id, name: bonusName.get(b.id) ?? String(b.id), value: b.value })),
|
|
163
|
+
behind: r.behind.map(name),
|
|
164
|
+
behindIncome: r.behindIncome,
|
|
165
|
+
breach: { territories: r.breach.territories.map(name), income: r.breach.income },
|
|
166
|
+
...(mayBeTeammate ? { mayBeTeammate: true } : {}),
|
|
167
|
+
}));
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* #275 (c): a warning for each border of a held bonus that falls to a single deploy below my own income,
|
|
171
|
+
* by id. A warning, never a refusal. `mayBeTeammate`: the teams are unknown, and the warning says so.
|
|
172
|
+
*/
|
|
173
|
+
export function headroomWarnings(rows, myIncome, mayBeTeammate = false) {
|
|
174
|
+
return rows
|
|
175
|
+
.filter((r) => r.bonuses.length > 0 && r.deploy !== null && r.deploy < myIncome)
|
|
176
|
+
.map((r) => `Territory ${r.territory} guards bonus${r.bonuses.length === 1 ? '' : 'es'} ${r.bonuses.map((b) => `${b.id} (+${b.value})`).join(', ')} ` +
|
|
177
|
+
`and these orders leave it falling to a deploy of ${r.deploy} by player ${r.opponent}` +
|
|
178
|
+
`${mayBeTeammate ? " (may be a teammate: this game's teams could not be read)" : ''} on territory ${r.from}` +
|
|
179
|
+
`${r.firstMover ? ` (when ${r.firstMover === 'me' ? 'you move' : 'it moves'} first)` : ''}: below your own income of ${myIncome} (#275 headroom). ` +
|
|
180
|
+
'An estimate is a floor; consider more armies there.');
|
|
181
|
+
}
|
|
182
|
+
/** The opponents' teams for the tripwire and the headroom table, from the players' team fields. */
|
|
183
|
+
export function teamsOf(players) {
|
|
184
|
+
const m = new Map();
|
|
185
|
+
for (const p of players)
|
|
186
|
+
if (carriesTeam(p.team))
|
|
187
|
+
m.set(p.id, p.team);
|
|
188
|
+
return m.size ? m : undefined;
|
|
189
|
+
}
|