From 0dc968bab085df048f46d5b86c616c2749842573 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 4 Sep 2022 23:44:10 +0300 Subject: feat: add castle to zobrist make_move --- src/main.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src') diff --git a/src/main.c b/src/main.c index a920cfd..360a4e8 100644 --- a/src/main.c +++ b/src/main.c @@ -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; } -- cgit v1.2.3