1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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()
}
}
}