Struct conway::Universe
[−]
[src]
pub struct Universe { /* fields omitted */ }
Represents a wrapping universe in Conway's game of life.
Methods
impl Universe
[src]
fn set(&mut self, col: usize, row: usize, cell: CellState)
fn toggle_unchecked(
&mut self,
col: usize,
row: usize,
opt_player_id: Option<usize>
) -> CellState
&mut self,
col: usize,
row: usize,
opt_player_id: Option<usize>
) -> CellState
fn toggle(
&mut self,
col: usize,
row: usize,
player_id: usize
) -> Result<CellState, ()>
&mut self,
col: usize,
row: usize,
player_id: usize
) -> Result<CellState, ()>
fn new(
width: usize,
height: usize,
is_server: bool,
history: usize,
num_players: usize,
player_writable: Vec<Region>
) -> Result<Universe, &'static str>
width: usize,
height: usize,
is_server: bool,
history: usize,
num_players: usize,
player_writable: Vec<Region>
) -> Result<Universe, &'static str>
Instantiate a new blank universe with the given width and height, in cells. The universe is at generation 1.
fn width(&self) -> usize
Return width in cells.
fn height(&self) -> usize
Return height in cells.
fn latest_gen(&self) -> usize
Get the latest generation number (1-based).
fn next(&mut self) -> usize
Compute the next generation. Returns the new latest generation number.
fn each_non_dead(
&self,
region: Region,
visibility: Option<usize>,
callback: &mut FnMut(usize, usize, CellState)
)
&self,
region: Region,
visibility: Option<usize>,
callback: &mut FnMut(usize, usize, CellState)
)
Iterate over every non-dead cell in the universe for the current generation. region
is
the rectangular area used for restricting results. visibility
is an optional player_id;
if specified, causes cells not visible to the player to be passed as CellState::Fog to the
callback.
Callback receives (x, y, cell_state).
fn each_non_dead_full(
&self,
visibility: Option<usize>,
callback: &mut FnMut(usize, usize, CellState)
)
&self,
visibility: Option<usize>,
callback: &mut FnMut(usize, usize, CellState)
)
Iterate over every non-dead cell in the universe for the current generation.
visibility
is an optional player_id, allowing filtering based on fog.
Callback receives (x, y, cell_state).
fn region(&self) -> Region
Get a Region of the same size as the universe