diff options
-rw-r--r-- | src/main.c | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -49,6 +49,35 @@ long hash_after_move(Move move, int* board, long* zobrist_seed, long hash) { hash ^= zobrist_seed[piece * 128 + move.destination]; // Add piece to destination hash ^= zobrist_seed[target_piece * 128 + move.destination]; // Remove target piece from destination + if ((piece & NO_COLOR) == KING && abs(move.destination - move.origin) == 2) { + // CASTLE! + if (move.destination == 2) { + int rook = board[0]; + hash ^= zobrist_seed[rook * 128 + 0]; // Rook is no longer on 0 + hash ^= zobrist_seed[EMPTY * 128 + 0]; // Empty square on 0 + hash ^= zobrist_seed[EMPTY * 128 + 3]; // Square 3 is not empty anymore + hash ^= zobrist_seed[rook * 128 + 3]; // Rook is now on 3 + } else if (move.destination == 6) { + int rook = board[7]; + hash ^= zobrist_seed[rook * 128 + 7]; + hash ^= zobrist_seed[EMPTY * 128 + 7]; + hash ^= zobrist_seed[EMPTY * 128 + 5]; + hash ^= zobrist_seed[rook * 128 + 5]; + } else if (move.destination == 114) { + int rook = board[112]; + hash ^= zobrist_seed[rook * 128 + 112]; + hash ^= zobrist_seed[EMPTY * 128 + 112]; + hash ^= zobrist_seed[EMPTY * 128 + 115]; + hash ^= zobrist_seed[rook * 128 + 115]; + } else if (move.destination == 118) { + int rook = board[119]; + hash ^= zobrist_seed[rook * 128 + 119]; + hash ^= zobrist_seed[EMPTY * 128 + 119]; + hash ^= zobrist_seed[EMPTY * 128 + 117]; + hash ^= zobrist_seed[rook * 128 + 117]; + } + } + return hash; } |