Chess-Challenge icon indicating copy to clipboard operation
Chess-Challenge copied to clipboard

board.GetLegalMoves includes illegal moves when in check

Open Apoptosis847639 opened this issue 2 years ago • 6 comments

When your king is in check board.GetLegalMoves includes moves that does not prevent the check so my bot will make an illegal move. I have no idea if this is intentional so if it is I will close the issue.

Apoptosis847639 avatar Jul 26 '23 19:07 Apoptosis847639

Are you sure? I've had no such problem. Do you have a way to reproduce this behavior?

mcthouacbb avatar Jul 26 '23 21:07 mcthouacbb

Screenshot 2023-07-27 105750 Screenshot 2023-07-27 105856 So my bot tried to play dxe4 which would have been legal if black was not in check so maybe its my bot or board.GetLegalMoves

Apoptosis847639 avatar Jul 27 '23 15:07 Apoptosis847639

So my bot tried to play dxe4 which would have been legal if black was not in check so maybe its my bot or board.GetLegalMoves

I can confirm that board.GetLegalMoves() is broken. The method returns illegal moves when the king is in check.

pmwmedia avatar Jul 27 '23 18:07 pmwmedia

It is unlikely that this is a bug in the GetLegalMoves method since the board UI was able to detect that the move is illegal.

The most common cause for a bot making illegal moves is if there's a mistake in the order that moves are made/undone on the board (for example forgetting to undo a move when exiting early from search due to checkmate/etc).

If you're struggling to track down the bug, I suggest asking in the discord if anyone's willing to lend a second pair of eyes. (link in readme)

SebLague avatar Jul 28 '23 00:07 SebLague

Pls share the relevant code snippets for help. I can confirm that the following FEN didn't produce any illegal moves for me.

Firestorm-253 avatar Jul 28 '23 09:07 Firestorm-253

I recommend to do a simple check in the main 'Think()' Method before returning the chosen Move: If (!board.GetLegalMoves().Contains(chosenMove)) { throw new Exception("ERROR: I messed smt up") }

otherwise what you can try to debug the error yourself is create a node class including infos like the FEN, played moves so far, eval, depth, subNodes, etc. and then track it down from where this d5e5 comes from.

Firestorm-253 avatar Jul 28 '23 09:07 Firestorm-253