dogefromage / Stalemater2000

Basic uci chess engine in c++
MIT License
2 stars 0 forks source link

Extra move reported #1

Closed redbullmarky closed 2 years ago

redbullmarky commented 2 years ago

This position:

position startpos moves a2a3 d7d5 c2c4 d5c4 d1a4

which leaves black to play gives d8d2 as a valid move. However, black is in check from the queen on a4, and d8d2 doesn't evade it. After a bit of digging the problem is the else here in Board::Init():

    Checks = 0;
    if (BitBoards[KW] & UnsafeForWhite)
        Checks |= CHECK_WHITE;
    else if (BitBoards[KB] & UnsafeForBlack)
        Checks |= CHECK_BLACK;

Although black's move is illegal, it's one that puts the white king immediately in check, so the first condition above is met but not the second. And just like that, black isn't in check as far as the game is concerned :)

Removing the else from the above code fixes the perft tests (found at startpos, depth 6 initially) and stops a few oddities.

dogefromage commented 2 years ago

issue fixed in commit 887b50