You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
964 B
28 lines
964 B
use enum_map::EnumMap;
|
|
use ndarray::Array2;
|
|
use strum::IntoEnumIterator;
|
|
use crate::binary::{Direction, State};
|
|
use crate::board_metadata::{BoardMetadata,CellLocation};
|
|
use crate::rules::Rules;
|
|
|
|
pub struct RulesEasy {}
|
|
|
|
impl Rules for RulesEasy {
|
|
fn get_next_state(current_state: State, neighbour_counts: EnumMap<State, usize>) -> State {
|
|
match current_state {
|
|
State::Alive if neighbour_counts[State::Alive] == 2 => State::Alive,
|
|
_ if neighbour_counts[State::Alive] == 3 => State::Alive,
|
|
_ => State::Dead,
|
|
}
|
|
}
|
|
|
|
fn get_neighbours(cell_location: CellLocation, board_metadata: &BoardMetadata, _original_states: &Array2<State>) -> EnumMap<Direction, Option<CellLocation>> {
|
|
let mut neighbours = EnumMap::new();
|
|
|
|
for direction in Direction::iter() {
|
|
neighbours[direction] = board_metadata.get_neighbour_location(cell_location, direction);
|
|
}
|
|
|
|
neighbours
|
|
}
|
|
}
|
|
|