summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/main.c b/src/main.c
index 7985d41..5fa9f8c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -13,16 +13,16 @@
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
void generate_zobrist_seed(int* seed) {
- for (int i = 0; i < 781; i++) {
+ for (int i = 0; i < MAX_ZOBRIST_SEEDS; i++) {
seed[i] = rand();
}
}
int zobrist_hash(int* seed, int* board, int color_to_move) {
- int result = 1;
+ int hash = 1;
// Last feature means white to move
- if (color_to_move == WHITE) result ^= seed[MAX_ZOBRIST_SEEDS - 1];
+ if (color_to_move == WHITE) hash ^= seed[MAX_ZOBRIST_SEEDS - 1];
for (int rank = 7; rank >= 0; rank--) {
for (int file = 0; file < 8; file++) {
@@ -31,10 +31,10 @@ int zobrist_hash(int* seed, int* board, int color_to_move) {
// Unique index of this piece on this position
int zobrist_index = piece * 128 + position;
- result ^= seed[zobrist_index];
+ hash ^= seed[zobrist_index];
}
}
- return result;
+ return hash;
}
int apply_move_zobrist(Move move, int* board, int* zobrist_seed, int hash) {
@@ -42,6 +42,7 @@ int apply_move_zobrist(Move move, int* board, int* zobrist_seed, int hash) {
int target_piece = board[move.destination];
hash ^= zobrist_seed[MAX_ZOBRIST_SEEDS - 1]; // Flip color
+ hash ^= zobrist_seed[EMPTY * 128 + move.origin]; // Add empty to origin
hash ^= zobrist_seed[piece * 128 + move.origin]; // Remove piece from origin
hash ^= zobrist_seed[piece * 128 + move.destination]; // Add piece to destination
hash ^= zobrist_seed[target_piece * 128 + move.destination]; // Remove target piece from destination
@@ -511,7 +512,7 @@ Move find_best_move(int* board, int color, int depth, int alpha, int beta, int*
Move available_moves[MAX_AVAILABLE_MOVES];
int available_moves_count = list_available_moves(available_moves, board, color);
int cache_hits = sort_moves(available_moves, available_moves_count, board, hash, transposition_table, zobrist_seed);
- if (cache_hits && (double)cache_hits / (double)available_moves_count > 0.75) printf("More than 75 percent cache hits (%i)\n", cache_hits);
+ if (depth == 0 && cache_hits && (double)cache_hits / (double)available_moves_count > 0.50) printf("More than 50 percent cache hits (%i)\n", cache_hits);
for (int i = 0; i < available_moves_count; i++) {
*metrics += 1;
@@ -561,7 +562,7 @@ int main() {
print_board(board);
while (1) {
- printf("Expected zobrist hash: %i (found %i)\n", hash, zobrist_hash(zobrist_seed, board, color));
+ printf("Zobrist hash: %i\n", hash);
if (color == PLAYER) {
printf("Enter a move for %s:\n", COLORS[color]);