wip
This commit is contained in:
parent
a3bcdb8912
commit
ff5ff74282
|
|
@ -9,6 +9,7 @@ pub trait BotStrategy: std::fmt::Debug {
|
||||||
fn calculate_points(&self) -> u8;
|
fn calculate_points(&self) -> u8;
|
||||||
fn calculate_adv_points(&self) -> u8;
|
fn calculate_adv_points(&self) -> u8;
|
||||||
fn choose_move(&self) -> (CheckerMove, CheckerMove);
|
fn choose_move(&self) -> (CheckerMove, CheckerMove);
|
||||||
|
fn choose_go(&self) -> bool;
|
||||||
fn set_player_id(&mut self, player_id: PlayerId);
|
fn set_player_id(&mut self, player_id: PlayerId);
|
||||||
fn set_color(&mut self, color: Color);
|
fn set_color(&mut self, color: Color);
|
||||||
fn init_players(&mut self) {
|
fn init_players(&mut self) {
|
||||||
|
|
@ -77,6 +78,18 @@ impl Bot {
|
||||||
player_id: self.player_id,
|
player_id: self.player_id,
|
||||||
moves: self.strategy.choose_move(),
|
moves: self.strategy.choose_move(),
|
||||||
}),
|
}),
|
||||||
|
TurnStage::HoldOrGoChoice => {
|
||||||
|
if self.strategy.choose_go() {
|
||||||
|
Some(GameEvent::Go {
|
||||||
|
player_id: self.player_id,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Some(GameEvent::Move {
|
||||||
|
player_id: self.player_id,
|
||||||
|
moves: self.strategy.choose_move(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,10 @@ impl BotStrategy for ClientStrategy {
|
||||||
self.calculate_points()
|
self.calculate_points()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn choose_go(&self) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
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.0 as i8, self.game.dice.values.1 as i8),
|
Color::White => (self.game.dice.values.0 as i8, self.game.dice.values.1 as i8),
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,10 @@ impl BotStrategy for DefaultStrategy {
|
||||||
self.calculate_points()
|
self.calculate_points()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn choose_go(&self) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
fn choose_move(&self) -> (CheckerMove, CheckerMove) {
|
fn choose_move(&self) -> (CheckerMove, CheckerMove) {
|
||||||
let rules = MoveRules::new(&self.color, &self.game.board, self.game.dice);
|
let rules = MoveRules::new(&self.color, &self.game.board, self.game.dice);
|
||||||
let possible_moves = rules.get_possible_moves_sequences(true);
|
let possible_moves = rules.get_possible_moves_sequences(true);
|
||||||
|
|
|
||||||
|
|
@ -315,6 +315,7 @@ impl GameState {
|
||||||
if self.turn_stage != TurnStage::Move
|
if self.turn_stage != TurnStage::Move
|
||||||
&& self.turn_stage != TurnStage::HoldOrGoChoice
|
&& self.turn_stage != TurnStage::HoldOrGoChoice
|
||||||
{
|
{
|
||||||
|
error!("bad stage {:?}", self.turn_stage);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let color = &self.players[player_id].color;
|
let color = &self.players[player_id].color;
|
||||||
|
|
@ -326,6 +327,7 @@ impl GameState {
|
||||||
*moves
|
*moves
|
||||||
};
|
};
|
||||||
if !rules.moves_follow_rules(&moves) {
|
if !rules.moves_follow_rules(&moves) {
|
||||||
|
error!("rules not followed ");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,7 @@ impl MoveRules {
|
||||||
|
|
||||||
/// ---- moves_possibles : First of three checks for moves
|
/// ---- moves_possibles : First of three checks for moves
|
||||||
fn moves_possible(&self, moves: &(CheckerMove, CheckerMove)) -> bool {
|
fn moves_possible(&self, moves: &(CheckerMove, CheckerMove)) -> bool {
|
||||||
|
println!("possible ???");
|
||||||
let color = &Color::White;
|
let color = &Color::White;
|
||||||
if let Ok(chained_move) = moves.0.chain(moves.1) {
|
if let Ok(chained_move) = moves.0.chain(moves.1) {
|
||||||
// Check intermediary move and chained_move : "Tout d'une"
|
// Check intermediary move and chained_move : "Tout d'une"
|
||||||
|
|
@ -84,6 +85,7 @@ impl MoveRules {
|
||||||
|| !self.board.move_possible(color, &moves.1)
|
|| !self.board.move_possible(color, &moves.1)
|
||||||
{
|
{
|
||||||
// Move is not physically possible
|
// Move is not physically possible
|
||||||
|
println!("no phys! {} {:?}", self.board, moves);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue