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> },
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
||||
pub enum Player {
|
||||
Human { elo: Option<u32> },
|
||||
Machine { elo: Option<u32> },
|
||||
Engine { elo: Option<u32> },
|
||||
}
|
||||
pub enum GameOption {
|
||||
WhiteTotalTime { value: Option<Duration> },
|
||||
|
@ -129,6 +129,10 @@ impl<Fi: Read, Fo: Write> UciEngine<Fi, Fo> {
|
|||
old_value
|
||||
}
|
||||
|
||||
pub fn get_player(&self, color: Color) -> Player {
|
||||
self.player[color.to_index()]
|
||||
}
|
||||
|
||||
/// Launch uci engine initialisation
|
||||
///
|
||||
/// 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) {
|
||||
self.initial = Board::default();
|
||||
self.game = Game::new_with_board(self.initial);
|
||||
self.push(GuiCommand::Stop);
|
||||
self.push(GuiCommand::UciNewGame);
|
||||
}
|
||||
|
||||
|
@ -326,14 +331,14 @@ impl<Fi: Read, Fo: Write> UciEngine<Fi, Fo> {
|
|||
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> {
|
||||
match self.player[self.side_to_move().to_index()] {
|
||||
Player::Human { .. } => Err("Not a machine to play for current color."),
|
||||
Player::Machine { elo } => {
|
||||
Player::Engine { elo } => {
|
||||
if self.is_uciok() {
|
||||
if let Some(elo) = elo {
|
||||
self.push(GuiCommand::SetOption {
|
||||
|
@ -362,7 +367,7 @@ impl<Fi: Read, Fo: Write> UciEngine<Fi, Fo> {
|
|||
pub fn stop(&mut self) -> Result<(), &'static str> {
|
||||
match self.player[self.side_to_move().to_index()] {
|
||||
Player::Human { .. } => Err("Not a machine to play for current color."),
|
||||
Player::Machine { .. } => {
|
||||
Player::Engine { .. } => {
|
||||
self.push(GuiCommand::Stop);
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ pub fn main() {
|
|||
value: Player::Human { elo: None },
|
||||
});
|
||||
uci.game_option(GameOption::BlackPlayer {
|
||||
value: Player::Machine { elo: Some(1500) },
|
||||
value: Player::Engine { elo: Some(1500) },
|
||||
});
|
||||
uci.init();
|
||||
|
||||
|
|
Loading…
Reference in New Issue