diff --git a/sgf/src/game.rs b/sgf/src/game.rs index 68754e0..7ba5aed 100644 --- a/sgf/src/game.rs +++ b/sgf/src/game.rs @@ -1,17 +1,10 @@ use crate::{ - parser::{self, Annotation, Evaluation, UnknownProperty}, + parser::{self, Annotation, Evaluation, SetupInstr, UnknownProperty}, Color, }; use std::{collections::HashSet, time::Duration}; use uuid::Uuid; -/* -#[derive(Clone, Debug, PartialEq)] -pub enum PropertyError { - ConflictingProperty, -} - */ - #[derive(Clone, Debug, PartialEq)] pub enum MoveNodeError { IncompatibleProperty, @@ -222,19 +215,6 @@ impl TryFrom<&parser::Node> for MoveNode { } } -/* -fn parse_position(s: &str) -> Result { - if s.len() == 2 { - Ok(Position { - row: s[0], - column: s[1], - }) - } else { - Err(ConversionError::InvalidPositionSyntax) - } -} -*/ - #[derive(Clone, Debug, PartialEq)] pub struct SetupNode { id: Uuid, @@ -245,6 +225,18 @@ pub struct SetupNode { impl SetupNode { pub fn new(positions: Vec) -> Result { + let mut board = HashSet::new(); + for position in positions.iter() { + let point = match position { + SetupInstr::Piece((_, point)) => point, + SetupInstr::Clear(point) => point, + }; + if board.contains(point) { + return Err(SetupNodeError::ConflictingPosition); + } + board.insert(point); + } + Ok(Self { id: Uuid::new_v4(), positions,