py-stockfish / stockfish

Integrates the Stockfish chess engine with Python (Official fork)
https://py-stockfish.github.io/stockfish/
MIT License
30 stars 9 forks source link

set_fen_position() with black turn FEN, then get_best_move() outputting incorrect move (for white) #52

Closed arikanev closed 1 year ago

arikanev commented 1 year ago

I'm passing in a FEN of "RNBK11NR/P1111P11/1P1B11P1/11P1111P/111Pp111/bp1n111p/p1ppbpp1/r111rk11" + " b"

And get_best_move() is still outputting a move for white.

It doesn't make sense. Am I doing something wrong?

Thanks

kieferro commented 1 year ago

The problem is that your string (RNBK11NR/P1111P11/1P1B11P1/11P1111P/111Pp111/bp1n111p/p1ppbpp1/r111rk11 b) is not a valid FEN. It is missing several parts like the Castling availability, the total number of moves so far. Furthermore several consecutive numbers should always be added together. The FEN wikipedia article has an overview of what a valid FEN should contain. A valid version of your FEN would be something like RNBK2NR/P4P2/1P1B2P1/2P4P/3Pp3/bp1n3p/p1ppbpp1/r3rk2 b - - 0 1 (which makes no sense as the total number of moves is too low to achieve such a position, but that is not important for the evaluation).

But you're right, of course, that it seems odd that the engine just evaluates anyway. Accordingly, perhaps we should at least introduce syntactic checking of the FEN by default. (Also relevant: #49)

arikanev commented 1 year ago

Even when doing this: RNBK2NR/P4P2/1P1B2P1/2P4P/3Pp3/bp1n3p/p1ppbpp1/r3rk2 b - - 0 1, the best move output doesn't seem to make sense...

kieferro commented 1 year ago

Ah okay, I took a closer look at the position itself and the problem is somewhere else. You have (most likely) created your FEN the wrong way around. The board is flipped which means that the black pawns are one step before promotion, so d2d1q would actually make sense as a move:

1

You should flip the board (2kr3r/1ppbpp1p/p3n1pb/3pP3/P4P2/1P2B1P1/2P4P/RN2KBNR b - - 0 1) or the colors (rnbk2nr/p4p2/1p1b2p1/2p4p/3pP3/BP1N3P/P1PPBPP1/R3RK2 b - - 0 1).

arikanev commented 1 year ago

Flipping the board gives a good move! Flipping the colors doesnt. Thank you!