Answers.Body: <p>If you do not want to use a library/API to get this information, then you will need to implement some parsing to get it, but in principle (almost) all the info you need is available via (non-standard) UCI commands:</p>
  <ol>
  <li>Legal moves</li>
  </ol>
  <p>Perft lists all legal moves. E.g., for the starting position <code>go perft 1</code> gives you:</p>
  <pre><code>a2a3: 1
  b2b3: 1
  c2c3: 1
  d2d3: 1
  e2e3: 1
  f2f3: 1
  g2g3: 1
  h2h3: 1
  a2a4: 1
  b2b4: 1
  c2c4: 1
  d2d4: 1
  e2e4: 1
  f2f4: 1
  g2g4: 1
  h2h4: 1
  b1a3: 1
  b1c3: 1
  g1f3: 1
  g1h3: 1
  
  Nodes searched: 20
  </code></pre>
  <p>2.+3. Game state</p>
  <p><code>d</code> is a non-standard UCI command in Stockfish to print debug information. It contains information like the FEN and pieces giving check, e.g.,</p>
  <pre><code>position startpos moves e2e3 f7f5 d1h5
  d
  </code></pre>
  <pre><code> +---+---+---+---+---+---+---+---+
   | r | n | b | q | k | b | n | r | 8
   +---+---+---+---+---+---+---+---+
   | p | p | p | p | p |   | p | p | 7
   +---+---+---+---+---+---+---+---+
   |   |   |   |   |   |   |   |   | 6
   +---+---+---+---+---+---+---+---+
   |   |   |   |   |   | p |   | Q | 5
   +---+---+---+---+---+---+---+---+
   |   |   |   |   |   |   |   |   | 4
   +---+---+---+---+---+---+---+---+
   |   |   |   |   | P |   |   |   | 3
   +---+---+---+---+---+---+---+---+
   | P | P | P | P |   | P | P | P | 2
   +---+---+---+---+---+---+---+---+
   | R | N | B |   | K | B | N | R | 1
   +---+---+---+---+---+---+---+---+
     a   b   c   d   e   f   g   h
  
  Fen: rnbqkbnr/ppppp1pp/8/5p1Q/8/4P3/PPPP1PPP/RNB1KBNR b KQkq - 1 2
  Key: 47C539B3DEE3D29B
  Checkers: h5 
  </code></pre>
  <p>In order to determine whether it is checkmate, you need to check whether perft 1 is zero and checkers from <code>d</code> is non-empty.</p>
  <p>For draw detection I think there is no straightforward way to do it with plain Stockfish. The only draw that can safely be detected is stalemate, similar to the checkmate detection mentioned above.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-05-09T10:40:29.483Z
Answers.Text: and if I do not mind to use some API / library,  what would you recommend for c#?
Answers.UserDisplayName: Aviv Aviv
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-05-09T11:23:05.410Z
Answers.Text: I do not have any experience with C#, but https://github.com/search?l=C%23&q=chess&type=Repositories seems to suggest some options like https://github.com/thomas-daniels/Chess.NET or https://github.com/rudzen/ChessLib.
Answers.UserDisplayName: Fabian Fichter
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-05-10T07:55:53.507Z
Answers.Text: Thanks for your answer! I know it is out of context, but I dont want to spam the site with any more questions. What uci command should I use to get the list of all possible moves + their rank (as in d2 d4 = 1.2, d2 d3 = -0.5 etc...) currently when you use the go command you only get the best move, but I need all of them + ranking
Answers.UserDisplayName: Aviv Aviv
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-05-10T17:33:59.880Z
Answers.Text: multiPV https://github.com/official-stockfish/Stockfish#multipv is perhaps what your are looking for
Answers.UserDisplayName: Fabian Fichter
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-05-09T10:30:55.830Z
Answers.LastActivityDate: 2021-05-09T10:30:55.830Z
Answers.UserDisplayName: Fabian Fichter
Body: <p>I want to know from Stockfish:</p>
  <ol>
  <li>All possible moves in a position, a.k.a. a depth 1 analysis with no score.</li>
  <li>If the king is in check, is checkmated, or if there is a draw.</li>
  <li>The current FEN string, after a move.</li>
  </ol>
  <p>How can I get all of those? I tried looking in the <a href="https://gist.github.com/aliostad/f4470274f39d29b788c1b09519e67372" rel="nofollow noreferrer">UCI specs</a> and there is nothing like it.  I found some answers as to the first question, but they were all in Python. I am looking for pure UCI commands as I am using C#</p>
  
Tags: <engines><stockfish><programming><computer-chess><uci>
Title: Obtain information about a a position from Stockfish
ThreadText: # Obtain information about a a position from Stockfish
  
  (Asked by: username_0 on 2021-05-09)
  
  I want to know from Stockfish:
  
  1. All possible moves in a position, a.k.a. a depth 1 analysis with no score.
  2. If the king is in check, is checkmated, or if there is a draw.
  3. The current FEN string, after a move.
  
  How can I get all of those? I tried looking in the [UCI specs](https://gist.github.com/aliostad/f4470274f39d29b788c1b09519e67372) and there is nothing like it. I found some answers as to the first question, but they were all in Python. I am looking for pure UCI commands as I am using C#
  
  **Tags:** engines, stockfish, programming, computer-chess, uci
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-05-09. Score: 4 | Accepted answer
  
  If you do not want to use a library/API to get this information, then you will need to implement some parsing to get it, but in principle (almost) all the info you need is available via (non-standard) UCI commands:
  
  1. Legal moves
  
  Perft lists all legal moves. E.g., for the starting position `go perft 1` gives you:
  
  ```
  a2a3: 1
  b2b3: 1
  c2c3: 1
  d2d3: 1
  e2e3: 1
  f2f3: 1
  g2g3: 1
  h2h3: 1
  a2a4: 1
  b2b4: 1
  c2c4: 1
  d2d4: 1
  e2e4: 1
  f2f4: 1
  g2g4: 1
  h2h4: 1
  b1a3: 1
  b1c3: 1
  g1f3: 1
  g1h3: 1
  
  Nodes searched: 20
  
  ```
  
  2.+3. Game state
  
  `d` is a non-standard UCI command in Stockfish to print debug information. It contains information like the FEN and pieces giving check, e.g.,
  
  ```
  position startpos moves e2e3 f7f5 d1h5
  d
  
  ```
  
  ```
   +---+---+---+---+---+---+---+---+
   | r | n | b | q | k | b | n | r | 8
   +---+---+---+---+---+---+---+---+
   | p | p | p | p | p |   | p | p | 7
   +---+---+---+---+---+---+---+---+
   |   |   |   |   |   |   |   |   | 6
   +---+---+---+---+---+---+---+---+
   |   |   |   |   |   | p |   | Q | 5
   +---+---+---+---+---+---+---+---+
   |   |   |   |   |   |   |   |   | 4
   +---+---+---+---+---+---+---+---+
   |   |   |   |   | P |   |   |   | 3
   +---+---+---+---+---+---+---+---+
   | P | P | P | P |   | P | P | P | 2
   +---+---+---+---+---+---+---+---+
   | R | N | B |   | K | B | N | R | 1
   +---+---+---+---+---+---+---+---+
     a   b   c   d   e   f   g   h
  
  Fen: rnbqkbnr/ppppp1pp/8/5p1Q/8/4P3/PPPP1PPP/RNB1KBNR b KQkq - 1 2
  Key: 47C539B3DEE3D29B
  Checkers: h5 
  
  ```
  
  In order to determine whether it is checkmate, you need to check whether perft 1 is zero and checkers from `d` is non-empty.
  
  For draw detection I think there is no straightforward way to do it with plain Stockfish. The only draw that can safely be detected is stalemate, similar to the checkmate detection mentioned above.
  
  > **Comments:**
  > **username_0**: and if I do not mind to use some API / library,  what would you recommend for c#?  
  > **username_1**: I do not have any experience with C#, but https://github.com/search?l=C%23&q=chess&type=Repositories seems to suggest some options like https://github.com/thomas-daniels/Chess.NET or https://github.com/rudzen/ChessLib.  
  > **username_0**: Thanks for your answer! I know it is out of context, but I dont want to spam the site with any more questions. What uci command should I use to get the list of all possible moves + their rank (as in d2 d4 = 1.2, d2 d3 = -0.5 etc...) currently when you use the go command you only get the best move, but I need all of them + ranking  
  > **username_1**: multiPV https://github.com/official-stockfish/Stockfish#multipv is perhaps what your are looking for  
  
  ---
  
  