@chrischall/warapp-mcp 0.24.0 → 0.26.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/cards-in-effect.js +19 -3
- package/dist/analysis/coalition.js +6 -3
- package/dist/analysis/commitments.js +253 -42
- package/dist/analysis/income-range.js +26 -0
- package/dist/analysis/pacts.js +327 -0
- package/dist/analysis/relations.js +10 -0
- package/dist/analysis/stress.js +8 -3
- package/dist/analysis/turn-order.js +145 -0
- package/dist/bundle.js +1895 -653
- package/dist/decision-log.js +20 -1
- package/dist/mod-alliances.js +14 -0
- package/dist/protocol/codec.js +4 -0
- package/dist/protocol/methods.js +9 -0
- package/dist/relations-store.js +83 -18
- package/dist/tools/chat-advice.js +2 -2
- package/dist/tools/chat.js +338 -75
- package/dist/tools/check-plan.js +14 -4
- package/dist/tools/commitments.js +40 -8
- package/dist/tools/diplomacy.js +42 -5
- package/dist/tools/game.js +13 -1
- package/dist/tools/mod-alliances.js +13 -1
- package/dist/tools/relations.js +413 -33
- package/dist/tools/turn-order.js +53 -0
- package/dist/tools/turn.js +105 -16
- package/dist/tools/uncommit.js +6 -6
- package/dist/turn-orders.js +27 -3
- 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.26.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.26.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.26.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",
|
|
@@ -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, fromTurn: a.untilTurn - durationOf(dipSettings) });
|
|
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. */
|
|
@@ -12,24 +13,26 @@ export const MAX_MESSAGE_COMMITMENTS = 10;
|
|
|
12
13
|
* it. `undefined` when it reads it (the private recipient, a member of the game group, anyone on the public
|
|
13
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
|
-
? undefined
|
|
21
|
-
: `the message goes privately to player ${audience.to}, so player ${partner}, the truce's partner, would never read it (D3: a truce changes only with the partner told)`;
|
|
21
|
+
return audience.to === partner ? undefined : `the message goes privately to player ${audience.to}, so player ${partner}, ${role}, would never read it (${d3})`;
|
|
22
22
|
if (audience.kind === 'group') {
|
|
23
|
-
|
|
24
|
-
return audience.to.includes(partner)
|
|
25
|
-
? undefined
|
|
26
|
-
: `the message goes to a group of players ${ids}, so player ${partner}, the truce's partner, would never read it (D3: a truce changes only with the partner told)`;
|
|
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})`;
|
|
27
24
|
}
|
|
28
25
|
const p = players.find((x) => x.id === partner);
|
|
29
|
-
return p?.team === audience.team
|
|
30
|
-
? undefined
|
|
31
|
-
: `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})`;
|
|
32
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}`;
|
|
33
36
|
const ownerOf = (board, t) => {
|
|
34
37
|
const s = board.territories.find((x) => x.territoryId === t);
|
|
35
38
|
return s && ownerShown(s) && s.owner.kind === 'player' ? s.owner.playerId : null;
|
|
@@ -63,21 +66,101 @@ const fullTerms = (t) => ({ ...t, scope: t.scope ?? 'all', noticeTurns: t.notice
|
|
|
63
66
|
/** A truce whose last turn has passed is over before it begins. */
|
|
64
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;
|
|
65
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]));
|
|
66
112
|
/**
|
|
67
|
-
* The agreement change a `propose`, `accept` or `notice` makes to `agreements` on `turn`, or
|
|
68
|
-
* 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
|
|
69
115
|
* apply the same rule to the ledger as it then stands. `players` is checked for a new commitment
|
|
70
|
-
* (`partyRefusal`) only when given.
|
|
116
|
+
* (`partyRefusal`) only when given. The change's agreement is a pact (`parties`) when the commitment is a pact's.
|
|
71
117
|
*/
|
|
72
118
|
export function agreementChange(c, o) {
|
|
73
119
|
const { agreements, turn, me } = o;
|
|
120
|
+
const pacts = o.pacts ?? [];
|
|
74
121
|
const party = (p) => (o.players ? partyRefusal(o.players, me, p) : undefined);
|
|
75
122
|
const scopeBad = (t) => (o.graph ? scopeRefusal(o.graph, t.scope) : undefined);
|
|
76
123
|
const move = (a, status) => {
|
|
77
124
|
const r = transitionAgreement(a, status, turn);
|
|
78
125
|
return 'refused' in r ? r : { agreement: r.agreement, before: a, created: false };
|
|
79
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
|
+
};
|
|
80
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' };
|
|
81
164
|
const a = agreements.find((x) => x.id === c.agreement);
|
|
82
165
|
if (!a)
|
|
83
166
|
return { refused: `there is no agreement ${c.agreement} in the ledger` };
|
|
@@ -87,10 +170,33 @@ export function agreementChange(c, o) {
|
|
|
87
170
|
return { refused: `agreement ${a.id} is ${a.status}: notice is given on an agreed truce` };
|
|
88
171
|
return move(a, 'notice-by-me');
|
|
89
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
|
+
}
|
|
90
193
|
if (c.kind === 'propose') {
|
|
91
194
|
const why = party(c.with) ?? scopeBad(c.terms) ?? pastUntil(c.terms, turn);
|
|
92
195
|
if (why)
|
|
93
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` };
|
|
94
200
|
const open = openWith(agreements, c.with);
|
|
95
201
|
if (!open)
|
|
96
202
|
return { agreement: newAgreement(o.nextAgreementId(agreements), c.with, 'proposed-by-me', turn, c.terms), before: undefined, created: true };
|
|
@@ -103,6 +209,8 @@ export function agreementChange(c, o) {
|
|
|
103
209
|
return 'refused' in r ? r : { agreement: r.agreement, before: open, created: false };
|
|
104
210
|
}
|
|
105
211
|
// accept
|
|
212
|
+
if (c.players !== undefined || (c.agreement !== undefined && pacts.some((x) => x.id === c.agreement)))
|
|
213
|
+
return acceptPact(c, o, move, newPact);
|
|
106
214
|
let target;
|
|
107
215
|
if (c.agreement !== undefined) {
|
|
108
216
|
target = agreements.find((x) => x.id === c.agreement);
|
|
@@ -137,8 +245,62 @@ export function agreementChange(c, o) {
|
|
|
137
245
|
const why = party(c.with) ?? scopeBad(terms) ?? pastUntil(terms, turn);
|
|
138
246
|
if (why)
|
|
139
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` };
|
|
140
251
|
return { agreement: newAgreement(o.nextAgreementId(agreements), c.with, 'agreed', turn, terms), before: undefined, created: true };
|
|
141
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
|
+
}
|
|
142
304
|
/**
|
|
143
305
|
* B4: each commitment checked against this turn's orders (`moves`: the plan made in the call, or the
|
|
144
306
|
* orders already submitted — `source` says which) and the ledger, in the message's order: a change an
|
|
@@ -149,6 +311,7 @@ export function agreementChange(c, o) {
|
|
|
149
311
|
export function checkCommitments(input) {
|
|
150
312
|
const { graph, board, me, turn, players, moves, source, audience } = input;
|
|
151
313
|
let agreements = [...input.agreements];
|
|
314
|
+
let pacts = [...(input.pacts ?? [])];
|
|
152
315
|
const orders = source === 'plan' ? 'planned' : 'submitted';
|
|
153
316
|
const named = (a) => `the ${orders} move ${a.index + 1} (${a.from} → ${a.to})`;
|
|
154
317
|
const checks = [];
|
|
@@ -223,63 +386,96 @@ export function checkCommitments(input) {
|
|
|
223
386
|
});
|
|
224
387
|
}
|
|
225
388
|
// notice, propose, accept: the ledger first, then the orders against what the agreement covers.
|
|
226
|
-
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 });
|
|
227
390
|
if ('refused' in change)
|
|
228
391
|
return out({ refused: change.refused });
|
|
229
392
|
const a = change.agreement;
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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))));
|
|
234
402
|
const hit = attacksOn(moves, covered);
|
|
235
403
|
const fog = attacksOn(moves, unseenNamed(graph, board, a.terms.scope));
|
|
236
|
-
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 } : {};
|
|
237
414
|
if (c.kind === 'notice') {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
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` });
|
|
245
439
|
if (c.endsTurn !== undefined && c.endsTurn !== endsTurn)
|
|
246
440
|
return out({
|
|
247
|
-
refused:
|
|
441
|
+
refused: `${pactOne ? 'pact' : 'agreement'} ${a.id} carries ${a.terms.noticeTurns} turn${a.terms.noticeTurns === 1 ? '' : 's'} of notice: given on turn ${noticeTurn}, ` +
|
|
248
442
|
`it binds until turn ${endsTurn}, so the message cannot say it ends on turn ${c.endsTurn}` +
|
|
249
443
|
(c.endsTurn > endsTurn ? ` (the ledger frees its territories on turn ${endsTurn}: to keep the truce longer, propose new terms)` : ''),
|
|
250
444
|
});
|
|
251
|
-
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)') : '';
|
|
252
447
|
if (endsNow) {
|
|
253
|
-
|
|
448
|
+
keep();
|
|
254
449
|
return out({
|
|
255
|
-
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}`,
|
|
256
451
|
record,
|
|
257
452
|
change,
|
|
258
453
|
});
|
|
259
454
|
}
|
|
260
455
|
if (hit.length)
|
|
261
|
-
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` });
|
|
262
457
|
if (fog.length)
|
|
263
|
-
return out({ refused: fogText(
|
|
264
|
-
|
|
458
|
+
return out({ refused: fogText(`${pactOne ? 'pact' : 'agreement'} ${a.id}`) });
|
|
459
|
+
keep();
|
|
265
460
|
return out({
|
|
266
|
-
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)}`,
|
|
267
462
|
record,
|
|
268
463
|
change,
|
|
269
464
|
});
|
|
270
465
|
}
|
|
466
|
+
const what = `the ${c.kind === 'propose' ? 'proposed' : 'accepted'} truce`;
|
|
271
467
|
if (hit.length)
|
|
272
|
-
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` });
|
|
273
469
|
if (fog.length)
|
|
274
|
-
return out({ refused: fogText(
|
|
275
|
-
|
|
470
|
+
return out({ refused: fogText(what) });
|
|
471
|
+
keep();
|
|
276
472
|
return out({
|
|
277
|
-
carried:
|
|
278
|
-
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 },
|
|
279
475
|
change,
|
|
280
476
|
});
|
|
281
477
|
});
|
|
282
|
-
return { checks, agreements };
|
|
478
|
+
return { checks, agreements, pacts };
|
|
283
479
|
}
|
|
284
480
|
/**
|
|
285
481
|
* B4 (warapp_submit_turn): the commitments I sent that `moves` would break on `turn` — an order that
|
|
@@ -329,6 +525,21 @@ export function commitmentWarnings(input) {
|
|
|
329
525
|
text: `${said(c)} said you would attack ${what} this turn: no order here does`,
|
|
330
526
|
});
|
|
331
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
|
+
}
|
|
332
543
|
else if (c.kind === 'propose') {
|
|
333
544
|
const a = input.agreements.find((x) => x.id === c.agreement);
|
|
334
545
|
if (!a || (a.status !== 'proposed-by-me' && a.status !== 'proposed-by-them'))
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { boardIncome } from './player.js';
|
|
2
|
+
/**
|
|
3
|
+
* The low end, from the plan's figures (pure). Taken as a difference from `nextIncome` so an army cap's cut (#253),
|
|
4
|
+
* which `nextIncome` already carries, is not run again. `undefined` when it equals `nextIncome` (nothing falls, or the
|
|
5
|
+
* falls cost nothing).
|
|
6
|
+
*/
|
|
7
|
+
export function nextIncomeLow(a) {
|
|
8
|
+
const after = new Set(a.captures);
|
|
9
|
+
for (const t of a.board.territories)
|
|
10
|
+
if (t.owner.kind === 'player' && t.owner.playerId === a.me)
|
|
11
|
+
after.add(t.territoryId);
|
|
12
|
+
const conceded = a.conceded.filter((t) => after.has(t));
|
|
13
|
+
const belowEstimate = [
|
|
14
|
+
...new Set(a.headroom
|
|
15
|
+
.filter((r) => after.has(r.territory) && !conceded.includes(r.territory) && r.deploy !== null && r.deploy < (a.estimateOf(r.opponent) ?? -Infinity))
|
|
16
|
+
.map((r) => r.territory)),
|
|
17
|
+
].sort((x, y) => x - y);
|
|
18
|
+
const falls = [...new Set([...conceded, ...belowEstimate])].sort((x, y) => x - y);
|
|
19
|
+
if (!falls.length)
|
|
20
|
+
return undefined;
|
|
21
|
+
const kept = new Set([...after].filter((t) => !falls.includes(t)));
|
|
22
|
+
const lost = boardIncome(a.graph, after, a.rules).total - boardIncome(a.graph, kept, a.rules).total;
|
|
23
|
+
if (lost <= 0)
|
|
24
|
+
return undefined;
|
|
25
|
+
return { low: Math.max(0, a.nextIncome - lost), falls, belowEstimate };
|
|
26
|
+
}
|