From 631a97f2b8dd4e3cca6f7f5fce82733691305404 Mon Sep 17 00:00:00 2001 From: Michael Pilosov Date: Mon, 28 Nov 2022 15:58:09 -0700 Subject: [PATCH] readme --- README.md | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..971191b --- /dev/null +++ b/README.md @@ -0,0 +1,63 @@ + + +# How to interact with stockfish running in docker + +Create a file called `stockfish` with the following contents: + +```sh +#!/bin/sh +nc localhost 23249 +``` + +Give it executable permissions with: +``` +chmod +x stockfish +``` + +Now you can run the following to start stockfish: +``` +docker run -d --rm --name stockfish -p 23249:23249 -p 23250:23250 -v $(pwd):/stockfish:ro -w /stockfish stockfish +``` + +This will start a stockfish instance that will listen on port 23249 for commands. + +You can now run `./stockfish` to interact with the stockfish instance. + +``` +./stockfish +uci +isready +quit +``` + +More examples of stockfish engine interaction are: +``` +./stockfish +uci +isready +ucinewgame +position startpos moves e2e4 e7e5 g1f3 g8f6 +go depth 20 +quit +``` + +For more information about stockfish, see the [stockfish github page](https://github.com/official-stockfish/Stockfish). + + +## PyChess Example + +```python +import chess +import chess.engine + +stockfish = chess.engine.SimpleEngine.popen_uci("./stockfish") + +board = chess.Board() + +while not board.is_game_over(): + result = stockfish.play(board, chess.engine.Limit(time=0.1)) + board.push(result.move) + print(board, "\n") + +stockfish.quit() +``` \ No newline at end of file