Single path brute force

This commit is contained in:
hal8174 2023-12-11 17:28:58 +01:00
parent c10843ad2f
commit 2bc323aa58
4 changed files with 413 additions and 2 deletions

View file

@ -6,7 +6,9 @@ use colored::{Color, Colorize};
use std::fmt::{write, Display};
use std::io::Write;
#[derive(Clone, Copy)]
pub mod brute_force;
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum Direction {
Up,
Right,
@ -14,6 +16,48 @@ pub enum Direction {
Left,
}
impl Direction {
fn vertical(&self) -> bool {
match self {
Direction::Up => true,
Direction::Right => false,
Direction::Down => true,
Direction::Left => false,
}
}
fn horizontal(&self) -> bool {
!self.vertical()
}
fn reverse(&self) -> Self {
match self {
Direction::Up => Direction::Down,
Direction::Right => Direction::Left,
Direction::Down => Direction::Up,
Direction::Left => Direction::Right,
}
}
fn clockwise(&self) -> Self {
match self {
Direction::Up => Direction::Right,
Direction::Right => Direction::Down,
Direction::Down => Direction::Left,
Direction::Left => Direction::Up,
}
}
fn counter_clockwise(&self) -> Self {
match self {
Direction::Up => Direction::Left,
Direction::Right => Direction::Up,
Direction::Down => Direction::Right,
Direction::Left => Direction::Down,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct Position {
pub x: usize,
@ -156,7 +200,7 @@ impl Display for Problem {
write!(f, "{}", "".color(COLORS[i]))?;
}
} else if self.map.get(x, y).blocked {
write!(f, "{}", "#")?;
write!(f, "#")?;
} else if x % 8 == 0 || y % 8 == 0 {
write!(f, "")?;
} else {