Skip to content

Commit

Permalink
feat: Revamp training code, start implementing Zobrist hasing
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillbobyrev committed Jun 15, 2024
1 parent 38ae8d1 commit 8611cb4
Show file tree
Hide file tree
Showing 21 changed files with 1,270 additions and 2,527 deletions.
397 changes: 341 additions & 56 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ readme = "README.md"
repository = "https://github.com/kirillbobyrev/pabi"
rust-version = "1.78"
version = "0.1.0"
# Reduce the package size by only including things necessary for building it.
include = [
"/src/**/*.rs",
"/src/",
"/generated/",
"/Cargo.toml",
"/Cargo.lock",
"/data/positions.fen",
"build.rs",
"LICENSE",
"README.md",
]
] # Reduce the package size by only including things necessary for building it.

[workspace]
members = ["tools"]
Expand All @@ -34,6 +34,7 @@ shadow-rs = "0.28.0"

[build-dependencies]
shadow-rs = "0.28.0"
rand = "0.8.5"

[dev-dependencies]
criterion = { version = "0.5.1", features = [
Expand Down
19 changes: 7 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ designed to perform well against other engines. Performance and good
time-management are crucial for doing well under time pressure.

<!-- TODO: User interface: supported commands + UCI options -->
<!-- Describe high-level features -->

## Project architecture

Expand Down Expand Up @@ -113,10 +114,6 @@ Contains code that extracts features from a given position and runs "static"
computes the score that determines how good it is for the player that is going
to make the next move.

The development of the Neural Network model is in another repo:
[kirillbobyrev/pabi-brain](https://github.com/kirillbobyrev/pabi-brain). The
Rust code only runs inference of an already trained model.

##### [`src/search/`](/src/search/)

Implements Minimax [search] with a number of extensions for efficiently reducing
Expand Down Expand Up @@ -168,15 +165,13 @@ arrays. These constants shouldn't change over time.

## [Milestones]

- [ ] [0.1.0]
- [ ] [0.2.0]
- [ ] [1.0.0]
- [ ] [2.0.0]
- [ ] [Proof of Concept]
- [ ] [Stable]
- [ ] [Strong]

[0.1.0]: https://github.com/kirillbobyrev/pabi/milestone/1
[0.2.0]: https://github.com/kirillbobyrev/pabi/milestone/4
[1.0.0]: https://github.com/kirillbobyrev/pabi/milestone/2
[2.0.0]: https://github.com/kirillbobyrev/pabi/milestone/3
[Proof of Concept]: https://github.com/kirillbobyrev/pabi/milestone/1
[Stable]: https://github.com/kirillbobyrev/pabi/milestone/2
[Strong]: https://github.com/kirillbobyrev/pabi/milestone/3
[Computer Chess Championship]: https://www.chess.com/computer-chess-championship
[Dependabot]: https://github.com/dependabot
[Fuzzing]: https://en.wikipedia.org/wiki/Fuzzing
Expand Down
37 changes: 31 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
//! environment. This information is then written to a file in the output
//! directory and can be accessed at runtime by the engine.

use std::path::Path;
use std::{env, fs};

fn generate_file(filename: &str, contents: &str) {
let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join(filename);
fs::write(dest_path, contents).unwrap();
let out_dir = std::env::var_os("OUT_DIR").unwrap();
let dest_path = std::path::Path::new(&out_dir).join(filename);
std::fs::write(dest_path, contents).unwrap();
}

// TODO: Add AVX, SSE, potentially MKL and other Candle features support.
Expand All @@ -24,7 +21,35 @@ fn generate_build_info() {
generate_file("features", &features);
}

fn generate_zobrist_keys() {
let mut rng = rand::thread_rng();
for piece in [
"white_king",
"white_queen",
"white_rook",
"white_bishop",
"white_knight",
"white_pawn",
"black_king",
"black_queen",
"black_rook",
"black_bishop",
"black_knight",
"black_pawn",
] {
let piece_keys: [u64; 64] = std::array::from_fn(|_| rand::Rng::gen(&mut rng));
generate_file(
&format!("{piece}_zobrist_keys"),
&format!("{:?}", piece_keys),
);
}

let en_passant_keys: [u64; 8] = std::array::from_fn(|_| rand::Rng::gen(&mut rng));
generate_file("en_passant_zobrist_keys", &format!("{:?}", en_passant_keys));
}

fn main() -> shadow_rs::SdResult<()> {
generate_zobrist_keys();
generate_build_info();
shadow_rs::new()
}
Loading

0 comments on commit 8611cb4

Please sign in to comment.