diff options
| author | Botahamec <botahamec@outlook.com> | 2021-07-09 17:31:15 -0400 |
|---|---|---|
| committer | Botahamec <botahamec@outlook.com> | 2021-07-09 17:31:15 -0400 |
| commit | d2b28aa31a84f43bf5c4f375357e0f013337cdaf (patch) | |
| tree | 338b2d01531f9f678b9185842afc91c507ba4ad4 | |
| parent | 60daeb29549c32ac0c0c985c47c64712ad0d7e96 (diff) | |
here's what i have so far
| -rw-r--r-- | .idea/vcs.xml | 1 | ||||
| -rw-r--r-- | ai/.gitignore | 2 | ||||
| -rw-r--r-- | ai/Cargo.toml | 13 | ||||
| -rw-r--r-- | ai/src/lib.rs | 27 |
4 files changed, 42 insertions, 1 deletions
diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 89a0da2..9661ac7 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,6 +2,5 @@ <project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
- <mapping directory="$PROJECT_DIR$/ai" vcs="Git" />
</component>
</project>
\ No newline at end of file diff --git a/ai/.gitignore b/ai/.gitignore new file mode 100644 index 0000000..96ef6c0 --- /dev/null +++ b/ai/.gitignore @@ -0,0 +1,2 @@ +/target +Cargo.lock diff --git a/ai/Cargo.toml b/ai/Cargo.toml new file mode 100644 index 0000000..64f7dcc --- /dev/null +++ b/ai/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "ai" +version = "0.1.0" +authors = ["botahamec"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +model = {path = "../model"} + +[dev-dependencies] +criterion = "0.3"
\ No newline at end of file diff --git a/ai/src/lib.rs b/ai/src/lib.rs new file mode 100644 index 0000000..4e22708 --- /dev/null +++ b/ai/src/lib.rs @@ -0,0 +1,27 @@ +pub use model::{CheckersBitBoard, Move, PieceColor, PossibleMoves}; + +const KING_WORTH: u32 = 2; + +fn eval_position(board: CheckersBitBoard) -> f32 { + let light_pieces = board.pieces_bits() & !board.color_bits(); + let dark_pieces = board.pieces_bits() & board.color_bits(); + + let light_peasants = light_pieces & !board.king_bits(); + let dark_peasants = dark_pieces & !board.king_bits(); + + let light_kings = light_pieces & board.king_bits(); + let dark_kings = dark_pieces & board.king_bits(); + + // if we assume the black player doesn't exist, how good is this for white? + let light_eval = + (light_peasants.count_ones() as f32) + ((light_kings.count_ones() * KING_WORTH) as f32); + let dark_eval = + (dark_peasants.count_ones() as f32) + ((dark_kings.count_ones() * KING_WORTH) as f32); + + // avoiding a divide by zero error + if dark_eval + light_eval != 0.0 { + light_eval / (dark_eval + light_eval) + } else { + 0.0 + } +} |
