summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index 5a66201..f1eb6a3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -12,6 +12,28 @@
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
+void generate_zobrist_seed(int* seed) {
+ for (int i = 0; i < 781; i++) {
+ seed[i] = rand();
+ }
+}
+
+int zobrist_hash(int* seed, int* board, int color_to_move) {
+ int result = seed[color_to_move];
+ for (int rank = 7; rank >= 0; rank--) {
+ for (int file = 0; file < 8; file++) {
+ int position = rank * 16 + file;
+ int piece = board[position];
+ if (piece != EMPTY) {
+ // Unique index of this piece on this position
+ int zobrist_index = (piece * 128) + position;
+ result ^= seed[zobrist_index];
+ }
+ }
+ }
+ return result;
+}
+
void print_board(int board[128]) {
for (int rank = 7; rank >= 0; rank--) {
@@ -500,7 +522,13 @@ int main() {
Move move;
int color = WHITE;
+ int zobrist_seed[MAX_ZOBRIST_SEEDS];
+ generate_zobrist_seed(zobrist_seed);
+
while (1) {
+ int 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]);
move = input_move();