This commit is contained in:
Henri Bourcereau 2025-01-08 17:42:05 +01:00
parent 3280e2a6d7
commit afbc5d3c13
2 changed files with 23 additions and 13 deletions

View file

@ -1,4 +1,5 @@
use crate::{BotStrategy, CheckerMove, Color, GameState, PlayerId, PointsRules};
use store::MoveRules;
#[derive(Debug)]
pub struct DefaultStrategy {
@ -50,19 +51,27 @@ impl BotStrategy for DefaultStrategy {
}
fn choose_move(&self) -> (CheckerMove, CheckerMove) {
let (dice1, dice2) = match self.color {
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 rules = MoveRules::new(&self.color, &self.game.board, self.game.dice);
let possible_moves = rules.get_possible_moves_sequences(true);
let choosen_move = *possible_moves
.first()
.unwrap_or(&(CheckerMove::default(), CheckerMove::default()));
println!("default strategy move : {:?}", choosen_move);
choosen_move
let fields = self.game.board.get_color_fields(self.color);
let first_field = fields.first().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(),
)
// let (dice1, dice2) = match self.color {
// 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 as i8 + dice1) as usize).unwrap(),
// CheckerMove::new(first_field.0, (first_field.0 as i8 + dice2) as usize).unwrap(),
// )
}
}

View file

@ -1,5 +1,6 @@
mod game;
mod game_rules_moves;
pub use game_rules_moves::MoveRules;
mod game_rules_points;
pub use game::{EndGameReason, GameEvent, GameState, Stage, TurnStage};
pub use game_rules_points::PointsRules;