use num_traits::{One, Signed, Zero}; use parity_scale_codec::{Decode, Encode}; pub type Position = (i32, i32); #[derive(Debug, Default)] pub struct Board { pub origin: (i32, i32), pub size: (i32, i32), } pub trait HasPosition { fn get_position(&self) -> (i32, i32); } #[derive(Clone, Copy, Debug, Decode, Encode, Eq, PartialEq, Hash)] pub enum Direction { East, North, South, West, } impl Direction { pub fn to_position(&self) -> (T, T) { match self { Self::East => (T::one(), T::zero()), Self::North => (T::zero(), T::one().neg()), Self::South => (T::zero(), T::one()), Self::West => (T::one().neg(), T::zero()), } } } impl sp_runtime_interface::pass_by::PassBy for Direction { type PassBy = sp_runtime_interface::pass_by::Codec; }