From f9f4405943248fb4d4ed764ab90f92a702477bee Mon Sep 17 00:00:00 2001 From: Henri Bourcereau Date: Mon, 4 Aug 2025 22:25:08 +0200 Subject: [PATCH] wip mirror --- bot/src/lib.rs | 23 +++++----------- bot/src/strategy/default.rs | 4 +-- store/src/game.rs | 52 +++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 18 deletions(-) diff --git a/bot/src/lib.rs b/bot/src/lib.rs index abb49bc..494b83c 100644 --- a/bot/src/lib.rs +++ b/bot/src/lib.rs @@ -34,9 +34,9 @@ impl Default for Bot { fn default() -> Self { let strategy = DefaultStrategy::default(); Self { - player_id: 2, + player_id: 1, strategy: Box::new(strategy), - // color: Color::Black, + color: Color::White, // schools_enabled: false, } } @@ -64,26 +64,17 @@ impl Bot { pub fn handle_event(&mut self, event: &GameEvent) -> Option { let game = self.strategy.get_mut_game(); - let mirror_event = if let GameEvent::Move { - player_id, - moves: (move1, move2), - } = event - { - &GameEvent::Move { - player_id: *player_id, - moves: (move1.mirror(), move2.mirror()), - } + let internal_event = if self.color == Color::Black { + &event.get_mirror() } else { event }; - game.consume(if self.color == Color::White { - event - } else { - mirror_event - }); + + game.consume(internal_event); if game.stage == Stage::Ended { return None; } + // TODO mirror if game.active_player_id == self.player_id { return match game.turn_stage { TurnStage::MarkAdvPoints => Some(GameEvent::Mark { diff --git a/bot/src/strategy/default.rs b/bot/src/strategy/default.rs index e01f406..628ce83 100644 --- a/bot/src/strategy/default.rs +++ b/bot/src/strategy/default.rs @@ -13,8 +13,8 @@ impl Default for DefaultStrategy { let game = GameState::default(); Self { game, - player_id: 2, - color: Color::Black, + player_id: 1, + color: Color::White, } } } diff --git a/store/src/game.rs b/store/src/game.rs index d500342..32697ee 100644 --- a/store/src/game.rs +++ b/store/src/game.rs @@ -733,6 +733,58 @@ impl GameEvent { _ => None, } } + + pub fn get_mirror(&self) -> Self { + // let mut mirror = self.clone(); + let mirror_player_id = if let Some(player_id) = self.player_id() { + if player_id == 1 { + 2 + } else { + 1 + } + } else { + 0 + }; + + match self { + Self::PlayerJoined { player_id: _, name } => Self::PlayerJoined { + player_id: mirror_player_id, + name: name.clone(), + }, + Self::PlayerDisconnected { player_id: _ } => GameEvent::PlayerDisconnected { + player_id: mirror_player_id, + }, + Self::Roll { player_id: _ } => GameEvent::Roll { + player_id: mirror_player_id, + }, + Self::RollResult { player_id: _, dice } => GameEvent::RollResult { + player_id: mirror_player_id, + dice: *dice, + }, + Self::Mark { + player_id: _, + points, + } => GameEvent::Mark { + player_id: mirror_player_id, + points: *points, + }, + Self::Go { player_id: _ } => GameEvent::Go { + player_id: mirror_player_id, + }, + Self::Move { + player_id: _, + moves: (move1, move2), + } => Self::Move { + player_id: mirror_player_id, + moves: (move1.mirror(), move2.mirror()), + }, + Self::BeginGame { goes_first } => GameEvent::BeginGame { + goes_first: (if *goes_first == 1 { 2 } else { 1 }), + }, + Self::EndGame { reason } => GameEvent::EndGame { reason: *reason }, + Self::PlayError => GameEvent::PlayError, + } + } } #[cfg(test)]