@chrischall/warapp-mcp 0.23.2 → 0.25.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 +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/dist/analysis/calibrate.js +54 -0
- package/dist/analysis/cards-in-effect.js +19 -3
- package/dist/analysis/coalition.js +6 -3
- package/dist/analysis/commitments.js +257 -40
- package/dist/analysis/pacts.js +285 -0
- package/dist/analysis/relations.js +10 -0
- package/dist/analysis/stress.js +8 -3
- package/dist/bundle.js +1478 -268
- package/dist/chat.js +73 -0
- package/dist/mod-alliances.js +14 -0
- package/dist/protocol/codec.js +4 -0
- package/dist/protocol/methods.js +29 -3
- package/dist/relations-store.js +83 -18
- package/dist/tools/calibration-harness.js +22 -6
- package/dist/tools/chat-advice.js +2 -2
- package/dist/tools/chat.js +419 -36
- package/dist/tools/check-plan.js +14 -4
- package/dist/tools/commitments.js +40 -8
- package/dist/tools/diplomacy.js +37 -5
- package/dist/tools/mod-alliances.js +13 -1
- package/dist/tools/relations.js +411 -33
- package/dist/tools/turn.js +53 -13
- package/dist/tools/uncommit.js +6 -6
- package/dist/version.js +1 -1
- package/manifest.json +1 -1
- package/package.json +1 -1
- package/server.json +2 -2
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
},
|
|
8
8
|
"metadata": {
|
|
9
9
|
"description": "MCP server for war.app (Warzone) — your games, players, settings, map bonuses and chokepoints, board analysis and route planning through war.app's per-player GameFeed API, plus the live board, territory picks, cards, turn planning and submission, turn notifications and game chat through your signed-in war.app tab (creating, joining, leaving or surrendering a game, accepting game invitations, closing out a finished game, accepting another player's surrender, a team surrender, a vote to end a game, booting a stalled player, Begin on a speed first turn, picks, turn orders, withdrawing them, chat sends, nudging a player, joining or leaving a ladder, answering a clan invite, joining or leaving a clan, changing quickmatch settings, voting on quickmatch templates, joining or declining a tournament, showing a tournament among your favourites, mail (new threads, replies, adding players, deleting threads), forum posts (new threads, replies, votes, watching a thread), chat reactions, marking notifications and chat read, deleting notifications, importing local history and linking a session are confirm-gated).",
|
|
10
|
-
"version": "0.
|
|
10
|
+
"version": "0.25.0"
|
|
11
11
|
},
|
|
12
12
|
"plugins": [
|
|
13
13
|
{
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"displayName": "war.app (Warzone)",
|
|
16
16
|
"source": "./",
|
|
17
17
|
"description": "war.app (Warzone) game advisor for Claude — games, maps, bonuses, routes, live board, picks, turns, cards and chat",
|
|
18
|
-
"version": "0.
|
|
18
|
+
"version": "0.25.0",
|
|
19
19
|
"author": {
|
|
20
20
|
"name": "Chris Hall"
|
|
21
21
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "warapp-mcp",
|
|
3
3
|
"displayName": "war.app (Warzone)",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.25.0",
|
|
5
5
|
"description": "war.app (Warzone) game advisor for Claude — games, maps, bonuses, routes, live board, picks, turns, cards and chat",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Chris Hall",
|
|
@@ -296,6 +296,60 @@ export function openingFlags(input) {
|
|
|
296
296
|
const bt = input.booted?.turn ?? null;
|
|
297
297
|
return { noOrderTurns, bootedTurn: bt !== null && bt >= 1 && bt <= window ? bt : null };
|
|
298
298
|
}
|
|
299
|
+
/**
|
|
300
|
+
* #506: the territories `player` held on history board N − 1 and another player (not a neutral, not one of
|
|
301
|
+
* `allies`) held on board N, for N in 1..`window` — land taken from it in the opening. A turn the history lacks
|
|
302
|
+
* is not read. Pure.
|
|
303
|
+
*/
|
|
304
|
+
export function openingLosses(input) {
|
|
305
|
+
const window = input.window ?? OPENING_WINDOW;
|
|
306
|
+
const boards = new Map(input.history.map((b) => [b.turn, b.board]));
|
|
307
|
+
const friends = new Set([input.player, ...(input.allies ?? [])]);
|
|
308
|
+
let territories = 0;
|
|
309
|
+
const turns = [];
|
|
310
|
+
for (let n = 1; n <= window; n++) {
|
|
311
|
+
const before = boards.get(n - 1);
|
|
312
|
+
const after = boards.get(n);
|
|
313
|
+
if (!before || !after)
|
|
314
|
+
continue;
|
|
315
|
+
const had = landOf(before, input.player);
|
|
316
|
+
let lost = 0;
|
|
317
|
+
for (const t of after.territories)
|
|
318
|
+
if (had.has(t.territoryId) && t.owner.kind === 'player' && !friends.has(t.owner.playerId))
|
|
319
|
+
lost++;
|
|
320
|
+
if (lost) {
|
|
321
|
+
territories += lost;
|
|
322
|
+
turns.push(n);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return { territories, turns };
|
|
326
|
+
}
|
|
327
|
+
function lossAggregate(entries) {
|
|
328
|
+
const won = entries.filter((e) => e.winner !== null);
|
|
329
|
+
return {
|
|
330
|
+
games: entries.length,
|
|
331
|
+
withWinner: won.length,
|
|
332
|
+
iWon: entries.filter((e) => e.iWon).length,
|
|
333
|
+
iLost: entries.filter((e) => e.mine.territories > 0).length,
|
|
334
|
+
winnerLost: won.filter((e) => e.winner.territories > 0).length,
|
|
335
|
+
myTerritories: entries.reduce((n, e) => n + e.mine.territories, 0),
|
|
336
|
+
winnerTerritories: won.reduce((n, e) => n + e.winner.territories, 0),
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
/** #506: the opening losses by era, then format. Pure. */
|
|
340
|
+
export function earlyLossesByEra(entries) {
|
|
341
|
+
const out = {};
|
|
342
|
+
for (const era of ['pre-tool', 'pre-rule-4f', 'current']) {
|
|
343
|
+
const of = entries.filter((e) => e.era === era);
|
|
344
|
+
if (!of.length)
|
|
345
|
+
continue;
|
|
346
|
+
const byFormat = {};
|
|
347
|
+
for (const f of [...new Set(of.map((e) => e.format))].sort())
|
|
348
|
+
byFormat[f] = lossAggregate(of.filter((e) => e.format === f));
|
|
349
|
+
out[era] = { all: lossAggregate(of), byFormat };
|
|
350
|
+
}
|
|
351
|
+
return out;
|
|
352
|
+
}
|
|
299
353
|
/** A map this many times the median map's territories or more is counted as large. */
|
|
300
354
|
export const LARGE_MAP_FACTOR = 5;
|
|
301
355
|
/** The benchmarks grouped by era, then format; flagged games apart; how many eras were read from which basis. Pure. */
|
|
@@ -87,7 +87,8 @@ function timingDoubt(card, turn, duration, name) {
|
|
|
87
87
|
const playing = (p) => (p.state ?? 'Playing') === 'Playing';
|
|
88
88
|
/**
|
|
89
89
|
* PLAN-TEAMS D3: which decoded active cards the planner may rely on. Only a Diplomacy that names me
|
|
90
|
-
* and Sanctions on me are reasoned about in `unsure`;
|
|
90
|
+
* and Sanctions on me are reasoned about in `unsure`; a Diplomacy between two other players is kept, when
|
|
91
|
+
* sure, in `diplomacyOthers` (#680, report only) and is otherwise left out.
|
|
91
92
|
*/
|
|
92
93
|
export function cardsInEffect(input) {
|
|
93
94
|
const { players, me, turn, settings } = input;
|
|
@@ -95,6 +96,7 @@ export function cardsInEffect(input) {
|
|
|
95
96
|
const myInGame = mine?.[0];
|
|
96
97
|
const myTeam = mine && carriesTeam(mine[1].team) ? mine[1].team : undefined;
|
|
97
98
|
const diplomacy = new Map();
|
|
99
|
+
const others = new Map();
|
|
98
100
|
const sanctionsOnMe = [];
|
|
99
101
|
const sanctionsOnOthers = [];
|
|
100
102
|
const unsure = [];
|
|
@@ -103,10 +105,23 @@ export function cardsInEffect(input) {
|
|
|
103
105
|
for (const a of input.active) {
|
|
104
106
|
if (a.card === 'Diplomacy' && a.players) {
|
|
105
107
|
const [x, y] = a.players;
|
|
106
|
-
if (myInGame === undefined || (x !== myInGame && y !== myInGame))
|
|
107
|
-
continue;
|
|
108
108
|
if (x === y)
|
|
109
109
|
continue;
|
|
110
|
+
if (myInGame !== undefined && x !== myInGame && y !== myInGame) {
|
|
111
|
+
// #680: a card between two other players is a pact between them, kept only when sure; never in `unsure`.
|
|
112
|
+
const [px, py] = [players.get(x), players.get(y)];
|
|
113
|
+
if (!settings?.cards.includes('Diplomacy') || !px || !py || px.id === py.id || !playing(px) || !playing(py))
|
|
114
|
+
continue;
|
|
115
|
+
if (timingDoubt(a, turn, durationOf(dipSettings), 'Diplomacy'))
|
|
116
|
+
continue;
|
|
117
|
+
const pair = [px.id, py.id].sort((p, q) => p - q);
|
|
118
|
+
const was = others.get(pair.join(','));
|
|
119
|
+
if (!was || a.untilTurn > was.untilTurn)
|
|
120
|
+
others.set(pair.join(','), { players: pair, untilTurn: a.untilTurn });
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (myInGame === undefined)
|
|
124
|
+
continue;
|
|
110
125
|
const otherIn = x === myInGame ? y : x;
|
|
111
126
|
const other = players.get(otherIn);
|
|
112
127
|
const label = `Diplomacy with player ${other?.id ?? `(in-game ${otherIn})`}`;
|
|
@@ -155,5 +170,6 @@ export function cardsInEffect(input) {
|
|
|
155
170
|
sanctionsOnMe,
|
|
156
171
|
sanctionsOnOthers,
|
|
157
172
|
unsure,
|
|
173
|
+
...(others.size ? { diplomacyOthers: [...others.values()].sort((p, q) => p.players[0] - q.players[0] || p.players[1] - q.players[1]) } : {}),
|
|
158
174
|
};
|
|
159
175
|
}
|
|
@@ -11,9 +11,10 @@
|
|
|
11
11
|
// - and the leader's income lead over me has not grown since the line was crossed.
|
|
12
12
|
// Otherwise the surrender advice returns. A viable partner borders the leader, is not at war with me (no truce
|
|
13
13
|
// broken in this game, no attack declared on it) and is not ruled out by the cross-game record (a truce broken
|
|
14
|
-
// against me in any game, owner decision 2026-11-22)
|
|
15
|
-
//
|
|
16
|
-
//
|
|
14
|
+
// against me in any game, owner decision 2026-11-22), and is not at peace with the leader by a pact I am not in
|
|
15
|
+
// (#680: a reported pact, a Diplomacy card or a Diplomacy 2 alliance between them). Every viable partner is
|
|
16
|
+
// ranked — by the largest leader bonus it borders, then its income, then id — and the top
|
|
17
|
+
// {@link OUTREACH_DRAFTS} get a #415 `propose` draft naming the leader's bonus we could break together, priced as warapp_advise_diplomacy counts a bonus (its
|
|
17
18
|
// value a turn, and the visible defenders on the weak member). Drafts are never sent here: with
|
|
18
19
|
// WARAPP_CHAT_AUTOMATION on a draft carries `send` (warapp_send_chat's arguments, `automated: true`), and every
|
|
19
20
|
// send still goes through warapp_send_chat's confirm gate.
|
|
@@ -99,6 +100,8 @@ export function coalitionAdvice(input) {
|
|
|
99
100
|
leftOut.push({ playerId: o.playerId, reason: 'broke-a-truce' });
|
|
100
101
|
else if (input.atWar?.has(o.playerId))
|
|
101
102
|
leftOut.push({ playerId: o.playerId, reason: 'at-war' });
|
|
103
|
+
else if (input.atPeace?.has(o.playerId))
|
|
104
|
+
leftOut.push({ playerId: o.playerId, reason: 'at-peace-with-leader' });
|
|
102
105
|
else if (!input.bordersLeader.has(o.playerId))
|
|
103
106
|
leftOut.push({ playerId: o.playerId, reason: 'not-bordering-leader' });
|
|
104
107
|
else
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ownerShown } from './plan/shared.js';
|
|
2
2
|
import { bonusTerritories } from './bonuses.js';
|
|
3
|
-
import {
|
|
3
|
+
import { isPact, noticeEnds, pactState, partiesOf } from './pacts.js';
|
|
4
|
+
import { agreementState, coveredTerritories, MAX_PARTIES, newAgreement, partyRefusal, scopeRefusal, TERMINAL_STATUSES, transitionAgreement, } from './relations.js';
|
|
4
5
|
/** Every commitment kind a message may declare. */
|
|
5
6
|
export const COMMITMENT_KINDS = ['no-attack', 'will-attack', 'notice', 'propose', 'accept'];
|
|
6
7
|
/** The most turns a `no-attack` promise may run. */
|
|
@@ -9,21 +10,29 @@ export const MAX_NO_ATTACK_TURNS = 10;
|
|
|
9
10
|
export const MAX_MESSAGE_COMMITMENTS = 10;
|
|
10
11
|
/**
|
|
11
12
|
* Why a propose, accept or notice with `partner` cannot go to `audience`: the partner would never read
|
|
12
|
-
* it. `undefined` when it reads it (the private recipient,
|
|
13
|
-
* team the message goes to).
|
|
13
|
+
* it. `undefined` when it reads it (the private recipient, a member of the game group, anyone on the public
|
|
14
|
+
* channel, a player on the team the message goes to).
|
|
14
15
|
*/
|
|
15
|
-
export function audienceRefusal(audience, partner, players) {
|
|
16
|
+
export function audienceRefusal(audience, partner, players, role = "the truce's partner") {
|
|
17
|
+
const d3 = role === "the truce's partner" ? 'D3: a truce changes only with the partner told' : 'D3: a truce changes only with every party told';
|
|
16
18
|
if (audience.kind === 'public')
|
|
17
19
|
return undefined;
|
|
18
20
|
if (audience.kind === 'private')
|
|
19
|
-
return audience.to === partner
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
return audience.to === partner ? undefined : `the message goes privately to player ${audience.to}, so player ${partner}, ${role}, would never read it (${d3})`;
|
|
22
|
+
if (audience.kind === 'group') {
|
|
23
|
+
return audience.to.includes(partner) ? undefined : `the message goes to a group of players ${listIds(audience.to)}, so player ${partner}, ${role}, would never read it (${d3})`;
|
|
24
|
+
}
|
|
22
25
|
const p = players.find((x) => x.id === partner);
|
|
23
|
-
return p?.team === audience.team
|
|
24
|
-
? undefined
|
|
25
|
-
: `the message goes to team ${audience.team} only, and player ${partner}, the truce's partner, is not on it: it would never read it (D3: a truce changes only with the partner told)`;
|
|
26
|
+
return p?.team === audience.team ? undefined : `the message goes to team ${audience.team} only, and player ${partner}, ${role}, is not on it: it would never read it (${d3})`;
|
|
26
27
|
}
|
|
28
|
+
/** Ids as a sentence lists them: `1`, `1 and 2`, `1, 2 and 3`. */
|
|
29
|
+
const listIds = (ids) => (ids.length > 1 ? `${ids.slice(0, -1).join(', ')} and ${ids.at(-1)}` : String(ids[0]));
|
|
30
|
+
/** #685: the parties of `a` other than me, ascending: a pact's, else its partner. */
|
|
31
|
+
const partnersOf = (a, me) => (isPact(a) ? partiesOf(a, me).filter((p) => p !== me) : [a.with]);
|
|
32
|
+
/** #685: how a sentence names `a`: `pact p1 with players 20 and 30`, or `agreement a1 with player 20`. */
|
|
33
|
+
const agreementName = (a, me) => (isPact(a) ? `pact ${a.id} with players ${listIds(partnersOf(a, me))}` : `agreement ${a.id} with player ${a.with}`);
|
|
34
|
+
/** #685: `p<n>` one above the highest pact id. */
|
|
35
|
+
export const defaultNextPactId = (pacts) => `p${pacts.reduce((m, a) => Math.max(m, Number(/^p(\d+)$/.exec(a.id)?.[1] ?? 0)), 0) + 1}`;
|
|
27
36
|
const ownerOf = (board, t) => {
|
|
28
37
|
const s = board.territories.find((x) => x.territoryId === t);
|
|
29
38
|
return s && ownerShown(s) && s.owner.kind === 'player' ? s.owner.playerId : null;
|
|
@@ -57,21 +66,101 @@ const fullTerms = (t) => ({ ...t, scope: t.scope ?? 'all', noticeTurns: t.notice
|
|
|
57
66
|
/** A truce whose last turn has passed is over before it begins. */
|
|
58
67
|
const pastUntil = (t, turn) => t.untilTurn !== undefined && t.untilTurn < turn ? `the truce would bind only until turn ${t.untilTurn}, before this turn (${turn})` : undefined;
|
|
59
68
|
const openWith = (agreements, p) => agreements.find((a) => a.with === p && !TERMINAL_STATUSES.has(a.status));
|
|
69
|
+
/** #685: a pact not ended that binds me and `p` (mine while my own notice has not run). */
|
|
70
|
+
function pactBinding(o, p, except) {
|
|
71
|
+
return (o.pacts ?? []).find((a) => {
|
|
72
|
+
if (a.id === except || TERMINAL_STATUSES.has(a.status) || !a.parties?.includes(o.me) || !a.parties.includes(p))
|
|
73
|
+
return false;
|
|
74
|
+
if (!o.players)
|
|
75
|
+
return true;
|
|
76
|
+
const st = pactState(a, o.turn, o.players, o.me);
|
|
77
|
+
return st.phase !== 'over' && st.includesMe && st.remaining.includes(p);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/** #685: why the other parties `ids` named for a new pact with me cannot be (me, twice, too few or many, not a party). */
|
|
81
|
+
function pactPartiesRefusal(ids, o) {
|
|
82
|
+
if (ids.includes(o.me))
|
|
83
|
+
return 'you are a party already: name the other players only';
|
|
84
|
+
const twice = ids.find((id, i) => ids.indexOf(id) !== i);
|
|
85
|
+
if (twice !== undefined)
|
|
86
|
+
return `player ${twice} is named twice`;
|
|
87
|
+
if (ids.length < 2)
|
|
88
|
+
return 'a pact names two or more other players: a truce with one is a propose or accept with `player`';
|
|
89
|
+
if (ids.length + 1 > MAX_PARTIES)
|
|
90
|
+
return `a pact has at most ${MAX_PARTIES} parties, you included`;
|
|
91
|
+
if (o.players)
|
|
92
|
+
for (const p of [...ids].sort((x, y) => x - y)) {
|
|
93
|
+
const why = partyRefusal(o.players, o.me, p);
|
|
94
|
+
if (why)
|
|
95
|
+
return why;
|
|
96
|
+
}
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
/** #685: why a party of a new pact is bound to me already: an open two-party truce, or another pact. */
|
|
100
|
+
function alreadyBound(ids, o, except) {
|
|
101
|
+
for (const p of [...ids].sort((x, y) => x - y)) {
|
|
102
|
+
const open = openWith(o.agreements, p);
|
|
103
|
+
if (open)
|
|
104
|
+
return `agreement ${open.id} with player ${p} is still ${open.status}: end it before a pact with player ${p}`;
|
|
105
|
+
const pact = pactBinding(o, p, except);
|
|
106
|
+
if (pact)
|
|
107
|
+
return `pact ${pact.id} already binds you and player ${p}: end it first`;
|
|
108
|
+
}
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
const samePartiesPact = (o, parties) => (o.pacts ?? []).find((a) => !TERMINAL_STATUSES.has(a.status) && a.parties?.length === parties.length && a.parties.every((p, i) => p === parties[i]));
|
|
60
112
|
/**
|
|
61
|
-
* The agreement change a `propose`, `accept` or `notice` makes to `agreements` on `turn`, or
|
|
62
|
-
* cannot. Shared by the check (`checkCommitments`) and the write once the message is sent, so both
|
|
113
|
+
* The agreement change a `propose`, `accept` or `notice` makes to `agreements` (or, #685, to `pacts`) on `turn`, or
|
|
114
|
+
* why it cannot. Shared by the check (`checkCommitments`) and the write once the message is sent, so both
|
|
63
115
|
* apply the same rule to the ledger as it then stands. `players` is checked for a new commitment
|
|
64
|
-
* (`partyRefusal`) only when given.
|
|
116
|
+
* (`partyRefusal`) only when given. The change's agreement is a pact (`parties`) when the commitment is a pact's.
|
|
65
117
|
*/
|
|
66
118
|
export function agreementChange(c, o) {
|
|
67
119
|
const { agreements, turn, me } = o;
|
|
120
|
+
const pacts = o.pacts ?? [];
|
|
68
121
|
const party = (p) => (o.players ? partyRefusal(o.players, me, p) : undefined);
|
|
69
122
|
const scopeBad = (t) => (o.graph ? scopeRefusal(o.graph, t.scope) : undefined);
|
|
70
123
|
const move = (a, status) => {
|
|
71
124
|
const r = transitionAgreement(a, status, turn);
|
|
72
125
|
return 'refused' in r ? r : { agreement: r.agreement, before: a, created: false };
|
|
73
126
|
};
|
|
127
|
+
const newPact = (ids, status, terms) => {
|
|
128
|
+
const others = [...ids].sort((x, y) => x - y);
|
|
129
|
+
const id = (o.nextPactId ?? defaultNextPactId)(pacts);
|
|
130
|
+
return {
|
|
131
|
+
agreement: { ...newAgreement(id, others[0], status, turn, terms), parties: [me, ...others].sort((x, y) => x - y), source: 'ledger' },
|
|
132
|
+
before: undefined,
|
|
133
|
+
created: true,
|
|
134
|
+
};
|
|
135
|
+
};
|
|
74
136
|
if (c.kind === 'notice') {
|
|
137
|
+
const p = pacts.find((x) => x.id === c.agreement);
|
|
138
|
+
if (p) {
|
|
139
|
+
if (!p.parties?.includes(me))
|
|
140
|
+
return { refused: `pact ${p.id} does not include you: there is no notice of yours to give` };
|
|
141
|
+
if (p.notices?.some((n) => n.player === me))
|
|
142
|
+
return { agreement: p, before: p, created: false };
|
|
143
|
+
if (p.status !== 'agreed')
|
|
144
|
+
return { refused: `pact ${p.id} is ${p.status}: notice is given on an agreed truce` };
|
|
145
|
+
const st = o.players ? pactState(p, turn, o.players, me) : undefined;
|
|
146
|
+
if (st && (st.phase === 'over' || !st.includesMe))
|
|
147
|
+
return { refused: `pact ${p.id} no longer binds you${st.reason ? ` (${st.reason})` : ''}: there is nothing to give notice on` };
|
|
148
|
+
const bound = st ? st.remaining.length : p.parties.length;
|
|
149
|
+
// The owner's decision: what becomes of the rest of a truce of three or more is never decided automatically.
|
|
150
|
+
if (c.rest === undefined && bound >= 3)
|
|
151
|
+
return {
|
|
152
|
+
refused: `notice on pact ${p.id} (${bound} parties still bound) needs \`rest\`: what becomes of the rest of the truce. Ask the owner, then ` +
|
|
153
|
+
'declare rest "continue" (you leave once your notice has run; the others stay bound) or "end" (the whole pact ends then)',
|
|
154
|
+
};
|
|
155
|
+
const notice = { player: me, turn, ...(c.rest !== undefined ? { rest: c.rest } : {}) };
|
|
156
|
+
return {
|
|
157
|
+
agreement: { ...p, notices: [...(p.notices ?? []), notice], history: [...p.history, { turn, status: 'notice-by-me', by: me }] },
|
|
158
|
+
before: p,
|
|
159
|
+
created: false,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
if (c.rest !== undefined)
|
|
163
|
+
return { refused: '`rest` applies only to a pact (an agreement "p<n>"): a two-party truce ends with its notice' };
|
|
75
164
|
const a = agreements.find((x) => x.id === c.agreement);
|
|
76
165
|
if (!a)
|
|
77
166
|
return { refused: `there is no agreement ${c.agreement} in the ledger` };
|
|
@@ -81,10 +170,33 @@ export function agreementChange(c, o) {
|
|
|
81
170
|
return { refused: `agreement ${a.id} is ${a.status}: notice is given on an agreed truce` };
|
|
82
171
|
return move(a, 'notice-by-me');
|
|
83
172
|
}
|
|
173
|
+
if (c.kind === 'propose' && c.players !== undefined) {
|
|
174
|
+
const why = pactPartiesRefusal(c.players, o) ?? scopeBad(c.terms) ?? pastUntil(c.terms, turn);
|
|
175
|
+
if (why)
|
|
176
|
+
return { refused: why };
|
|
177
|
+
const parties = [me, ...c.players].sort((x, y) => x - y);
|
|
178
|
+
const same = samePartiesPact(o, parties);
|
|
179
|
+
if (same) {
|
|
180
|
+
if (same.status !== 'proposed-by-me' && same.status !== 'proposed-by-them')
|
|
181
|
+
return { refused: `${agreementName(same, me)} is already ${same.status}: end it before proposing new terms` };
|
|
182
|
+
const withTerms = { ...same, terms: c.terms };
|
|
183
|
+
if (same.status === 'proposed-by-me')
|
|
184
|
+
return { agreement: withTerms, before: same, created: false };
|
|
185
|
+
const r = transitionAgreement(withTerms, 'proposed-by-me', turn);
|
|
186
|
+
return 'refused' in r ? r : { agreement: r.agreement, before: same, created: false };
|
|
187
|
+
}
|
|
188
|
+
const bound = alreadyBound(c.players, o);
|
|
189
|
+
if (bound)
|
|
190
|
+
return { refused: bound };
|
|
191
|
+
return newPact(c.players, 'proposed-by-me', c.terms);
|
|
192
|
+
}
|
|
84
193
|
if (c.kind === 'propose') {
|
|
85
194
|
const why = party(c.with) ?? scopeBad(c.terms) ?? pastUntil(c.terms, turn);
|
|
86
195
|
if (why)
|
|
87
196
|
return { refused: why };
|
|
197
|
+
const pact = pactBinding(o, c.with);
|
|
198
|
+
if (pact)
|
|
199
|
+
return { refused: `pact ${pact.id} already binds you and player ${c.with}: end it first` };
|
|
88
200
|
const open = openWith(agreements, c.with);
|
|
89
201
|
if (!open)
|
|
90
202
|
return { agreement: newAgreement(o.nextAgreementId(agreements), c.with, 'proposed-by-me', turn, c.terms), before: undefined, created: true };
|
|
@@ -97,6 +209,8 @@ export function agreementChange(c, o) {
|
|
|
97
209
|
return 'refused' in r ? r : { agreement: r.agreement, before: open, created: false };
|
|
98
210
|
}
|
|
99
211
|
// accept
|
|
212
|
+
if (c.players !== undefined || (c.agreement !== undefined && pacts.some((x) => x.id === c.agreement)))
|
|
213
|
+
return acceptPact(c, o, move, newPact);
|
|
100
214
|
let target;
|
|
101
215
|
if (c.agreement !== undefined) {
|
|
102
216
|
target = agreements.find((x) => x.id === c.agreement);
|
|
@@ -131,8 +245,62 @@ export function agreementChange(c, o) {
|
|
|
131
245
|
const why = party(c.with) ?? scopeBad(terms) ?? pastUntil(terms, turn);
|
|
132
246
|
if (why)
|
|
133
247
|
return { refused: why };
|
|
248
|
+
const pact = pactBinding(o, c.with);
|
|
249
|
+
if (pact)
|
|
250
|
+
return { refused: `pact ${pact.id} already binds you and player ${c.with}: end it first` };
|
|
134
251
|
return { agreement: newAgreement(o.nextAgreementId(agreements), c.with, 'agreed', turn, terms), before: undefined, created: true };
|
|
135
252
|
}
|
|
253
|
+
/** #685: an accept of a pact: a recorded pact proposal (by id or by its other parties), or offered terms as a new agreed pact. */
|
|
254
|
+
function acceptPact(c, o, move, newPact) {
|
|
255
|
+
const { me, turn } = o;
|
|
256
|
+
let target;
|
|
257
|
+
if (c.agreement !== undefined) {
|
|
258
|
+
target = (o.pacts ?? []).find((x) => x.id === c.agreement);
|
|
259
|
+
// `players` beside an id that is no pact (a two-party truce, or none): refused, never read as one.
|
|
260
|
+
if (!target)
|
|
261
|
+
return { refused: `there is no pact ${c.agreement} in the ledger: an n-way accept names a pact "p<n>", or only \`players\`` };
|
|
262
|
+
if (!target.parties?.includes(me))
|
|
263
|
+
return { refused: `pact ${target.id} does not include you: there is nothing of yours to accept` };
|
|
264
|
+
const named = c.players !== undefined ? [...c.players].sort((x, y) => x - y) : c.with !== undefined ? [c.with] : undefined;
|
|
265
|
+
const partners = partnersOf(target, me);
|
|
266
|
+
if (named && (named.length !== partners.length || named.some((p, i) => p !== partners[i])))
|
|
267
|
+
return { refused: `pact ${target.id} is with players ${listIds(partners)}, not ${named.length === 1 ? 'player' : 'players'} ${listIds(named)}` };
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
const why = pactPartiesRefusal(c.players, o);
|
|
271
|
+
if (why)
|
|
272
|
+
return { refused: why };
|
|
273
|
+
const open = samePartiesPact(o, [me, ...c.players].sort((x, y) => x - y));
|
|
274
|
+
if (open && (open.status === 'proposed-by-me' || open.status === 'proposed-by-them'))
|
|
275
|
+
target = open;
|
|
276
|
+
else if (open)
|
|
277
|
+
return { refused: `${agreementName(open, me)} is already ${open.status}` };
|
|
278
|
+
}
|
|
279
|
+
if (target) {
|
|
280
|
+
if (target.status !== 'proposed-by-me' && target.status !== 'proposed-by-them')
|
|
281
|
+
return { refused: `pact ${target.id} is ${target.status}: only a proposal is accepted` };
|
|
282
|
+
if (c.terms && !sameGivenTerms(c.terms, target.terms))
|
|
283
|
+
return { refused: `the terms differ from pact ${target.id}'s: a counter-offer is a propose, not an accept` };
|
|
284
|
+
const partners = partnersOf(target, me);
|
|
285
|
+
for (const p of partners) {
|
|
286
|
+
const why = o.players ? partyRefusal(o.players, me, p) : undefined;
|
|
287
|
+
if (why)
|
|
288
|
+
return { refused: why };
|
|
289
|
+
}
|
|
290
|
+
const why = alreadyBound(partners, o, target.id) ?? pastUntil(target.terms, turn);
|
|
291
|
+
if (why)
|
|
292
|
+
return { refused: why };
|
|
293
|
+
return move(target, 'agreed');
|
|
294
|
+
}
|
|
295
|
+
const ids = [...c.players].sort((x, y) => x - y);
|
|
296
|
+
if (!c.terms)
|
|
297
|
+
return { refused: `no pact proposal from players ${listIds(ids)} is recorded: give the terms accepted` };
|
|
298
|
+
const terms = fullTerms(c.terms);
|
|
299
|
+
const why = (o.graph ? scopeRefusal(o.graph, terms.scope) : undefined) ?? pastUntil(terms, turn) ?? alreadyBound(ids, o);
|
|
300
|
+
if (why)
|
|
301
|
+
return { refused: why };
|
|
302
|
+
return newPact(ids, 'agreed', terms);
|
|
303
|
+
}
|
|
136
304
|
/**
|
|
137
305
|
* B4: each commitment checked against this turn's orders (`moves`: the plan made in the call, or the
|
|
138
306
|
* orders already submitted — `source` says which) and the ledger, in the message's order: a change an
|
|
@@ -143,6 +311,7 @@ export function agreementChange(c, o) {
|
|
|
143
311
|
export function checkCommitments(input) {
|
|
144
312
|
const { graph, board, me, turn, players, moves, source, audience } = input;
|
|
145
313
|
let agreements = [...input.agreements];
|
|
314
|
+
let pacts = [...(input.pacts ?? [])];
|
|
146
315
|
const orders = source === 'plan' ? 'planned' : 'submitted';
|
|
147
316
|
const named = (a) => `the ${orders} move ${a.index + 1} (${a.from} → ${a.to})`;
|
|
148
317
|
const checks = [];
|
|
@@ -217,63 +386,96 @@ export function checkCommitments(input) {
|
|
|
217
386
|
});
|
|
218
387
|
}
|
|
219
388
|
// notice, propose, accept: the ledger first, then the orders against what the agreement covers.
|
|
220
|
-
const change = agreementChange(c, { agreements, turn, me, players, graph, nextAgreementId: input.nextAgreementId });
|
|
389
|
+
const change = agreementChange(c, { agreements, pacts, turn, me, players, graph, nextAgreementId: input.nextAgreementId, nextPactId: input.nextPactId });
|
|
221
390
|
if ('refused' in change)
|
|
222
391
|
return out({ refused: change.refused });
|
|
223
392
|
const a = change.agreement;
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
393
|
+
const pactOne = isPact(a);
|
|
394
|
+
// #685: a pact binds every party: each must read the message, and no order may attack any party's covered land.
|
|
395
|
+
const partners = partnersOf(a, me);
|
|
396
|
+
for (const p of partners) {
|
|
397
|
+
const unread = audienceRefusal(audience, p, players, pactOne ? 'a party to the truce' : undefined);
|
|
398
|
+
if (unread)
|
|
399
|
+
return out({ refused: unread });
|
|
400
|
+
}
|
|
401
|
+
const covered = new Set(partners.flatMap((p) => coveredTerritories(graph, a.terms.scope, heldBy(board, p))));
|
|
228
402
|
const hit = attacksOn(moves, covered);
|
|
229
403
|
const fog = attacksOn(moves, unseenNamed(graph, board, a.terms.scope));
|
|
230
|
-
const
|
|
404
|
+
const whose = pactOne ? `a party's (players ${listIds(partners)})` : `player ${a.with}'s`;
|
|
405
|
+
const fogText = (what) => `${named(fog[0])} attacks territory ${fog[0].to}, which ${what} names and whose owner is not shown: it may be ${whose}`;
|
|
406
|
+
const name = agreementName(a, me);
|
|
407
|
+
const keep = () => {
|
|
408
|
+
if (pactOne)
|
|
409
|
+
pacts = [...pacts.filter((x) => x.id !== a.id), a];
|
|
410
|
+
else
|
|
411
|
+
agreements = [...agreements.filter((x) => x.id !== a.id), a];
|
|
412
|
+
};
|
|
413
|
+
const withParties = pactOne ? { parties: partners } : {};
|
|
231
414
|
if (c.kind === 'notice') {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
415
|
+
let endsNow;
|
|
416
|
+
let endsTurn;
|
|
417
|
+
let noticeTurn;
|
|
418
|
+
if (pactOne) {
|
|
419
|
+
// My own notice on a pact: it binds me until it has run (`noticeEnds`), whatever the rest choose.
|
|
420
|
+
const mine = a.notices?.find((n) => n.player === me);
|
|
421
|
+
noticeTurn = mine?.turn;
|
|
422
|
+
endsTurn = mine ? noticeEnds(a, mine) : undefined;
|
|
423
|
+
if (endsTurn !== undefined && endsTurn < turn)
|
|
424
|
+
return out({ refused: `your notice on pact ${a.id} has run (turn ${endsTurn}): there is nothing to give notice on` });
|
|
425
|
+
endsNow = endsTurn === turn && mine?.turn === turn;
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
const state = agreementState(a, turn, players);
|
|
429
|
+
// A truce with no notice (0 turns, an agreed term) ends with the message: notice served this turn
|
|
430
|
+
// has already run, so it binds no more from this turn and an attack this turn breaks nothing.
|
|
431
|
+
endsNow = a.status === 'notice-by-me' && a.noticeTurn === turn && state.phase === 'over' && state.reason === 'notice-served';
|
|
432
|
+
endsTurn = endsNow ? turn : state.endsTurn;
|
|
433
|
+
noticeTurn = a.noticeTurn;
|
|
434
|
+
if (endsTurn === undefined || (!endsNow && state.phase !== 'notice'))
|
|
435
|
+
return out({ refused: `agreement ${a.id} is over (${state.reason ?? state.phase}): there is nothing to give notice on` });
|
|
436
|
+
}
|
|
437
|
+
if (endsTurn === undefined)
|
|
438
|
+
return out({ refused: `pact ${a.id} carries no notice of yours` });
|
|
239
439
|
if (c.endsTurn !== undefined && c.endsTurn !== endsTurn)
|
|
240
440
|
return out({
|
|
241
|
-
refused:
|
|
441
|
+
refused: `${pactOne ? 'pact' : 'agreement'} ${a.id} carries ${a.terms.noticeTurns} turn${a.terms.noticeTurns === 1 ? '' : 's'} of notice: given on turn ${noticeTurn}, ` +
|
|
242
442
|
`it binds until turn ${endsTurn}, so the message cannot say it ends on turn ${c.endsTurn}` +
|
|
243
443
|
(c.endsTurn > endsTurn ? ` (the ledger frees its territories on turn ${endsTurn}: to keep the truce longer, propose new terms)` : ''),
|
|
244
444
|
});
|
|
245
|
-
const record = { sentTurn: turn, kind: 'notice', agreement: a.id, with: a.with, endsTurn };
|
|
445
|
+
const record = { sentTurn: turn, kind: 'notice', agreement: a.id, with: a.with, ...withParties, endsTurn };
|
|
446
|
+
const restSaid = pactOne && c.rest !== undefined ? (c.rest === 'end' ? '; the whole pact ends then (rest: end)' : '; the others stay bound (rest: continue)') : '';
|
|
246
447
|
if (endsNow) {
|
|
247
|
-
|
|
448
|
+
keep();
|
|
248
449
|
return out({
|
|
249
|
-
carried:
|
|
450
|
+
carried: `${name} carries no notice: ${pactOne ? 'you leave it' : 'it ends'} with this message, so it no longer binds ${pactOne ? 'you ' : ''}from this turn (${turn}) and an attack on its territories this turn breaks nothing${restSaid}`,
|
|
250
451
|
record,
|
|
251
452
|
change,
|
|
252
453
|
});
|
|
253
454
|
}
|
|
254
455
|
if (hit.length)
|
|
255
|
-
return out({ refused: `${named(hit[0])} attacks territory ${hit[0].to}, which agreement ${a.id} covers while its notice runs` });
|
|
456
|
+
return out({ refused: `${named(hit[0])} attacks territory ${hit[0].to}, which ${pactOne ? 'pact' : 'agreement'} ${a.id} covers while its notice runs` });
|
|
256
457
|
if (fog.length)
|
|
257
|
-
return out({ refused: fogText(
|
|
258
|
-
|
|
458
|
+
return out({ refused: fogText(`${pactOne ? 'pact' : 'agreement'} ${a.id}`) });
|
|
459
|
+
keep();
|
|
259
460
|
return out({
|
|
260
|
-
carried:
|
|
461
|
+
carried: `${name}: ${pactOne ? 'my ' : ''}notice from turn ${noticeTurn}, binding until turn ${endsTurn}${restSaid}, and no ${orders} order this turn attacks a territory it covers${unchecked(a.terms.scope)}`,
|
|
261
462
|
record,
|
|
262
463
|
change,
|
|
263
464
|
});
|
|
264
465
|
}
|
|
466
|
+
const what = `the ${c.kind === 'propose' ? 'proposed' : 'accepted'} truce`;
|
|
265
467
|
if (hit.length)
|
|
266
|
-
return out({ refused: `${named(hit[0])} attacks player ${a.with}'s territory ${hit[0].to}, which
|
|
468
|
+
return out({ refused: `${named(hit[0])} attacks player ${pactOne ? (ownerOf(board, hit[0].to) ?? a.with) : a.with}'s territory ${hit[0].to}, which ${what} covers` });
|
|
267
469
|
if (fog.length)
|
|
268
|
-
return out({ refused: fogText(
|
|
269
|
-
|
|
470
|
+
return out({ refused: fogText(what) });
|
|
471
|
+
keep();
|
|
270
472
|
return out({
|
|
271
|
-
carried:
|
|
272
|
-
record: { sentTurn: turn, kind: c.kind, agreement: a.id, with: a.with },
|
|
473
|
+
carried: `${name} (${a.status}), and no ${orders} order this turn attacks a territory it covers${unchecked(a.terms.scope)}`,
|
|
474
|
+
record: { sentTurn: turn, kind: c.kind, agreement: a.id, with: a.with, ...withParties },
|
|
273
475
|
change,
|
|
274
476
|
});
|
|
275
477
|
});
|
|
276
|
-
return { checks, agreements };
|
|
478
|
+
return { checks, agreements, pacts };
|
|
277
479
|
}
|
|
278
480
|
/**
|
|
279
481
|
* B4 (warapp_submit_turn): the commitments I sent that `moves` would break on `turn` — an order that
|
|
@@ -323,6 +525,21 @@ export function commitmentWarnings(input) {
|
|
|
323
525
|
text: `${said(c)} said you would attack ${what} this turn: no order here does`,
|
|
324
526
|
});
|
|
325
527
|
}
|
|
528
|
+
else if (c.kind === 'propose' && c.parties !== undefined) {
|
|
529
|
+
// #685: a pact I proposed, still open: an attack on any party's covered territory.
|
|
530
|
+
const a = input.pacts?.find((x) => x.id === c.agreement);
|
|
531
|
+
if (!a || (a.status !== 'proposed-by-me' && a.status !== 'proposed-by-them'))
|
|
532
|
+
continue;
|
|
533
|
+
const partners = partnersOf(a, me);
|
|
534
|
+
const each = partners.map((p) => hitsOn(a.terms.scope, p));
|
|
535
|
+
const hit = [...new Map(each.flatMap((e) => e.hit).map((h) => [h.index, h])).values()].sort((x, y) => x.index - y.index);
|
|
536
|
+
const note = [...new Set(each.map((e) => e.note).filter(Boolean))].join('');
|
|
537
|
+
const said2 = `${said(c)} proposed pact ${a.id} to players ${listIds(partners)}, still open`;
|
|
538
|
+
if (hit.length)
|
|
539
|
+
out.push({ commitment: c.id, kind: c.kind, with: a.with, moves: hit, text: `${said2}: ${list(hit)} attacks a territory it covers${note}` });
|
|
540
|
+
else if (each[0]?.fog.length)
|
|
541
|
+
out.push({ commitment: c.id, kind: c.kind, with: a.with, moves: each[0].fog, unchecked: true, text: `${said2}: ${intoFog(each[0].fog)} — it may be a party's, which was not checked` });
|
|
542
|
+
}
|
|
326
543
|
else if (c.kind === 'propose') {
|
|
327
544
|
const a = input.agreements.find((x) => x.id === c.agreement);
|
|
328
545
|
if (!a || (a.status !== 'proposed-by-me' && a.status !== 'proposed-by-them'))
|