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?

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

1 Answer 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


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.