Skip to content

Instantly share code, notes, and snippets.

@d4rkc0de
Last active April 1, 2024 00:00
Show Gist options
  • Save d4rkc0de/40e17cec42ee7fcbcc4fe255e32ab683 to your computer and use it in GitHub Desktop.
Save d4rkc0de/40e17cec42ee7fcbcc4fe255e32ab683 to your computer and use it in GitHub Desktop.
$ 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