summaryrefslogtreecommitdiff
path: root/src/game.rs
diff options
context:
space:
mode:
authorDylan <boss@tehbox.org>2026-10-19 00:37:17 +1300
committerDylan <boss@tehbox.org>2026-10-19 00:38:55 +1300
commit15bdaa5d550115d97be3f89126c924b49c10a70f (patch)
tree079fc3554598ae92a7b588b34ea7e787629133b9 /src/game.rs
downloadtigers-and-sheep-15bdaa5d550115d97be3f89126c924b49c10a70f.tar.gz
tigers-and-sheep-15bdaa5d550115d97be3f89126c924b49c10a70f.zip
feat: Initial commit
What works: - Minimax search - With a simple player claude designed - Manual player - Move generation - Board display What needs improvement: - Manual player - Game coordinator - Draw checking - Nix setup
Diffstat (limited to 'src/game.rs')
-rw-r--r--src/game.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/game.rs b/src/game.rs
new file mode 100644
index 0000000..96f71b3
--- /dev/null
+++ b/src/game.rs
@@ -0,0 +1,44 @@
+use crate::{board::{GameBoard, Turn}, player::Player};
+
+pub struct GameHandler
+{
+ board: GameBoard,
+}
+
+impl Default for GameHandler
+{
+ fn default() -> Self
+ {
+ Self
+ {
+ board: GameBoard::default()
+ }
+ }
+}
+
+impl GameHandler
+{
+ // fn play_move<T: Player>(&mut self, player: &mut T)
+ // {
+ // let m = player.pick_move(self.board);
+ // self.board.make_move(m).unwrap();
+ // }
+
+ /// Play until someone wins, with `p1` as the sheep and `p2` as the tigers. Returns the winner.
+ pub fn play_game<T1: Player, T2: Player>(&mut self, p1: &mut T1, p2: &mut T2) -> Turn
+ {
+ let mut turn = Turn::Sheep;
+ while !self.board.check_win(turn)
+ {
+ let m = match turn
+ {
+ Turn::Sheep => p1.pick_move(self.board, turn),
+ Turn::Tiger => p2.pick_move(self.board, turn),
+ };
+ self.board.make_move(m).unwrap();
+ turn = turn.next_turn();
+ }
+ // check_win runs before `turn`'s move, so whoever moved last has won.
+ turn.next_turn()
+ }
+}