Skip to content

The Stockfish Chess Engine for dart/Flutter.

License

Notifications You must be signed in to change notification settings

lichess-org/dart-stockfish

This branch is 10 commits ahead of, 7 commits behind ArjanAswal/Stockfish:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

47cbf16 · Jan 31, 2025

History

81 Commits
Oct 4, 2023
Oct 21, 2021
Jan 31, 2025
Sep 12, 2024
Apr 18, 2024
Oct 4, 2023
Dec 27, 2020
Dec 27, 2020
Dec 19, 2020
Sep 19, 2021
Jul 27, 2024
Apr 12, 2023
Apr 18, 2024
Sep 12, 2024
Sep 12, 2024
Dec 19, 2020

Repository files navigation

stockfish

Pipeline

The Stockfish Chess Engine for Flutter.

Example

@PScottZero was kind enough to create a working chess game using this package.

Usages

iOS project must have IPHONEOS_DEPLOYMENT_TARGET >=12.0.

Add dependency

Update dependencies section inside pubspec.yaml:

  stockfish: ^1.6.0

Init engine

import 'package:stockfish/stockfish.dart';

// create a new instance
final stockfish = Stockfish();

// state is a ValueListenable<StockfishState>
print(stockfish.state.value); # StockfishState.starting

// the engine takes a few moment to start
await Future.delayed(...)
print(stockfish.state.value); # StockfishState.ready

UCI command

Waits until the state is ready before sending commands.

stockfish.stdin = 'isready';
stockfish.stdin = 'go movetime 3000';
stockfish.stdin = 'go infinite';
stockfish.stdin = 'stop';

Engine output is directed to a Stream<String>, add a listener to process results.

stockfish.stdout.listen((line) {
  // do something useful
  print(line);
});

Dispose / Hot reload

There are two active isolates when Stockfish engine is running. That interferes with Flutter's hot reload feature so you need to dispose it before attempting to reload.

// sends the UCI quit command
stockfish.stdin = 'quit';

// or even easier...
stockfish.dispose();

Note: only one instance can be created at a time. The factory method Stockfish() will return null if it was called when an existing instance is active.

About

The Stockfish Chess Engine for dart/Flutter.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published

Languages

  • C++ 95.3%
  • Dart 1.9%
  • C 1.9%
  • Ruby 0.5%
  • CMake 0.1%
  • Java 0.1%
  • Other 0.2%