pub struct ZobristArrays {
pub to_move: u64,
pub pieces: [[[u64; 64]; 6]; 2],
pub castling_rights: [u64; 16],
pub enpassant_file: [u64; 16],
pub halfmove_clock: [u64; 100],
}
impl ZobristArrays {
fn new() -> ZobristArrays {
use rand::{Rng, SeedableRng};
use rand::isaac::Isaac64Rng;
let seed: &[_] = &[1, 2, 3, 4];
let mut rng: Isaac64Rng = SeedableRng::from_seed(seed);
let to_move = rng.gen();
let mut pieces = [[[0; 64]; 6]; 2];
let mut castling_rights = [0; 16];
let mut enpassant_file = [0; 16];
let mut halfmove_clock = [0; 100];
for color in 0..2 {
for piece in 0..6 {
for square in 0..64 {
pieces[color][piece][square] = rng.gen();
}
}
}
for value in 0..16 {
castling_rights[value] = rng.gen();
}
for file in 0..8 {
enpassant_file[file] = rng.gen();
}
for n in 0..100 {
halfmove_clock[n] = rng.gen();
}
ZobristArrays {
to_move: to_move,
pieces: pieces,
castling_rights: castling_rights,
enpassant_file: enpassant_file,
halfmove_clock: halfmove_clock,
}
}
pub fn get() -> &'static ZobristArrays {
use std::sync::{Once, ONCE_INIT};
static INIT_ARRAYS: Once = ONCE_INIT;
static mut ARRAYS: Option<ZobristArrays> = None;
unsafe {
INIT_ARRAYS.call_once(|| { ARRAYS = Some(ZobristArrays::new()); });
ARRAYS.as_ref().unwrap()
}
}
}