Function classify_puzzle

Source
pub fn classify_puzzle(puzzle: &Puzzle) -> Result<ComplexityClass, DominoError>
Expand description

Classifies the given puzzle and returns its complexity as a ComplexityClass.

This function retrieves the puzzle’s dimension, calculates a derived length l based on whether the dimension is even or odd, and determines if the puzzle is planar (n ≤ 3). Depending on planarity, it computes a maximum allowed hole length (max_hole). Holes in the puzzle are then detected, and if none are found, a DominoError::InvalidLength is returned. If the entire puzzle consists of empty tiles, a DominoError::EmptyPuzzle is thrown. Otherwise, the puzzle’s complexity ComplexityClass is computed.

§Arguments

  • puzzle - A reference to the puzzle, represented as a Vec<Option<Tile>>.

§Returns

  • Ok(ComplexityClass) containing the computed ComplexityClass, or
  • Err(DominoError) if an error occurs (for example, if no holes are detected, the puzzle is empty, or if get_n(puzzle) fails).