@wsl233/dsh-gomoku 0.0.0-stage → 0.3.1

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/README.md CHANGED
@@ -1,3 +1,146 @@
1
- # Temporary Holding Version
1
+ # dsh-gomoku
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ DeepSeek Harness(DSH)的五子棋插件。左侧栏增加「五子棋」入口,主页面提供棋盘、对手选择和对局操作。
4
+
5
+ > **当前状态:阶段 6(功能完整)。** 已安装到 DSH 插件管理器,支持本地双人、「大肥鱼」算法对战(简单 / 中等 / 困难)、局域网双人对战、DSH 模型服务驱动的 DeepSeek 对战,以及提示、复盘、保存 / 导入、撤销和新局。本目录是独立插件,不依赖也不修改网页版项目 `../`。
6
+
7
+ ## 安装
8
+
9
+ 已发布到 npm:`@wsl233/dsh-gomoku`。
10
+
11
+ ```bash
12
+ npm install -g @wsl233/dsh-gomoku
13
+ ```
14
+
15
+ DSH 插件管理器也可以直接安装该包;本机开发时使用
16
+ `plugin_manager install_bundle target="file:C:/Users/rache/Desktop/DENNIS/wuziqi/dsh-gomoku"`。
17
+
18
+ ## 预览
19
+
20
+ 不需要安装 DSH,也不需要构建工具,直接用浏览器打开:
21
+
22
+ ```text
23
+ dsh-gomoku/preview.html
24
+ ```
25
+
26
+ 可选查询参数:
27
+
28
+ | 参数 | 作用 |
29
+ | --- | --- |
30
+ | `demo=0` | 空盘、未选择对手的初始状态(默认 `demo=1` 展示示例棋局和思考提示) |
31
+ | `menu=1` | 打开右上角对手菜单(默认关闭) |
32
+
33
+ 也可以启动一个临时静态服务器后访问 `preview.html`:
34
+
35
+ ```powershell
36
+ npx --yes http-server . -p 8123 -c-1
37
+ # http://127.0.0.1:8123/preview.html?demo=1&menu=1
38
+ ```
39
+
40
+ 预览截图在 [`docs/`](./docs) 下:`ui-desktop.png`(算法对局)、`ui-idle.png`(空盘初始态)、`ui-menu.png`(对手菜单与难度)、`ui-narrow.png`(窄屏);局域网弹窗实际界面见阶段 3 后的版本。
41
+
42
+ ## 已实现的界面与对局(阶段 3)
43
+
44
+ - 白色 / 橙色主题,顶部品牌 + 图标操作条(新局、撤销、提示、复盘、保存、导入、全屏)。
45
+ - 顶部横条左侧有实时胜率胶囊(如「黑 50% · 白 50%」),每次落子、撤销或新局后即时更新。
46
+ - 中间 19×19 棋盘:坐标、星位、最后一手标记、悬停幽灵子、五连橙色连线。
47
+ - 左下角「你」头像,可点击改名;两侧头像为扁平白底、橙色描边的圆形;右上角对手头像带 `+` 徽标,点击展开对手菜单。
48
+ - **本地双人对战**:双方轮流落子,完整胜负与平局判定,撤销、新局可用。
49
+ - **与大肥鱼对战(算法)**:你执黑先行,大肥鱼执白自动应对;支持简单 / 中等 / 困难三档,困难档会主动加深搜索,简单局面自动降低深度。
50
+ - **局域网对战**:点「局域网对战」后插件会在本机启动服务端并生成加入链接 / 二维码;同一局域网内的另一台电脑打开链接即可执白加入,落子、胜负、重新开局实时同步。
51
+ - **与 DeepSeek 对战**:复用 DSH 已配置的模型服务,宿主端 `index.js` 的 `/dsh-gomoku/deepseek/move` 负责把紧凑棋谱发给模型、解析并校验落子;浏览器只拿到坐标,不接触 API Key。请求使用短提示词和 32 token 上限,棋盘下方可展开「DeepSeek 过程」查看模型、提示词、原始输出和用时;失败或超时会自动改用算法应对。
52
+ - 棋盘上沿的思考提示胶囊,显示当前深度;对局中 AI 思考时棋盘锁定。
53
+ - **提示**:调用 `Gomoku.AI.HINT` 搜索当前行棋方的最佳落子,在棋盘上用绿色圆圈标出,并提示坐标;局域网中只允许在自己的回合使用。
54
+ - **复盘**:棋盘下方出现「上一手 / 下一手 / 退出复盘」,可在 0 到终局之间回看,胜率胶囊随复盘局面更新;复盘时禁止落子。
55
+ - **导出 / 导入棋谱**:导出只生成一串 `GM1.` 开头的字符(压缩 JSON + base64url),并自动复制到剪贴板;导入时把该串粘贴进弹窗即可,同时兼容旧 JSON 棋谱和纯 moves 数组,会校验坐标、重复落子和满盘;未选择模式时自动进入本地双人继续。
56
+ - **对局保留**:DSH 面板离开再回来时会从 `localStorage` 恢复本地 / 人机棋局、昵称、难度和模式;局域网棋局不持久化。
57
+ - **全屏**:工具栏全屏按钮优先使用 Fullscreen API,失败时回退为覆盖视口的固定布局;只保留棋盘界面,等效隐藏 DSH 侧栏。
58
+ - **局域网**:昵称修改会实时同步;对局中禁用撤销和导入,避免双方状态不一致。
59
+
60
+ ## 局域网对战
61
+
62
+ - 服务端由宿主插件 `lan-server.js` 提供:在 `8790–8799` 中选空闲端口监听 `0.0.0.0`,同时提供加入页、静态 UI 和 `/ws` WebSocket;不依赖 npm 包,二维码由 `vendor/qrcode.mjs` 本地生成。
63
+ - 房间为 4 位数字;房主执黑先行,加入者执白;落子、胜负、五连连线、重新开局由服务端判定并广播。
64
+ - 加入链接形如 `http://<本机局域网 IP>:8790/lan.html?room=1234`;弹窗右侧可复制链接或展开二维码。
65
+ - 需要本机防火墙允许 Node/DSH 监听该端口;如果对方打不开,确认两台电脑在同一局域网,并把链接中的 IP 换成本机实际局域网 IP。
66
+ - `ui/lan.html` 是加入页;`lan.html?host=1` 仅用于本机联调(正常使用从 DSH 面板点击「局域网对战」)。
67
+
68
+ ## 算法引擎
69
+
70
+ `ui/engine/` 复制自网页版的规则与搜索实现,随插件独立打包:
71
+
72
+ - `board.js`:19×19 棋盘、落子 / 撤销、四方向五连判定。
73
+ - `evaluate.js`:棋型表增量评估(活四、冲四、活三等),黑视角分值。
74
+ - `ai.js`:negamax + alpha-beta + 迭代加深,主线程分时让出;困难档含强制着法、置换表、killer / history、叶子威胁延伸、自适应限深与提前终止。
75
+
76
+ 算法 AI 在 `ui/gomoku-ui.js` 中通过 `triggerAI()` 调用,失败或超时会给出提示,不会卡死界面。
77
+
78
+ ## 胜率估算
79
+
80
+ 顶部「黑 xx% · 白 xx%」胶囊来自 `computeWinRate()`:用 `Gomoku.Evaluate.Engine` 对当前棋盘做增量棋型评估,取黑视角分值,再用 `winRateFromBlackScore()` 的 sigmoid 映射到 0–100%,白方为 `100 - 黑方`。这是局面启发式估算,不是严格胜率,也不额外发起搜索,因此落子后能立即更新;胜 / 负 / 和棋会直接显示 100% / 0% / 50%。
81
+
82
+ ## 目录结构
83
+
84
+ ```text
85
+ dsh-gomoku/
86
+ ├─ package.json DSH 插件清单(Host / Client 双入口)
87
+ ├─ cordis.patch.yml DSH bundle 插入配置
88
+ ├─ index.js Host 入口:静态资源 + 局域网信息 / 二维码路由
89
+ ├─ lan-server.js 局域网服务端:HTTP 加入页 + 原生 WebSocket 房间
90
+ ├─ client.js Client 入口:注册侧栏行与主面板
91
+ ├─ preview.html 独立 UI 预览页(不依赖 DSH)
92
+ ├─ ui/
93
+ │ ├─ gomoku.css 白 / 橙主题与响应式样式
94
+ │ ├─ gomoku-ui.js 共享 UI 控制器(纯 DOM + canvas)
95
+ │ ├─ lan.html 局域网加入页
96
+ │ └─ engine/ 规则与算法(board / evaluate / ai)
97
+ ├─ vendor/
98
+ │ └─ qrcode.mjs 二维码生成(MIT,随插件打包)
99
+ ├─ assets/
100
+ │ └─ dsniang.png 大肥鱼头像
101
+ ├─ docs/ 预览截图
102
+ └─ README.md
103
+ ```
104
+
105
+ ## 在 DSH 中安装
106
+
107
+ 当前已通过 DSH 插件管理器安装为 `dsh-gomoku@0.2.0`,安装后左侧栏会多出「五子棋」入口;如果界面没有更新,刷新或重启 DSH 客户端。
108
+
109
+ 本地重新安装:
110
+
111
+ ```text
112
+ plugin_manager install_bundle target="file:C:/Users/rache/Desktop/DENNIS/wuziqi/dsh-gomoku"
113
+ ```
114
+
115
+ 插件管理器安装的是文件副本,源码修改后需要重新安装(或同步 `~/.dsh/profiles/desktop/node_modules/dsh-gomoku`)才会进入 DSH。
116
+
117
+ ## 后续阶段
118
+
119
+ | 阶段 | 内容 |
120
+ | --- | --- |
121
+ | 1 | UI 预览:布局、头像菜单、棋盘绘制、思考提示、局域网弹窗占位(已完成) |
122
+ | 2 | 本地安装、棋局规则、本地双人、算法 AI 三档、撤销(已完成) |
123
+ | 3 | 局域网对战:本机 HTTP + WebSocket 服务端、房间号、链接 / 二维码、实时落子与重开(已完成) |
124
+ | 4 | DeepSeek 对战:复用 DSH 已配置模型服务,棋盘 JSON 请求、返回坐标校验、失败提示(已完成) |
125
+ | 5 | 提示 / 复盘 / 保存 / 导入、README 完整化、测试与发布检查(已完成) |
126
+ | 6 | DeepSeek 省 token、过程输出、对局保留、单串棋谱、全屏(已完成) |
127
+
128
+ ## 开发检查
129
+
130
+ ```powershell
131
+ node --check index.js
132
+ node --check client.js
133
+ node --check ui/gomoku-ui.js
134
+ node --check ui/engine/board.js
135
+ node --check ui/engine/evaluate.js
136
+ node --check ui/engine/ai.js
137
+ node --check lan-server.js
138
+ ```
139
+
140
+ UI 预览不发送网络请求;局域网模式下由 `lan-server.js` 提供 HTTP / WebSocket 服务;DeepSeek 模式通过宿主路由调用 DSH 的 `llm` 服务。
141
+
142
+ ## 说明
143
+
144
+ - 不修改 `../` 下的网页版项目;`introduction.md` 也不再更新。
145
+ - 本阶段没有引入任何第三方运行时依赖,DSH 只加载 `react` 与宿主服务。
146
+ - 头像素材来自用户提供、已随插件打包。
Binary file
package/client.js ADDED
@@ -0,0 +1,212 @@
1
+ /**
2
+ * dsh-gomoku — Client half.
3
+ *
4
+ * Registers:
5
+ * - a sidebar row (sidebar.panellist) labelled 五子棋;
6
+ * - a main panel (main, key "gomoku") that mounts the shared plain-DOM UI.
7
+ *
8
+ * The UI itself lives in ui/gomoku-ui.js so the exact same code can be loaded
9
+ * by preview.html outside DSH. This file only bridges React slots to that UI.
10
+ *
11
+ * Phase 1: no game logic, no network, no AI. The panel is a visual preview.
12
+ */
13
+
14
+ window.__ModuleLoader__.load({
15
+ id: 'dsh-gomoku',
16
+ factory(require) {
17
+ 'use strict';
18
+
19
+ const React = require('react');
20
+ const h = React.createElement;
21
+
22
+ const PANEL_ID = 'gomoku';
23
+ const UI_BASE = '/dsh-gomoku';
24
+ const STYLE_ID = 'dsh-gomoku-style';
25
+ const UI_VERSION = '0.2.0-25';
26
+ const withVersion = (src) => src + '?v=' + UI_VERSION;
27
+
28
+ let scriptPromise = null;
29
+ const ENGINE_FILES = ['board.js', 'evaluate.js', 'ai.js'];
30
+
31
+ function loadScript(src) {
32
+ return new Promise((resolve, reject) => {
33
+ const script = document.createElement('script');
34
+ script.src = src;
35
+ script.async = false;
36
+ script.onload = () => resolve();
37
+ script.onerror = () => reject(new Error('无法加载脚本:' + src));
38
+ document.head.appendChild(script);
39
+ });
40
+ }
41
+
42
+ function ensureEngine() {
43
+ if (
44
+ window.Gomoku &&
45
+ window.Gomoku.__build === UI_VERSION &&
46
+ window.Gomoku.AI &&
47
+ window.Gomoku.Board
48
+ ) {
49
+ return Promise.resolve();
50
+ }
51
+ delete window.Gomoku;
52
+ return ENGINE_FILES.reduce(
53
+ (chain, file) => chain.then(() => loadScript(withVersion(UI_BASE + '/ui/engine/' + file))),
54
+ Promise.resolve(),
55
+ ).then(() => {
56
+ window.Gomoku.__build = UI_VERSION;
57
+ });
58
+ }
59
+
60
+ function ensureStyle() {
61
+ let link = document.getElementById(STYLE_ID);
62
+ if (!link) {
63
+ link = document.createElement('link');
64
+ link.id = STYLE_ID;
65
+ link.rel = 'stylesheet';
66
+ document.head.appendChild(link);
67
+ }
68
+ const href = withVersion(UI_BASE + '/ui/gomoku.css');
69
+ if (link.getAttribute('href') !== href) link.href = href;
70
+ }
71
+
72
+ function loadUiScript() {
73
+ if (
74
+ window.DshGomokuUI &&
75
+ window.DshGomokuUI.version === UI_VERSION &&
76
+ typeof window.DshGomokuUI.mount === 'function'
77
+ ) {
78
+ return Promise.resolve();
79
+ }
80
+ if (scriptPromise) return scriptPromise;
81
+ scriptPromise = ensureEngine().then(
82
+ () =>
83
+ new Promise((resolve, reject) => {
84
+ const script = document.createElement('script');
85
+ script.src = withVersion(UI_BASE + '/ui/gomoku-ui.js');
86
+ script.async = true;
87
+ script.onload = () => resolve();
88
+ script.onerror = () => reject(new Error('无法加载五子棋界面资源'));
89
+ document.head.appendChild(script);
90
+ }),
91
+ );
92
+ return scriptPromise;
93
+ }
94
+
95
+ function SidebarIcon() {
96
+ return h(
97
+ 'svg',
98
+ {
99
+ viewBox: '0 0 24 24',
100
+ width: 22,
101
+ height: 22,
102
+ fill: 'none',
103
+ stroke: 'currentColor',
104
+ strokeWidth: 1.6,
105
+ strokeLinecap: 'round',
106
+ 'aria-hidden': 'true',
107
+ },
108
+ h('rect', { x: 3.5, y: 3.5, width: 17, height: 17, rx: 4 }),
109
+ h('path', { d: 'M9 3.8v16.4M15 3.8v16.4M3.8 9h16.4M3.8 15h16.4' }),
110
+ h('circle', { cx: 9, cy: 9, r: 1.8, fill: 'currentColor', stroke: 'none' }),
111
+ h('circle', { cx: 15, cy: 15, r: 1.8, fill: 'none', stroke: 'currentColor', strokeWidth: 1.4 }),
112
+ );
113
+ }
114
+
115
+ function GomokuPanel() {
116
+ const hostRef = React.useRef(null);
117
+
118
+ React.useEffect(() => {
119
+ let disposed = false;
120
+ let unmount = null;
121
+
122
+ ensureStyle();
123
+
124
+ loadUiScript()
125
+ .then(() => {
126
+ if (disposed || !hostRef.current) return;
127
+ if (!window.DshGomokuUI || typeof window.DshGomokuUI.mount !== 'function') {
128
+ throw new Error('五子棋界面模块未初始化');
129
+ }
130
+ unmount = window.DshGomokuUI.mount(hostRef.current, {
131
+ demo: false,
132
+ preview: false,
133
+ assetBase: UI_BASE + '/assets/',
134
+ });
135
+ })
136
+ .catch((error) => {
137
+ console.warn('[dsh-gomoku]', error);
138
+ if (disposed || !hostRef.current) return;
139
+ hostRef.current.innerHTML =
140
+ '<div style="padding:48px 24px;text-align:center;color:#9a5b27;font:14px/1.7 \'Segoe UI\',\'Microsoft YaHei\',sans-serif;">' +
141
+ '五子棋界面加载失败。请重启 DSH 后再试。<br><span style="font-size:12px;color:#b9a99a;">' +
142
+ String(error && error.message ? error.message : error) +
143
+ '</span></div>';
144
+ });
145
+
146
+ return () => {
147
+ disposed = true;
148
+ if (typeof unmount === 'function') {
149
+ try {
150
+ unmount();
151
+ } catch (error) {
152
+ console.warn('[dsh-gomoku] unmount failed:', error);
153
+ }
154
+ }
155
+ if (scriptPromise) {
156
+ // Keep the loaded script for fast remounts; only clear a failed load.
157
+ scriptPromise.catch(() => {
158
+ scriptPromise = null;
159
+ });
160
+ }
161
+ };
162
+ }, []);
163
+
164
+ return h('div', {
165
+ className: 'gk-plugin-root',
166
+ ref: hostRef,
167
+ style: { minHeight: '100%', width: '100%', background: '#fff' },
168
+ }, h('div', {
169
+ style: {
170
+ padding: '64px 24px',
171
+ textAlign: 'center',
172
+ color: '#9a5b27',
173
+ font: '14px/1.7 "Segoe UI","Microsoft YaHei",sans-serif',
174
+ },
175
+ }, '正在准备棋盘…'));
176
+ }
177
+
178
+ function apply(ctx) {
179
+ try {
180
+ ctx.slots.inject('sidebar.panellist', () =>
181
+ ctx.slots.register(
182
+ {
183
+ name: 'sidebar.panellist',
184
+ id: PANEL_ID,
185
+ order: 6,
186
+ label: () => '五子棋',
187
+ },
188
+ SidebarIcon,
189
+ ),
190
+ );
191
+ } catch (error) {
192
+ console.warn('[dsh-gomoku] sidebar row registration failed:', error);
193
+ }
194
+
195
+ try {
196
+ ctx.slots.inject('main', () =>
197
+ ctx.slots.register(
198
+ {
199
+ name: 'main',
200
+ key: PANEL_ID,
201
+ },
202
+ GomokuPanel,
203
+ ),
204
+ );
205
+ } catch (error) {
206
+ console.warn('[dsh-gomoku] main panel registration failed:', error);
207
+ }
208
+ }
209
+
210
+ return { inject: ['slots'], apply, name: 'dsh-gomoku' };
211
+ },
212
+ });
@@ -0,0 +1,7 @@
1
+ # ============================================================================
2
+ # dsh-gomoku — DSH bundle patch
3
+ # ============================================================================
4
+ # 把五子棋插件插入 desktop profile 的配置树。安装后需要重启 / 刷新 DSH。
5
+ - insert:
6
+ - id: dsh-gomoku
7
+ name: '@wsl233/dsh-gomoku'
Binary file
Binary file
Binary file
Binary file
Binary file