-
Notifications
You must be signed in to change notification settings - Fork 18
Description
I'm running into this really annoying crash that happens occasionally during gameplay. The app dies with this assertion:
Assertion failed: (type_of(captured) != KING), function do_move, file position.cpp, line 698.
It's pretty clear what's happening - somehow a move that captures the king is making it through to the engine, which obviously shouldn't happen since you can't capture the king in chess.
How to reproduce
Not super consistent, but I can trigger it by:
- Playing until I have a piece that could theoretically move to the king's square
- Trying to make that move (happens with both human players and AI)
- Crash
What should happen vs what actually happens
Obviously the engine should never even see a king-capture move. The game should end in checkmate/stalemate way before anyone can "capture" a king. But instead, something is slipping through and the engine is rightfully freaking out about it.
Debugging so far
I've spent way too much time on this already:
- Went through all the move generation code - looks clean, king captures should be filtered out
- Added extra checks in the move validation - still happening
- Wrote a bunch of unit tests to make sure king captures get rejected - they do
But the crash still pops up sometimes. I'm wondering if there's some kind of race condition or the board state is getting out of sync between the UI and engine somehow.
Questions
Has anyone seen this before? A few specific things I'm wondering:
- Are there any weird edge cases in the engine where king captures could slip through?
- What's the best way to add more defensive checks at the engine boundary?
- Could this be a FEN parsing issue or board state desync?
- Any suggestions for better logging/debugging to catch this?
Anyone have ideas? This is driving me crazy since the assertion is totally correct - we should never be capturing kings - but somehow we're getting there anyway.