Skip to content

Commit

Permalink
Botlink: fix coord conversion (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
Terkwood authored Apr 22, 2020
1 parent 55064ca commit d756a05
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
24 changes: 12 additions & 12 deletions botlink/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion botlink/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "botlink"
version = "0.1.2"
version = "0.1.3"
authors = ["terkwood <38859656+Terkwood@users.noreply.github.com>"]
edition = "2018"

Expand Down
4 changes: 2 additions & 2 deletions botlink/src/repo/board_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ impl BoardSizeRepo for RedisBoardSizeRepo {
}
fn set(&self, game_id: &GameId, board_size: u16) -> Result<(), RepoErr> {
let mut conn = self.pool.get().expect("pool");
let result = conn.set(self.key_provider.board_size(&game_id.0), board_size)?;
conn.set(self.key_provider.board_size(&game_id.0), board_size)?;
self.expire(game_id, &mut conn)?;
Ok(result)
Ok(())
}
}

Expand Down
14 changes: 13 additions & 1 deletion botlink/src/stream/write_moves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ pub fn write_moves(
}

fn convert(a: AlphaNumCoord, board_size: u16) -> Coord {
let r: Vec<char> = (b'A'..=b'Z').map(char::from).collect();
let r: Vec<char> = (b'A'..=b'Z')
.filter(|l| l != &b'I')
.map(char::from)
.collect();
let x = r.iter().position(|l| l == &a.0).expect("convert") as u16;

Coord {
Expand All @@ -58,4 +61,13 @@ mod tests {
let expected = Coord { x: 0, y: 8 };
assert_eq!(actual, expected)
}

#[test]
fn test_skip_i() {
let j = AlphaNumCoord('J', 19);
let board_size = 19;
let actual = convert(j, board_size);
let expected = Coord { x: 8, y: 0 };
assert_eq!(actual, expected)
}
}

0 comments on commit d756a05

Please sign in to comment.