diff --git a/tinybrain/src/err.rs b/tinybrain/src/err.rs new file mode 100644 index 000000000..6032f899b --- /dev/null +++ b/tinybrain/src/err.rs @@ -0,0 +1,20 @@ +use serde_derive::{Deserialize, Serialize}; +#[derive(Debug, Copy, Clone, Serialize, Deserialize)] +pub struct CoordOutOfRange; + +impl From for CoordOutOfRange { + fn from(_: std::num::ParseIntError) -> Self { + CoordOutOfRange + } +} + +#[derive(Debug)] +pub enum KataGoParseErr { + UuidErr(uuid::Error), + WrongFormat, +} +impl From for KataGoParseErr { + fn from(u: uuid::Error) -> Self { + KataGoParseErr::UuidErr(u) + } +} diff --git a/tinybrain/src/lib.rs b/tinybrain/src/lib.rs index 2680edd24..32dcacb64 100644 --- a/tinybrain/src/lib.rs +++ b/tinybrain/src/lib.rs @@ -12,6 +12,7 @@ extern crate http; mod authorization; pub mod env; +mod err; pub mod katago; pub mod websocket; @@ -29,7 +30,7 @@ pub struct ComputeMove { pub struct MoveComputed(MakeMoveCommand); impl MoveComputed { - pub fn from(response: KataGoResponse) -> Result { + pub fn from(response: KataGoResponse) -> Result { let game_id = response.game_id()?; let player = response.player()?; let coord: Option = todo!("figure out the reverse conversion"); @@ -43,6 +44,23 @@ impl MoveComputed { } } +fn from_alphanum(a: &str) -> Result { + if a.len() < 2 { + Err(err::CoordOutOfRange) + } else { + let letter: char = a.chars().collect::>()[0]; + let number = &a[1..]; + let y_plus_one = number.to_string().parse::()?; + let r = (b'A'..=b'Z'); + todo!(); + + Ok(Coord { + x: todo!(), + y: y_plus_one - 1, + }) + } +} + #[cfg(test)] mod tests { use super::*;