koishi-plugin-cchess 0.0.2 → 0.0.4
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/lib/index.d.ts +1 -0
- package/lib/index.js +34 -9
- package/package.json +2 -2
- package/readme.md +10 -8
package/lib/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export interface Config {
|
|
|
9
9
|
boardSkin: string;
|
|
10
10
|
pieceSkin: string;
|
|
11
11
|
defaultEngineThinkingDepth: number;
|
|
12
|
+
allowFreePieceMovementInHumanMachineMode: boolean;
|
|
12
13
|
defaultMaxLeaderboardEntries: number;
|
|
13
14
|
retractDelay: number;
|
|
14
15
|
isChessImageWithOutlineEnabled: boolean;
|
package/lib/index.js
CHANGED
|
@@ -59,6 +59,7 @@ const boardSkins = ["棋弈无限红绿棋盘", "一鸣惊人棋盘", "三星堆
|
|
|
59
59
|
exports.Config = koishi_1.Schema.object({
|
|
60
60
|
boardSkin: koishi_1.Schema.union(boardSkins).default('木制棋盘').description(`棋盘皮肤。`),
|
|
61
61
|
pieceSkin: koishi_1.Schema.union(pieceSkins).default('木制棋子').description(`棋子皮肤。`),
|
|
62
|
+
allowFreePieceMovementInHumanMachineMode: koishi_1.Schema.boolean().default(false).description(` 是否允许在人机模式下自由移动棋子,开启后可以不需要加入游戏直接开始玩人机模式。`),
|
|
62
63
|
defaultEngineThinkingDepth: koishi_1.Schema.number().min(0).max(100).default(10).description(`默认引擎思考深度,越高 AI 棋力越强。由于 Nodejs 不支持 SIMD,所以不建议设置过高。`),
|
|
63
64
|
defaultMaxLeaderboardEntries: koishi_1.Schema.number().min(0).default(10).description(`显示排行榜时默认的最大人数。`),
|
|
64
65
|
retractDelay: koishi_1.Schema.number().min(0).default(0).description(`自动撤回等待的时间,单位是秒。值为 0 时不启用自动撤回功能。`),
|
|
@@ -174,16 +175,28 @@ function apply(ctx, config) {
|
|
|
174
175
|
});
|
|
175
176
|
// zjj*
|
|
176
177
|
ctx.middleware(async (session, next) => {
|
|
177
|
-
let { channelId, content, userId } = session;
|
|
178
|
+
let { channelId, content, userId, username } = session;
|
|
178
179
|
const gameRecord = await getGameRecord(channelId);
|
|
179
180
|
if (!gameRecord.isStarted) {
|
|
180
181
|
return await next();
|
|
181
182
|
}
|
|
182
|
-
|
|
183
|
-
if (playerRecord.length === 0) {
|
|
184
|
-
|
|
183
|
+
let playerRecord = await ctx.database.get('cchess_gaming_player_records', { channelId, userId });
|
|
184
|
+
if (playerRecord.length === 0 && !config.allowFreePieceMovementInHumanMachineMode) {
|
|
185
|
+
if (!(gameRecord.isEnginePlayRed || gameRecord.isEnginePlayBlack)) {
|
|
186
|
+
return await next();
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
if (gameRecord.isEnginePlayRed) {
|
|
190
|
+
await ctx.database.create('cchess_gaming_player_records', { channelId, userId, username, side: '黑方' });
|
|
191
|
+
playerRecord = await ctx.database.get('cchess_gaming_player_records', { channelId, userId });
|
|
192
|
+
}
|
|
193
|
+
else if (gameRecord.isEnginePlayBlack) {
|
|
194
|
+
await ctx.database.create('cchess_gaming_player_records', { channelId, userId, username, side: '红方' });
|
|
195
|
+
playerRecord = await ctx.database.get('cchess_gaming_player_records', { channelId, userId });
|
|
196
|
+
}
|
|
197
|
+
}
|
|
185
198
|
}
|
|
186
|
-
|
|
199
|
+
if (playerRecord.length !== 0) {
|
|
187
200
|
const turn = gameRecord.turn;
|
|
188
201
|
const sideString = turn === 'w' ? '红方' : '黑方';
|
|
189
202
|
if (playerRecord[0].side !== sideString) {
|
|
@@ -349,7 +362,7 @@ function apply(ctx, config) {
|
|
|
349
362
|
let blackPlayers = getPlayerRecords.filter((player) => player.side === '黑方');
|
|
350
363
|
let message = '';
|
|
351
364
|
let AISide = '';
|
|
352
|
-
if (playersNum < 1) {
|
|
365
|
+
if (playersNum < 1 && !config.allowFreePieceMovementInHumanMachineMode) {
|
|
353
366
|
return await sendMessage(session, `【@${username}】\n当前玩家人数不足 1 人,无法开始游戏!`);
|
|
354
367
|
}
|
|
355
368
|
else {
|
|
@@ -462,11 +475,23 @@ function apply(ctx, config) {
|
|
|
462
475
|
}
|
|
463
476
|
const turn = gameRecord.turn;
|
|
464
477
|
const sideString = convertTurnToString(turn);
|
|
465
|
-
|
|
478
|
+
let playerRecord = await ctx.database.get('cchess_gaming_player_records', { channelId, userId });
|
|
466
479
|
if (playerRecord.length === 0) {
|
|
467
|
-
|
|
480
|
+
if (config.allowFreePieceMovementInHumanMachineMode) {
|
|
481
|
+
if (gameRecord.isEnginePlayRed) {
|
|
482
|
+
await ctx.database.create('cchess_gaming_player_records', { channelId, userId, username, side: '黑方' });
|
|
483
|
+
playerRecord = await ctx.database.get('cchess_gaming_player_records', { channelId, userId });
|
|
484
|
+
}
|
|
485
|
+
else if (gameRecord.isEnginePlayBlack) {
|
|
486
|
+
await ctx.database.create('cchess_gaming_player_records', { channelId, userId, username, side: '红方' });
|
|
487
|
+
playerRecord = await ctx.database.get('cchess_gaming_player_records', { channelId, userId });
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
else {
|
|
491
|
+
return await sendMessage(session, `【@${username}】\n您还未加入游戏呢!`);
|
|
492
|
+
}
|
|
468
493
|
}
|
|
469
|
-
|
|
494
|
+
if (playerRecord[0].side !== sideString) {
|
|
470
495
|
return await sendMessage(session, `【@${username}】\n还没轮到${sideString}走棋哦!\n当前走棋方为:【${convertTurnToString(gameRecord.turn)}】`);
|
|
471
496
|
}
|
|
472
497
|
await checkEngine(channelId);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-cchess",
|
|
3
|
-
"description": "
|
|
4
|
-
"version": "0.0.
|
|
3
|
+
"description": "欢迎来到中国象棋游戏,支持人人/人机对战、纵线/坐标操作方式、编辑棋盘、导入/导出FEN等功能,提供 40+ 棋盘/棋子皮肤及排行榜系统。🎪",
|
|
4
|
+
"version": "0.0.4",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
package/readme.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
## 🎐 简介
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
欢迎来到中国象棋游戏,支持人人/人机对战、纵线/坐标操作方式、编辑棋盘、导入/导出FEN等功能,提供 40+ 棋盘/棋子皮肤及排行榜系统。🎪
|
|
8
8
|
|
|
9
9
|
## 🎉 安装
|
|
10
10
|
|
|
@@ -14,17 +14,19 @@
|
|
|
14
14
|
|
|
15
15
|
- 建议自行添加别名,如 `cc` 等更方便的指令。
|
|
16
16
|
- 请安装并启用所需服务,`canvas` 服务可使用 `puppeteer` 提供。
|
|
17
|
-
-
|
|
17
|
+
-
|
|
18
|
+
支持使用中国象棋纵线(炮二平五/炮8平5)和字母坐标(a0a1)进行移动。[了解详情 - 中国象棋着法表示](https://www.xqbase.com/protocol/cchess_move.htm)
|
|
18
19
|
|
|
19
20
|
## ⚙️ 配置项
|
|
20
21
|
|
|
21
|
-
- `boardSkin`: 棋盘皮肤,可选值有:木制棋盘、玉石太极棋盘等数十种精美皮肤。
|
|
22
|
-
- `pieceSkin`: 棋子皮肤,可选值有:红黑棋子、隶书棋子等数十种不同风格。
|
|
23
|
-
- `defaultEngineThinkingDepth`: 默认 AI 思考深度,数值越大棋力越强,但耗费资源也更多。
|
|
24
|
-
- `retractDelay`: 自动撤回等待时间(秒),设为0则不自动撤回。
|
|
25
22
|
- `imageType`: 发送图片类型,可选 `png/jpeg/webp`。
|
|
23
|
+
- `retractDelay`: 自动撤回等待时间(秒),设为0则不自动撤回。
|
|
24
|
+
- `pieceSkin`: 棋子皮肤,可选值有:红黑棋子、隶书棋子等数十种不同风格。
|
|
26
25
|
- `isTextToImageConversionEnabled`: 是否开启文字转图片功能(可选)。
|
|
26
|
+
- `boardSkin`: 棋盘皮肤,可选值有:木制棋盘、玉石太极棋盘等数十种精美皮肤。
|
|
27
|
+
- `defaultEngineThinkingDepth`: 默认 AI 思考深度,数值越大棋力越强,但耗费资源也更多。
|
|
27
28
|
- `isChessImageWithOutlineEnabled`:是否为象棋图片添加辅助外框,关闭后可以显著提升图片速度,但无辅助外框,玩起来可能会比较累。
|
|
29
|
+
- `allowFreePieceMovementInHumanMachineMode`: 是否允许在人机模式下自由移动棋子,开启后可以不需要加入游戏直接开始玩人机模式。
|
|
28
30
|
|
|
29
31
|
## 🌼 指令
|
|
30
32
|
|
|
@@ -43,11 +45,11 @@
|
|
|
43
45
|
|
|
44
46
|
## 🍧 致谢
|
|
45
47
|
|
|
46
|
-
- [Koishi](https://koishi.chat/) - 出色的机器人框架 🤖
|
|
47
48
|
- [风满楼]() - 提供棋盘与棋子素材 🎨
|
|
49
|
+
- [Koishi](https://koishi.chat/) - 出色的机器人框架 🤖
|
|
48
50
|
- [皮卡鱼网页版](https://xiangqiai.com/#/) - 强大的象棋引擎 🐟
|
|
49
|
-
- [中国象棋电脑应用规范](https://www.xqbase.com/protocol/cchess_intro.htm) - 遵循标准规范 📜
|
|
50
51
|
- [中国象棋云库查询](https://www.chessdb.cn/query/) - 囊括海量棋谱 📖
|
|
52
|
+
- [中国象棋电脑应用规范](https://www.xqbase.com/protocol/cchess_intro.htm) - 遵循标准规范 📜
|
|
51
53
|
|
|
52
54
|
## ✨ License
|
|
53
55
|
|