maze

Trait MazeSolver

Source
pub trait MazeSolver {
    // Required method
    fn solve(&self) -> Result<MazeSolution, Error>;
}
Expand description

Represents a maze solver interface

Required Methods§

Source

fn solve(&self) -> Result<MazeSolution, Error>

Attempts to solve the path between the start and end points defined within the maze instance

§Returns

A Result containing either the solution if successful, or an Error if an error occurs

§Examples
use data_model::{Maze, MazePoint};
use maze::MazeSolver;
let grid: Vec<Vec<char>> = vec![
   vec!['S', 'W', ' ', ' ', 'W'],
   vec![' ', 'W', ' ', 'W', ' '],
   vec![' ', ' ', ' ', 'W', 'F'],
   vec!['W', ' ', 'W', ' ', ' '],
   vec![' ', ' ', ' ', 'W', ' '],
   vec!['W', 'W', ' ', ' ', ' '],
   vec!['W', 'W', ' ', 'W', ' '],
];
let maze = Maze::from_vec(grid);
let result = maze.solve();
match result {
   Ok(solution) => {
      println!("Successfully solved maze, solution path => {}", solution.path);
   }
   Err(error) => {
       panic!(
           "failed to solve maze => {}",
          error
       );
   }
}

Implementations on Foreign Types§

Source§

impl MazeSolver for Maze

Implementors§