cleanify and export user type
This commit is contained in:
parent
69cbe46f1d
commit
eb840f5b93
|
@ -54,10 +54,10 @@ pub enum UciOption {
|
||||||
UCIElo { value: Option<u32> },
|
UCIElo { value: Option<u32> },
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
||||||
pub enum Player {
|
pub enum Player {
|
||||||
Human { elo: Option<u32> },
|
Human { elo: Option<u32> },
|
||||||
Machine { elo: Option<u32> },
|
Engine { elo: Option<u32> },
|
||||||
}
|
}
|
||||||
pub enum GameOption {
|
pub enum GameOption {
|
||||||
WhiteTotalTime { value: Option<Duration> },
|
WhiteTotalTime { value: Option<Duration> },
|
||||||
|
@ -129,6 +129,10 @@ impl<Fi: Read, Fo: Write> UciEngine<Fi, Fo> {
|
||||||
old_value
|
old_value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_player(&self, color: Color) -> Player {
|
||||||
|
self.player[color.to_index()]
|
||||||
|
}
|
||||||
|
|
||||||
/// Launch uci engine initialisation
|
/// Launch uci engine initialisation
|
||||||
///
|
///
|
||||||
/// Retrieve data from uci engine (until uciok command from engine)
|
/// Retrieve data from uci engine (until uciok command from engine)
|
||||||
|
@ -149,6 +153,7 @@ impl<Fi: Read, Fo: Write> UciEngine<Fi, Fo> {
|
||||||
pub fn new_game(&mut self) {
|
pub fn new_game(&mut self) {
|
||||||
self.initial = Board::default();
|
self.initial = Board::default();
|
||||||
self.game = Game::new_with_board(self.initial);
|
self.game = Game::new_with_board(self.initial);
|
||||||
|
self.push(GuiCommand::Stop);
|
||||||
self.push(GuiCommand::UciNewGame);
|
self.push(GuiCommand::UciNewGame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -326,14 +331,14 @@ impl<Fi: Read, Fo: Write> UciEngine<Fi, Fo> {
|
||||||
Err("Invalid move for human player")
|
Err("Invalid move for human player")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Player::Machine { .. } => Err("Not a human to play for current color."),
|
Player::Engine { .. } => Err("Not a human to play for current color."),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn go(&mut self) -> Result<(), &'static str> {
|
pub fn go(&mut self) -> Result<(), &'static str> {
|
||||||
match self.player[self.side_to_move().to_index()] {
|
match self.player[self.side_to_move().to_index()] {
|
||||||
Player::Human { .. } => Err("Not a machine to play for current color."),
|
Player::Human { .. } => Err("Not a machine to play for current color."),
|
||||||
Player::Machine { elo } => {
|
Player::Engine { elo } => {
|
||||||
if self.is_uciok() {
|
if self.is_uciok() {
|
||||||
if let Some(elo) = elo {
|
if let Some(elo) = elo {
|
||||||
self.push(GuiCommand::SetOption {
|
self.push(GuiCommand::SetOption {
|
||||||
|
@ -362,7 +367,7 @@ impl<Fi: Read, Fo: Write> UciEngine<Fi, Fo> {
|
||||||
pub fn stop(&mut self) -> Result<(), &'static str> {
|
pub fn stop(&mut self) -> Result<(), &'static str> {
|
||||||
match self.player[self.side_to_move().to_index()] {
|
match self.player[self.side_to_move().to_index()] {
|
||||||
Player::Human { .. } => Err("Not a machine to play for current color."),
|
Player::Human { .. } => Err("Not a machine to play for current color."),
|
||||||
Player::Machine { .. } => {
|
Player::Engine { .. } => {
|
||||||
self.push(GuiCommand::Stop);
|
self.push(GuiCommand::Stop);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ pub fn main() {
|
||||||
value: Player::Human { elo: None },
|
value: Player::Human { elo: None },
|
||||||
});
|
});
|
||||||
uci.game_option(GameOption::BlackPlayer {
|
uci.game_option(GameOption::BlackPlayer {
|
||||||
value: Player::Machine { elo: Some(1500) },
|
value: Player::Engine { elo: Some(1500) },
|
||||||
});
|
});
|
||||||
uci.init();
|
uci.init();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue