# @fortemate/dicechess-engine-wasm 中文文档

规范地址：https://npmcn.com/package/%40fortemate/dicechess-engine-wasm/

版本：0\.18\.4
npm 元数据更新时间：2026-11-13T13:54:29.010Z
中文译文更新时间：2026-11-15T17:53:10.467Z
软件包许可：AGPL-3\.0-only

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40fortemate/dicechess-engine-wasm
原文对照：https://npmcn.com/package/%40fortemate/dicechess-engine-wasm/?lang=original
项目主页：https://fortemate.com/
源码仓库：https://github.com/fortemate/dicechess-engine

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：1.1 MB，8 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- Node.js 要求：\>=18
- 运行依赖：0 个
- 首次发布：2026-08-19T19:41:22.580Z
- 最新版本发布：2026-11-13T13:54:28.671Z
- 近 30 天下载量：2007（2026-10-16 至 2026-11-14，npm 官方下载统计）
- 已发布版本数：39（近 12 个月 39 个）

## 中文简介

高性能 Dice 国际象棋引擎和移动生成器编译到ES模块和WebAssembly

## 安装

```sh
npm install @fortemate/dicechess-engine-wasm
```

也可以使用：`pnpm add @fortemate/dicechess-engine-wasm`、`yarn add @fortemate/dicechess-engine-wasm`、`bun add @fortemate/dicechess-engine-wasm`

## README

# @fortemate/dicechess-engine ###################################################################################################################################################################################################################################################

高性能、跨平台游戏引擎和移动生成器 **双子棋**,被编译为纯Javascript (ES Modules),并附有完整的TypeScript类型声明.

为网页浏览器,混合应用程序,和Node.js服务器中的最大性能所设计.

* * *

## 安装

通过 npm 或您喜欢的软件包管理器从 npmjs.org 安装软件包 。 没有登记册映射或 需要认证令牌 :

```bash
npm install @fortemate/dicechess-engine
```

还可以从 [GitHub 软件包](https://github.com/fortemate/dicechess-engine/pkgs/npm/dicechess-engine)。 。 。 .

* * *

## 两个条目: 整个引擎,或仅规则

套件有两个切入点. 他们来自一个建筑 共享他们共同的代码, 所以在同一应用程序中导入两者都加载共享的一半一次.

| 导入 | 它给你什么 | 装满什么 |
| :-- | :-- | :-- |
| `@fortemate/dicechess-engine` | 所有东西: `DiceChess`, (中文(简体) ), `EngineFacade`合法倒转的树 花瓶, `getBestMove`、公平、加倍和决定 | 1,308,539 B (191,262 B gzipped) (英语) |
| `@fortemate/dicechess-engine/rules` | 只有规则: `getLegalUciMoves`, (中文(简体) ), `generateMoves`, (中文(简体) ), `applyMove`, (中文(简体) ), `endTurn`, (中文(简体) ), `perft`, (中文(简体) ), `getPieceFromDice`, (中文(简体) ), `canonicalKey` | 891 712 B (138 394 B gzipped) (英语) |

使用 `/rules` 应用程序验证、应用和移动但从未询问引擎 改为 _播放_ ——活游戏与另一个人,板编辑,分析取景. 职能是: 其名称和行为与 `DiceChess` 因此,移民是一个进口:

```javascript
import { DiceChess } from '@fortemate/dicechess-engine/rules';

const dfen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 PN";
const legalMoves = DiceChess.getLegalUciMoves(dfen);
const nextDfen = DiceChess.applyMove(dfen, "e2", "e4");
```

两个条目还输出其功能为平面命名出口 (单位:千美元)`import { getLegalUciMoves } from '@fortemate/dicechess-engine/rules'`)),每个都有自己的 类型脚本声明( E)`dicechess-rules.d.ts` 以给养.

网络大会软件包 `@fortemate/dicechess-engine-wasm` 已经 **没有** `/rules` 子路径: Scala.js WebAssembly后端会发出一个单一的模块,这样包只传送完整的API.

* * *

## 快速启动( JavaScript / TypeScript)

软件包作为标准ES模块分发(`type: "module"`) (中文(简体) ).

```javascript
import { DiceChess } from '@fortemate/dicechess-engine';

// Dice Chess FEN (DFEN) encodes the board state and the current dice pool as the 7th field
// (e.g. "PN" represents a rolled Pawn (P) and Knight (N))
const dfen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 PN";

// 1. Get all legal moves as a flat array of UCI strings for the DFEN position
const legalMoves = DiceChess.getLegalUciMoves(dfen);

console.log("Legal moves in this turn:", legalMoves);
// e.g. ["e2e3", "e2e4", "b1c3", "b1a3", ...]

// 2. Get every legal turn as a prefix tree of UCI micro-moves. A node without children is a
// complete turn. getLegalUciMoves judges each position in isolation, so a client that follows
// a turn one action at a time walks this tree instead of calling getLegalUciMoves again.
const turns = DiceChess.getLegalTurnTree(dfen);
console.log("Continuations of e2e4:", Object.keys(turns["e2e4"]));
// e.g. ["b1a3", "b1c3", "g1e2", "g1f3", "g1h3"]

// The dice a legal turn can still spend: pass the rolled DFEN and the moves played since, not the
// DFEN after them, because the turn is judged as a whole. A client can dim every other die.
console.log("Playable after e2e4:", DiceChess.getPlayableDice(dfen, ["e2e4"]));
// "N"

// 3. Apply a micro-move. applyMove preserves the active color (White), since a Dice Chess turn
// may consist of multiple micro-moves, and keeps the dice the move did not spend ("N" here).
// Arguments: (dfen, fromSquare, toSquare, optionalPromotionPiece)
const nextDfen = DiceChess.applyMove(dfen, "e2", "e4");
console.log("DFEN after micro-move:", nextDfen);

// Spend the knight die too: the turn ends at a leaf of the tree, here after e2e4 then g1f3.
const turnDfen = DiceChess.applyMove(nextDfen, "g1", "f3");

// 4. Explicitly end the turn when the player has exhausted their dice.
// This toggles the active color to Black, clears the dice pool (the full-move number advances
// only after Black's turn), and clears any stale en-passant targets from the previous turn.
const finalDfen = DiceChess.endTurn(turnDfen);
console.log("DFEN after ending turn:", finalDfen);

// 5. Discover available bots (search algorithms)
const bots = DiceChess.getAvailableBots();
console.log("Available bots:", bots);
// e.g. [ { id: 'random', name: 'Random', description: '...', difficulty: 1, isExperimental: false }, ... ]

// 6. Discover the built-in time-management policies.
const timePolicies = DiceChess.getAvailableTimePolicies();
console.log("Available time policies:", timePolicies);
// [ "empirical-v1", "legacy-linear-v1" ]

// 7. Compute the best sequence of micro-moves using the greedy bot search.
// The bot needs Black's roll: append the dice (lowercase for Black), here a Pawn and a Knight.
// Arguments: (dfen, optionalOptions)
const rolledDfen = `${finalDfen} pn`;
const botResult = DiceChess.getBestMove(rolledDfen, { algorithm: "greedy" });
console.log("Bot moves:", botResult.moves);
// e.g. [ { from: "b8", to: "c6" }, { from: "a7", to: "a5" } ]

// Clock-aware searches use empirical-v1 by default. Pass legacy-linear-v1 to
// reproduce the original allocation for rollback or an A/B comparison.
const timedResult = DiceChess.getBestMove(rolledDfen, {
  algorithm: "monte-carlo",
  clock: { remainingMs: 180_000, incrementMs: 2_000, moveNumber: 8 },
  timePolicy: "empirical-v1",
});
console.log("Effective budget (ms):", timedResult.budgetMs);

// 8. Doubling Cube & Draw Offers (New)
// Check if the bot wants to offer a double before its turn:
const shouldDouble = DiceChess.shouldBotOfferDouble(finalDfen, 1);

// Check if the bot accepts a double proposed by the opponent (Take/Drop):
const acceptDouble = DiceChess.shouldBotAcceptDouble(finalDfen, 2);

// Check if the bot wants to offer a draw:
const offerDraw = DiceChess.shouldBotOfferDraw(finalDfen);

// Check if the bot accepts a draw proposed by the opponent:
const acceptDraw = DiceChess.shouldBotAcceptDraw(finalDfen);

```

* * *

## 特征

-   **完整的国际象棋规则**: 执行转弯顺序、解封、晋升路径计算和严格 **最大微移动过滤**。 。 。 .
-   **类型安全**: 以手写类型Script定义文件(`.d.ts`对于这两个条目,与出口的Scala.js API保持一致.
-   **侧效果自由**配置为 `sideEffects: false` 允许在Vite,Webpack,和Rollup等现代捆绑机上高级摇树.
-   **快速射击**:通过高级Scala.js优化链接器来编译优化位元操作.

* * *

## API 参考文献

-   **[交互式用户和开发者指南](https://fortemate.github.io/dicechess-engine/)**: 完整规则,建筑文献,以及现场互动视觉目录.
-   **[GitHub 仓库](https://github.com/fortemate/dicechess-engine)**:出处代码,出处追踪器,贡献指南.

* * *

## 许可证

此软件包仅根据 GNU Affero 通用公共许可证 v3. 0 (SPDX) 获得许可 `AGPL-3.0-only`) (中文(简体) ).

## 常见问题

### @fortemate/dicechess-engine-wasm 是什么？

高性能 Dice 国际象棋引擎和移动生成器编译到ES模块和WebAssembly

### 如何安装 @fortemate/dicechess-engine-wasm？

在项目目录运行 npm install @fortemate/dicechess-engine-wasm，或使用 pnpm add / yarn add / bun add。

### @fortemate/dicechess-engine-wasm 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @fortemate/dicechess-engine-wasm 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @fortemate/dicechess-engine-wasm 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=18。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @fortemate/dicechess-engine-wasm 可以商用吗？

@fortemate/dicechess-engine-wasm 使用 AGPL-3\.0-only 许可。最严格的 Copyleft：除分发外，通过网络向用户提供基于它的服务也需要开源对应源码。闭源 SaaS 使用前务必评估。以上为概括，不构成法律意见，请以许可原文为准。

### @fortemate/dicechess-engine-wasm 的下载量有多少？

根据 npm 官方下载统计，@fortemate/dicechess-engine-wasm 在 2026/10/16 – 2026/11/14 这 30 天内被下载 2,007 次，日均约 67 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @fortemate/dicechess-engine-wasm 还在维护吗？

最新版本 0\.18\.4 发布于 2026/11/13（2 天前）；至今共发布 39 个版本，其中过去 12 个月发布了 39 个；首次发布于 2026/08/20。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

