From 6cbb389ee765f11afde602be488d865bc64f9d7f Mon Sep 17 00:00:00 2001 From: hal8174 Date: Wed, 21 Feb 2024 23:14:07 +0100 Subject: [PATCH] Add helper functions. --- src/belt_finding/common.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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)]