Crates.io | conway-gol-rs |
lib.rs | conway-gol-rs |
version | 0.1.2 |
source | src |
created_at | 2024-06-22 12:12:22.52841 |
updated_at | 2024-06-22 13:54:49.199487 |
description | A Conway's Game of Life implementation in Rust |
homepage | |
repository | https://github.com/kanishka-sahoo/conway-gol-rs |
max_upload_size | |
id | 1280418 |
size | 7,566 |
A Rust library implementation of Conway's Game of Life.
Add this to your Cargo.toml
:
[dependencies]
conway_game_of_life = "0.1.0"
Here's a quick example of how to use the library:
use conway_game_of_life::ConwayGameGrid;
fn main() {
// Create a 10x10 grid
let mut game = ConwayGameGrid::new(10, 10);
// Set some initial live cells
game.set_cell_state(1, 1, true);
game.set_cell_state(1, 2, true);
game.set_cell_state(1, 3, true);
// Run a single iteration
game.iterate();
// Print the current state
println!("{}", game.dump());
}
ConwayGameGrid
The main struct representing the game grid.
new(width: usize, height: usize) -> Self
: Create a new game grid.iterate(&mut self)
: Advance the game state by one generation.update_cells(&mut self, cells: &[UpdatedCell])
: Update multiple cells at once.get_cell_state(&self, row: usize, col: usize) -> Option<bool>
: Get the state of a specific cell.set_cell_state(&mut self, row: usize, col: usize, state: bool) -> bool
: Set the state of a specific cell.dimensions(&self) -> (usize, usize)
: Get the dimensions of the grid.dump(&self) -> String
: Get a string representation of the current grid state.UpdatedCell
A struct representing a cell update.
row: usize
: The row of the cell.col: usize
: The column of the cell.state: bool
: The new state of the cell.Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.