push commands
This commit is contained in:
		
							parent
							
								
									4aa7ee9f2e
								
							
						
					
					
						commit
						5dc2457a15
					
				| @ -140,31 +140,34 @@ impl<Fi: Read, Fo:  Write> UciEngine<Fi, Fo> { | ||||
|     ///
 | ||||
|     /// if `EngineCommand::Id`: update name or authorship of the engine
 | ||||
|     /// if `EngineCommand::UciOk`: end engine initialization phase
 | ||||
|     pub fn exec(&mut self, command: &str){ | ||||
|         match parse (&mut command.to_string()) { | ||||
|     pub fn exec(&mut self, command: &str) -> std::result::Result<EngineCommand, &'static str> { | ||||
|         let uci_command = parse (&mut command.to_string()); | ||||
|         match  uci_command.clone() { | ||||
|             Ok(EngineCommand::Id{id}) => self.update(&id), | ||||
|             Ok(EngineCommand::UciOk) => self.uciok(), | ||||
|             Ok(EngineCommand::Opt { options: _ }) => {}, | ||||
|             Ok(_) => {unimplemented!("command not implemented")}, | ||||
|             Err(_) => warn!("Not a command"), | ||||
|         } | ||||
|         }; | ||||
|         uci_command | ||||
|     } | ||||
| 
 | ||||
|     /// Retrieve a line from the uci engine input stream and parse it
 | ||||
|     pub fn pull(&mut self) { | ||||
|     pub fn pull(&mut self) -> Option<EngineCommand> { | ||||
| 
 | ||||
|         if let Some(source) = &mut self.source { | ||||
|             let mut command = String::new(); | ||||
|             match source.read_line(&mut command) { | ||||
|                 Ok(0) => self.terminate("Chess engine closed connection."), | ||||
|                 Ok(0) => {self.terminate("Chess engine closed connection."); None}, | ||||
|                 Ok(_) => { | ||||
|                     info!("← {}", command); | ||||
|                     self.exec(&command) | ||||
|                     self.exec(&command).ok() | ||||
|                 }, | ||||
|                 Err(reason) => warn!("Unable to read from engine: {reason}"), | ||||
|                 Err(reason) => {warn!("Unable to read from engine: {reason}"); None}, | ||||
|             } | ||||
|         } else { | ||||
|             info!("❌ No connected uci engine"); | ||||
|             None | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -6,6 +6,7 @@ use chess::{ChessMove, Board, Action}; | ||||
| 
 | ||||
| mod uci_command{} | ||||
| 
 | ||||
| #[derive(Clone)] | ||||
| pub struct Id {name: Option<String>, author: Option<String>} | ||||
| impl Id { | ||||
|     pub fn new() -> Id { | ||||
| @ -30,11 +31,12 @@ impl Id { | ||||
|         self.author.clone() | ||||
|     } | ||||
| } | ||||
| #[derive(Debug)] | ||||
| #[derive(Debug, Clone)] | ||||
| pub struct Info {} | ||||
| #[derive(Debug)] | ||||
| #[derive(Debug, Clone)] | ||||
| pub struct Opt{} | ||||
| 
 | ||||
| #[derive(Clone)] | ||||
| pub enum EngineCommand { | ||||
|     Id{id: Id}, | ||||
|     UciOk, | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Baptiste Fouques
						Baptiste Fouques