Answers.Body: <blockquote>
  <p>For example, after entering the following commands: position startpos
  moves e2e4 e7e5, I would like stockfish to report to me that white's
  (or black's) total mobility after e2e4 e7e5 is equal to 29 (there are
  29 legal moves available for white or black after e2e4 e7e5).</p>
  </blockquote>
  <p>Note that your definition of mobility and the definition of mobility used by many chess engines differs. Chess engines generally understand mobility as an evaluation figure that's a good bit more complicated than just the total number of legal moves.</p>
  <p>So for future searching, it might be best to use phrasing like calculating the legal move count for a given position, instead of mobility.</p>
  <p>Anyhow, what you're asking is possible with Stockfish by using the command <code>go perft 1</code> which will display the total number of legal moves for the current position:</p>
  <pre><code>Stockfish 14.1 by the Stockfish developers (see AUTHORS file)
  position startpos moves e2e4 e7e5
  go perft 1
  a2a3: 1
  b2b3: 1
  c2c3: 1
  d2d3: 1
  f2f3: 1
  g2g3: 1
  h2h3: 1
  a2a4: 1
  b2b4: 1
  c2c4: 1
  d2d4: 1
  f2f4: 1
  g2g4: 1
  h2h4: 1
  b1a3: 1
  b1c3: 1
  g1e2: 1
  g1f3: 1
  g1h3: 1
  f1e2: 1
  f1d3: 1
  f1c4: 1
  f1b5: 1
  f1a6: 1
  d1e2: 1
  d1f3: 1
  d1g4: 1
  d1h5: 1
  e1e2: 1
  
  Nodes searched: 29
  </code></pre>
  <p>The <code>go perft</code> command more generally is used to verify that Stockfish's move generation is working correctly, by counting the total number of legal moves up to a certain depth.</p>
  <p>In your example you only wanted the number of legal moves at a depth of 1. If for example, you wanted all of the possible legal moves from a position up till depth n, you would type <code>go perft n</code>:</p>
  <pre><code>Stockfish 14.1 by the Stockfish developers (see AUTHORS file)
  go perft 2
  a2a3: 20
  b2b3: 20
  c2c3: 20
  d2d3: 20
  e2e3: 20
  f2f3: 20
  g2g3: 20
  h2h3: 20
  a2a4: 20
  b2b4: 20
  c2c4: 20
  d2d4: 20
  e2e4: 20
  f2f4: 20
  g2g4: 20
  h2h4: 20
  b1a3: 20
  b1c3: 20
  g1f3: 20
  g1h3: 20
  
  Nodes searched: 400
  </code></pre>
  <p>Do note that the number of legal moves from a given position increases quite rapidly as the depth grows, so typing in large depth numbers will start taking quite a long time to calculate.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-04T16:14:06.723Z
Answers.Text: Thank you very much—that was exactly what I was looking for! Side note: I’ve updated the question title (and body) to say “number of legal moves” instead of “mobility.”
Answers.UserDisplayName: stewy0013
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-04T16:15:11.980Z
Answers.Text: Awesome! @stewy0013 Glad I could help you out!
Answers.UserDisplayName: Chris
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-03T17:49:58.620Z
Answers.LastActivityDate: 2022-06-04T21:51:55.127Z
Answers.LastEditDate: 2022-06-04T21:51:55.127Z
Answers.UserDisplayName: Chris
Body: <p>I am running stockfish 15 from the command line. I'm wondering if there is an easy way for Stockfish to report the total number of legal moves (safe, or otherwise) for each side after a given move.</p>
  <p>For example, after entering the following commands: <em>position startpos moves e2e4 e7e5</em>, I would like stockfish to report to me that white's (or black's) total number of legal moves after e2e4 e7e5 is equal to 29 (there are 29 legal moves available for white or black after e2e4 e7e5).</p>
  <p>Is there some way for stockfish to report this to me in the command line, and if not, is there a way to modify the existing code to accomplish this?</p>
  
Tags: <stockfish><programming>
Title: Using stockfish from command line to calculate the total number of legal moves for each side after a given move
ThreadText: # Using stockfish from command line to calculate the total number of legal moves for each side after a given move
  
  (Asked by: username_0 on 2022-06-03)
  
  I am running stockfish 15 from the command line. I'm wondering if there is an easy way for Stockfish to report the total number of legal moves (safe, or otherwise) for each side after a given move.
  
  For example, after entering the following commands: *position startpos moves e2e4 e7e5*, I would like stockfish to report to me that white's (or black's) total number of legal moves after e2e4 e7e5 is equal to 29 (there are 29 legal moves available for white or black after e2e4 e7e5).
  
  Is there some way for stockfish to report this to me in the command line, and if not, is there a way to modify the existing code to accomplish this?
  
  **Tags:** stockfish, programming
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-06-03. Score: 4
  
  > For example, after entering the following commands: position startpos
  > moves e2e4 e7e5, I would like stockfish to report to me that white's
  > (or black's) total mobility after e2e4 e7e5 is equal to 29 (there are
  > 29 legal moves available for white or black after e2e4 e7e5).
  
  Note that your definition of mobility and the definition of mobility used by many chess engines differs. Chess engines generally understand mobility as an evaluation figure that's a good bit more complicated than just the total number of legal moves.
  
  So for future searching, it might be best to use phrasing like calculating the legal move count for a given position, instead of mobility.
  
  Anyhow, what you're asking is possible with Stockfish by using the command `go perft 1` which will display the total number of legal moves for the current position:
  
  ```
  Stockfish 14.1 by the Stockfish developers (see AUTHORS file)
  position startpos moves e2e4 e7e5
  go perft 1
  a2a3: 1
  b2b3: 1
  c2c3: 1
  d2d3: 1
  f2f3: 1
  g2g3: 1
  h2h3: 1
  a2a4: 1
  b2b4: 1
  c2c4: 1
  d2d4: 1
  f2f4: 1
  g2g4: 1
  h2h4: 1
  b1a3: 1
  b1c3: 1
  g1e2: 1
  g1f3: 1
  g1h3: 1
  f1e2: 1
  f1d3: 1
  f1c4: 1
  f1b5: 1
  f1a6: 1
  d1e2: 1
  d1f3: 1
  d1g4: 1
  d1h5: 1
  e1e2: 1
  
  Nodes searched: 29
  
  ```
  
  The `go perft` command more generally is used to verify that Stockfish's move generation is working correctly, by counting the total number of legal moves up to a certain depth.
  
  In your example you only wanted the number of legal moves at a depth of 1. If for example, you wanted all of the possible legal moves from a position up till depth n, you would type `go perft n`:
  
  ```
  Stockfish 14.1 by the Stockfish developers (see AUTHORS file)
  go perft 2
  a2a3: 20
  b2b3: 20
  c2c3: 20
  d2d3: 20
  e2e3: 20
  f2f3: 20
  g2g3: 20
  h2h3: 20
  a2a4: 20
  b2b4: 20
  c2c4: 20
  d2d4: 20
  e2e4: 20
  f2f4: 20
  g2g4: 20
  h2h4: 20
  b1a3: 20
  b1c3: 20
  g1f3: 20
  g1h3: 20
  
  Nodes searched: 400
  
  ```
  
  Do note that the number of legal moves from a given position increases quite rapidly as the depth grows, so typing in large depth numbers will start taking quite a long time to calculate.
  
  > **Comments:**
  > **username_0**: Thank you very much—that was exactly what I was looking for! Side note: I’ve updated the question title (and body) to say “number of legal moves” instead of “mobility.”  
  > **username_1**: Awesome! @username_0 Glad I could help you out!  
  
  ---
  
  