rudzen / ChessLib

C# chess library containing a complete data structure and move generation.
MIT License
81 stars 23 forks source link

Promoting a pawn to Queen with check #60

Closed JMSSVLC closed 1 year ago

JMSSVLC commented 1 year ago

I think there is an issue with promotion of a pawn to Queen with check in the following scenario:

fen position "8/6pk/pb5p/8/1P2qP2/P7/2r2pNP/1QR4K b - - 1 2"

the best moves (mate in 3) are e3f2 g1h1 f2f1q, by the last one the function position.GivesCheck(move) does not return true.

I cannot upload a test because I am still working with VS2019 and I run an adapted version to my environment. It could also be my mistake in my adapted version.

Thank you for your attention

rudzen commented 1 year ago

The position based on 8/6pk/pb5p/8/1P2qP2/P7/2r2pNP/1QR4K b - - 1 2

Doesn't contain the move series you point out

e3f2[?] g1h1[?] f2f1q

image

The first two moves are impossible from the FEN you supply, and if the last move is performed black is not mating, since white could take using rook c1f1.

If you would supply new information I would be happy to look into any potential issue(s) with the GivesCheck() functionality. I would recommend installing the latest VS, which might makes things a bit easier for you.

JMSSVLC commented 1 year ago

I am very sorry I made a copy/paste mistake by the starting FEN Position and I see now that it was also very bad explained. The starting position is "8/6pk/pb5p/8/1P2qP2/P3p3/2r2PNP/1QR3K1 b - - 0 1" then the best moves (mate in 3) are e3f2 g1h1 f2f1q c1f1 e4g2 leading to the FEN Position "8/6pk/pb5p/8/1P3P2/P7/2r3qP/1Q3R1K w - - 0 4", check mate Probaly it was a mistake from my environment or a test with an older version of your library, I am not sure, because reviewing my test now I see that position.GivesCheck("e4g2") returns true although it is a check mate, of course it is also a check. So you can close this issue. We can see it is a check mate because there are no available legal moves . As said I am very sorry about that, but my intention was to help you. From my side I will investigate further to see if there is something else related to the position I can't see now. It was last month and now I can't remember anymore if there was. Thank you for your effort developing this library!!

rudzen commented 1 year ago

I am very sorry I made a copy/paste mistake by the starting FEN Position and I see now that it was also very bad explained.

Np, copy-paste is the enemy of the people!

The starting position is "8/6pk/pb5p/8/1P2qP2/P3p3/2r2PNP/1QR3K1 b - - 0 1" then the best moves (mate in 3) are e3f2 g1h1 f2f1q c1f1 e4g2 leading to the FEN Position "8/6pk/pb5p/8/1P3P2/P7/2r3qP/1Q3R1K w - - 0 4", check mate

As a note, the library has extensive tests to make sure that the move generator is working - since that is usually the most error-prone in general. In case you notice anything strange, the best way is properly to create a unit test with the moves, the UCI functionality can convert UCI moves with no problems.

Probaly it was a mistake from my environment or a test with an older version of your library, I am not sure, because reviewing my test now I see that position.GivesCheck("e4g2") returns true although it is a check mate, of course it is also a check. So you can close this issue. We can see it is a check mate because there are no available legal moves .

Yes, the gives check doesn't really care if the position is mate or not. To check for mate you can generate moves and see if there are any moves available. This is also how the notation functionality detects mate etc.

Thank you for your effort developing this library!!

Your welcome!