generate zobrist masks
This commit is contained in:
3
include/chess/rand.h
Normal file
3
include/chess/rand.h
Normal file
@ -0,0 +1,3 @@
|
||||
#include <stdint.h>
|
||||
|
||||
uint_least64_t rand_64();
|
||||
10
src/common/rand.c
Normal file
10
src/common/rand.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <chess/rand.h>
|
||||
|
||||
uint_least64_t rand_64() {
|
||||
uint_least64_t u1, u2, u3, u4;
|
||||
u1 = (uint_least64_t)(rand()) & 0xFFFF; u2 = (uint_least64_t)(rand()) & 0xFFFF;
|
||||
u3 = (uint_least64_t)(rand()) & 0xFFFF; u4 = (uint_least64_t)(rand()) & 0xFFFF;
|
||||
return u1 | (u2 << 16) | (u3 << 32) | (u4 << 48);
|
||||
}
|
||||
@ -9,18 +9,12 @@
|
||||
#include <chess/magic.h>
|
||||
#include <chess/generated/moveConsts.h>
|
||||
#include <chess/bitboard.h>
|
||||
#include <chess/rand.h>
|
||||
|
||||
#define MAX_BITS 12
|
||||
#define MAX_SIZE (1 << MAX_BITS)
|
||||
#define ATTACK_TABLE_LENGTH (2 * MAX_SIZE * TOTAL_BOARD_SIZE)
|
||||
|
||||
static uint_least64_t rand_64() {
|
||||
uint_least64_t u1, u2, u3, u4;
|
||||
u1 = (uint_least64_t)(rand()) & 0xFFFF; u2 = (uint_least64_t)(rand()) & 0xFFFF;
|
||||
u3 = (uint_least64_t)(rand()) & 0xFFFF; u4 = (uint_least64_t)(rand()) & 0xFFFF;
|
||||
return u1 | (u2 << 16) | (u3 << 32) | (u4 << 48);
|
||||
}
|
||||
|
||||
static uint_least64_t randFewBits() {
|
||||
return rand_64() & rand_64() & rand_64();
|
||||
}
|
||||
|
||||
30
src/generateCode/zobrist.c
Normal file
30
src/generateCode/zobrist.c
Normal file
@ -0,0 +1,30 @@
|
||||
#include "chess/types.h"
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <chess/rand.h>
|
||||
#include <stdlib.h>
|
||||
#include <chess/print.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
static uint_least64_t zobristPieceI(struct piece_t piece, uint_least8_t field) {
|
||||
return field * 2 * PIECES_LENGTH + piece.color * PIECES_LENGTH + piece.type;
|
||||
}
|
||||
|
||||
int main() {
|
||||
uint_least64_t zobristPiece[TOTAL_BOARD_SIZE * 2 * PIECES_LENGTH];
|
||||
srand(0xc0229b8e);
|
||||
printf("#ifndef CHESS_GENERATED_ZOBRIST_H\n"
|
||||
"#define CHESS_GENERATED_ZOBRIST_H\n"
|
||||
"#include <stdint.h>\n"
|
||||
);
|
||||
for(uint_least8_t color = BLACK; color <= WHITE; ++color) {
|
||||
for(uint_least8_t pieceType = KING; pieceType < PIECES_LENGTH; ++pieceType) {
|
||||
const struct piece_t piece = {pieceType, color};
|
||||
for(uint_least8_t field = 0; field < TOTAL_BOARD_SIZE; ++field) {
|
||||
zobristPiece[zobristPieceI(piece, field)] = rand_64();
|
||||
}
|
||||
}
|
||||
}
|
||||
defineArray("#define defineZobristPiece const static uint_least64_t ZOBRIST_PIECE", printerull, zobristPiece);
|
||||
printf("#define defineZobristBlackMove const uint_least64_t ZOBRIST_BLACK_MOVE = %" PRIuLEAST64 "\n", rand_64());
|
||||
}
|
||||
Reference in New Issue
Block a user