Answers.Body: <p>There is a library for Python (<code>import chess.engine</code>) that allows you to use an engine (like Stockfish) to analyse games in a PGN file.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-17T18:12:03.003Z
Answers.LastActivityDate: 2020-06-17T18:12:03.003Z
Answers.UserDisplayName: Marco
Body: <p>I am looking for a way to use Stockfish for an automated analysis of games which I have in pgn format. Similar to Fritz/Chessbase's Blunder Check function I would like Stockfish (or any other UCI engine) to "simply" go through each position of each game in the pgn-file (convert to FENs?), let Stockfish run for a fixed amount of seconds and then return the evaluation and depth reached. Maybe later I would like to add things like node count or the eval in each depth reached. Finally, the program should format the output to a human readable format.</p>
  
  <p>Maybe there is a similar program already out there which I could use as a template but if not what would be the easiest way to get started. I have limited programming skills in Python and VB.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-06-15T11:32:20.270Z
Comments.Text: "I would like Stockfish... to "simply" go through each position of each game in the pgn-file..., let Stockfish run for a fixed amount of seconds and then return the evaluation and depth reached" - There are already programs which do this much. Did you *want* to program your own, or would you be happy with just this?
Comments.UserDisplayName: D M
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-06-15T12:04:34.080Z
Comments.Text: I would like to add custom elements like node count and evals at different depths - all info that SF returns. If there is an open source program that does some parts then I could add those features perhaps. But please let me know any programs that can do it. I only know of Chessbase and Aquarium.
Comments.UserDisplayName: Gecko
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-06-16T05:41:51.647Z
Comments.Text: Reading your question makes me wonder - you are already using Fritz/Chessbase and for some reason don't like those products - or you know they can do it but you don't want to pay and ask someone to make it for free? Because obviously you can do what you ask for 100% using Chessbase 15... not sure about other versions and Fritz interface - possible that it would work too - someone else could confirm
Comments.UserDisplayName: Drako
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-06-16T11:15:40.977Z
Comments.Text: @Drako Are you saying that if I give to CB15 for instance a PGN with 1000 FENs representing 1000 positions, there's a way to tell CB15 to output (with a chosen engine, let's say our default kibitzer) somewhere (in the PGN, by completing it, or somewhere else) the list of evaluations (how to parametrize them ?) of these positions ?
Comments.UserDisplayName: Olórin
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-06-16T12:00:42.583Z
Comments.Text: yes - its called tactics analysis - you open DB, select games you want - you can select all if you want - right click and choose tactics analysis, set time per move there, choose to store evaluations, etc. read CB manual for more.
Comments.UserDisplayName: Drako
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-06-16T15:25:54.730Z
Comments.Text: @Drako I bought Fritz 13 a while ago and I find the Blunder Check quite useful but I think more flexibility would make sense, e.g. if the abs(eval)>2 then spend less time on a position or if it is +0.00 for 10 moves then spend less time on a move and conversely, if the eval changes a lot while the engines searches, spend more time. I bet it would be easy to implement for the guys at Chessbase but I do not think they have done it.
Comments.UserDisplayName: Gecko
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-06-16T15:27:35.703Z
Comments.Text: @Drako [part2] Secondly, I find the output of Fritz/Chessbase within a game useful (adding comments like `21. Rc1 {0.33/22}` for indicating evaluation/depth) but if I want to analyze, say, 100 games then a sort of summary would be good, showing which games had how many blunders or which games "were boring". Such an analysis could be automated relatively easily (if one knew how to program :-).
Comments.UserDisplayName: Gecko
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-06-18T12:47:03.697Z
Comments.Text: Stockfish can analyze a PGN file easily.  Why isn't that enough?
Comments.UserDisplayName: Thorbjørn Ravn Andersen
Tags: <stockfish><programming><uci>
Title: Using Stockfish in an automated way, for example, to analyze games in pgn format
ThreadText: # Using Stockfish in an automated way, for example, to analyze games in pgn format
  
  (Asked by: username_0 on 2020-06-15)
  
  I am looking for a way to use Stockfish for an automated analysis of games which I have in pgn format. Similar to Fritz/Chessbase's Blunder Check function I would like Stockfish (or any other UCI engine) to "simply" go through each position of each game in the pgn-file (convert to FENs?), let Stockfish run for a fixed amount of seconds and then return the evaluation and depth reached. Maybe later I would like to add things like node count or the eval in each depth reached. Finally, the program should format the output to a human readable format.
  
  Maybe there is a similar program already out there which I could use as a template but if not what would be the easiest way to get started. I have limited programming skills in Python and VB.
  
  **Tags:** stockfish, programming, uci
  
  > **Comments:**
  > **username_1**: "I would like Stockfish... to "simply" go through each position of each game in the pgn-file..., let Stockfish run for a fixed amount of seconds and then return the evaluation and depth reached" - There are already programs which do this much. Did you *want* to program your own, or would you be happy with just this?  
  > **username_0**: I would like to add custom elements like node count and evals at different depths - all info that SF returns. If there is an open source program that does some parts then I could add those features perhaps. But please let me know any programs that can do it. I only know of Chessbase and Aquarium.  
  > **username_2**: Reading your question makes me wonder - you are already using Fritz/Chessbase and for some reason don't like those products - or you know they can do it but you don't want to pay and ask someone to make it for free? Because obviously you can do what you ask for 100% using Chessbase 15... not sure about other versions and Fritz interface - possible that it would work too - someone else could confirm  
  > **username_3**: @username_2 Are you saying that if I give to CB15 for instance a PGN with 1000 FENs representing 1000 positions, there's a way to tell CB15 to output (with a chosen engine, let's say our default kibitzer) somewhere (in the PGN, by completing it, or somewhere else) the list of evaluations (how to parametrize them ?) of these positions ?  
  > **username_2**: yes - its called tactics analysis - you open DB, select games you want - you can select all if you want - right click and choose tactics analysis, set time per move there, choose to store evaluations, etc. read CB manual for more.  
  > **username_0**: @username_2 I bought Fritz 13 a while ago and I find the Blunder Check quite useful but I think more flexibility would make sense, e.g. if the abs(eval)>2 then spend less time on a position or if it is +0.00 for 10 moves then spend less time on a move and conversely, if the eval changes a lot while the engines searches, spend more time. I bet it would be easy to implement for the guys at Chessbase but I do not think they have done it.  
  > **username_0**: @username_2 [part2] Secondly, I find the output of Fritz/Chessbase within a game useful (adding comments like `21. Rc1 {0.33/22}` for indicating evaluation/depth) but if I want to analyze, say, 100 games then a sort of summary would be good, showing which games had how many blunders or which games "were boring". Such an analysis could be automated relatively easily (if one knew how to program :-).  
  > **username_4**: Stockfish can analyze a PGN file easily.  Why isn't that enough?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_5 on 2020-06-17. Score: 2 | Accepted answer
  
  There is a library for Python (`import chess.engine`) that allows you to use an engine (like Stockfish) to analyse games in a PGN file.
  
  
  ---
  
  