~athorp96/conway.rs

63995b3124f8e1724bb46b13c9110fbc6378887a — Andrew Thorp 1 year, 9 days ago bf091e8 main
Minor refactor
4 files changed, 9 insertions(+), 9 deletions(-)

M src/conway/board.rs
R src/conway/{conway.rs => cell.rs}
M src/conway/mod.rs
M src/main.rs
M src/conway/board.rs => src/conway/board.rs +5 -5
@@ 1,7 1,7 @@
use rand::prelude::*;
use std::fmt;

use crate::conway::conway::{Cell, CellState, Coordinate, SimpleCell};
use crate::conway::cell::{Cell, CellState, SimpleCell, Coordinate};

pub struct Board {
    width: usize,


@@ 29,9 29,9 @@ impl Board {
        }
    }

    pub fn get(&self, x: usize, y: usize) -> Option<SimpleCell> {
        if x < self.width && x >= 0 && y < self.height && y >= 0 {
            Some(self.cells[x][y].clone())
    pub fn get(&self, x: i32, y: i32) -> Option<SimpleCell> {
        if x < self.width as i32 && x >= 0 && y < self.height as i32 && y >= 0 {
            Some(self.cells[x as usize][y as usize].clone())
        } else {
            None
        }


@@ 76,7 76,7 @@ impl Board {
    fn get_cells(&self, coordinates: Vec<Coordinate>) -> Vec<SimpleCell> {
        let mut cells = Vec::new();
        for c in coordinates {
            if let Some(cell) = self.get(c.x as usize, c.y as usize) {
            if let Some(cell) = self.get(c.x, c.y) {
                cells.push(cell);
            }
        }

R src/conway/conway.rs => src/conway/cell.rs +0 -0
M src/conway/mod.rs => src/conway/mod.rs +1 -1
@@ 1,2 1,2 @@
pub mod board;
pub mod conway;
pub mod cell;

M src/main.rs => src/main.rs +3 -3
@@ 3,7 3,7 @@ use std::{thread, time};
mod conway;

use conway::board::Board;
use conway::conway::CellState;
use conway::cell::CellState;

fn sleep(time_ms: usize) {
    let sleep_time = time::Duration::from_millis(time_ms as u64);


@@ 19,8 19,8 @@ fn main() {
    b.set(2, 0, CellState::Alive);
    b.set(2, 1, CellState::Alive);

    for i in 0..50 {
        println!("Board:\n{}", b);
    for i in 0..=30 {
        println!("Board: {}\n{}", i, b);
        b.step();
        sleep(100);
    }