use rand::prelude::*; use movegen::{PieceType}; use bitboard::Square; pub type Hash = u64; pub struct ZobristTable { board: [[Hash; 12]; 64], en_passant: [Hash; 8], castling_rights: [Hash; 4], turn: Hash, } impl ZobristTable { pub fn new() -> Self { let mut zt = ZobristTable { board: [[0; 12]; 64], en_passant: [0; 8], castling_rights: [0; 4], turn: 0 }; let seed: [u8; 32] = [0x3f, 0x64, 0x5, 0x48, 0xef, 0x2d, 0xcb, 0x8e, 0xe6, 0x67, 0xc, 0x90, 0xcf, 0x10, 0x2d, 0x1e, 0x32, 0xb5, 0xbf, 0xe3, 0xf, 0x95, 0x8c, 0xf1, 0xbc, 0xe7, 0xb5, 0x76, 0x16, 0x4a, 0x17, 0x39]; let mut rng = StdRng::from_seed(seed); for piece in &mut zt.board { for sq in piece { *sq = rng.next_u64(); } } for file in &mut zt.en_passant { *file = rng.next_u64(); } for cr in &mut zt.castling_rights { *cr = rng.next_u64(); } zt.turn = rng.next_u64(); return zt; } pub fn piece_hash(&self, piece_type: PieceType, sq: Square) -> Hash { self.board[sq as usize][piece_type as usize] } pub fn en_passant_hash(&self, file: u8) -> Hash { self.en_passant[file as usize] } pub fn castling_rights_hash(&self, cr: u8) -> Hash { self.castling_rights[cr as usize] } pub fn turn_hash(&self) -> Hash { self.turn } }