fix: 2 bots play
This commit is contained in:
parent
447ec8cc58
commit
d38913cbd7
|
|
@ -10,6 +10,7 @@ pub trait BotStrategy: std::fmt::Debug {
|
|||
fn calculate_adv_points(&self) -> u8;
|
||||
fn choose_move(&self) -> (CheckerMove, CheckerMove);
|
||||
fn set_player_id(&mut self, player_id: PlayerId);
|
||||
fn set_color(&mut self, color: Color);
|
||||
fn init_players(&mut self) {
|
||||
self.get_mut_game().init_player("p1");
|
||||
self.get_mut_game().init_player("p2");
|
||||
|
|
@ -47,6 +48,7 @@ impl Bot {
|
|||
Color::Black => 2,
|
||||
};
|
||||
strategy.set_player_id(player_id);
|
||||
strategy.set_color(color);
|
||||
Self {
|
||||
player_id,
|
||||
strategy,
|
||||
|
|
@ -58,10 +60,6 @@ impl Bot {
|
|||
pub fn handle_event(&mut self, event: &GameEvent) -> Option<GameEvent> {
|
||||
let game = self.strategy.get_mut_game();
|
||||
game.consume(event);
|
||||
// println!(
|
||||
// "bot player_id {:?} (active player_id {:?})",
|
||||
// self.player_id, game.active_player_id
|
||||
// );
|
||||
if game.active_player_id == self.player_id {
|
||||
return match game.turn_stage {
|
||||
TurnStage::MarkAdvPoints => Some(GameEvent::Mark {
|
||||
|
|
|
|||
|
|
@ -30,6 +30,10 @@ impl BotStrategy for ClientStrategy {
|
|||
self.player_id = player_id;
|
||||
}
|
||||
|
||||
fn set_color(&mut self, color: Color) {
|
||||
self.color = color;
|
||||
}
|
||||
|
||||
fn calculate_points(&self) -> u8 {
|
||||
let dice_roll_count = self
|
||||
.get_game()
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ impl BotStrategy for DefaultStrategy {
|
|||
&mut self.game
|
||||
}
|
||||
|
||||
fn set_color(&mut self, color: Color) {
|
||||
self.color = color;
|
||||
}
|
||||
|
||||
fn set_player_id(&mut self, player_id: PlayerId) {
|
||||
self.player_id = player_id;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,11 @@ impl GameRunner {
|
|||
) -> Self {
|
||||
let mut state = GameState::new(schools_enabled);
|
||||
// local : player
|
||||
let player_id: Option<PlayerId> = state.init_player("myself");
|
||||
let player_id: Option<PlayerId> = if bot_strategies.len() > 1 {
|
||||
None
|
||||
} else {
|
||||
state.init_player("myself")
|
||||
};
|
||||
|
||||
// bots
|
||||
let bots: Vec<Bot> = bot_strategies
|
||||
|
|
@ -74,7 +78,6 @@ impl GameRunner {
|
|||
|
||||
let mut next_event = None;
|
||||
for bot_event in bot_events {
|
||||
println!("bot event {:?}", bot_event);
|
||||
let bot_result_event = self.handle_event(&bot_event);
|
||||
if let Some(bot_id) = bot_event.player_id() {
|
||||
next_event = if self.bot_needs_dice_roll(bot_id) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue