diff options
author | Justin Worthe <justin@worthe-it.co.za> | 2019-04-22 11:19:16 +0200 |
---|---|---|
committer | Justin Worthe <justin@worthe-it.co.za> | 2019-04-22 11:19:16 +0200 |
commit | 29a323e0a3bd3ab3e6109b23e15bb5f9e88398e3 (patch) | |
tree | a151c612b5993f127d99c29d4c4fdcf252528436 /src/command.rs |
Start the project from the starter bot
Diffstat (limited to 'src/command.rs')
-rw-r--r-- | src/command.rs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/command.rs b/src/command.rs new file mode 100644 index 0000000..06dd400 --- /dev/null +++ b/src/command.rs @@ -0,0 +1,61 @@ +use std::fmt; + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Command { + Move(u32, u32), + Dig(u32, u32), + Shoot(Direction), + DoNothing, +} + +impl fmt::Display for Command { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + use Command::*; + match self { + Move(x, y) => write!(f, "move {} {}", x, y), + Dig(x, y) => write!(f, "dig {} {}", x, y), + Shoot(dir) => write!(f, "shoot {}", dir), + DoNothing => write!(f, "nothing"), + } + } +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Direction { + North, + NorthEast, + East, + SouthEast, + South, + SouthWest, + West, + NorthWest, +} + +impl fmt::Display for Direction { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + use Direction::*; + let s = match self { + North => "N", + NorthEast => "NE", + East => "E", + SouthEast => "SE", + South => "S", + SouthWest => "SW", + West => "W", + NorthWest => "NW", + }; + f.write_str(s) + } +} + +impl Direction { + pub fn is_diagonal(&self) -> bool { + use Direction::*; + + match self { + NorthEast | SouthEast | SouthWest | NorthWest => true, + _ => false, + } + } +} |