Go to file
Michael Pilosov 631a97f2b8 readme
2022-11-28 15:58:09 -07:00
README.md readme 2022-11-28 15:58:09 -07:00

How to interact with stockfish running in docker

Create a file called stockfish with the following contents:

#!/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.

PyChess Example

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()