Answers.Body: <p>Of course there's a way: I'm going to show you one way of doing it on your own, using only free software. We'll write a small script in <a href="https://en.wikipedia.org/wiki/Python_(programming_language)" rel="noreferrer">Python</a> (I'm using <a href="https://www.python.org/download/releases/2.7/" rel="noreferrer">v2.7</a>) and only use the wonderful <a href="https://pypi.python.org/pypi/python-chess" rel="noreferrer">python-chess library</a> (licensed under <a href="https://en.wikipedia.org/wiki/GNU_General_Public_License" rel="noreferrer">GPL3</a>, note that I'm using the version 0.14.0).</p>
  
  <p>In short, the script will first load up the engine, we will stick to free and open source software so we'll use the amazing <a href="https://stockfishchess.org/" rel="noreferrer">Stockfish engine</a> [*], then create a board instance of the position you want analyzed (using the <a href="https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation" rel="noreferrer">FEN notation</a>), generate all legal moves, and finally ask the engine to evaluate each move for a predefined amount of time (in this example it is set to 1 second ponder time). Here's a working sample: </p>
  
  <pre><code>import chess
  import chess.uci
  
  #Let's try our code with the starting position of chess:
  fen = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'
  board = chess.Board(fen)
  handler = chess.uci.InfoHandler()
  
  #Now make sure you give the correct location for your stockfish engine file
  #...in the line that follows: e.g., /home/.../stockfish_6_x64
  engine = chess.uci.popen_engine('stockfish_6_x64')
  
  engine.info_handlers.append(handler)
  engine.position(board)
  if board.turn: print 'White to move'
  else: print 'black to move'
  
  for el in board.legal_moves:
      engine.go(searchmoves=[el],movetime=1000)
      print str(board.san(el)), 'eval = ', round(handler.info["score"][1].cp/100.0,2)
  </code></pre>
  
  <p>Note that this is not necessarily the best/most efficient way of doing it, I wrote this in 5 minutes just to showcase it at a basic level <em>without</em> using any advanced features of the engine, I'm sure you will do much better on your own. Anyhow here's the output once you run it (assuming you have python installed on whatever OS you're using, same goes for the python-chess library):</p>
  
  <pre><code>White to move
  Na3 eval =  -0.39
  Nc3 eval =  0.15
  Nf3 eval =  0.15
  Nh3 eval =  -0.37
  a3 eval =  0.01
  b3 eval =  -0.15
  c3 eval =  -0.03
  d3 eval =  -0.06
  e3 eval =  0.12
  f3 eval =  -0.49
  g3 eval =  -0.33
  h3 eval =  0.0
  a4 eval =  -0.12
  b4 eval =  -0.67
  c4 eval =  0.07
  d4 eval =  0.17
  e4 eval =  0.17
  f4 eval =  -0.15
  g4 eval =  -0.74
  h4 eval =  -0.15
  </code></pre>
  
  <p>There you go! The beauty of all this is of course the fact that you have now <strong>your</strong> own software to work with, modify and extend it as you wish...no limitations. All very easy to do, just acquaint yourself with the workings of the library we're using by following its <a href="http://python-chess.readthedocs.io/en/v0.15.3/" rel="noreferrer">documentation</a>, and knock yourself out ;)</p>
  
  <p>Don't hesitate to ask if you have any questions about the code, or adding potential functionalities. </p>
  
  <p>[*]: which also happens to be one of the <a href="http://www.computerchess.org.uk/ccrl/4040/" rel="noreferrer">strongest current chess engines</a>.</p>
  
  <hr>
  
  <h2>Edit to address the common request:</h2>
  
  <p>Here's the <strong>updated version</strong> of the same code using the latest version:</p>
  
  <h2><strong>python-chess 0.30.0 and using the latest Stockfish</strong></h2>
  
  <pre><code>import chess
  import chess.engine
  import os
  
  #here we assume the engine file is in same folder as our python script
  path = os.getcwd()
  #Let's try our code with the starting position of chess:
  fen = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'
  board = chess.Board(fen)
  #Now make sure you give the correct location for your stockfish engine file
  #...in the line that follows by correctly defining path
  engine = chess.engine.SimpleEngine.popen_uci(path+'/'+'stockfish-10-64')
  
  if board.turn: print('White to move')
  else: print('black to move')
  
  for el in board.legal_moves:
      info = engine.analyse(board, chess.engine.Limit(time=1), root_moves=[el])
      t = str(info["score"])
      if t.startswith('#'):
              print(str(board.san(el))," eval = mate in ", t)
      else: print(str(board.san(el))," eval = ", round(int(t)/100.,2))
  engine.quit()
  </code></pre>
  
  <p>The output for ponder time set to 1 second per found move <code>chess.engine.Limit(time=1)</code>:</p>
  
  <pre><code>White to move
  Nh3  eval =  -0.43
  Nf3  eval =  0.69
  Nc3  eval =  0.29
  Na3  eval =  -0.35
  h3  eval =  0.41
  g3  eval =  -0.2
  f3  eval =  -0.62
  e3  eval =  0.45
  d3  eval =  0.03
  c3  eval =  0.19
  b3  eval =  0.1
  a3  eval =  0.46
  h4  eval =  -0.42
  g4  eval =  -1.22
  f4  eval =  -0.07
  e4  eval =  0.82
  d4  eval =  0.63
  c4  eval =  0.57
  b4  eval =  -0.26
  a4  eval =  -0.02
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-06T19:30:48.103Z
Answers.Text: can you update the code with last version of the lib please ?
Answers.UserDisplayName: shar
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-06T22:56:41.107Z
Answers.Text: Seconding @shar's comment
Answers.UserDisplayName: Jordan Mackie
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-07T04:31:27.957Z
Answers.Text: @JordanMackie see the edit.
Answers.UserDisplayName: Ellie
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2016-10-30T20:35:43.323Z
Answers.LastActivityDate: 2020-01-07T04:35:41.697Z
Answers.LastEditDate: 2020-01-07T04:35:41.697Z
Answers.UserDisplayName: Ellie
Body: <p>I am looking for a way to return scores for all possible moves from a chess engine (preferably, Stockfish).</p>
  
  <p>The <a href="http://wbec-ridderkerk.nl/html/UCIProtocol.html" rel="noreferrer">UCI protocol</a> does not seem to require it, but is seems like a useful feature to include.</p>
  
  <p>Are there any chess engines/extensions of UCI that implement that?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-26T13:10:19.613Z
Comments.Text: Set multipv to a big number.
Comments.UserDisplayName: SmallChess
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-26T16:18:31.853Z
Comments.Text: wouldn't that just give me 100 different lines all starting with e4?
Comments.UserDisplayName: QuarterlyQuotaOfQuotes
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-26T21:41:47.437Z
Comments.Text: Do you know what multi pv is?
Comments.UserDisplayName: SmallChess
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-01-27T23:35:05.957Z
Comments.Text: Cool. Can we use it on opening pgn file which has multiple variations?
  I am trying to get such evaluation on all moves of side lines also. Thanks Nh3 eval = -0.43
  Nf3 eval = 0.69
  Nc3 eval = 0.29
  Na3 eval = -0.35
Comments.UserDisplayName: Ram Lal
Tags: <engines><stockfish><uci>
Title: Returning scores for all possible moves from a chess engine
ThreadText: # Returning scores for all possible moves from a chess engine
  
  (Asked by: username_0 on 2016-10-26)
  
  I am looking for a way to return scores for all possible moves from a chess engine (preferably, Stockfish).
  
  The [UCI protocol](http://wbec-ridderkerk.nl/html/UCIProtocol.html) does not seem to require it, but is seems like a useful feature to include.
  
  Are there any chess engines/extensions of UCI that implement that?
  
  **Tags:** engines, stockfish, uci
  
  > **Comments:**
  > **username_1**: Set multipv to a big number.  
  > **username_0**: wouldn't that just give me 100 different lines all starting with e4?  
  > **username_1**: Do you know what multi pv is?  
  > **username_2**: Cool. Can we use it on opening pgn file which has multiple variations? I am trying to get such evaluation on all moves of side lines also. Thanks Nh3 eval = -0.43 Nf3 eval = 0.69 Nc3 eval = 0.29 Na3 eval = -0.35  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_3 on 2016-10-30. Score: 17 | Accepted answer
  
  Of course there's a way: I'm going to show you one way of doing it on your own, using only free software. We'll write a small script in [Python](https://en.wikipedia.org/wiki/Python_(programming_language)) (I'm using [v2.7](https://www.python.org/download/releases/2.7/)) and only use the wonderful [python-chess library](https://pypi.python.org/pypi/python-chess) (licensed under [GPL3](https://en.wikipedia.org/wiki/GNU_General_Public_License), note that I'm using the version 0.14.0).
  
  In short, the script will first load up the engine, we will stick to free and open source software so we'll use the amazing [Stockfish engine](https://stockfishchess.org/) [\*], then create a board instance of the position you want analyzed (using the [FEN notation](https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation)), generate all legal moves, and finally ask the engine to evaluate each move for a predefined amount of time (in this example it is set to 1 second ponder time). Here's a working sample:
  
  ```
  import chess
  import chess.uci
  
  #Let's try our code with the starting position of chess:
  fen = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'
  board = chess.Board(fen)
  handler = chess.uci.InfoHandler()
  
  #Now make sure you give the correct location for your stockfish engine file
  #...in the line that follows: e.g., /home/.../stockfish_6_x64
  engine = chess.uci.popen_engine('stockfish_6_x64')
  
  engine.info_handlers.append(handler)
  engine.position(board)
  if board.turn: print 'White to move'
  else: print 'black to move'
  
  for el in board.legal_moves:
      engine.go(searchmoves=[el],movetime=1000)
      print str(board.san(el)), 'eval = ', round(handler.info["score"][1].cp/100.0,2)
  
  ```
  
  Note that this is not necessarily the best/most efficient way of doing it, I wrote this in 5 minutes just to showcase it at a basic level *without* using any advanced features of the engine, I'm sure you will do much better on your own. Anyhow here's the output once you run it (assuming you have python installed on whatever OS you're using, same goes for the python-chess library):
  
  ```
  White to move
  Na3 eval =  -0.39
  Nc3 eval =  0.15
  Nf3 eval =  0.15
  Nh3 eval =  -0.37
  a3 eval =  0.01
  b3 eval =  -0.15
  c3 eval =  -0.03
  d3 eval =  -0.06
  e3 eval =  0.12
  f3 eval =  -0.49
  g3 eval =  -0.33
  h3 eval =  0.0
  a4 eval =  -0.12
  b4 eval =  -0.67
  c4 eval =  0.07
  d4 eval =  0.17
  e4 eval =  0.17
  f4 eval =  -0.15
  g4 eval =  -0.74
  h4 eval =  -0.15
  
  ```
  
  There you go! The beauty of all this is of course the fact that you have now **your** own software to work with, modify and extend it as you wish...no limitations. All very easy to do, just acquaint yourself with the workings of the library we're using by following its [documentation](http://python-chess.readthedocs.io/en/v0.15.3/), and knock yourself out ;)
  
  Don't hesitate to ask if you have any questions about the code, or adding potential functionalities.
  
  [\*]: which also happens to be one of the [strongest current chess engines](http://www.computerchess.org.uk/ccrl/4040/).
  
  ---
  
  ## Edit to address the common request:
  
  Here's the **updated version** of the same code using the latest version:
  
  ## **python-chess 0.30.0 and using the latest Stockfish**
  
  ```
  import chess
  import chess.engine
  import os
  
  #here we assume the engine file is in same folder as our python script
  path = os.getcwd()
  #Let's try our code with the starting position of chess:
  fen = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'
  board = chess.Board(fen)
  #Now make sure you give the correct location for your stockfish engine file
  #...in the line that follows by correctly defining path
  engine = chess.engine.SimpleEngine.popen_uci(path+'/'+'stockfish-10-64')
  
  if board.turn: print('White to move')
  else: print('black to move')
  
  for el in board.legal_moves:
      info = engine.analyse(board, chess.engine.Limit(time=1), root_moves=[el])
      t = str(info["score"])
      if t.startswith('#'):
              print(str(board.san(el))," eval = mate in ", t)
      else: print(str(board.san(el))," eval = ", round(int(t)/100.,2))
  engine.quit()
  
  ```
  
  The output for ponder time set to 1 second per found move `chess.engine.Limit(time=1)`:
  
  ```
  White to move
  Nh3  eval =  -0.43
  Nf3  eval =  0.69
  Nc3  eval =  0.29
  Na3  eval =  -0.35
  h3  eval =  0.41
  g3  eval =  -0.2
  f3  eval =  -0.62
  e3  eval =  0.45
  d3  eval =  0.03
  c3  eval =  0.19
  b3  eval =  0.1
  a3  eval =  0.46
  h4  eval =  -0.42
  g4  eval =  -1.22
  f4  eval =  -0.07
  e4  eval =  0.82
  d4  eval =  0.63
  c4  eval =  0.57
  b4  eval =  -0.26
  a4  eval =  -0.02
  
  ```
  
  > **Comments:**
  > **username_4**: can you update the code with last version of the lib please ?  
  > **username_5**: Seconding @username_4's comment  
  > **username_3**: @username_5 see the edit.  
  
  ---
  
  