diff --git a/source/main.cpp b/source/main.cpp index 4505175..cc5ff63 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,14 +1,17 @@ #include "board.h" #include "movegen.h" #include "uci.h" +#include "tt.h" int main() { initLeaperAttacks(); initSliderAttacks(); + InitZobrist(); Board board; UCILoop(board); + return 0; } diff --git a/source/tt.cpp b/source/tt.cpp new file mode 100644 index 0000000..1d87a13 --- /dev/null +++ b/source/tt.cpp @@ -0,0 +1,44 @@ +#include "tt.h" +#include "types.h" + +static inline U64 initialSeed = 0x60919C48E57863B9; + +// 2[colors] * 6[pieces] * 64[squares] +static U64 zKeys[768]; + +// There are 8 files +static U64 zEnPassant[8]; + +static U64 zCastle[16]; +static U64 zSide; + +static U64 RandomNum() { + initialSeed ^= initialSeed << 13; + initialSeed ^= initialSeed >> 17; + initialSeed ^= initialSeed << 5; + return initialSeed; +} + +void InitZobrist() { + // init piece square keys + for (int i = White; i <= Black; i++) { + for (int j = Pawn; j <= King; j++) { + for (int k = a1; k <= h8; k++) { + zKeys[i+j+k] = RandomNum(); + } + } + } + + // init en passant file keys + for (int i = 0; i < 8; i++) { + zEnPassant[i] = RandomNum(); + } + + // init castling rights keys + for (int i = 0; i < 16; i++) { + zCastle[i] = RandomNum(); + } + + // init side key + zSide = RandomNum(); +} diff --git a/source/tt.h b/source/tt.h new file mode 100644 index 0000000..56c31c5 --- /dev/null +++ b/source/tt.h @@ -0,0 +1,3 @@ +#pragma once + +void InitZobrist();