GameOfLife

Struct GameOfLife 

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

Class of game of life.
To create a new game of life with a grid of 25 collumns wide and 45 lines height, use :\

fn main(){
    let mut game = GameOfLife::new(25, 45);
}

Implementations§

Source§

impl GameOfLife

Source

pub fn new(nb_col: usize, nb_lig: usize) -> GameOfLife

Examples found in repository?
examples/basic.rs (line 6)
5fn main(){
6	let mut g = GameOfLife::new(45, 25);
7	g.set_element(5, 5);
8	g.set_element(6, 5);
9	g.set_element(7, 5);
10	g.set_element(6, 6);
11	clear();
12	reverse();
13	loop {
14		g.show();
15		g.update();
16		refresh();
17		clear();
18		sleep(Duration::from_millis(500));
19	}
20}
Source

pub fn set_element(&mut self, i_col: usize, i_lig: usize)

Function to set the value of an element.
For exemple, to set the element at position 5, 5 (e.g. to make the cell alive), do :
/!\ Pay attention ! : It is the collumn first, and after the line.\

fn main(){
    let mut game = GameOfLife::new(25, 45);
    game.set_element(5,5);
}
Examples found in repository?
examples/basic.rs (line 7)
5fn main(){
6	let mut g = GameOfLife::new(45, 25);
7	g.set_element(5, 5);
8	g.set_element(6, 5);
9	g.set_element(7, 5);
10	g.set_element(6, 6);
11	clear();
12	reverse();
13	loop {
14		g.show();
15		g.update();
16		refresh();
17		clear();
18		sleep(Duration::from_millis(500));
19	}
20}
Source

pub fn unset_element(&mut self, i_col: usize, i_lig: usize)

Function to reset the value of an element.
For exemple, to reset the element at position 5, 5 (e.g. to kill the cell), do :
/!\ Pay attention ! : It is the collumn first, and after the line.\

fn main(){
    let mut game = GameOfLife::new(25, 45);
    game.unset_element(5,5);
}
Source

pub fn show(&self)

Function to show the actual state of the game.
For exemple :\

fn main(){
    let mut game = GameOfLife::new(25, 45);
    game.show();
}
Examples found in repository?
examples/basic.rs (line 14)
5fn main(){
6	let mut g = GameOfLife::new(45, 25);
7	g.set_element(5, 5);
8	g.set_element(6, 5);
9	g.set_element(7, 5);
10	g.set_element(6, 6);
11	clear();
12	reverse();
13	loop {
14		g.show();
15		g.update();
16		refresh();
17		clear();
18		sleep(Duration::from_millis(500));
19	}
20}
Source

pub fn update(&mut self)

Function which update the game (e.g. pass to the next state)
For exemple :\

fn main(){
    let mut game = GameOfLife::new(25, 45);
    game.update();
}
Examples found in repository?
examples/basic.rs (line 15)
5fn main(){
6	let mut g = GameOfLife::new(45, 25);
7	g.set_element(5, 5);
8	g.set_element(6, 5);
9	g.set_element(7, 5);
10	g.set_element(6, 6);
11	clear();
12	reverse();
13	loop {
14		g.show();
15		g.update();
16		refresh();
17		clear();
18		sleep(Duration::from_millis(500));
19	}
20}
Source

pub fn get_grid(&self) -> &Vec<Vec<bool>>

Funtion to get the grid of the automata

Auto Trait Implementations§

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.