Last active
April 1, 2024 00:00
-
-
Save d4rkc0de/40e17cec42ee7fcbcc4fe255e32ab683 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo apt install stockfish | |
$ sudo apt upgrade stockfish | |
$ pip install chess | |
import chess.pgn | |
import chess.engine | |
# Load the PGN file | |
pgn = open("./file.pgn") | |
engine = chess.engine.SimpleEngine | |
engine = chess.engine.SimpleEngine.popen_uci("/usr/games/stockfish") | |
time_limit = 0.01 | |
# Read the game from the PGN file | |
game = chess.pgn.read_game(pgn) | |
# Get the initial board position | |
board = game.board() | |
# Iterate through the moves and apply them to the board | |
for move in game.mainline_moves(): | |
board.push(move) | |
result = engine.analyse(board, chess.engine.Limit(time=time_limit)) | |
print(result['score']) | |
# Print the final position | |
print(board) | |
# if you want to use stockfish | |
$ pip install stockfish | |
from stockfish import Stockfish | |
stockfish = Stockfish() | |
def print_board(): | |
print(stockfish.get_board_visual().replace('\\n', '\n')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment