- Home
- Plugins
- Just for Fun
- dsh-mahjong-solo
dsh-mahjong-solo
dingchenhui0618-arch/dsh-mahjong-solo
Solo Sichuan mahjong (血战到底) in the Harness sidebar: one human against three AI players, with the full local rule set — 108 tiles with no honours, a forced void suit (定缺) that also forbids peng/gang of that suit, no chi, winners leave the table while the rest play on, multiple winners on one discard, wall-empty settlement (查大叫 / 查花猪) and per-gang payments. Fan is additive (平胡 / 对对胡 / 七对 / 龙七对 plus 清一色 / 金钩钓 / 根 / 杠上花 / 杠上炮 / 海底捞月 / 自摸) and capped at 8. A hand is determined by its seed plus the actions the human took: the wall comes from mulberry32, and the AI random stream lives in serialisable game state that is part of the state hash, so the same seed and the same action list replay the identical hand. At the end the record is written to JSON (initial wall, every event, settlement, tenpai and deal-in stats); the replay panel steps or scrubs through it and verifies the state hash, the recorded wall and the event list. Zero-dependency build (src to lib with the client CSS inlined), node --test covers engine, golden vectors and host routes, and a preflight script scans for secrets, checks .gitignore and hunts stray files before pushing. Its HTTP routes have no DSH access check, so a web page open in your browser could call them.
Install
dsh plugin --profile web add github:dingchenhui0618-arch/dsh-mahjong-soloREADME
dsh-mahjong-solo
DeepSeek Harness 侧栏里的单机四川麻将·血战到底:你一家、AI 三家,规则完整;一局由种子唯一确定,同一个种子可以把整局一步步复盘;局末导出牌谱 JSON,并给出听牌/放铳统计。

它是什么
- 侧栏入口:左侧栏点「麻将」进入牌桌。不改会话、不弹窗、不打扰正在跑的对话。
- 血战到底:定缺、缺一门才能和、不能吃只能碰/杠、一家和牌后离场、其余三家继续打,直到三家胡完或牌墙摸空。
- 固定种子:种子决定牌墙;AI 的每个决策也来自同一可序列化随机流。同一
seed+ 同一串人类动作 = 完全相同的一局。 - 可复盘:局末牌谱只记
seed与人类动作,复盘时由引擎重算整局——包括 AI 的每一步——并用状态哈希校验。复盘面板能按事件前后步进、拖进度条、自动播放。 - 导出与统计:牌谱 JSON 含初始牌墙、全部事件、结算明细、听牌/放铳/自摸统计;落盘到
$DSH_HOME/mahjong-solo/,也能一键下载。 - 规则开关:多响(一炮多响)、流局查大叫、查花猪,可开可关。
为什么同一局能完整复盘
createGame({seed})用mulberry32(seed)洗出 108 张牌墙,种子相同牌墙就相同。- AI 不调用
Math.random():随机流存在game.ai.state里,随每一步推进,并且进入状态哈希。 - 人类动作单独记进
humanActions;复盘只喂seed + humanActions重算,AI 动作由引擎按同一条流重放。 - 重算结束的
hashState(game)必须等于牌谱里记录的hash——POST /replay会把它作为verified返回,界面显示「校验通过 / 校验失败」。牌谱里的seedWall与events也会和重算结果逐项对比(wallVerified/eventsVerified),所以改过牌谱再复盘会被判失败,而不是只看一个状态哈希。
这也是测试里最硬的一条断言:整局自动托管后,用种子重放得到的哈希必须与记录逐字节一致。

规则与结算
牌:万/条/筒三门,每门 1–9,各 4 张,共 108 张;无字牌、无花牌。
流程:洗牌发牌(每家 13 张)→ 定缺(每人选一门必须缺的花色)→ 庄家摸牌出牌 → 其他家可碰/杠/胡 → 和牌者离场,其余继续 → 三家胡完或牌墙摸空结束。
和牌:缺一门(手牌与副露都不能有定缺花色)+ 四副面子一将,或七对/龙七对。
番表(加法叠加,默认上限 8 番;points = 2^(min(fan, capFan) - 1)):
| 牌型 | 番 |
|---|---|
| 平胡 | 1 |
| 对对胡 | 2 |
| 七对 | 4 |
| 龙七对(七对里带四张同牌) | 8 |
| 清一色(含副露) | +4 |
| 金钩钓(四副全亮、单吊将) | +2 |
| 根(每个已声明的杠) | +1 |
| 杠上花 / 杠上炮 / 海底捞月 / 自摸 | 各 +1 |
结算:点炮者付分,自摸其他未离场者各付;明杠每家 1 分、暗杠 2 分、补杠 1 分(刮风下雨,立即结算);流局时查花猪(三门齐全者付每家 8 分)、查大叫(未听牌者付每个听牌者 4 分)。

安装
dsh plugin --profile <你的 profile> add github:dingchenhui0618-arch/dsh-mahjong-solo
桌面端直接在应用内安装插件,profile 由应用自己管理。装好后左侧栏出现「麻将」图标。
怎么玩
- 点左侧栏「麻将」,填入种子(留空即随机)后点「开新局」;种子相同牌墙就相同,想复现某一局就填那一局的种子。
- 按提示定缺一门,然后轮到你时点手牌打出;听牌时牌桌上方显示听哪几张、还剩几张。
- 别人打出的牌能碰/杠/胡时,底部出现按钮;不想要就点「过」。
- 想快速看结果或做演示,点「托管到底」:AI 接手你的座位(包括你自己的出牌决策)一路打到局末。
- 局末:看四家结算与统计 → 导出牌谱(下载 JSON)→ 复盘(按事件步进/自动播放)。
牌谱 JSON
{
"app": "dsh-mahjong-solo",
"version": 1,
"seed": 759487739,
"humanSeat": 0,
"rules": { "duoXiang": true, "chaDaJiao": true, "huaZhu": true, "capFan": 8 },
"createdAt": "2026-11-27T06:04:47.741Z",
"finishedAt": "2026-11-27T06:21:32.045Z",
"humanActions": [ { "type": "lack", "suit": 2 }, { "type": "discard", "tile": 20 } ],
"events": [ { "i": 0, "type": "lack", "seat": 0, "tile": null, "text": "你 定缺 筒", "human": true } ],
"seedWall": [ "...108 张初始牌墙..." ],
"hash": "9b5524fba179864c…",
"result": {
"reason": "three-won",
"winners": [ { "seat": 3, "tile": 24, "from": 2, "selfDraw": false, "fan": 2, "points": 2, "patterns": [ "平胡", "根" ] } ],
"settlement": [ { "kind": "win", "from": 2, "to": 3, "points": 2, "fan": 2, "selfDraw": false, "tile": 24 } ]
},
"stats": {
"hands": 1,
"winners": [ { "seat": 3, "tile": 24, "from": 2, "selfDraw": false, "fan": 2, "points": 2, "patterns": [ "平胡", "根" ] } ],
"dealIns": [ { "seat": 2, "tile": 21, "victim": 1 } ],
"fanTotal": 4,
"fanAverage": 1.33,
"perSeat": [ { "seat": 0, "points": 0, "wins": 1, "selfDraws": 0, "dealIns": 0, "tenpaiAtEnd": false, "wasTenpai": true, "fanTotal": 1 } ]
}
}
result.reason 只有两种:three-won(三家胡完)和 wall-empty(牌墙摸空流局)。events[].text 是引擎直接给的旁白,界面与导出共用同一份。
perSeat 口径:points 净得分、wins 和牌次数、selfDraws 自摸次数、dealIns 放铳次数、wasTenpai 本局是否听牌过、tenpaiAtEnd 流局时是否听牌、fanTotal 番数合计;fanAverage 是全部和牌的平均番。跨局累计统计在 $DSH_HOME/mahjong-solo/stats.json。
边界(明确没做的)
- 没有换三张、抢杠胡、过水/过手、天胡/地胡,也没有「将对/幺九/门清」这类地方番型加成。
- 一局一档:不做连庄、不做多局累计积分排行(累计统计只做跨局汇总)。
- AI 是确定性规则策略,不是模型;它只保证合法、会优先打缺门、会保听牌,不保证打得最好。
- 不联网、不联机、不写会话内容。
独立实现与参考
- 骨架照抄本机
dsh-warden的工程结构:零依赖构建(scripts/build.mjs拷贝src/到lib/并内联客户端样式)、cordis.patch.yml、host/client 双半区、CI、node --test测试结构;scripts/wrap-client.mjs沿用该骨架的包装方式。 - 侧栏注册写法参考了本机已装的
dsh-in-hand(sidebar.panellist+main的注册方式)。只参考注册模式,没有复制它的业务代码。 - 规则引擎(和牌/听牌/番表)、对局状态机、AI、统计、复盘、面板与样式均为本项目自写;没有 fork、没有 clone 任何仓库在其上修改、没有整段搬运他人代码。
- 生态现状:开工时本地
awesome-dsh-plugin索引里的 12,203 个插件条目中没有 mahjong / 麻将;GitHub 搜索也没有返回 DSH 麻将插件。日报里这条方向标注的是「无直接证据」,这里只陈述上述已核实的检索结果,不把它当成「全生态都没有」的既成事实。
开发
node scripts/build.mjs # 零依赖构建,产出 lib/
node --test # 引擎 + 黄金用例 + host 路由测试
node scripts/preflight.mjs # 推送前三步检查:密钥扫描 / .gitignore 核对 / 无关文件
lib/ 是构建产物且入库(安装时不需要构建);改 src/ 后必须重新 build。
License
MIT
Related plugins
dsh-web-ui (dsh-pet)
zhu1090093659/dsh-web-ui
dsh-pet (dsh-pet)
pc2005-cloud/dsh-pet
dsh-tavern (dsh-tavern)
flizzywine/dsh-tavern
dsh-tavern (dsh-profile-bridge)
flizzywine/dsh-tavern