Skip to content

Commit

Permalink
delete test
Browse files Browse the repository at this point in the history
  • Loading branch information
tigerros committed Sep 22, 2024
1 parent 7b86d82 commit 9fa24b7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 42 deletions.
13 changes: 6 additions & 7 deletions examples/go.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@
use ruci::messages::{GoMessage, GuiMessage};
use ruci::EngineConnection;
use std::io;
use tokio::io::AsyncBufReadExt;

#[tokio::main]
async fn main() -> io::Result<()> {
let mut engine_conn = EngineConnection::from_path("stockfish").unwrap();

println!("== Sending use UCI message, waiting for uciok");

let (id, options) = engine_conn.use_uci().await?;

println!("== Received uciok");
println!("== ID: {id:?}");
println!("== Options: {options:?}");
println!("== Sending isready message, waiting for readyok");

let (infos, best_move) = engine_conn
.go(GoMessage {
search_moves: None,
Expand All @@ -39,13 +38,13 @@ async fn main() -> io::Result<()> {
infinite: false,
})
.await?;

for info in infos {
println!("Info: {info:?}");
}

println!("Best move: {best_move:?}");

println!("== Sending quit message");
engine_conn.send_message(&GuiMessage::Quit).await?;
println!("== Sent. Program terminated");
Expand Down
Binary file removed resources/stockfish.exe
Binary file not shown.
51 changes: 16 additions & 35 deletions src/uci_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,22 @@ where
// _phantom: PhantomData,
// }
// }
//
//
// /// # Errors
// ///
// /// [`UciCreationError::Spawn`] is guaranteed not to occur here.
// pub fn from_process(mut process: Child) -> Result<Self, UciCreationError> {
// let Some(stdout) = process.stdout.take() else {
// return Err(UciCreationError::StdoutIsNone);
// };
//
//
// let Some(stdin) = process.stdin.take() else {
// return Err(UciCreationError::StdinIsNone);
// };
//
//
// let stdout = BufReader::new(stdout);
// let stdin = BufWriter::new(stdin);
//
//
// Ok(Self {
// process,
// stdout,
Expand Down Expand Up @@ -104,7 +104,7 @@ where
let Some(stdout) = process.stdout.take() else {
return Err(UciCreationError::StdoutIsNone);
};

let Some(stdin) = process.stdin.take() else {
return Err(UciCreationError::StdinIsNone);
};
Expand Down Expand Up @@ -135,25 +135,25 @@ where
/// See [`Read::read_exact`].
pub async fn skip_lines(&mut self, count: usize) -> io::Result<()> {
let mut buf = String::new();

for _ in 0..count {
self.stdout.read_line(&mut buf).await?;
}

// loop {
// self.stdout.read_exact(&mut buf).await?;
//
//
// if buf[0] == b'\n' {
// // CLIPPY: `skipped_count` never overflows because it starts at 0, increments by 1, and stops once `count` is reached.
// #[allow(clippy::arithmetic_side_effects)]
// {
// skipped_count += 1;
// }
//
//
// if skipped_count == count {
// break;
// }
//
//
// continue;
// }
// }
Expand All @@ -171,10 +171,12 @@ where
&mut self,
) -> Result<MReceive, UciReadMessageError<MReceive::ParameterPointer>> {
let mut line = String::new();
self.stdout.read_line(&mut line).await.map_err(UciReadMessageError::Io)?;

MReceive::from_str(&line)
.map_err(UciReadMessageError::MessageParse)
self.stdout
.read_line(&mut line)
.await
.map_err(UciReadMessageError::Io)?;

MReceive::from_str(&line).map_err(UciReadMessageError::MessageParse)
}
}

Expand Down Expand Up @@ -335,25 +337,4 @@ fn update_id(old_id: &mut Option<IdMessageKind>, new_id: IdMessageKind) {
IdMessageKind::NameAndAuthor { name, author }
}
});
}

#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod tests {
use super::*;
use pretty_assertions::assert_eq;

#[tokio::test]
async fn skip_lines() {
let mut engine_conn = EngineConnection::from_path("/resources/stockfish.exe").unwrap();

engine_conn.send_message(&GuiMessage::UseUci).await.unwrap();

engine_conn.skip_lines(4).await.unwrap();

let mut line = String::new();
engine_conn.stdout.read_line(&mut line).await.unwrap();

assert_eq!(line, "option name Debug Log File type string default\n");
}
}
}

0 comments on commit 9fa24b7

Please sign in to comment.