@fortemate/dicechess-engine-wasm

中文文档
0.18.4发布于 2026/11/13AGPL-3.0-onlyTypeScriptES Module零依赖构建来源已验证近 30 天下载 2007

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

中文使用文档
文档目录6 节
  1. 安装
  2. 两个条目: 整个引擎,或仅规则
  3. 快速启动( JavaScript / TypeScript)
  4. 特征
  5. API 参考文献
  6. 许可证

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

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

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


安装

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

npm install @fortemate/dicechess-engine

还可以从 GitHub 软件包。 。 。 .


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

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

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

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

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") (中文(简体) ).

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 参考文献


许可证

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

版本与发布记录

@fortemate/dicechess-engine-wasm 共发布 39 个版本,首次发布于 2026/08/20;过去 12 个月发布了 39 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.18.4latest2026/11/132 天前
0.18.32026/11/124 天前
0.18.22026/11/078 天前
0.18.12026/11/0610 天前
0.18.02026/11/0511 天前
0.17.12026/11/0411 天前

关于 @fortemate/dicechess-engine-wasm 的常见问题

@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 和提交记录判断。