5

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 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#

1 Answer 1

4

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.

4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.