Skip to content

Commit

Permalink
Fix bug handling repeated stones
Browse files Browse the repository at this point in the history
The SGF specification explicitly allows placing stones over top of
existing stones, but for some reason I was explicitly disallowing that.

The fix is simple - don't throw an error in this case!
  • Loading branch information
julianandrews committed Sep 16, 2024
1 parent 6364a73 commit f49af1f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/lib/goban.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,6 @@ impl Goban {
return Err(GobanError::InvalidMove);
}
let key = (stone.x, stone.y);
if self.stones.contains_key(&key) {
return Err(GobanError::InvalidMove);
}
self.stones.insert(key, stone.color);

Ok(())
Expand Down Expand Up @@ -365,3 +362,14 @@ fn get_board_size(sgf_node: &SgfNode<go::Prop>) -> (u8, u8) {
Some(_) => unreachable!(),
}
}

#[cfg(test)]
mod tests {
use super::Goban;

#[test]
fn play_over_existing_stone() {
let result = Goban::from_sgf("(;AB[ac];B[ac])", &Default::default());
assert!(result.is_ok());
}
}

0 comments on commit f49af1f

Please sign in to comment.