use std::fs::File;
use std::io::Write;
use crate::color::NUM_COLORS;
use crate::file::NUM_FILES;
use crate::piece::NUM_PIECES;
use crate::square::NUM_SQUARES;
use rand::{weak_rng, Rng, SeedableRng};
pub fn write_zobrist(f: &mut File) {
let mut rng = weak_rng();
rng.reseed([0xDEADBEEF, 0xBEEFDEAD, 0xABCDEFAB, 0x12345678]);
write!(f, "const SIDE_TO_MOVE: u64 = {};\n\n", rng.next_u64()).unwrap();
write!(
f,
"const ZOBRIST_PIECES: [[[u64; NUM_SQUARES]; NUM_PIECES]; NUM_COLORS] = [[[\n"
)
.unwrap();
for i in 0..NUM_COLORS {
for j in 0..NUM_PIECES {
for _ in 0..NUM_SQUARES {
write!(f, " {},\n", rng.next_u64()).unwrap();
}
if j != NUM_PIECES - 1 {
write!(f, " ], [\n").unwrap();
}
}
if i != NUM_COLORS - 1 {
write!(f, " ]], [[\n").unwrap();
}
}
write!(f, "]]];\n\n").unwrap();
write!(f, "const ZOBRIST_CASTLES: [[u64; 4]; NUM_COLORS] = [[\n").unwrap();
for i in 0..NUM_COLORS {
for _ in 0..4 {
write!(f, " {},\n", rng.next_u64()).unwrap();
}
if i != NUM_COLORS - 1 {
write!(f, " ], [\n").unwrap();
}
}
write!(f, "]];\n\n").unwrap();
write!(f, "const ZOBRIST_EP: [[u64; NUM_FILES]; NUM_COLORS] = [[\n").unwrap();
for i in 0..NUM_COLORS {
for _ in 0..NUM_FILES {
write!(f, " {},\n", rng.next_u64()).unwrap();
}
if i != NUM_COLORS - 1 {
write!(f, "], [\n").unwrap();
}
}
write!(f, "]];\n\n").unwrap();
}