4

I have a list of PGN files that are games between top grandmasters where one player resigned at the end of the game. I am looking to find solutions to those position using stockfish/or another chess engine(programmatically). Ideally - I should be able to pass a PGN or FEN string and get the solution as the output.

How can I do that?

sebastian
  • 41
  • 1
  • 3
    Hi, sebastian! Welcome to Chess.SE. Could you explain in more detail what you mean by finding solutions? – Brandon_J Aug 31 '22 at 15:18

1 Answers1

1

In Python this can be done as follows:

Using the python-chess module, iterate through the games in your pgn database. Docs: https://python-chess.readthedocs.io/en/latest/pgn.html

https://python-chess.readthedocs.io/en/latest/core.html#board

Now to use Stockfish, download the Stockfish engine, and then use the stockfish python module: https://pypi.org/project/stockfish/. python-chess can also be used to interact with Stockfish, but I'm not familiar myself with how to do this.

For each position in a game (that you want to find the best move for), get its FEN (using python-chess), and then set the stockfish module object's position to it (using the set_fen_position method). Finally, you can call the get_best_move function of the stockfish module.

Inertial Ignorance
  • 19,788
  • 22
  • 68