fix: some clean
This commit is contained in:
parent
7d1162f117
commit
6131589084
41
src/main.rs
41
src/main.rs
@ -30,16 +30,6 @@ impl TryFrom<String> for Item {
|
||||
}
|
||||
}
|
||||
|
||||
impl Item {
|
||||
fn next(&self) -> Self {
|
||||
match self {
|
||||
Item::X => Item::O,
|
||||
Item::O => Item::X,
|
||||
Item::Empty => Item::Empty,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// In order to visualize the board game
|
||||
trait Displayer {
|
||||
fn show(&self);
|
||||
@ -225,20 +215,6 @@ impl Player {
|
||||
fn new(item: Item, is_bot: bool) -> Self {
|
||||
Player { item, is_bot }
|
||||
}
|
||||
|
||||
fn as_bot() -> Self {
|
||||
Player {
|
||||
item: Item::Empty,
|
||||
is_bot: true,
|
||||
}
|
||||
}
|
||||
|
||||
fn as_human() -> Self {
|
||||
Player {
|
||||
item: Item::Empty,
|
||||
is_bot: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Player {
|
||||
@ -385,7 +361,7 @@ impl TicTacToe {
|
||||
}
|
||||
}
|
||||
|
||||
self.set_players_item();
|
||||
self.set_players_item().unwrap();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -433,7 +409,7 @@ impl TicTacToe {
|
||||
}
|
||||
}
|
||||
|
||||
// for now, use a dummy bot
|
||||
// for now, use a dump bot
|
||||
let mut rng = rand::thread_rng();
|
||||
let mut available_indexes = self.board.get_available_indexes();
|
||||
available_indexes.shuffle(&mut rng);
|
||||
@ -441,19 +417,6 @@ impl TicTacToe {
|
||||
Ok(available_indexes[0] + 1)
|
||||
}
|
||||
|
||||
/// minimax algorithm used by the bot player to find the best move (minimizing the loses)
|
||||
fn minimax(&self, board: Option<Board>, player: Player, depth: usize) -> usize {
|
||||
let mut board = match board {
|
||||
Some(b) => b,
|
||||
None => self.board.clone(),
|
||||
};
|
||||
let availables_indexes = board.get_available_indexes();
|
||||
for index in availables_indexes {
|
||||
board.set_item(player.item, index);
|
||||
}
|
||||
0
|
||||
}
|
||||
|
||||
fn run(&mut self) {
|
||||
self.select_game_type();
|
||||
self.select_first_player();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user