搜尋套件、儲存庫與 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

所屬分類

原始碼儲存庫

使用此套件的專案