use std::fmt; use crate::geometry::Direction; use crate::geometry::Point2d; #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub struct Command { pub worm: Option, pub action: Action } impl fmt::Display for Command { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self.worm { Some(worm) => write!(f, "select {};{}", worm, self.action), None => write!(f, "{}", self.action) } } } impl Command { pub fn with_select(worm: i32, action: Action) -> Command { Command { worm: Some(worm), action } } pub fn new(action: Action) -> Command { Command { worm: None, action } } } #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum Action { Move(Point2d), Dig(Point2d), Shoot(Direction), Bomb(Point2d), DoNothing, } impl fmt::Display for Action { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { use Action::*; match self { Move(p) => write!(f, "move {} {}", p.x, p.y), Dig(p) => write!(f, "dig {} {}", p.x, p.y), Shoot(dir) => write!(f, "shoot {}", dir), Bomb(p) => write!(f, "banana {} {}", p.x, p.y), DoNothing => write!(f, "nothing"), } } }