bigger refactor in several files
This commit is contained in:
1 parent
8d5024a4a4
commit
0ffc2c77de
7 files changed
+111
-112
No files matched your search
@@ -1,6 +1,76 @@
|
||||
#include "utils.h"
|
||||
#include "movegen.h"
|
||||
|
||||
namespace UTILS {
|
||||
|
||||
// Zobrist //
|
||||
|
||||
U64 initialSeed = 0x60919C48E57863B9;
|
||||
|
||||
// PRNG using xorshift
|
||||
static U64 RandomNum() {
|
||||
initialSeed ^= initialSeed << 13;
|
||||
initialSeed ^= initialSeed >> 7;
|
||||
initialSeed ^= initialSeed << 17;
|
||||
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();
|
||||
}
|
||||
|
||||
U64 GetHashKey(Board &board) {
|
||||
U64 key = 0ULL;
|
||||
|
||||
// XORing pieces
|
||||
for (int color = White; color <= Black; color++) {
|
||||
for (int piece = Pawn; piece <= King; piece++) {
|
||||
Bitboard pieceSet = board.pieces[piece] & board.colors[color];
|
||||
|
||||
while (pieceSet) {
|
||||
int square = pieceSet.getLS1BIndex();
|
||||
|
||||
key ^= zKeys[color][piece][square];
|
||||
|
||||
pieceSet.PopBit(square);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// XORing en passant
|
||||
if (board.enPassantTarget != -1) {
|
||||
key ^= zEnPassant[board.enPassantTarget % 8];
|
||||
}
|
||||
|
||||
// XORing castling rights
|
||||
key ^= zCastle[board.castlingRights];
|
||||
|
||||
// XORing side to move
|
||||
if (board.sideToMove) key ^= zSide;
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
std::vector<std::string> split(std::string_view str, char delim) {
|
||||
std::vector<std::string> results;
|
||||
|
||||
@@ -76,3 +146,4 @@ Move parseMove(Board &board, std::string_view str) {
|
||||
|
||||
return Move(from, to, flag);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user