From d2b28aa31a84f43bf5c4f375357e0f013337cdaf Mon Sep 17 00:00:00 2001 From: Botahamec Date: Fri, 9 Jul 2021 17:31:15 -0400 Subject: here's what i have so far --- .idea/vcs.xml | 1 - ai/.gitignore | 2 ++ ai/Cargo.toml | 13 +++++++++++++ ai/src/lib.rs | 27 +++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 ai/.gitignore create mode 100644 ai/Cargo.toml create mode 100644 ai/src/lib.rs 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 @@ - \ 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 + } +} -- cgit v1.2.3