feat: bot random strategy

This commit is contained in:
Henri Bourcereau 2025-08-08 16:24:12 +02:00
parent b02ce8d185
commit bf820ecc4e
10 changed files with 106 additions and 27 deletions

View file

@ -37,7 +37,7 @@ impl Default for CheckerMove {
impl CheckerMove {
pub fn to_display_string(self) -> String {
format!("{:?} ", self)
format!("{self:?} ")
}
pub fn new(from: Field, to: Field) -> Result<Self, Error> {
@ -569,7 +569,7 @@ impl Board {
}
let checker_color = self.get_checkers_color(field)?;
if Some(color) != checker_color {
println!("field invalid : {:?}, {:?}, {:?}", color, field, self);
println!("field invalid : {color:?}, {field:?}, {self:?}");
return Err(Error::FieldInvalid);
}
let unit = match color {

View file

@ -4,7 +4,7 @@ use crate::dice::Dice;
use crate::game_rules_moves::MoveRules;
use crate::game_rules_points::{PointsRules, PossibleJans};
use crate::player::{Color, Player, PlayerId};
use log::{error, info};
use log::{debug, error, info};
// use itertools::Itertools;
use serde::{Deserialize, Serialize};
@ -521,14 +521,14 @@ impl GameState {
self.inc_roll_count(self.active_player_id);
self.turn_stage = TurnStage::MarkPoints;
(self.dice_jans, self.dice_points) = self.get_rollresult_jans(dice);
info!("points from result : {:?}", self.dice_points);
debug!("points from result : {:?}", self.dice_points);
if !self.schools_enabled {
// Schools are not enabled. We mark points automatically
// the points earned by the opponent will be marked on its turn
let new_hole = self.mark_points(self.active_player_id, self.dice_points.0);
if new_hole {
let holes_count = self.get_active_player().unwrap().holes;
info!("new hole -> {holes_count:?}");
debug!("new hole -> {holes_count:?}");
if holes_count > 12 {
self.stage = Stage::Ended;
} else {
@ -606,7 +606,7 @@ impl GameState {
fn get_rollresult_jans(&self, dice: &Dice) -> (PossibleJans, (u8, u8)) {
let player = &self.players.get(&self.active_player_id).unwrap();
info!(
debug!(
"get rollresult for {:?} {:?} {:?} (roll count {:?})",
player.color, self.board, dice, player.dice_roll_count
);
@ -654,7 +654,7 @@ impl GameState {
// if points > 0 && p.holes > 15 {
if points > 0 {
info!(
debug!(
"player {player_id:?} holes : {:?} (+{holes:?}) points : {:?} (+{points:?} - {jeux:?})",
p.holes, p.points
)

View file

@ -5,7 +5,7 @@ use crate::player::Color;
use crate::CheckerMove;
use crate::Error;
use log::info;
use log::debug;
use serde::{Deserialize, Serialize};
use std::cmp;
use std::collections::HashMap;
@ -384,7 +384,7 @@ impl PointsRules {
pub fn get_result_jans(&self, dice_rolls_count: u8) -> (PossibleJans, (u8, u8)) {
let jans = self.get_jans(&self.board, dice_rolls_count);
info!("jans : {jans:?}");
debug!("jans : {jans:?}");
let points_jans = jans.clone();
(jans, self.get_jans_points(points_jans))
}