summaryrefslogtreecommitdiff
path: root/ai
diff options
context:
space:
mode:
authorBotahamec <botahamec@outlook.com>2021-07-09 17:31:15 -0400
committerBotahamec <botahamec@outlook.com>2021-07-09 17:31:15 -0400
commitd2b28aa31a84f43bf5c4f375357e0f013337cdaf (patch)
tree338b2d01531f9f678b9185842afc91c507ba4ad4 /ai
parent60daeb29549c32ac0c0c985c47c64712ad0d7e96 (diff)
here's what i have so far
Diffstat (limited to 'ai')
-rw-r--r--ai/.gitignore2
-rw-r--r--ai/Cargo.toml13
-rw-r--r--ai/src/lib.rs27
3 files changed, 42 insertions, 0 deletions
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
+ }
+}