Prevent conflicting instructions in a setup node
This commit is contained in:
parent
7fc1530245
commit
3ed09bfc32
|
@ -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<Position, ConversionError> {
|
||||
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<parser::SetupInstr>) -> Result<Self, SetupNodeError> {
|
||||
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,
|
||||
|
|
Loading…
Reference in New Issue