mark points

This commit is contained in:
Henri Bourcereau 2024-03-26 21:07:47 +01:00
parent f61d2044f8
commit dff9f7f3e1
3 changed files with 12 additions and 5 deletions

View file

@ -67,15 +67,18 @@ impl Bot {
fn choose_move(&self) -> (CheckerMove, CheckerMove) { fn choose_move(&self) -> (CheckerMove, CheckerMove) {
let (dice1, dice2) = match self.color { let (dice1, dice2) = match self.color {
Color::White => self.game.dice.values, Color::White => (self.game.dice.values.0 as i8, self.game.dice.values.1 as i8),
Color::Black => (0 - self.game.dice.values.0, 0 - self.game.dice.values.1), 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 fields = self.game.board.get_color_fields(self.color);
let first_field = fields.first().unwrap(); 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 as i8 + 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 + dice2) as usize).unwrap(),
) )
} }
} }

View file

@ -28,6 +28,7 @@ fn transpose(matrix: Vec<Vec<String>>) -> Vec<Vec<String>> {
impl CheckerMove { impl CheckerMove {
pub fn new(from: Field, to: Field) -> Result<Self, Error> { pub fn new(from: Field, to: Field) -> Result<Self, Error> {
println!("from {} to {}", from, to);
// check if the field is on the board // check if the field is on the board
// we allow 0 for 'to', which represents the exit of a checker // we allow 0 for 'to', which represents the exit of a checker
if from < 1 || 24 < from || 24 < to { if from < 1 || 24 < from || 24 < to {

View file

@ -448,7 +448,10 @@ impl GameState {
} }
fn mark_points(&mut self, player_id: PlayerId, points: u8) { 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
});
} }
} }