-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.rs
51 lines (43 loc) · 1.83 KB
/
main.rs
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
use std::{fs::File, io::BufWriter, path::PathBuf};
use precompile::book::book_generator::generate_opening_book;
use precompile::{magic::find_magics::find_and_write_all_magics, zobrist::write_zobrist_tables};
fn file_exists_in_build_cache(file_name: &str) -> bool {
let mut out: PathBuf = std::env::var("OUT_DIR").unwrap().into();
out.push(file_name);
out.exists()
}
fn build_zobrist_tables(filename: &str) {
let mut out: PathBuf = std::env::var("OUT_DIR").unwrap().into();
out.push(filename);
let mut out = BufWriter::new(File::create(out).unwrap());
write_zobrist_tables(&mut out).unwrap();
}
fn build_magics_tables(filename: &str) {
let mut out: PathBuf = std::env::var("OUT_DIR").unwrap().into();
out.push(filename);
let mut out = BufWriter::new(File::create(out).unwrap());
find_and_write_all_magics(&mut out).unwrap();
}
fn build_opening_book(filename: &str) {
let mut out: PathBuf = std::env::var("OUT_DIR").unwrap().into();
out.push(filename);
let mut out = BufWriter::new(File::create(out).unwrap());
generate_opening_book("opening_lines.txt", &mut out).unwrap();
}
fn main() {
if !file_exists_in_build_cache("zobrist_table.rs") {
println!("cargo:warning=Building zobrist tables...");
build_zobrist_tables("zobrist_table.rs");
println!("cargo:warning=Finished building zobrist tables.");
}
if !file_exists_in_build_cache("magic_table.rs") {
println!("cargo:warning=Building magic tables...");
build_magics_tables("magic_table.rs");
println!("cargo:warning=Finished building magic tables.");
}
if !file_exists_in_build_cache("opening_book.rs") {
println!("cargo:warning=Building opening book...");
build_opening_book("opening_book.rs");
println!("cargo:warning=Finished building opening book.");
}
}