@fortemate/dicechess-engine-wasm

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

High-performance Dice Chess engine and move generator compiled to ES Modules and WebAssembly

原始使用文档
文档目录6 节
  1. Installation
  2. Two entries: the whole engine, or the rules alone
  3. Quick Start (JavaScript / TypeScript)
  4. Features
  5. API Reference & Documentation
  6. License

@fortemate/dicechess-engine 🎲♟️

High-performance, cross-platform game engine and move generator for Dice Chess, compiled to pure Javascript (ES Modules) with full TypeScript type declarations.

Designed for maximum performance in web browsers, hybrid apps, and Node.js servers.


Installation

Install the package from npmjs.org via npm or your preferred package manager. No registry mapping or authentication token is required:

npm install @fortemate/dicechess-engine

An authenticated mirror is also available from GitHub Packages.


Two entries: the whole engine, or the rules alone

The package has two entry points. They come from one build and share the code they have in common, so importing both in the same application loads the shared half once.

ImportWhat it gives youWhat it loads
@fortemate/dicechess-engineeverything: DiceChess, EngineFacade, the legal turn tree, the bots, getBestMove, equity, doubling and draw decisions1,308,539 B (191,262 B gzipped)
@fortemate/dicechess-engine/rulesthe rules only: getLegalUciMoves, generateMoves, applyMove, endTurn, perft, getPieceFromDice, canonicalKey891,712 B (138,394 B gzipped)

Use /rules wherever the application validates, applies and renders moves but never asks the engine to play — a live game against another human, a board editor, an analysis view. The functions are identical in name and behaviour to their DiceChess counterparts, so migrating is one import:

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");

Both entries also export their functions as plain named exports (import { getLegalUciMoves } from '@fortemate/dicechess-engine/rules'), and each has its own TypeScript declarations (dicechess-rules.d.ts for the subpath).

The WebAssembly package @fortemate/dicechess-engine-wasm has no /rules subpath: the Scala.js WebAssembly backend emits a single module, so that package ships the full API only.


Quick Start (JavaScript / TypeScript)

The package is distributed as a standard ES Module (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);


Features

  • Complete Dice Chess Rules: Implements turn sequencing, unblocking, promotion path calculations, and strict Maximal Micro-moves Filtering.
  • Type-Safe: Shipped with hand-written TypeScript definition files (.d.ts) for both entries, kept in step with the exported Scala.js API.
  • Side-Effect Free: Configured with sideEffects: false to allow advanced tree-shaking in modern bundlers like Vite, Webpack, and Rollup.
  • Blazing Fast: Optimized bitwise operations compiled via the advanced Scala.js optimizing linker.

API Reference & Documentation


License

This package is licensed under the GNU Affero General Public License v3.0 only (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 是什么?

High-performance Dice Chess engine and move generator compiled to ES Modules and 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 和提交记录判断。