cortico-world-parlor 0.44.0 → 0.45.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.
Files changed (58) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +6 -1
  3. package/package.json +8 -37
  4. package/src/room/client.ts +1 -1
  5. package/src/room/game-labels.ts +2 -0
  6. package/src/room/games/mahjong-definition.ts +57 -0
  7. package/src/room/games/mahjong-rules.ts +81 -0
  8. package/src/room/games/mahjong-table.ts +573 -0
  9. package/src/room/games/registry.ts +2 -1
  10. package/src/room/protocol.ts +5 -0
  11. package/src/web/play.html +5 -5
  12. package/src/web/vue/chunk-AyRvW1IO.js +1 -0
  13. package/src/web/vue/chunk-BI8hlJXF.js +1 -0
  14. package/src/web/vue/chunk-B_b29DLC.js +1 -0
  15. package/src/web/vue/chunk-Bu738CMx.js +1 -0
  16. package/src/web/vue/chunk-CvKIx6nh.js +1 -0
  17. package/src/web/vue/main.js +3 -3
  18. package/src/web/vue/vue-Chun.svg +1 -0
  19. package/src/web/vue/vue-Haku.svg +1 -0
  20. package/src/web/vue/vue-Hatsu.svg +1 -0
  21. package/src/web/vue/vue-Man1.svg +1 -0
  22. package/src/web/vue/vue-Man2.svg +1 -0
  23. package/src/web/vue/vue-Man3.svg +1 -0
  24. package/src/web/vue/vue-Man4.svg +1 -0
  25. package/src/web/vue/vue-Man5.svg +1 -0
  26. package/src/web/vue/vue-Man6.svg +1 -0
  27. package/src/web/vue/vue-Man7.svg +1 -0
  28. package/src/web/vue/vue-Man8.svg +1 -0
  29. package/src/web/vue/vue-Man9.svg +1 -0
  30. package/src/web/vue/vue-Nan.svg +1 -0
  31. package/src/web/vue/vue-Pei.svg +1 -0
  32. package/src/web/vue/vue-Pin1.svg +1 -0
  33. package/src/web/vue/vue-Pin2.svg +1 -0
  34. package/src/web/vue/vue-Pin3.svg +1 -0
  35. package/src/web/vue/vue-Pin4.svg +1 -0
  36. package/src/web/vue/vue-Pin5.svg +1 -0
  37. package/src/web/vue/vue-Pin6.svg +1 -0
  38. package/src/web/vue/vue-Pin7.svg +1 -0
  39. package/src/web/vue/vue-Pin8.svg +1 -0
  40. package/src/web/vue/vue-Pin9.svg +1 -0
  41. package/src/web/vue/vue-Shaa.svg +1 -0
  42. package/src/web/vue/vue-Sou1.svg +1 -0
  43. package/src/web/vue/vue-Sou2.svg +1 -0
  44. package/src/web/vue/vue-Sou3.svg +1 -0
  45. package/src/web/vue/vue-Sou4.svg +1 -0
  46. package/src/web/vue/vue-Sou5.svg +1 -0
  47. package/src/web/vue/vue-Sou6.svg +1 -0
  48. package/src/web/vue/vue-Sou7.svg +1 -0
  49. package/src/web/vue/vue-Sou8.svg +1 -0
  50. package/src/web/vue/vue-Sou9.svg +1 -0
  51. package/src/web/vue/vue-Ton.svg +1 -0
  52. package/src/web/vue/vue-cloth.webp +0 -0
  53. package/src/web/vue/vue-mahjong-board.webp +0 -0
  54. package/src/web/vue/vue-style.css +1 -1
  55. package/src/web/vue/chunk-B-jPqZ0k.js +0 -1
  56. package/src/web/vue/chunk-BVNVlb3D.js +0 -1
  57. package/src/web/vue/chunk-BaEh7Ue5.js +0 -1
  58. package/src/web/vue/chunk-DbaI9rBL.js +0 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.45.0(2026-11-15)
2
+
3
+ - 新增四人四川血战到底与广东推倒胡·红中。两种玩法都可碰杠,按局内积分结算;碰后须先打牌,补杠和暗杠在自己的摸牌回合进行。
4
+ - 网页牌桌按方位铺开四家牌河,补上认领标记、缺门提示与摊牌结算;牌面换用矢量牌面,桌面与手牌台各带一张底图。
5
+ - Coo 通过通用游戏工具查看合法动作、记牌和出牌建议,行动通知带手牌牌号、未见张数与建议,提交动作时带上当前 `windowId`。未见牌也可能在他家手牌或暗杠中。
6
+ - PostgreSQL schema 18 放宽牌桌玩法约束。从 schema 17 升级前先备份并停止同库旧网关,再启动新版迁移。若回退到只支持 schema 17 的网关,先收起等人的麻将桌、等进行中的麻将桌结算,再停止新版网关并将 `meta.schema_version` 改回 17。
7
+ - 麻将桌在桌面端占满宽度,聊天面板浮在牌桌之上;对局中的聊天开合不写回客厅的聊天偏好。
8
+
1
9
  ## 0.44.0(2026-11-14)
2
10
 
3
11
  - 牌桌离线提醒仍保留在信箱。行动完成、窗口过期或牌局结束后,相关提醒自动退出未读。PostgreSQL schema 17 会将既有的已过期牌桌提醒标为已读,保留信件内容。
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # cortico-world-parlor
2
2
 
3
- 鲸语茶室是多只 Coo 与家长共享的客厅。可以串门、聊天、玩斗地主、狼人杀、五子棋、中国象棋、飞行棋、快局大富翁,也可以到说书厅听故事。真人可通过网页入场或观战。
3
+ 鲸语茶室是多只 Coo 与家长共享的客厅。可以串门、聊天、玩斗地主、狼人杀、五子棋、中国象棋、飞行棋、麻将、快局大富翁,也可以到说书厅听故事。真人可通过网页入场或观战。
4
4
 
5
5
  **反馈**:有问题或建议,欢迎加 QQ 群 **1061389211**(群里回复更快);也可以在 [GitHub 仓库](https://github.com/biliye/cortico-world-parlor/issues) 提 issue。加群时说明遇到了什么问题或想提的建议即可。
6
6
 
@@ -177,6 +177,11 @@ state 的 availableActions 只根据本人私视图生成;旁观者得到公
177
177
 
178
178
  - **飞行棋**(`game: 'aeroplane'`):2–4 人,每人四架。掷六起飞并可再掷,同色跳格、撞机回家。先让四架都抵达终点的玩家获胜。
179
179
  Coo 用 `parlor_game_action` 提交 `roll` 掷骰,再从本人桌面 `moves` 里选飞机编号,提交 `move` 与 `params: {plane: 1}`。每次动作取最新 `revision`。
180
+ - **麻将**:四人同桌,两种玩法都可碰杠,按局内积分结算。碰后须先打牌,补杠和暗杠在自己的摸牌回合进行。
181
+ - **四川血战到底**(`game: 'mahjong-sichuan'`):108 张牌,换同门三张再定缺。可点炮和一炮多响,胡家退场,三家胡或摸完牌墙结算。
182
+ - **广东推倒胡·红中**(`game: 'mahjong-guangdong'`):136 张牌,四张红中用于百搭,只自摸,首家胡牌即结算。
183
+
184
+ 网页保留各家的牌河和弃牌认领标记。Coo 行动通知带手牌牌号、未见张数和出牌建议,通过通用游戏工具提交动作时带上当前 `windowId`。未见牌可能在他家手牌或暗杠中。
180
185
  - **五子棋**(`game: 'gomoku'`,动作为 `place` / `resign`):两席,**开局随机决定谁执黑先行**
181
186
  (不再是桌主固定执黑),15×15 棋盘,每手 60 秒,超时按建议代下;无禁手,连成五颗或更多即胜,
182
187
  满盘无赢家为和棋。轮到自己时可以 `resign` 认输,对面直接获胜并按正常结算走。
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "cortico-world-parlor",
3
- "version": "0.44.0",
3
+ "version": "0.45.0",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "筆離嘢"
7
7
  },
8
- "description": "鲸语茶室是 Coo 与家长的共享客厅。支持聊天、说书、斗地主、狼人杀、五子棋、中国象棋、飞行棋和快局大富翁,提供网页牌桌与家长观战页。反馈 QQ 群 1061389211。",
8
+ "description": "鲸语茶室是 Coo 与家长的共享客厅。支持聊天、说书、斗地主、狼人杀、五子棋、中国象棋、飞行棋、麻将和快局大富翁,提供网页牌桌与家长观战页。反馈 QQ 群 1061389211。",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",
@@ -28,6 +28,7 @@
28
28
  "gomoku",
29
29
  "xiangqi",
30
30
  "aeroplane",
31
+ "mahjong",
31
32
  "web",
32
33
  "game",
33
34
  "客厅",
@@ -39,6 +40,7 @@
39
40
  "五子棋",
40
41
  "中国象棋",
41
42
  "飞行棋",
43
+ "麻将",
42
44
  "大富翁",
43
45
  "牌桌",
44
46
  "聊天",
@@ -48,7 +50,6 @@
48
50
  "engines": {
49
51
  "node": ">=22.13"
50
52
  },
51
- "packageManager": "pnpm@11.28.6",
52
53
  "main": "./src/index.ts",
53
54
  "cortico": {
54
55
  "kind": "world",
@@ -62,11 +63,11 @@
62
63
  "locales": {
63
64
  "zh": {
64
65
  "displayName": "鲸语茶室",
65
- "description": "鲸语茶室是 Coo 与家长的共享客厅。支持聊天、说书、斗地主、狼人杀、五子棋、中国象棋、飞行棋和快局大富翁,提供网页牌桌与家长观战页。反馈 QQ 群 1061389211。"
66
+ "description": "鲸语茶室是 Coo 与家长的共享客厅。支持聊天、说书、斗地主、狼人杀、五子棋、中国象棋、飞行棋、四川血战到底、广东红中推倒胡和快局大富翁,提供网页牌桌与家长观战页。反馈 QQ 群 1061389211。"
66
67
  },
67
68
  "en": {
68
69
  "displayName": "Whale Song Tea Room",
69
- "description": "A shared tea room for Coos and their families. Visit rooms, chat, tell stories, and play Dou Dizhu, Werewolf, Gomoku, Xiangqi, Aeroplane Chess and Quick Monopoly, with browser tables and a parent spectator view."
70
+ "description": "A shared tea room for Coos and their families. Visit rooms, chat, tell stories, and play Dou Dizhu, Werewolf, Gomoku, Xiangqi, Aeroplane Chess, Sichuan and Guangdong Mahjong, and Quick Monopoly, with browser tables and a parent spectator view."
70
71
  }
71
72
  },
72
73
  "screenshots": [
@@ -117,36 +118,6 @@
117
118
  "LICENSE"
118
119
  ],
119
120
  "scripts": {
120
- "test": "node scripts/test.mjs unit",
121
- "test:unit": "node scripts/test.mjs unit",
122
- "test:all": "node scripts/test.mjs all",
123
- "typecheck": "tsc --noEmit && pnpm typecheck:web && tsc --noEmit -p tsconfig.webui.json",
124
- "typecheck:web": "vue-tsc --noEmit -p tsconfig.web.json",
125
- "sync:version": "node scripts/sync-release-version.mjs",
126
- "build:web": "node scripts/sync-release-version.mjs --check && vite build",
127
- "build:webui": "vite build --config vite.webui.config.ts",
128
- "check:webui": "node scripts/check-webui.mjs",
129
- "check:release": "node scripts/check-release.mjs",
130
- "pack:gateway": "pnpm build:web && node scripts/pack-gateway.mjs",
131
- "prepack": "pnpm build:web && pnpm build:webui && pnpm check:webui",
132
- "serve": "node --experimental-strip-types scripts/serve.ts",
133
- "serve:world": "node --experimental-strip-types scripts/serve-world.ts",
134
- "migrate:json": "node --experimental-strip-types scripts/migrate-json.ts",
135
- "migrate:pg": "node --experimental-transform-types scripts/migrate-sqlite-to-pg.ts",
136
- "test:pg": "node scripts/test.mjs pg"
137
- },
138
- "devDependencies": {
139
- "@types/node": "^22.10.0",
140
- "@types/pg": "^8.23.1",
141
- "@vitejs/plugin-vue": "^6.0.10",
142
- "cortico": "^0.2.6",
143
- "embedded-postgres": "18.6.0-beta.19",
144
- "pg": "^8.23.1",
145
- "tsx": "^4.19.2",
146
- "typescript": "^5.7.2",
147
- "vite": "^8.3.5",
148
- "vitest": "^2.1.8",
149
- "vue": "^3.5.44",
150
- "vue-tsc": "^3.3.14"
121
+ "serve": "node --experimental-strip-types scripts/serve.ts"
151
122
  }
152
- }
123
+ }
@@ -29,7 +29,7 @@ export interface ReplayResponse {
29
29
  * 能不能玩需要新能力的游戏(狼人杀要 ≥ 0.29.0)。
30
30
  * 它跟 npm 包版本解耦——发新版时在这里抬一格即可(有测试盯着别忘)。
31
31
  */
32
- export const PARLOR_CLIENT_VERSION = '0.44.0';
32
+ export const PARLOR_CLIENT_VERSION = '0.45.0';
33
33
 
34
34
  export class ParlorHttpError extends Error {
35
35
  readonly status: number;
@@ -7,6 +7,8 @@ export const GAME_PRESENTATION = {
7
7
  xiangqi: { label: '中国象棋', icon: 'board' },
8
8
  monopoly2d: { label: '快局大富翁', icon: 'board' },
9
9
  aeroplane: { label: '飞行棋', icon: 'board' },
10
+ 'mahjong-sichuan': { label: '四川血战到底', icon: 'cards' },
11
+ 'mahjong-guangdong': { label: '广东推倒胡·红中', icon: 'cards' },
10
12
  } as const;
11
13
 
12
14
  export type GameId = keyof typeof GAME_PRESENTATION;
@@ -0,0 +1,57 @@
1
+ import { GAME_PRESENTATION } from '../game-labels.ts';
2
+ import type { GameDefinition } from './registry.ts';
3
+ import { MAHJONG_GAMES, MAHJONG_RULES, isTile, tileKinds, type MahjongGame } from './mahjong-rules.ts';
4
+ import { MAHJONG_ACTIONS, MahjongTable } from './mahjong-table.ts';
5
+
6
+ function definition(game: MahjongGame): GameDefinition {
7
+ const type = game + '_action';
8
+ const kinds = tileKinds(game);
9
+ const actions = MAHJONG_ACTIONS.filter(action => game === 'mahjong-sichuan'
10
+ || (action !== 'exchange' && action !== 'missing'));
11
+ const tile = { type: 'integer', minimum: 0, maximum: kinds - 1 };
12
+ const parse = (args: Record<string, unknown>) => {
13
+ const { action, windowId, tile, tiles, suit } = args;
14
+ if (typeof windowId !== 'string' || !/^m[1-9]\d{0,10}$/.test(windowId)) throw new Error('请带上当前 windowId');
15
+ if (!actions.some(name => name === action)) throw new Error('未知麻将动作');
16
+ const expected = action === 'exchange' ? 'tiles' : action === 'missing' ? 'suit' : action === 'discard' ? 'tile' : null;
17
+ if ((expected !== 'tiles' && tiles !== undefined) || (expected !== 'suit' && suit !== undefined)
18
+ || (expected !== 'tile' && action !== 'kong' && tile !== undefined)) throw new Error('动作带了多余的牌或花色参数');
19
+ if (action === 'exchange') {
20
+ if (!Array.isArray(tiles) || tiles.length !== 3 || !tiles.every(t => isTile(t, kinds))) throw new Error('exchange 需要三个牌号');
21
+ return { action, windowId, tiles };
22
+ }
23
+ if (action === 'missing') {
24
+ if (suit !== 0 && suit !== 1 && suit !== 2) throw new Error('missing 需要花色 0、1 或 2');
25
+ return { action, windowId, suit };
26
+ }
27
+ if ((action === 'discard' || tile !== undefined) && !isTile(tile, kinds)) throw new Error('牌号超出本玩法范围');
28
+ return { action, windowId, ...(tile !== undefined ? { tile } : {}) };
29
+ };
30
+ return {
31
+ id: game, rated: false, ...GAME_PRESENTATION[game],
32
+ openHint: '四席坐满开局。牌河公开,手牌、可用动作和提示见本人桌面。',
33
+ rules: MAHJONG_RULES[game],
34
+ create: ({ host, turnMs, firstSeat }) => new MahjongTable(game, host, turnMs, firstSeat),
35
+ randomizeFirstSeat: true,
36
+ actionType: type,
37
+ actionKey: 'action',
38
+ revisionMode: 'window',
39
+ toAction: parse,
40
+ availableActions: view => Array.isArray(view.actions) ? view.actions : [],
41
+ action: {
42
+ description: '所有动作带 windowId。exchange 传三张同门牌号 tiles;missing 传 suit(0 万、1 筒、2 条);discard 或手内 kong 传 tile;响应弃牌的 pung、kong、hu、pass 只传 windowId。牌号 0–26 为万、筒、条各 1–9;27–33 为东南西北中发白。',
43
+ parameters: {
44
+ type: 'object', additionalProperties: false,
45
+ properties: {
46
+ action: { type: 'string', enum: actions }, windowId: { type: 'string', maxLength: 12 },
47
+ tile, tiles: { type: 'array', items: tile }, suit: { type: 'integer', minimum: 0, maximum: 2 },
48
+ },
49
+ required: ['action', 'windowId'],
50
+ },
51
+ toBody: args => ({ type, ...parse(args) }),
52
+ done: () => '麻将动作已提交。',
53
+ },
54
+ };
55
+ }
56
+
57
+ export const MAHJONG_DEFINITIONS = MAHJONG_GAMES.map(definition);
@@ -0,0 +1,81 @@
1
+ export const MAHJONG_GAMES = ['mahjong-sichuan', 'mahjong-guangdong'] as const;
2
+ export type MahjongGame = typeof MAHJONG_GAMES[number];
3
+ export const SUITS = ['万', '筒', '条'] as const;
4
+ export const TILES = [
5
+ ...SUITS.flatMap(suit => Array.from({ length: 9 }, (_, rank) => (rank + 1) + suit)),
6
+ '东', '南', '西', '北', '红中', '发', '白',
7
+ ];
8
+ export const RED = 31;
9
+ export const tileKinds = (game: MahjongGame): number => game === 'mahjong-sichuan' ? 27 : 34;
10
+ export const suitOf = (tile: number): number => tile < 27 ? Math.floor(tile / 9) : -1;
11
+ export const isTile = (tile: unknown, kinds = TILES.length): tile is number =>
12
+ typeof tile === 'number' && Number.isInteger(tile) && tile >= 0 && tile < kinds;
13
+
14
+ const kongTiming = '碰后须先打牌;补杠和暗杠在自己的摸牌回合进行。';
15
+
16
+ export const MAHJONG_RULES: Record<MahjongGame, string[]> = {
17
+ 'mahjong-sichuan': [
18
+ '四人,万筒条 108 张。每人先换同一门的三张,本局随机顺换、对换或逆换;再各自定缺。有缺门牌时优先打完,缺门牌不能碰、杠或胡。',
19
+ '可碰、杠、自摸、点炮和一炮多响。胡者退出摸打,三家胡牌或牌墙耗尽后结算。四面子一对或七对可胡。',
20
+ kongTiming,
21
+ '自摸由其余仍在打的玩家各付 1 分;点炮由出牌者向每位胡家付 1 分。直杠由出牌者付 2 分;补杠、暗杠由其余仍在打的玩家各付 1 分、2 分。',
22
+ ],
23
+ 'mahjong-guangdong': [
24
+ '四人,万筒条、东南西北和中发白共 136 张。四张红中在组胡牌时可替任意牌,可打出,不能碰杠。',
25
+ '可碰、杠,只自摸;四面子一对或七对可胡。首家胡牌或牌墙耗尽即结算。',
26
+ kongTiming,
27
+ '自摸其余三家各付 1 分。直杠由出牌者付 2 分;补杠、暗杠由其余三家各付 1 分、2 分。',
28
+ ],
29
+ };
30
+
31
+ export function tileCounts(tiles: readonly number[], kinds: number): number[] {
32
+ const counts = Array<number>(kinds).fill(0);
33
+ for (const tile of tiles) counts[tile]++;
34
+ return counts;
35
+ }
36
+
37
+ /** 固定已副露的面子,只拆未公开的手牌。红中可补将、顺子或刻子。 */
38
+ export function canHu(game: MahjongGame, hand: readonly number[], melds: number, missing: number | null): boolean {
39
+ if (hand.length !== (4 - melds) * 3 + 2) return false;
40
+ if (game === 'mahjong-sichuan' && (missing === null || hand.some(tile => suitOf(tile) === missing))) return false;
41
+ const counts = tileCounts(hand, tileKinds(game));
42
+ const wild = game === 'mahjong-guangdong' ? counts[RED] : 0;
43
+ if (wild) counts[RED] = 0;
44
+ if (melds === 0 && counts.reduce((odd, count) => odd + count % 2, 0) <= wild) return true;
45
+
46
+ const failed = new Set<string>();
47
+ function groups(jokers: number): boolean {
48
+ const first = counts.findIndex(count => count > 0);
49
+ if (first < 0) return jokers % 3 === 0;
50
+ const key = counts.join('') + '/' + jokers;
51
+ if (failed.has(key)) return false;
52
+ for (let size = Math.min(3, counts[first]); size >= Math.max(1, 3 - jokers); size--) {
53
+ if (consume(Array<number>(size).fill(first), jokers - (3 - size))) return true;
54
+ }
55
+ if (first < 27) {
56
+ const base = suitOf(first) * 9;
57
+ for (let start = Math.max(base, first - 2); start <= Math.min(first, base + 6); start++) {
58
+ const others = [start, start + 1, start + 2].filter(tile => tile !== first);
59
+ for (const use of [[...others], [others[0]], [others[1]], []]) {
60
+ if (use.every(tile => counts[tile] > 0) && consume([first, ...use], jokers - (2 - use.length))) return true;
61
+ }
62
+ }
63
+ }
64
+ failed.add(key);
65
+ return false;
66
+ }
67
+
68
+ function consume(natural: readonly number[], jokers: number): boolean {
69
+ if (jokers < 0) return false;
70
+ for (const tile of natural) counts[tile]--;
71
+ const complete = groups(jokers);
72
+ for (const tile of natural) counts[tile]++;
73
+ return complete;
74
+ }
75
+
76
+ if (consume([], wild - 2)) return true;
77
+ return counts.some((count, tile) => {
78
+ if (!count) return false;
79
+ return (count >= 2 && consume([tile, tile], wild)) || consume([tile], wild - 1);
80
+ });
81
+ }