69 lines
1.1 KiB
Markdown
69 lines
1.1 KiB
Markdown
|
|
|
|
# How to interact with stockfish running in docker
|
|
|
|
Build the container `stockfish:15`:
|
|
|
|
```sh
|
|
make build
|
|
```
|
|
|
|
Create a file called `stockfish` with the following contents (one is included in this repo):
|
|
|
|
```sh
|
|
#!/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](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()
|
|
``` |