commit 2a405850e30c3ef98e8c5f2271326260be4269b5 Author: Kris Lamoureux Date: Wed Mar 15 00:52:32 2023 -0400 Very basic functionality diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..68461e7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +env +bin diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..421c3d7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM debian:11-slim +ARG STOCKFISH_VERSION=sf_15.1 + +RUN apt-get update && apt-get install -y \ + git make curl g++ \ + && rm -rf /var/lib/apt/lists/* + +RUN git clone --quiet https://github.com/official-stockfish/Stockfish.git +RUN cd Stockfish/src \ + && git checkout --quiet ${STOCKFISH_VERSION} \ + && make -j build ARCH=x86-64-modern + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..77261b3 --- /dev/null +++ b/LICENSE @@ -0,0 +1,12 @@ +Copyright (C) 2023 by Kris Lamoureux + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..36024fc --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +# ChessCLI + +ChessCLI is a simple hobby command-line interface (CLI) chess program written +in Python that lets you play against chess engines such as Stockfish, or any +other engine that supports the Universal Chess Interface (UCI) protocol. The +CLI will prompt you for moves in standard algebraic notation (SAN) to play the +game. You would typically use this with a physical chessboard for visualizing. +Therefore, if you are looking for graphics, this will not be the software for +you. + +### Docker + +A `Dockerfile` and a `docker-compose.yml` file are included to aid in compiling +the desired version of Stockfish and to place the resulting binary in an +adjacent bin directory for use by the application. + +#### Copyright and License +Copyright (C) 2023 Kris Lamoureux + +This project is licensed under the 0BSD License - see the LICENSE file for +details. + diff --git a/chesscli.py b/chesscli.py new file mode 100644 index 0000000..2b642ec --- /dev/null +++ b/chesscli.py @@ -0,0 +1,18 @@ +import chess +import chess.engine + +board = chess.Board() +engine = chess.engine.SimpleEngine.popen_uci("bin/stockfish") +count = 1 + +while not board.is_game_over(): + if board.turn == chess.WHITE: + move = input(str(count) + " ") + board.push_san(move) + else: + result = engine.play(board, chess.engine.Limit(time=2.0)) + print(str(count) + "...", board.san(result.move)) + board.push(result.move) + count += 1 + +engine.quit() diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7a7735d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +version: "3.7" + +services: + stockfish: + build: + context: . + dockerfile: Dockerfile + command: sh -c "cp /Stockfish/src/stockfish /output" + volumes: + - ./bin:/output + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d45aee8 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +chess==1.9.4