use rand::{thread_rng, Rng};

pub mod model;
mod grid;

pub use self::grid::Grid;
pub use self::model::Model;

// A direction that the snake head can travel in
#[derive(Clone, Copy, PartialEq)]
pub enum Direction {
    Up,
    Down,
    Left,
    Right,
}

impl Direction {
    pub fn is_opposite_direction(&self, other: Direction) -> bool {
        match *self {
            Direction::Up => other == Direction::Down,
            Direction::Down => other == Direction::Up,
            Direction::Left => other == Direction::Right,
            Direction::Right => other == Direction::Left,
        }
#[derive(Clone)]
pub enum GridCell {
    Empty,
    Food,
    SnakePart,
}

impl GridCell {
    pub fn change_cell(&mut self, value: GridCell) {
        *self = value;
    }

    pub fn is_empty(&self) -> bool {
        match *self {
            GridCell::Empty => true,
            _ => false,
        }
    }

    pub fn is_food(&self) -> bool {
        match *self {
            GridCell::Food => true,
            _ => false,
        }
    }
}

// A cell locaiton in the arena
#[derive(Clone, Copy)]
pub struct CellLocation {
    x: usize,
    y: usize,
}

impl CellLocation {
    pub fn get_neighbour(&self, direction: Direction) -> CellLocation {
        match direction {
            Direction::Up => {
                CellLocation {
                    x: self.x + 1,
                    y: self.y,
                }
            }
            Direction::Down => {
                CellLocation {
                    x: self.x - 1,
                    y: self.y,
                }
            }
            Direction::Left => {
                CellLocation {
                    x: self.x,
                    y: self.y - 1,
                }
            }
            Direction::Right => {
                CellLocation {
                    x: self.x,
                    y: self.y + 1,
                }
            }
        }
    }
}
    }
}

// A cell in the grid is either empty, occupied by a snake part (with a direction the
// tail should continue in when it hits it), or contains a piece of food.