Struct snake::Snake[][src]

pub struct Snake { /* fields omitted */ }

Instance of game Snake containing board state, rng, and display

Implementations

impl Snake[src]

pub fn new(seed: u64, size: u8) -> Snake[src]

Creates a game instance with no display

Arguments

  • seed - Seed for random generation of food
  • size - The width/height of game board grid

Example

use snake::Snake;
let mut game = Snake::new(0, 10);

pub fn length(&self) -> usize[src]

Returns length of snake

pub fn current_direction(&self) -> Direction[src]

Returns current direction of snake

pub fn walls(&self) -> Vec<f32>[src]

Returns distance of head from walls in the following order left, up-left, up, up-right, right, down-right, down, down-left

pub fn snake(&self) -> Vec<f32>[src]

Returns distance of head from snake in each direction in the following order left, up-left, up, up-right, right, down-right, down, down-left

pub fn food(&self) -> Vec<f32>[src]

Returns distance of head from food in each direction in the following order left, up-left, up, up-right, right, down-right, down, down-left

pub fn turn(&mut self, dir: Direction) -> bool[src]

Elapses game one move. Returns true if game is still active and false if game is over (once snake has died).

Arguments

  • dir - Direction for the snake to move. If the provided direction is center or opposite the last provided direction (left/right, up/down), the snake will continue in the last provided direction

Auto Trait Implementations

impl RefUnwindSafe for Snake

impl Send for Snake

impl Sync for Snake

impl Unpin for Snake

impl UnwindSafe for Snake

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,