cortico-world-parlor 0.35.2 → 0.35.5

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/CHANGELOG.md CHANGED
@@ -1,3 +1,34 @@
1
+ ## 0.35.5(2026-11-02)
2
+
3
+ - 修复超时代打和脚本陪练跟炸弹时错误回退到更小炸弹的问题:压不过则过牌,有王炸时仍可使用王炸,避免非法代打使牌桌作废。
4
+
5
+ - 去掉新版网页所有牌桌下方重复的长段文字事件记录,包括狼人杀和斗地主;桌面内的操作、发言、历史与聊天照常保留。
6
+
7
+ - 修复斗地主带牌牌型按最小附件误判主牌的问题:三带一、三带二、四带二、四带两对及带翅膀的飞机均按主体比较;“666 带 99”不能压“222 带 44”。旧牌局恢复时根据实际出牌重新识别上一手与本轮出牌的主牌点数,保留原牌、回合和结算历史。
8
+
9
+ - 狼人杀预言家的查验结果在动作回执及本人私视图中持续显示,白天、出局、恢复与终局仍可查看;其他玩家和旁观者不能读取。
10
+ - 未开局明确显示等待入座与尚未分配角色,不再显示假倒计时或 undefined;提前列出人数、真人/Coo 与客户端能力条件,名单采用真实席位类型。
11
+ - Coo 升级后,快照与 SSE 续连刷新本人在等人桌中的能力记录,不必退桌重入;保留真正旧客户端门禁,不延长等人期限或改变已开局状态。
12
+
13
+ - 斗地主建议改用公开记牌、余牌静态拆手和上下家公开座次综合排序,补上报单/报双封堵、需要时接管队友小牌、地主争取主动权及大牌/炸弹消耗成本。记牌能证明较小牌已能控住时,优先节省更大牌。
14
+ - 余牌拆手使用有固定搜索额度的共享缓存,达到额度后采用真实合法拆分的上界;提示写“余牌可组成几手(不含压牌)”,不把它说成必胜、最优步数或连续出牌保证。不新增模型调用,不读取别家隐藏手牌。
15
+ - 四带二用掉四张同点牌时明确提示失去独立炸弹;只在实际留下炸弹时才写“保留炸弹”。候选按打法去重,不再让三项建议全是同一牌型换附件。
16
+
17
+ - 大厅首屏重排:客厅内容放左栏,灯下空桌及“找一桌”匹配/招募告示牌放右栏;招募默认露出两条,更多内容在面板内滚动,另补宽屏与手机布局。只调整展示,不改匹配与入桌规则。
18
+ - 修复手机顶条的外观按钮图标被旧页样式隐藏:深浅切换按钮在窄屏上显示太阳/月亮图标。
19
+
20
+ ## 0.35.4(2026-11-02)
21
+
22
+ - 修浮窗可读性:私聊窗的气泡还是旧版的浅色底,字却用着给深色背景配的浅色,深色下几乎读不出来;浅色下气泡字也是同一套浅色。现在气泡、输入框、会话列表、时间与短号都走外观 token,深浅两套都清楚。
23
+ - 同一轮把前端各处的对比度过了一遍(私聊、信箱、聊天面板、成员管理、换客厅、提示条、加入页;1440 与 390;深浅两套):浅色下门牌栏小字、房间卡箭头、成员副标题、信箱角标等偏淡的字调深一档;深色下私聊输入框白底白字修好;浅色下提示条、错误字样也按浅色配色。
24
+ - 纯样式与文案层级调整,不改服务端、接口与存档。
25
+
26
+ ## 0.35.3(2026-11-02)
27
+
28
+ - 顶条和加入页的外观按钮改成「点一下就切」:整颗按钮(太阳/月亮图标、文字、留白)都能点,按当前是深色还是浅色切到另一套;手机窄屏只留图标时也能点。
29
+ - 按钮的图标与文字跟着当前外观走(浅色是太阳 +「浅色」,深色是月亮 +「深色」),悬停和读屏说明写明点一下会切到哪套。
30
+ - 旧页 `?legacy=1` 的外观下拉保持不变;换色仍由 `theme.js` 与浏览器里记住的选择负责。
31
+
1
32
  ## 0.35.2(2026-11-02)
2
33
 
3
34
  - 恢复窄侧栏和手机底栏的“反馈”入口,在新标签页打开“反馈与公告”,沿用同站已有身份;大厅、客厅和牌桌均可使用。
package/README.md CHANGED
@@ -5,11 +5,30 @@ Owner: `src/definition.ts`
5
5
  一个共享的「客厅」:多只 Coo(以及它们的主人)在多个持久客厅里待着、说话、一起打牌。
6
6
  每个版本改了什么见 [CHANGELOG.md](CHANGELOG.md)。
7
7
 
8
+ 0.35.5:整合本轮服务端与前端改动。
9
+
10
+ 新版网页不再在牌桌下方额外铺开长段事件文字;狼人杀、斗地主等游戏统一使用桌面内的操作与记录。
11
+
12
+ 修正斗地主带牌牌型的主牌大小判断,按三张、四张或飞机主体比较,附件不参与大小;旧牌局恢复时也会重新识别已有出牌的主牌点数。
13
+
14
+ 狼人杀查验结果会直接附在 Coo 的动作回执中,并在本人查看时保留;等人时明确显示尚未分配角色和开局条件。
15
+ 升级后的 Coo 通过快照或重连即可更新等人桌的能力记录,无需退桌重入;这不会给等人桌续期,也不会改变已开局的牌局。完整生效需要服务器与 Coo 扩展一起更新。
16
+
17
+ 斗地主建议会结合已出牌、余牌组合和座次判断报单/报双封堵及队友让牌;四带二消耗炸弹会明确说明。
18
+ 提示里的“余牌可组成几手”仅指合法牌型分组,不表示这些牌能连续打出,也不是胜率或必胜承诺。
19
+
20
+ 大厅首屏把“找一桌”的匹配/招募面板移到灯下空桌旁,与左侧客厅内容分栏;招募超过两条时在面板内滚动,另补宽屏与手机布局。匹配规则不变。
21
+ 手机顶条的外观按钮恢复太阳/月亮图标。
22
+
23
+ 0.35.4 私聊、信箱、聊天面板等浮窗在深浅两套外观下都能读清了(气泡、输入框、次要小字与提示条)。
24
+
25
+ 0.35.3 外观按钮改成点一下就切深色 / 浅色:整颗按钮都能点,手机只显示图标时也能点。
26
+
8
27
  0.35.2 恢复侧栏(手机底栏)的“反馈”入口,可打开“反馈与公告”;刷新会馆页面即可看到。
9
28
 
10
29
  0.35.1 修复“全部客厅”海报卡无法进入,并把快速匹配卡移到首屏主按钮下方、缩短到最多 560px。
11
30
 
12
- ## 快速匹配与大厅牌桌招募(本地待发布)
31
+ ## 快速匹配与大厅牌桌招募(0.35.0 起)
13
32
 
14
33
  大厅的「快速匹配」按斗地主、狼人杀或骰子,选择当前服务器公开客厅中主动开放、未开局、
15
34
  未过期、有空位且无押注的桌,成功后一次完成换厅与上桌。优先凑人数较多的桌,再按开桌时间排序。
@@ -45,7 +64,7 @@ Coo 工具示例:
45
64
 
46
65
  **升级前备份**:SQLite schema 8 / PostgreSQL schema 3 新增 `table_discovery`、`table_entry_receipts`,
47
66
  SQLite→PG 迁移覆盖两表并兼容缺少它们的旧 schema 7。旧程序不能直接打开新库,回退需兼容版或恢复备份。
48
- 网页需要服务器更新;Coo 新工具需要各自更新扩展并重启。本地源码完成不代表服务器和真实 Coo 已更新。
67
+ 该能力已随 0.35.0 发布。网页需要服务器更新;Coo 新工具需要各自更新扩展并重启,服务器更新不代表各 Coo 已更新。
49
68
 
50
69
  0.35.0:本日的 Vue 客户端迁移、夜航会馆视觉、牌桌组件化、连接与改名修复、快速匹配及大厅招募一起交付。
51
70
  快速匹配涉及 SQLite schema 8 / PostgreSQL schema 3,升级前备份;旧版不能直接打开新库。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortico-world-parlor",
3
- "version": "0.35.2",
3
+ "version": "0.35.5",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "筆離嘢"
@@ -27,7 +27,7 @@ export interface ReplayResponse {
27
27
  * 能不能玩需要新能力的游戏(狼人杀要 ≥ 0.29.0)。
28
28
  * 它跟 npm 包版本解耦——发新版时在这里抬一格即可(有测试盯着别忘)。
29
29
  */
30
- export const PARLOR_CLIENT_VERSION = '0.35.2';
30
+ export const PARLOR_CLIENT_VERSION = '0.35.5';
31
31
 
32
32
  export class ParlorHttpError extends Error {
33
33
  readonly status: number;
@@ -418,6 +418,8 @@ export class ParlorClient {
418
418
  }
419
419
 
420
420
  private async headers(extra: Record<string, string>): Promise<Record<string, string>> {
421
+ // 快照与 SSE 续连也携带能力,升级后无需退桌重入。
422
+ extra = { 'x-parlor-client': PARLOR_CLIENT_VERSION, ...extra };
421
423
  if (!this.identity) return extra;
422
424
  if (this.global) {
423
425
  if (extra.authorization) return extra;
@@ -1,6 +1,7 @@
1
1
  /** 决策辅助只接收本人手牌、公开出牌和公开座次信息;不接收任何别家的私牌。 */
2
2
  import { canBeat, DECK, isCard, moveLabel, parseMove, RANKS, sortCards, type Card, type Move } from './doudizhu.ts';
3
3
  import type { BotContext } from './doudizhu-bot.ts';
4
+ import { createHandPlanner } from './doudizhu-hand-plan.ts';
4
5
 
5
6
  export const countCards = (cards: readonly Card[]): Record<Card, number> => Object.fromEntries(
6
7
  RANKS.map((rank) => [rank, cards.filter((card) => card === rank).length]),
@@ -96,37 +97,105 @@ export interface DoudizhuAssist {
96
97
  canBeat: boolean;
97
98
  }
98
99
 
99
- export function buildAssist(hand: readonly Card[], played: readonly Card[], target: Move | null, context: BotContext): DoudizhuAssist {
100
+ export interface AssistContext extends BotContext {
101
+ /** 都是公开信息;不传其他席位的手牌。 */
102
+ opponentCardsLeft?: readonly number[];
103
+ nextRole?: 'landlord' | 'farmer';
104
+ nextCardsLeft?: number;
105
+ }
106
+
107
+ /** 合并余牌只用来保守判断“可能有更大的牌”,不推断牌具体在谁手里。 */
108
+ function responsePossible(move: Move, pool: Record<Card, number>, maxCards: number): boolean {
109
+ if (move.type === 'rocket') return false;
110
+ if (maxCards >= 2 && pool.SJ && pool.BJ) return true;
111
+ if (maxCards >= 4 && RANKS.some((rank, index) => pool[rank] === 4 && (move.type !== 'bomb' || index > move.rank))) return true;
112
+ if (move.type === 'bomb' || maxCards < move.cards.length) return false;
113
+ const per = move.type === 'single' ? 1 : move.type === 'pair' ? 2 : move.type === 'triple' ? 3 : 0;
114
+ if (per) return RANKS.some((rank, index) => index > move.rank && pool[rank] >= per);
115
+ const sequence = move.type === 'straight' ? 1 : move.type === 'pair-straight' ? 2 : move.type === 'airplane' ? 3 : 0;
116
+ if (sequence) {
117
+ for (let start = move.rank + 1; start + move.length - 1 <= RANKS.indexOf('A'); start++) {
118
+ if (RANKS.slice(start, start + move.length).every((rank) => pool[rank] >= sequence)) return true;
119
+ }
120
+ return false;
121
+ }
122
+ // 带牌牌型不作“不可压”的保证,避免把附件主牌判断或隐藏归属猜成事实。
123
+ return true;
124
+ }
125
+
126
+ export function buildAssist(hand: readonly Card[], played: readonly Card[], target: Move | null, context: AssistContext): DoudizhuAssist {
100
127
  const counts = countCards(hand);
128
+ const unseen = countCards(subtractCards(DECK, [...played, ...hand]));
101
129
  const plays = legalPlays(hand, target);
130
+ const plan = createHandPlanner(hand, target ? legalPlays(hand, null) : plays);
131
+ const beforeGroups = plan(hand);
132
+ const opponentLeft = context.opponentCardsLeft ?? [context.minOpponentLeft];
133
+ const maxOpponentLeft = context.opponentCardsLeft ? Math.max(...opponentLeft) : Math.max(20, context.minOpponentLeft);
134
+ const singleDanger = opponentLeft.includes(1) && (!target || target.type === 'single');
135
+ const pairDanger = opponentLeft.includes(2) && (!target || target.type === 'pair');
136
+ const teammate = context.role === 'farmer' && context.lastPlayBy === 'farmer';
137
+ const nextEnemy = context.nextRole !== undefined && context.nextRole !== context.role;
138
+ const mustCoverTeammate = teammate && nextEnemy && !!target
139
+ && context.nextCardsLeft === target.cards.length && ['single', 'pair'].includes(target.type)
140
+ && responsePossible(target, unseen, context.nextCardsLeft);
102
141
  const rated = plays.map((move) => {
103
142
  const used = countCards(move.cards);
143
+ const rest = subtractCards(hand, move.cards);
144
+ const groups = plan(rest);
104
145
  const splitBomb = RANKS.some((rank) => counts[rank] === 4 && used[rank] > 0 && used[rank] < 4);
105
146
  const splitRocket = counts.SJ > 0 && counts.BJ > 0 && used.SJ + used.BJ === 1;
106
147
  const splitPair = RANKS.filter((rank) => counts[rank] === 2 && used[rank] === 1).length;
107
148
  const bomb = move.type === 'bomb' || move.type === 'rocket';
149
+ const usesBombAsAttachment = !bomb && RANKS.some((rank) => counts[rank] === 4 && used[rank] === 4);
108
150
  const finished = move.cards.length === hand.length;
109
151
  const urgent = context.minOpponentLeft <= 2;
110
- const score = finished ? 10_000 : (target ? 20 : move.cards.length * 5)
111
- - move.rank * 0.3 - splitPair * 6 - (splitBomb ? 80 : 0) - (splitRocket ? 90 : 0)
112
- - (bomb ? urgent ? 12 : 65 : 0);
113
- const reasons = [finished ? '可直接出完' : `出后剩 ${hand.length - move.cards.length} 张`];
152
+ const controlled = !responsePossible(move, unseen, maxOpponentLeft);
153
+ let score = -groups * 24 + move.cards.length * 1.5 - move.rank * 0.25
154
+ - splitPair * 5 - (splitBomb ? 70 : 0) - (splitRocket ? 80 : 0)
155
+ - (usesBombAsAttachment ? urgent ? 12 : 30 : 0) - (bomb ? urgent ? 8 : 30 : 0);
156
+ const highCardCost = used.A + used['2'] * 2 + used.SJ * 3 + used.BJ * 4;
157
+ score -= highCardCost * (urgent ? 0.1 : 1.5);
158
+ // 地主需要持续争取主动权;不把“拆手数暂时没减少”机械地当作应该过牌。
159
+ if (target && !teammate) score += context.role === 'landlord' ? 18 : 8;
160
+ // 平时节约控制牌;真正需要封堵时优先选能控住的最小牌,否则尽力顶大。
161
+ if (controlled && !urgent && groups > 1) score -= 12;
162
+ if ((singleDanger && move.type === 'single') || (pairDanger && move.type === 'pair')) {
163
+ score += controlled ? 140 : -180 + move.rank * 5;
164
+ } else if (!target && ((singleDanger && move.cards.length > 1) || (pairDanger && move.type !== 'pair'))) score += 60;
165
+ else if (target && urgent && controlled) score += 100;
166
+ if (teammate && !mustCoverTeammate) score -= 180;
167
+ if (finished) score = 100_000;
168
+ const reasons = [finished ? '可直接出完' : `出后剩 ${rest.length} 张,余牌可组成 ${groups} 手(不含压牌)`];
169
+ if (!finished && singleDanger && move.type === 'single') reasons.push(controlled ? '对手报单,按公开余牌可封住单张' : '对手报单,这手仍可能被压');
170
+ else if (!finished && pairDanger && move.type === 'pair') reasons.push(controlled ? '对手报双,按公开余牌可封住对子' : '对手报双,这手仍可能被压');
171
+ else if (!target && singleDanger && move.cards.length > 1) reasons.push('对手报单,领出多张避免其直接接走');
172
+ if (mustCoverTeammate) reasons.push('下家对手可能接走队友这手,需要考虑接管');
114
173
  if (bomb) reasons.push('使用炸弹会使倍数翻倍');
174
+ if (usesBombAsAttachment) reasons.push('四张同点牌用作带牌,失去独立炸弹');
115
175
  if (splitBomb) reasons.push('需要拆开四张同点牌');
116
176
  if (splitRocket) reasons.push('需要拆开王炸');
117
177
  if (splitPair) reasons.push('需要拆对子');
118
- if (!finished && !bomb && !splitBomb && !splitRocket && !splitPair) reasons.push(target ? '合法压牌,保留完整对子与炸弹' : '先走组合牌或散牌,保留完整对子与炸弹');
119
- return { score, suggestion: { action: { move: 'play' as const, cards: sortCards(move.cards) }, label: moveLabel(move), reason: reasons.join(';'), remaining: hand.length - move.cards.length } };
178
+ if (RANKS.some((rank) => counts[rank] === 4 && used[rank] === 0)) reasons.push('保留炸弹');
179
+ const family = `${move.type}:${['single', 'pair'].includes(move.type) ? `${move.rank >= RANKS.indexOf('A') ? 'high' : 'low'}:${controlled}` : ''}`;
180
+ return { score, family, suggestion: { action: { move: 'play' as const, cards: sortCards(move.cards) }, label: moveLabel(move), reason: reasons.join(';'), remaining: rest.length } };
120
181
  }).sort((a, b) => b.score - a.score || a.suggestion.action.cards.join(',').localeCompare(b.suggestion.action.cards.join(',')));
121
- const suggestions: DoudizhuSuggestion[] = rated.slice(0, target ? 2 : 3).map((entry) => entry.suggestion);
182
+ const selected: typeof rated = [];
183
+ for (const entry of rated) {
184
+ if (selected.some((other) => other.family === entry.family)) continue;
185
+ selected.push(entry);
186
+ if (selected.length === (target ? 2 : 3)) break;
187
+ }
188
+ const suggestions: DoudizhuSuggestion[] = selected.map((entry) => entry.suggestion);
122
189
  if (target) {
123
- const teammate = context.role === 'farmer' && context.lastPlayBy === 'farmer';
124
190
  const pass: DoudizhuSuggestion = {
125
191
  action: { move: 'pass' }, label: '不要', remaining: hand.length,
126
- reason: !plays.length ? '没有合法压牌,只能过牌' : teammate ? '队友当前领牌,可选择让牌;并非无法压牌' : '允许过牌,保留手牌;并非无法压牌',
192
+ reason: !plays.length ? '没有合法压牌,只能过牌' : mustCoverTeammate ? '可过,但下家对手可能接走队友的牌;并非无法压牌'
193
+ : teammate ? '队友当前领牌,可选择让牌;并非无法压牌' : '允许过牌,保留手牌组合;并非无法压牌',
127
194
  };
128
- const passFirst = !plays.length || (rated[0]?.score ?? 0) < 0 || (teammate && rated[0]?.score !== 10_000);
195
+ const passScore = -beforeGroups * 24 + 8 + (teammate && !mustCoverTeammate ? 100 : 0)
196
+ - (mustCoverTeammate || (!teammate && (singleDanger || pairDanger)) ? 300 : 0);
197
+ const passFirst = !plays.length || passScore >= rated[0].score;
129
198
  if (passFirst) suggestions.unshift(pass); else suggestions.push(pass);
130
199
  }
131
- return { played: countCards(played), otherRemaining: countCards(subtractCards(DECK, [...played, ...hand])), suggestions, canBeat: plays.length > 0 };
200
+ return { played: countCards(played), otherRemaining: unseen, suggestions, canBeat: plays.length > 0 };
132
201
  }
@@ -0,0 +1,46 @@
1
+ import { RANKS, type Card, type Move } from './doudizhu.ts';
2
+
3
+ /** 静态拆手:每组均为合法领出,不假定能连续拿到出牌权。 */
4
+ export function createHandPlanner(hand: readonly Card[], moves: readonly Move[]): (cards: readonly Card[]) => number {
5
+ const powers = RANKS.map((_, index) => 5 ** index);
6
+ const tally = (cards: readonly Card[]): number[] => RANKS.map((rank) => cards.filter((card) => card === rank).length);
7
+ const keyOf = (counts: readonly number[]): number => counts.reduce((sum, count, rank) => sum + count * powers[rank], 0);
8
+ const entries = moves.map((move) => {
9
+ const counts = tally(move.cards);
10
+ return { counts, key: keyOf(counts), size: move.cards.length };
11
+ }).sort((a, b) => b.size - a.size || a.key - b.key);
12
+ const singleMoves = new Set(entries.map((entry) => entry.key));
13
+ const containing = RANKS.map((_, rank) => entries.filter((entry) => entry.counts[rank] > 0));
14
+ const memo = new Map<number, number>([[0, 0]]);
15
+ const fits = (move: readonly number[], counts: readonly number[]): boolean => move.every((n, rank) => n <= counts[rank]);
16
+ // 所有候选共用缓存和确定性的搜索额度;大手牌达到额度后返回真实合法拆分的上界。
17
+ const budget = hand.length <= 12 ? 4096 : 1200;
18
+ let visited = 0;
19
+ const greedy = (counts: readonly number[]): number => {
20
+ const rest = [...counts];
21
+ let groups = 0;
22
+ for (const entry of entries) while (fits(entry.counts, rest)) {
23
+ for (let rank = 0; rank < rest.length; rank++) rest[rank] -= entry.counts[rank];
24
+ groups++;
25
+ }
26
+ return groups;
27
+ };
28
+ const solve = (counts: number[], key: number): number => {
29
+ const cached = memo.get(key);
30
+ if (cached !== undefined) return cached;
31
+ if (singleMoves.has(key)) { memo.set(key, 1); return 1; }
32
+ let best = greedy(counts);
33
+ if (best > 2 && visited++ < budget) {
34
+ const anchor = counts.findIndex((count) => count > 0);
35
+ for (const entry of containing[anchor]) {
36
+ if (!fits(entry.counts, counts)) continue;
37
+ const rest = counts.map((count, rank) => count - entry.counts[rank]);
38
+ best = Math.min(best, 1 + solve(rest, key - entry.key));
39
+ if (best === 2) break;
40
+ }
41
+ }
42
+ memo.set(key, best);
43
+ return best;
44
+ };
45
+ return (cards) => { const counts = tally(cards); return solve(counts, keyOf(counts)); };
46
+ }
@@ -57,6 +57,14 @@ const DEFAULT_BOT_DELAY_MS = 1500;
57
57
  const BOT_NAMES = ['陪练甲', '陪练乙'];
58
58
  const MAX_REDEALS = 5;
59
59
 
60
+ /** 主牌点数是从实际出牌派生的;旧存档可能把较小附件误存成主牌。 */
61
+ const restoreMove = (value: unknown): Move => {
62
+ const cards = (value as { cards?: unknown } | null)?.cards;
63
+ const parsed = Array.isArray(cards) ? parseMove(cards) : null;
64
+ if (!parsed) throw new Error('斗地主存档的出牌牌型不合法');
65
+ return parsed;
66
+ };
67
+
60
68
  export class DoudizhuTable implements TableEngine {
61
69
  readonly game = 'ddz';
62
70
  readonly label = '斗地主';
@@ -423,7 +431,7 @@ export class DoudizhuTable implements TableEngine {
423
431
  if (typeof id !== 'string' || !row || typeof row !== 'object') throw new Error('斗地主存档的轮次出牌形状不对');
424
432
  this.roundPlays.set(id, {
425
433
  seat: String(row.seat ?? id),
426
- move: row.move as Move,
434
+ move: restoreMove(row.move),
427
435
  cards: Array.isArray(row.cards) ? row.cards as PhysCard[] : [],
428
436
  });
429
437
  }
@@ -435,7 +443,7 @@ export class DoudizhuTable implements TableEngine {
435
443
  this.lastPlay = last && typeof last === 'object'
436
444
  ? {
437
445
  seat: String(last.seat ?? ''),
438
- move: last.move as Move,
446
+ move: restoreMove(last.move),
439
447
  cards: Array.isArray(last.cards) ? last.cards as PhysCard[] : [],
440
448
  }
441
449
  : undefined;
@@ -713,7 +721,13 @@ export class DoudizhuTable implements TableEngine {
713
721
  }
714
722
 
715
723
  private assistFor(seat: Seat): DoudizhuAssist {
716
- return buildAssist(seat.hand, this.playedCards(), this.lastPlay?.move ?? null, this.botContext(seat));
724
+ const next = this.seats[(this.seats.indexOf(seat) + 1) % SEAT_COUNT];
725
+ return buildAssist(seat.hand, this.playedCards(), this.lastPlay?.move ?? null, {
726
+ ...this.botContext(seat),
727
+ opponentCardsLeft: this.seats.filter((other) => other.role !== seat.role).map((other) => other.hand.length),
728
+ nextRole: next.role ?? undefined,
729
+ nextCardsLeft: next.hand.length,
730
+ });
717
731
  }
718
732
 
719
733
  /** 轮到自己时给网页一个可点的建议;不轮到时没有。 */
@@ -116,9 +116,9 @@ const wingsOf = (groups: readonly Group[], window: readonly Group[]): Group[] =>
116
116
  .filter((group) => group.count > 0);
117
117
  };
118
118
 
119
- const move = (type: MoveType, groups: readonly Group[], length = 0): Move => {
119
+ const move = (type: MoveType, groups: readonly Group[], length = 0, rank = groups[0].rank): Move => {
120
120
  const cards = groups.flatMap((group) => Array.from({ length: group.count }, () => group.card));
121
- return { type, rank: groups[0].rank, length, cards: sortCards(cards) };
121
+ return { type, rank, length, cards: sortCards(cards) };
122
122
  };
123
123
 
124
124
  /** 认得就返回牌型,不认得返回 null。 */
@@ -138,21 +138,21 @@ export function parseMove(input: readonly string[]): Move | null {
138
138
  if (size === 3 && groups.length === 1) return move('triple', groups);
139
139
  if (size === 4) {
140
140
  const triple = groups.find((group) => group.count === 3);
141
- if (triple) return move('triple-single', groups);
141
+ if (triple) return move('triple-single', groups, 0, triple.rank);
142
142
  }
143
143
  if (size === 5) {
144
144
  const triple = groups.find((group) => group.count === 3);
145
145
  const pair = groups.find((group) => group.count === 2);
146
- if (triple && pair && groups.length === 2) return move('triple-pair', groups);
146
+ if (triple && pair && groups.length === 2) return move('triple-pair', groups, 0, triple.rank);
147
147
  }
148
148
  if (size === 6) {
149
149
  const four = groups.find((group) => group.count === 4);
150
- if (four) return move('four-two', groups);
150
+ if (four) return move('four-two', groups, 0, four.rank);
151
151
  }
152
152
  if (size === 8) {
153
153
  const four = groups.find((group) => group.count === 4);
154
154
  const pairs = groups.filter((group) => group.count === 2);
155
- if (four && pairs.length === 2) return move('four-two-pair', groups);
155
+ if (four && pairs.length === 2) return move('four-two-pair', groups, 0, four.rank);
156
156
  }
157
157
 
158
158
  const top = groups[groups.length - 1].rank;
@@ -171,7 +171,7 @@ export function parseMove(input: readonly string[]): Move | null {
171
171
  const wings = wingsOf(groups, window);
172
172
  const wingCount = wings.reduce((sum, group) => sum + group.count, 0);
173
173
  if (wingCount === need && wings.every((group) => group.count <= 2)) {
174
- return move('airplane-single', groups, need);
174
+ return move('airplane-single', groups, need, window[0].rank);
175
175
  }
176
176
  }
177
177
  }
@@ -180,7 +180,7 @@ export function parseMove(input: readonly string[]): Move | null {
180
180
  for (const window of tripleWindows(groups, need)) {
181
181
  const wings = wingsOf(groups, window);
182
182
  if (wings.length === need && wings.every((group) => group.count === 2)) {
183
- return move('airplane-pair', groups, need);
183
+ return move('airplane-pair', groups, need, window[0].rank);
184
184
  }
185
185
  }
186
186
  }
@@ -393,7 +393,7 @@ export function suggestMove(hand: readonly string[], target: Move | null): Card[
393
393
  break;
394
394
  }
395
395
 
396
- const bomb = groups.find((group) => group.count === 4);
396
+ const bomb = groups.find((group) => group.count === 4 && (target.type !== 'bomb' || group.rank > target.rank));
397
397
  if (bomb) return take(bomb.card, 4);
398
398
  if ((groups.find((group) => group.card === 'SJ')?.count ?? 0) > 0
399
399
  && (groups.find((group) => group.card === 'BJ')?.count ?? 0) > 0) {
@@ -219,7 +219,7 @@ const werewolf: GameDefinition = {
219
219
  case 'vote': return body.target === undefined || body.target === null ? '弃票交了;到点统一揭晓。' : `投给 ${body.target} 号了;到点统一揭晓。`;
220
220
  case 'wolf_chat': return '狼队的话交了;同伴能看到。';
221
221
  case 'wolf_kill': return body.target === undefined || body.target === null ? '弃刀交了。' : `刀票投给 ${body.target} 号了;到点锁定刀口。`;
222
- case 'inspect': return body.target === undefined ? '今夜不查验,槽已交。' : `查验 ${body.target} 号的请求交了;结果进你的秘密记录,用 parlor_table_view 立刻看。`;
222
+ case 'inspect': return body.target === undefined ? '今夜不查验,槽已交。' : `已查验 ${body.target} 号;结果与历史见下方本人私视图。`;
223
223
  case 'witch': return body.choice === 'save' ? '解药用掉了。' : body.choice === 'poison' ? '毒药用掉了。' : '今夜不用药,槽已交。';
224
224
  case 'shoot': return body.target === undefined ? '放弃开枪了。' : `开枪带走 ${body.target} 号了。`;
225
225
  default: return '动作交了。';
@@ -237,6 +237,29 @@ export class WerewolfTable implements TableEngine {
237
237
  return seat ? `${seatNo}号 ${seat.name}` : `${seatNo}号`;
238
238
  }
239
239
 
240
+ /** 只更新等人桌本席位的能力;缺头不擦掉原记录,已开局不改。 */
241
+ updateClientVersion(seatId: string, version: string): boolean {
242
+ const seat = this.seatOf(seatId);
243
+ if (this.status !== 'open' || !seat || seat.kind !== 'pet' || seat.clientVersion === version) return false;
244
+ seat.clientVersion = version;
245
+ return true;
246
+ }
247
+
248
+ private startBlockers(): string[] {
249
+ const issues: string[] = [];
250
+ if (this.seats.length !== WEREWOLF_SEAT_COUNT) {
251
+ issues.push(`狼人杀要正好 ${WEREWOLF_SEAT_COUNT} 个人,现在 ${this.seats.length} 个`);
252
+ }
253
+ const pets = this.seats.filter((seat) => seat.kind === 'pet');
254
+ if (!this.seats.some((seat) => seat.kind === 'human')) issues.push('狼人杀要至少一名真人(家长下场玩)同桌');
255
+ if (!pets.length) issues.push('狼人杀要至少一只 Coo 同桌');
256
+ const stale = pets.filter((seat) => !versionAtLeast(seat.clientVersion, WEREWOLF_MIN_CLIENT));
257
+ if (stale.length) {
258
+ issues.push(`这些 Coo 的客厅扩展还没有狼人杀能力(旧版 World):${stale.map((seat) => `${seat.seatNo}号 ${seat.name}`).join('、')}。请先升级他们的扩展到 ≥ ${WEREWOLF_MIN_CLIENT} 再开局。`);
259
+ }
260
+ return issues;
261
+ }
262
+
240
263
  join(seat: TableSeat): TableEvent {
241
264
  if (this.status !== 'open') throw new WerewolfError('not_open', '这张桌子已经开始了');
242
265
  if (this.has(seat.id)) throw new WerewolfError('seated', '你已经在桌上了');
@@ -283,21 +306,8 @@ export class WerewolfTable implements TableEngine {
283
306
  start(by: string, now: number): TableStep {
284
307
  if (this.status !== 'open') throw new WerewolfError('not_open', '这张桌子已经开始了');
285
308
  if (by !== this.host) throw new WerewolfError('not_host', '只有开桌的人可以开始');
286
- if (this.seats.length !== WEREWOLF_SEAT_COUNT) {
287
- throw new WerewolfError('not_open', `狼人杀要正好 ${WEREWOLF_SEAT_COUNT} 个人,现在 ${this.seats.length} 个`);
288
- }
289
- const humans = this.seats.filter((seat) => seat.kind === 'human');
290
- const pets = this.seats.filter((seat) => seat.kind === 'pet');
291
- if (humans.length === 0) throw new WerewolfError('not_open', '狼人杀要至少一名真人(家长下场玩)同桌');
292
- if (pets.length === 0) throw new WerewolfError('not_open', '狼人杀要至少一只 Coo 同桌');
293
- const stale = pets.filter((seat) => !versionAtLeast(seat.clientVersion, WEREWOLF_MIN_CLIENT));
294
- if (stale.length > 0) {
295
- const names = stale.map((seat) => `${seat.seatNo}号 ${seat.name}`).join('、');
296
- throw new WerewolfError(
297
- 'not_open',
298
- `这些 Coo 的客厅扩展还没有狼人杀能力(旧版 World):${names}。请先升级他们的扩展到 ≥ ${WEREWOLF_MIN_CLIENT} 再开局。`,
299
- );
300
- }
309
+ const blocked = this.startBlockers()[0];
310
+ if (blocked) throw new WerewolfError('not_open', blocked);
301
311
  this.status = 'playing';
302
312
  const roles = dealRoles(this.rng);
303
313
  this.seats.forEach((seat, index) => { seat.role = roles[index]; });
@@ -1114,8 +1124,9 @@ export class WerewolfTable implements TableEngine {
1114
1124
  alive: seat.alive,
1115
1125
  status: this.status,
1116
1126
  day: this.day,
1117
- phase: phase.kind === 'night' ? 'night' : phase.kind,
1127
+ phase: this.status === 'open' ? 'waiting' : phase.kind,
1118
1128
  phaseLabel: this.phaseLabel(),
1129
+ ...(this.status === 'open' ? { startBlockers: this.startBlockers() } : {}),
1119
1130
  ...(phase.kind === 'speech' ? { stage: phase.stage, speechKind: phase.speechKind } : {}),
1120
1131
  ...(phase.kind === 'vote' && phase.voteVariant ? { voteVariant: phase.voteVariant } : {}),
1121
1132
  windowId: myWindowId ?? phase.windowId,
@@ -1217,8 +1228,9 @@ export class WerewolfTable implements TableEngine {
1217
1228
  status: this.status,
1218
1229
  host: this.host,
1219
1230
  day: this.day,
1220
- phase: phase.kind === 'night' ? 'night' : phase.kind,
1231
+ phase: this.status === 'open' ? 'waiting' : phase.kind,
1221
1232
  phaseLabel: this.phaseLabel(),
1233
+ ...(this.status === 'open' ? { startBlockers: this.startBlockers() } : {}),
1222
1234
  ...(turn ? { turn } : {}),
1223
1235
  deadline: this.publicDeadline(),
1224
1236
  seats: this.seats
@@ -1240,6 +1252,7 @@ export class WerewolfTable implements TableEngine {
1240
1252
  }
1241
1253
 
1242
1254
  private phaseLabel(): string {
1255
+ if (this.status === 'open') return '等待入座';
1243
1256
  const phase = this.phase;
1244
1257
  switch (phase.kind) {
1245
1258
  case 'reveal': return '看身份';
@@ -1297,7 +1310,13 @@ export class WerewolfTable implements TableEngine {
1297
1310
  privateText(seatId: string, now: number): string | null {
1298
1311
  const seat = this.seatOf(seatId);
1299
1312
  if (!seat) return null;
1300
- if (this.status === 'ended') return this.endedText(seat);
1313
+ if (this.status === 'open') {
1314
+ return `${this.publicText()}\n尚未分配角色;坐满九席且至少一名真人、一只 Coo,客户端能力符合后由开桌者开始。\n${this.startBlockers().join(';')}\n未开局可用 parlor_table_leave 退桌;开桌者退桌即收桌。`;
1315
+ }
1316
+ const history = seat.role === 'seer'
1317
+ ? `查验历史(仅自己可见):${this.inspections.length ? this.inspections.map((entry) => `第${entry.day}夜查 ${entry.target}号=${entry.result === 'wolf' ? '狼人' : '好人'}`).join(';') : '还没有查验记录'}。`
1318
+ : '';
1319
+ if (this.status === 'ended') return [this.endedText(seat), history].filter(Boolean).join('\n');
1301
1320
  const phase = this.phase;
1302
1321
  const lines: string[] = [];
1303
1322
  const clock = (at?: number): string => (at ? `${serverClockLabel(at)}(还剩 ${secondsLeft(at, now)} 秒)` : '到点自动推进');
@@ -1312,6 +1331,7 @@ export class WerewolfTable implements TableEngine {
1312
1331
  } else {
1313
1332
  lines.push(`【狼人杀】第${this.day}天·${this.phaseLabel()}。`);
1314
1333
  }
1334
+ if (history) lines.push(history);
1315
1335
  const aliveList = this.aliveSeats().map((entry) => `${entry.seatNo}号 ${entry.name}`).join('、');
1316
1336
  const deadList = this.seats.filter((entry) => !entry.alive)
1317
1337
  .map((entry) => `${entry.seatNo}号 ${entry.name}`)
@@ -1341,11 +1361,8 @@ export class WerewolfTable implements TableEngine {
1341
1361
  }
1342
1362
  lines.push('两个动作都交完就不用再等;到点锁定刀口。');
1343
1363
  } else if (pending === 'inspect') {
1344
- const history = this.inspections.length
1345
- ? this.inspections.map((entry) => `第${entry.day}夜查 ${entry.target}号=${entry.result === 'wolf' ? '狼人' : '好人'}`).join(';')
1346
- : '还没有查验记录';
1347
1364
  lines.push(`查验(${clock(phase.deadline)}):parlor_werewolf_action {move:"inspect", windowId:"${phase.windowId}", target:座号};不带 target = 今夜不查验。`);
1348
- lines.push(`查验历史:${history}。结果交完就能在 parlor_table_view 里看到。`);
1365
+ lines.push('结果提交后立即显示在本人私视图,之后用 parlor_table_view 随时回看。');
1349
1366
  } else {
1350
1367
  lines.push('夜里有人在行动;你不需要做任何事,天亮会公布结果。');
1351
1368
  }
@@ -1429,7 +1446,7 @@ export class WerewolfTable implements TableEngine {
1429
1446
 
1430
1447
  publicText(): string {
1431
1448
  if (this.status === 'open') {
1432
- return `【狼人杀桌】还开着,${this.seats.length}/${WEREWOLF_SEAT_COUNT} 席:${this.seats.map((seat) => `${seat.seatNo}号 ${seat.name}`).join('、')}。`;
1449
+ return `【狼人杀桌·等待入座】${this.seats.length}/${WEREWOLF_SEAT_COUNT} 席:${this.seats.map((seat) => `${seat.seatNo}号 ${seat.name}`).join('、')}。`;
1433
1450
  }
1434
1451
  if (this.status === 'playing') {
1435
1452
  const alive = this.aliveSeats();
@@ -658,6 +658,10 @@ export class RoomHost {
658
658
  return this.tableHost.join(cooId, tableId, requestId, clientVersion, transition);
659
659
  }
660
660
 
661
+ refreshClientVersion(cooId: string, version?: string): Promise<boolean> {
662
+ return this.tableHost.refreshClientVersion(cooId, version);
663
+ }
664
+
661
665
  tableDiscovery(cooId: string, tableId: string, input: { matchOpen?: boolean; text?: string; withdraw?: boolean }, requestId: string) {
662
666
  return this.tableHost.discovery(cooId, tableId, input, requestId);
663
667
  }
@@ -68,6 +68,8 @@ export interface TableEngine {
68
68
  autoPlay(seatId: string, now: number): TableStep | null;
69
69
  has(seatId: string): boolean;
70
70
  seatIds(): string[];
71
+ /** 认证客户端续连时刷新等人桌本席位的能力;不改游戏状态或等待期限。 */
72
+ updateClientVersion?(seatId: string, version: string): boolean;
71
73
  join(seat: TableSeat): TableEvent;
72
74
  /** 未开局时主动离桌;开局后不能离(调用方先判状态,引擎再兜一层)。 */
73
75
  leave(seatId: string): TableEvent;
@@ -399,6 +399,39 @@ export class TableHost {
399
399
 
400
400
  // —— 开桌 / 坐下 / 开始 / 动作 / 收桌 ——
401
401
 
402
+ /** 只接受已认证席位的自报能力,串行提交副本;查看/重连不延长等人期限。 */
403
+ async refreshClientVersion(cooId: string, version?: string): Promise<boolean> {
404
+ if (!version || version.length > 64 || !/^\d+\.\d+\.\d+(?:-[\w.-]+)?$/.test(version)) return false;
405
+ const table = await this.tableOf(cooId);
406
+ if (!table?.engine.updateClientVersion || table.frozen || table.engine.status !== 'open') return false;
407
+ const release = await this.lockTable(table.id);
408
+ try {
409
+ if (this.tables.get(table.id) !== table || table.frozen || table.engine.status !== 'open'
410
+ || this.now() >= table.openDeadlineAt) return false;
411
+ const seat = await this.seats.activeSeat(cooId);
412
+ if (!seat || seat.kind !== 'pet') return false;
413
+ return await withTransaction(this.db, async () => {
414
+ if (await lockTableRow(this.db, table.id) !== table.revision) {
415
+ throw new HostError('conflict', '这张桌子已经变化,请刷新后重试');
416
+ }
417
+ const draft = await this.draft(table);
418
+ if (!draft.updateClientVersion?.(seat.id, version)) return false;
419
+ const revision = table.revision + 1;
420
+ const stateJson = JSON.stringify(draft.exportState());
421
+ await this.db.prepare('UPDATE tables SET state_json = ?, revision = ?, turn_seq = ?, updated_at = ? WHERE id = ?')
422
+ .run(stateJson, revision, revision, this.now(), table.id);
423
+ // 复用非决策私视图刷新,让桌主的开始条件同步更新,不额外叫醒 Coo。
424
+ await this.recordStep(table, draft, { events: [], views: [], refreshViews: draft.seatIds() }, this.now());
425
+ this.db.afterCommit(() => {
426
+ table.engine = draft;
427
+ table.revision = revision;
428
+ table.stateJson = stateJson;
429
+ });
430
+ return true;
431
+ });
432
+ } finally { release(); }
433
+ }
434
+
402
435
  async open(cooId: string, input: { game?: string; stake?: unknown; clientVersion?: string; matchOpen?: boolean } = {}, requestId?: string): Promise<TableOpenResult> {
403
436
  // 开桌还没有 tableId,用房间级键;开桌与「数桌上限」要串行。
404
437
  const releaseOpen = await this.lockTable('#room');