sandermvdb / chess22k

Chessengine written in Java
GNU General Public License v3.0
32 stars 8 forks source link

King blocked at last rank #2

Closed ratosh closed 6 years ago

ratosh commented 6 years ago

It seems that it does not consider enemy attacks. Tested on this board: 6k1/4rp1p/6pP/3p2P1/5P2/3bP1K1/1q6/2R5 w - -

sandermvdb commented 6 years ago

Thanks for raising this issue 👍 I've updated the code which will be part of the 1.8 release:

private static boolean kingBlockedAtLastRank(final int kingIndex, final int kingColor, final ChessBoard cb) {
    return cb.colorToMove != kingColor && (Bitboard.RANKS[7 * kingColor] & cb.pieces[kingColor][KING]) != 0 
      && (StaticMoves.KING_MOVES[kingIndex] & cb.emptySpaces & ~cb.attacksAll[1 - kingColor] & Bitboard.RANKS[7 * kingColor]) 
      == (StaticMoves.KING_MOVES[kingIndex] & cb.emptySpaces & ~cb.attacksAll[1 - kingColor]);
}
ratosh commented 6 years ago

Still a small problem when moving a rook or a queen from rank6 to rank7. attacksAll will have attacks to rank6 and this function when detecting safe rook checks will return the king is blocked. 3k4/7R/8/8/8/8/8/7K w - -

sandermvdb commented 6 years ago

Performance vs accuracy...