nvzqz / Sage

A cross-platform chess library for Swift
Apache License 2.0
375 stars 43 forks source link

game.kingIsChecked wrong after own king was in check before delivering check #18

Open SuperGeroy opened 6 years ago

SuperGeroy commented 6 years ago

When your own king is in check and your move removes the check and at the same time delivers check to the opponent king then the game.kingIsChecked variable is wrong, it is false but should be true.

I stumbled upon the error with the following position FEN: 2K1r3/3P1k2/8/8/8/8/8/2R5 w - - 0 1 where White is in check already. After the promotion move dxe8Q+ the black king is in check but kingIsChecked is false. After the promotion move d8N+ the black king is also in check but kingIsChecked is false.

The error has nothing to do with the promotion, I tried it with different positions and the common condition for the error is that the own king is in check directly before you put the enemy king in check.

SuperGeroy commented 6 years ago

The fix by @werner77 (#19) works for me. Thanks.