搜索插件、代码仓与 APP 分类

插件详情v0.8.1

chess

一个用于生成合法国际象棋走法、维护国际象棋游戏状态以及在 FEN 和 PGN 格式之间转换的库。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
1.2万
喜欢数
47
Pub 分数
125

安装插件

flutter pub add chess

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

该国际象棋包是一个 Dart 库,旨在管理国际象棋游戏状态、生成合法走法,并在 FEN(福尔思-爱德华兹记谱法)和 PGN(便携式棋局记谱法)格式之间进行转换。它为构建具有准确走法验证和状态追踪功能的国际象棋应用提供了坚实的基础。非常适合需要精确国际象棋逻辑的开发者创建国际象棋游戏或工具,支持移动、网页和桌面等多种平台。该库文档齐全且持续维护,便于集成到 Flutter 项目中。

适合场景

  • 构建国际象棋游戏
  • 解析和生成 PGN 文件
  • 验证国际象棋走法
  • 在 FEN 和 PGN 之间转换
  • 实现国际象棋人工智能
  • 跟踪游戏状态

主要特点

  • 合法走法生成
  • FEN 和 PGN 转换
  • 游戏状态管理
  • 跨平台支持
  • 准确的国际象棋规则执行
  • 轻便且快速

适合对象

  • Flutter 游戏开发者
  • 国际象棋应用开发者
  • 教育类国际象棋工具
  • 国际象棋引擎集成
  • 拼图和训练应用

使用建议

  • 需要理解国际象棋记谱法
  • 仅限标准国际象棋规则
  • 无内置 UI 组件
  • 未针对大规模游戏数据库进行优化
  • 依赖外部对源代码的维护

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

chess.dart

chess.dart is a library for legal chess move generation, maintenance of chess game state, and conversion to and from the formats FEN and PGN. It has no external dependencies.

In 2014, chess.dart started as a port of chess.js to Dart, including all of the functionality in the original library, while making the API a little bit more Dart-like. It has since accumulated bug fixes and performance improvements thanks to contributions from the Dart community.

chess.dart includes a test suite composed of all of the original chess.js unit tests as well as newer tests specific to bug fixes and feature additions specific to the Dart version (which you can find in the test directory). chess.dart is depended upon by multiple popular packages for chess board display.

Installation

The package is just called chess on pub. If for some strange reason you can't use pub, you can also just add the chess.dart file from the lib directory to your project. Adding the pub package is:

 $ dart pub add chess

Or you can manually add chess to your pubspec.yaml.

Then importing chess.dart in your code is simply:

import 'package:chess/chess.dart';

A Random Game

import "package:chess/chess.dart";

void main() {
  Chess chess = new Chess();
  while (!chess.game_over) {
    print('position: ' + chess.fen);
    print(chess.ascii);
    var moves = chess.moves();
    moves.shuffle();
    var move = moves[0];
    chess.move(move);
    print('move: ' + move);
  }
}

Documentation

The chess.js documentation is largely relevant, but there are also DartDocs generated within the lib/docs directory. The only change in naming from chess.js, is that history() has been changed to getHistory() due to a conflict with the history ivar and some methods have been changed into properties.

Versioning

chess.dart version 0.6.5 and above requires Dart 2. For Dart 1, use version 0.6.4.

Testing

The test directory contains tests.dart which is a port of chess.js's unit tests. The program random.dart plays a random game of chess. ai.dart is an example of a simple 4 ply alpha beta search for black (yes a simple chess-playing program) that uses a purely material evaluation function (it is rather slow). You can run the unit tests using pub:

pub get
dart run test/tests.dart

And you can also run performance tests.

dart run test/perft.dart

And, finally you can run the simple AI:

dart run test/ai.dart

Links

所属分类

源码仓库

使用此插件的项目