From 08a39c258e7d322d4cadb53642b64d6741e6490e Mon Sep 17 00:00:00 2001 From: Baptiste Fouques Date: Mon, 16 Jan 2023 11:49:42 +0100 Subject: [PATCH] Does not constraint on BufRead trait, create bufreader dynamically --- chess_uci/src/lib.rs | 10 ++++++---- chess_uci_demo/src/main.rs | 3 +-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/chess_uci/src/lib.rs b/chess_uci/src/lib.rs index 34563c3..da288b0 100644 --- a/chess_uci/src/lib.rs +++ b/chess_uci/src/lib.rs @@ -31,8 +31,8 @@ use chess::{Game, Board, ChessMove}; /// // .. uci.init(); .. /// uci.push_raw("quit\n"); /// ``` -pub struct UciEngine { - source: Fi, +pub struct UciEngine { + source: BufReader, destination: Fo, uciok: bool, id: Id, @@ -40,14 +40,15 @@ pub struct UciEngine { game: Game, } -impl UciEngine { +impl UciEngine { /// Create new game manager /// /// Requires line by line input and output streams to communicate with uci engine pub fn new(source: Fi, destination: Fo) -> UciEngine { UciEngine::{ - source, destination, + source: BufReader::new(source), + destination, id: Id::new(), uciok: false, initial: Board::default(), @@ -146,6 +147,7 @@ impl UciEngine { /// Retrieve a line from the uci engine input stream and parse it pub fn pull(&mut self) { + let mut command = String::new(); match self.source.read_line(&mut command) { Ok(0) => self.terminate("Chess engine closed connection."), diff --git a/chess_uci_demo/src/main.rs b/chess_uci_demo/src/main.rs index e09822d..db3cd31 100644 --- a/chess_uci_demo/src/main.rs +++ b/chess_uci_demo/src/main.rs @@ -5,7 +5,6 @@ use chess::ChessMove; use chess_uci::*; use std::process::{Command, Stdio}; -use std::io::BufReader; use std::str::FromStr; pub fn main(){ @@ -23,7 +22,7 @@ pub fn main(){ }; let (sf_in,sf_out) = (process.stdin.expect("Program stdin"), process.stdout.expect("Program stdout")); - let mut uci = UciEngine::new(BufReader::new(sf_out), sf_in); + let mut uci = UciEngine::new(sf_out, sf_in); uci.init(); println!("Engine: {} \nby: {}",