Snake

Struct Snake 

Source
pub struct Snake { /* private fields */ }
Expand description

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

Implementations§

Source§

impl Snake

Source

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

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);
Source

pub fn length(&self) -> usize

Returns length of snake

Source

pub fn current_direction(&self) -> Direction

Returns current direction of snake

Source

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

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

Source

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

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

Source

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

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

Source

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

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 Freeze for Snake

§

impl RefUnwindSafe for Snake

§

impl Send for Snake

§

impl Sync for Snake

§

impl Unpin for Snake

§

impl UnwindSafe for Snake

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

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

Source§

fn vzip(self) -> V