stockfish_chess_engine 0.4.1
stockfish_chess_engine: ^0.4.1 copied to clipboard
Use Stockfish chess engine directly in your Flutter project.
stockfish_chess_engine #
Use Stockfish chess engine in your Flutter project.
This project is based on sources for Stockfish 15.
Note : I apologize for not releasing for IOS nor Mac, because I can't test on those machines. I'm open to pull request if someone can help me.
Usage #
final stockfish = new Stockfish()
// Create a subscribtion on stdout : subscription that you'll have to cancel before disposing Stockfish.
final stockfishSubscription = stockfish.stdout.listen((message) {
print(message);
});
// Get Stockfish ready
stockfish.stdin = 'isready'
// Send you commands to Stockfish stdin
stockfish.stdin = 'position startpos' // set up start position
stockfish.stdin = 'position fen rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2' // set up custom position
stockfish.stdin = 'go movetime 1500' // search move for at most 1500ms
// Don't remember to dispose Stockfish when you're done.
stockfishSubscription.cancel();
stockfish.dispose();
You can see an example usage in example folder.
Important notes #
-
You must check the position validity before sending it to stdin, otherwise program will crash on illegal position ! For that, you can use the chess package.
-
As the library creates two isolates, you must dispose Stockfish before perfoming an hot reload / hot restart, and then creating a new Stockfish instance.
For stockfish chess engine developpers #
- Run
flutter pub get
. - Uncomment line
#define _ffigen
on top of src/stockfish.h (for the ffi generation to pass). - Run command
flutter pub run ffigen --config ffigen.yaml
. More on https://pub.dev/packages/ffigen for the prerequesites per OS. - Comment line
#define _ffigen
in src/stockfish.h (otherwise Stockfish engine compilation will pass but be incorrect). - In the file lib/stockfish_bindings_generated.dart, add the following import line :
import 'package:ffi/ffi.dart';
- In the same file, replace Pointer<ffi.Char> by Pointer
Changing the downloaded NNUE file #
- Go to Stockfish NNUE files page and select a reference from the list.
- Modify CMakeLists.txt, by replacing lines starting by
set (NNUE_NAME )
by setting your reference name, without any quote. - Modify the reference name in
evaluate.h
in the line containing#define EvalFileDefaultName
, by setting your nnue file name, with the quotes of course. - Don't forget to clean project before building again (
flutter clean
thenflutter pub get
).
Credits #
- Using source code from Stockfish.
- Using source code from Flutter Stockfish.