SebLague / Chess-Challenge

Create your own tiny chess bot!
https://www.youtube.com/watch?v=Ne40a5LkK6A
MIT License
1.77k stars 1.06k forks source link

Fix for bug in cachedInCheckValue when doing/undoing turnskips #350

Open RobotLazerShark opened 1 year ago

RobotLazerShark commented 1 year ago

This PR fixes a bug in the ForceSkipTurn(), TrySkipTurn(), and UndoSkipTurn() methods. Currently if you use any of these three methods to change the turn and then on that same turn use IsInCheck(), you will always get back false.

I did two full runs of the tests, one where after every board setup or move I added a ForceSkipTurn() followed by an UndoSkipTurn(), and one where I updated the position setup fens to flip the turn order and then added a ForceSkipTurn() immediately after. In both cases all the tests still passed.

I did see a comment on the MakeNullMove() method in the Chess.Board class about being in check potentially being an issue, but I didn't see any (other) code that seemed like that would be an issue (and also didn't notice any issues with this in the tests).