From dff9f7f3e16c051da8e74be332c59eab249bde4d Mon Sep 17 00:00:00 2001 From: Henri Bourcereau Date: Tue, 26 Mar 2024 21:07:47 +0100 Subject: [PATCH] mark points --- bot/src/lib.rs | 11 +++++++---- store/src/board.rs | 1 + store/src/game.rs | 5 ++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/bot/src/lib.rs b/bot/src/lib.rs index e8b7108..08ec998 100644 --- a/bot/src/lib.rs +++ b/bot/src/lib.rs @@ -67,15 +67,18 @@ impl Bot { fn choose_move(&self) -> (CheckerMove, CheckerMove) { let (dice1, dice2) = match self.color { - Color::White => self.game.dice.values, - Color::Black => (0 - self.game.dice.values.0, 0 - self.game.dice.values.1), + Color::White => (self.game.dice.values.0 as i8, self.game.dice.values.1 as i8), + Color::Black => ( + 0 - self.game.dice.values.0 as i8, + 0 - self.game.dice.values.1 as i8, + ), }; let fields = self.game.board.get_color_fields(self.color); let first_field = fields.first().unwrap(); ( - CheckerMove::new(first_field.0, first_field.0 + dice1 as usize).unwrap(), - CheckerMove::new(first_field.0, first_field.0 + dice2 as usize).unwrap(), + CheckerMove::new(first_field.0, (first_field.0 as i8 + dice1) as usize).unwrap(), + CheckerMove::new(first_field.0, (first_field.0 as i8 + dice2) as usize).unwrap(), ) } } diff --git a/store/src/board.rs b/store/src/board.rs index de956aa..a3d365c 100644 --- a/store/src/board.rs +++ b/store/src/board.rs @@ -28,6 +28,7 @@ fn transpose(matrix: Vec>) -> Vec> { impl CheckerMove { pub fn new(from: Field, to: Field) -> Result { + println!("from {} to {}", from, to); // check if the field is on the board // we allow 0 for 'to', which represents the exit of a checker if from < 1 || 24 < from || 24 < to { diff --git a/store/src/game.rs b/store/src/game.rs index 32b2aef..2b9d6d9 100644 --- a/store/src/game.rs +++ b/store/src/game.rs @@ -448,7 +448,10 @@ impl GameState { } fn mark_points(&mut self, player_id: PlayerId, points: u8) { - todo!() + self.players.get_mut(&player_id).map(|p| { + p.points = p.points + points; + p + }); } }