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:
- 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.