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.