2022-09-11 14:48:20 +00:00
|
|
|
use actix::Addr;
|
|
|
|
use uuid::Uuid;
|
|
|
|
|
2022-09-14 16:30:33 +00:00
|
|
|
use crate::data::{BoatsLayout, CurrentGameStatus, GameRules};
|
|
|
|
use crate::game::{Fire, Game, Player, SetBoatsLayout};
|
2022-09-11 14:48:20 +00:00
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct RandomBot {
|
|
|
|
game: Addr<Game>,
|
|
|
|
uuid: Uuid,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RandomBot {
|
|
|
|
pub fn new(game: Addr<Game>) -> Self {
|
|
|
|
Self {
|
|
|
|
game,
|
|
|
|
uuid: Uuid::new_v4(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Player for RandomBot {
|
|
|
|
fn get_name(&self) -> &str {
|
|
|
|
"Random Bot"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_uid(&self) -> Uuid {
|
|
|
|
self.uuid
|
|
|
|
}
|
|
|
|
|
|
|
|
fn query_boats_layout(&self, rules: &GameRules) {
|
2022-09-13 17:02:26 +00:00
|
|
|
match BoatsLayout::gen_random_for_rules(rules) {
|
|
|
|
Ok(layout) => self.game.do_send(SetBoatsLayout(self.uuid, layout)),
|
|
|
|
|
|
|
|
Err(e) => log::error!(
|
|
|
|
"Failed to use game rules to construct boats layout: {:?}",
|
|
|
|
e
|
|
|
|
),
|
|
|
|
}
|
2022-09-11 14:48:20 +00:00
|
|
|
}
|
2022-09-13 17:02:26 +00:00
|
|
|
|
|
|
|
fn notify_other_player_ready(&self) {}
|
|
|
|
|
|
|
|
fn notify_game_starting(&self) {}
|
2022-09-14 16:30:33 +00:00
|
|
|
|
|
|
|
fn request_fire(&self, status: CurrentGameStatus) {
|
|
|
|
self.game
|
|
|
|
.do_send(Fire(self.uuid, status.find_valid_random_fire_location()));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn other_player_must_fire(&self, _status: CurrentGameStatus) {}
|
2022-09-11 14:48:20 +00:00
|
|
|
}
|