multistockfish 0.4.0 copy "multistockfish: ^0.4.0" to clipboard
multistockfish: ^0.4.0 copied to clipboard

Multiple flavors of Stockfish Engine

multistockfish #

Multiple flavors of Stockfish Engine.

This plugin provides the following Stockfish engines:

Usage #

Start engine #

Stockfish is a singleton. Access it via Stockfish.instance and call start() to run the engine.

Note

When using the StockfishFlavor.latestNoNNUE flavor, you need to download the .nnue files before starting an evaluation, since it is not embedded in the binary.

import 'package:multistockfish/multistockfish.dart';

final stockfish = Stockfish.instance;

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

// start the engine (defaults to StockfishFlavor.sf16)
await stockfish.start();
print(stockfish.state.value); // StockfishState.ready

// to change flavor, quit first then start with new configuration
await stockfish.quit();
await stockfish.start(
  flavor: StockfishFlavor.variant,
  variant: 'atomic',
);

// for latestNoNNUE flavor, NNUE file paths are required
await stockfish.quit();
await stockfish.start(
  flavor: StockfishFlavor.latestNoNNUE,
  bigNetPath: '/path/to/big.nnue',
  smallNetPath: '/path/to/small.nnue',
);

UCI command #

Wait 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);
});

Quit / Hot reload #

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

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

// or even easier...
await stockfish.quit();