diff options
author | eug-vs <eugene@eug-vs.xyz> | 2022-09-04 23:44:10 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2022-09-04 23:44:10 +0300 |
commit | 0dc968bab085df048f46d5b86c616c2749842573 (patch) | |
tree | 46b1256c11a7054139f44aeccda16aaed1376630 | |
parent | 43ce3c7deb85363102d810bf8478982c956cd0fe (diff) | |
download | c-chess-0dc968bab085df048f46d5b86c616c2749842573.tar.gz |
feat: add castle to zobrist make_move
-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; } |