chess/README.md
Michael Pilosov bc8474ec9b update readme
2022-11-28 16:05:08 -07:00

1.1 KiB

How to interact with stockfish running in docker

Build the container stockfish:15:

make build

Create a file called stockfish with the following contents (one is included in this repo):

#!/bin/sh
nc localhost 23249

Give it executable permissions with:

chmod +x stockfish

Now you can run the following to start stockfish:

make start

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