Skip to content

Commit

Permalink
Work on function
Browse files Browse the repository at this point in the history
  • Loading branch information
Terkwood committed Mar 14, 2020
1 parent 18be481 commit 4cc7371
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
20 changes: 20 additions & 0 deletions tinybrain/src/err.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use serde_derive::{Deserialize, Serialize};
#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
pub struct CoordOutOfRange;

impl From<std::num::ParseIntError> for CoordOutOfRange {
fn from(_: std::num::ParseIntError) -> Self {
CoordOutOfRange
}
}

#[derive(Debug)]
pub enum KataGoParseErr {
UuidErr(uuid::Error),
WrongFormat,
}
impl From<uuid::Error> for KataGoParseErr {
fn from(u: uuid::Error) -> Self {
KataGoParseErr::UuidErr(u)
}
}
20 changes: 19 additions & 1 deletion tinybrain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ extern crate http;

mod authorization;
pub mod env;
mod err;
pub mod katago;
pub mod websocket;

Expand All @@ -29,7 +30,7 @@ pub struct ComputeMove {
pub struct MoveComputed(MakeMoveCommand);

impl MoveComputed {
pub fn from(response: KataGoResponse) -> Result<Self, katago::json::KataGoParseErr> {
pub fn from(response: KataGoResponse) -> Result<Self, err::KataGoParseErr> {
let game_id = response.game_id()?;
let player = response.player()?;
let coord: Option<Coord> = todo!("figure out the reverse conversion");
Expand All @@ -43,6 +44,23 @@ impl MoveComputed {
}
}

fn from_alphanum(a: &str) -> Result<Coord, err::CoordOutOfRange> {
if a.len() < 2 {
Err(err::CoordOutOfRange)
} else {
let letter: char = a.chars().collect::<Vec<char>>()[0];
let number = &a[1..];
let y_plus_one = number.to_string().parse::<u16>()?;
let r = (b'A'..=b'Z');
todo!();

Ok(Coord {
x: todo!(),
y: y_plus_one - 1,
})
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 4cc7371

Please sign in to comment.