I got annoyed
You know that *cough*chess.com*cough* only allows basic members one game analysis per day? Well, I got annoyed today and wasted an hour of my life programming this contraption. It comments on your moves (inaccuracy, mistake, blunder), gives the evaluation of the position and the best move, and gives you a funny graph at the end. The simple code is down below and here’s a demonstration video.
import chess.pgn
from stockfish import Stockfish
import matplotlib.pyplot as plt
stockfish = Stockfish('/Users/kevinfong/Downloads/stockfish/14/bin/stockfish')
pgn = open("PGNTEST.pgn")
game = chess.pgn.read_game(pgn)
board = game.board()
ply_list = []
eval_list = []
ply = 0
plt.axhline(y=0, color='r', linestyle='-')
for move in game.mainline_moves():
best_move = stockfish.get_best_move()
best_eval = stockfish.get_evaluation()['value']/100
board.push(move)
stockfish.set_fen_position(board.fen())
move_eval = stockfish.get_evaluation()['value']/100
comment = ""
if best_eval - move_eval > 0.8:
comment = "Inaccuracy"
elif best_eval - move_eval > 2:
comment = "Mistake"
elif best_eval - move_eval > 3:
comment = "Blunder"
else:
comment = ""
print(f"Move Played: {move}, {move_eval} Best Move: {best_move}, {best_eval} {comment}")
ply_list.append(ply)
eval_list.append(move_eval)
ply += 1
plt.plot(ply_list, eval_list, '.b-')
print(board)
plt.show()