|
|
@ -4,6 +4,8 @@ |
|
|
|
|
|
|
|
|
|
|
|
mod commands; |
|
|
|
mod commands; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use std::io::{BufRead, Write}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)] |
|
|
|
#[derive(Debug)] |
|
|
|
pub struct Engine<'a, R, W> { |
|
|
|
pub struct Engine<'a, R, W> { |
|
|
@ -31,11 +33,16 @@ pub struct Engine<'a, R, W> { |
|
|
|
/// Additionally this code should have a parser. You call it with the reader supplied and it waits for a command
|
|
|
|
/// Additionally this code should have a parser. You call it with the reader supplied and it waits for a command
|
|
|
|
/// and parses it into a tuple of some kind for the user.
|
|
|
|
/// and parses it into a tuple of some kind for the user.
|
|
|
|
|
|
|
|
|
|
|
|
impl<'a, R, W> Engine<'a, R, W> { |
|
|
|
impl<'a, R, W> Engine<'a, R, W> |
|
|
|
|
|
|
|
where |
|
|
|
|
|
|
|
R: BufRead, |
|
|
|
|
|
|
|
W: Write, |
|
|
|
|
|
|
|
{ |
|
|
|
pub fn new(name: &'a str, author: &'a str, reader: R, writer: W) -> Engine<'a, R, W> { |
|
|
|
pub fn new(name: &'a str, author: &'a str, reader: R, writer: W) -> Engine<'a, R, W> { |
|
|
|
|
|
|
|
|
|
|
|
// TODO: This should also take an EngineOptions thing that indicates which options are supported
|
|
|
|
// TODO: This should also take an EngineOptions thing that indicates which options are supported
|
|
|
|
// so that when called it can send them easily.
|
|
|
|
// so that when called it can send them easily.
|
|
|
|
|
|
|
|
// Engine options are all optional and appeared to be fixed by the UCI standard.
|
|
|
|
|
|
|
|
|
|
|
|
Engine { |
|
|
|
Engine { |
|
|
|
name: name, |
|
|
|
name: name, |
|
|
@ -47,8 +54,8 @@ impl<'a, R, W> Engine<'a, R, W> { |
|
|
|
|
|
|
|
|
|
|
|
/// Sends identification messages to the writer for the GUI to pick up
|
|
|
|
/// Sends identification messages to the writer for the GUI to pick up
|
|
|
|
pub fn identify(&mut self) { |
|
|
|
pub fn identify(&mut self) { |
|
|
|
let name_id: String = format!("{} {} {}", commands::ID, commands::NAME, self.name); |
|
|
|
let name_id: String = format!("{} {} {}\n", commands::ID, commands::NAME, self.name); |
|
|
|
let author_id: String = format!("{} {} {}", commands::ID, commands::AUTHOR, self.author); |
|
|
|
let author_id: String = format!("{} {} {}\n", commands::ID, commands::AUTHOR, self.author); |
|
|
|
|
|
|
|
|
|
|
|
// For these two writes we can panic - there's no possibility of recovery if the engine fails at this stage
|
|
|
|
// For these two writes we can panic - there's no possibility of recovery if the engine fails at this stage
|
|
|
|
write!(&mut self.writer, "{}", name_id).expect("failed to send name identification to writer"); |
|
|
|
write!(&mut self.writer, "{}", name_id).expect("failed to send name identification to writer"); |
|
|
|