Skip to content

Engine crashes on King Capture Assertion #26

@alex-x-x-x-x

Description

@alex-x-x-x-x

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:

  1. Playing until I have a piece that could theoretically move to the king's square
  2. Trying to make that move (happens with both human players and AI)
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions