From a46ff43db48e74d6c5ef5acec60bc95beceb1741 Mon Sep 17 00:00:00 2001 From: Baptiste Fouques Date: Thu, 26 Jan 2023 17:21:00 +0100 Subject: [PATCH] Add skeleton for options --- chess_uci/src/lib.rs | 45 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/chess_uci/src/lib.rs b/chess_uci/src/lib.rs index 22798fc..91b9be2 100644 --- a/chess_uci/src/lib.rs +++ b/chess_uci/src/lib.rs @@ -5,6 +5,7 @@ pub mod uci_command; use log::{info, warn}; use std::io::*; +use std::time::Duration; use crate::uci_command::*; use chess::{Game, Board, ChessMove}; @@ -38,6 +39,26 @@ pub struct UciEngine { id: Id, initial: Board, game: Game, + /// white (total, incr), black (total, incr) + time: ((Option, Option), (Option, Option)), + /// white, black + player: (Player, Player) +} + +pub enum UciOption { + Ponder{value: bool}, + UCIElo{value: Option}, +} + +#[derive(Clone, Copy)] +pub enum Player{Human{elo: Option}, Machine{elo: Option}} +pub enum GameOption { + WhiteTotalTime{value: Option}, + BlackTotalTime{value: Option}, + WhiteIncrement{value: Option}, + BlackIncrement{value: Option}, + WhitePlayer{value: Player}, + BlackPlayer{value: Player}, } impl UciEngine { @@ -52,10 +73,32 @@ impl UciEngine { id: Id::new(), uciok: false, initial: Board::default(), - game: Game::new() + game: Game::new(), + time: ((None, None), (None, None)), + player: (Player::Human{elo: None}, Player::Human{elo: None}), } } + pub fn game_option(&mut self, option: GameOption) -> GameOption { + let old_value: GameOption; + match option { + GameOption::WhiteTotalTime{value} => {old_value = GameOption::WhiteTotalTime { value: self.time.0.0 }; + self.time.0.0 = value}, + GameOption::BlackTotalTime{value} => {old_value = GameOption::BlackTotalTime { value: self.time.1.0 }; + self.time.1.0 = value}, + GameOption::WhiteIncrement{value} => {old_value = GameOption::WhiteIncrement { value: self.time.0.1 }; + self.time.0.1 = value}, + GameOption::BlackIncrement{value} => {old_value = GameOption::BlackIncrement { value: self.time.1.1 }; + self.time.1.1 = value}, + GameOption::WhitePlayer{value} => {old_value = GameOption::WhitePlayer { value: self.player.0 }; + self.player.0 = value}, + GameOption::BlackPlayer{value} => {old_value = GameOption::WhitePlayer { value: self.player.1 }; + self.player.1 = value}, + } + + old_value + } + /// Launch uci engine initialisation /// /// Retrieve data from uci engine (until uciok command from engine)