use super::rand::{thread_rng, Rng};
#[derive(Clone, PartialEq, Debug)]
pub enum Direction {
Left,
Right,
Up,
Down
}
lazy_static! {
static ref DIRECTIONS: Vec<Direction> = vec![
Direction::Left,
Direction::Right,
Direction::Up,
Direction::Down
];
}
impl Direction {
pub fn sample() -> Direction {
match thread_rng().gen_range(0, 4) {
0 => Direction::Left,
1 => Direction::Right,
2 => Direction::Down,
3 => Direction::Up,
_ => Direction::Up
}
}
pub fn without(dirs: &Vec<Direction>) -> Vec<Direction> {
let mut filtered = DIRECTIONS.clone();
filtered.retain(|dir| dirs.iter().all(|tried| &dir != &tried));
filtered
}
pub fn sample_without(dirs: &Vec<Direction>) -> Direction {
let filtered = &Self::without(dirs);
filtered[thread_rng().gen_range(0, filtered.len())].clone()
}
}