diff --git a/src/belt_finding/common.rs b/src/belt_finding/common.rs index 1c46caf..28c9719 100644 --- a/src/belt_finding/common.rs +++ b/src/belt_finding/common.rs @@ -1,3 +1,4 @@ +use core::panic; use std::io::Write; use base64::write; @@ -68,6 +69,25 @@ impl Direction { Direction::Left => Direction::Down, } } + + pub fn get_index(&self) -> u8 { + match self { + Direction::Up => 0, + Direction::Right => 1, + Direction::Down => 2, + Direction::Left => 3, + } + } + + pub fn from_index(i: u8) -> Self { + match i { + 0 => Direction::Up, + 1 => Direction::Right, + 2 => Direction::Down, + 3 => Direction::Left, + _ => panic!(), + } + } } #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]