From 209beef484894ad5c27bfea28e381bc2812e7cf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20GUEZO?= Date: Sat, 3 May 2025 11:42:18 +0200 Subject: [PATCH] feat: README --- README.md | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++-- src/main.rs | 4 ++- 2 files changed, 102 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c37213c..f062e91 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,99 @@ -# GameOfLife_rs -simple game of life based in rust +

Game of Life

+ +

+ A simple implementation of Conway's Game of Life in Rust.
Experience the magic of cellular automata directly in your terminal. +

+ +

+ Rust + GitHub Repo +

+ + +## Prerequisites + +Before you begin, make sure [**Rust**](https://www.rust-lang.org) is installed on your machine. +```bash +rustc --version +cargo --version +``` + + +## Installation +Clone and run the project locally: +```bash +git clone https://github.com/guezoloic/GameOfLife.git +cd GameOfLife +cargo build --release +cargo run +``` + +## Features +- Simple and efficient 2D grid-based simulation. +- Add your own patterns (glider, beacon, etc.) +- Console-based visualization. + +## Usage + +You can easily insert patterns in `main.rs` like: + +- **Glider:** + ```rust + // X . . + // . X X + // X X . + + Cell::new(14, 14, "glider", &[ + (-1, 1), (0, 0), (1, 0), + (-1, -1), (0, -1), + ]); + ``` + +- **Blinker:** + ```rust + // X + // X + // X + + // Blinker (horizontal): + // X X X + + Cell::new(10, 10, "blinker", &[ + (1, 0), (0, 0), (-1, 0) + ]); + ``` + +- **Beacon:** + ```rust + // X X . . + // X X . . + // . . X X + // . . X X + + Cell::new(6, 6, "beacon", &[ + (-1, 1), (0, 1), (-1, 0), (0, 0), + (-3, 3), (-2, 3), (-3, 2), (-2, 2) + ]); + ``` + +- **Toad:** + ```rust + // . X + // X X + // X X + // X . + Cell::new(24, 24, "toad", &[ + (-1, 1), (-1, 0), (-1, -1), + (0, 0), (0, -1), (0, -2) + ]); + ``` + +You can create additional patterns by modifying the positions or creating new shapes. The Cell::new(x, y, name, array) constructor accepts a starting position (x, y) and a list of directions (i8, i8) that represent the neighbors of the cell. +If you need inspiration or want to explore existing patterns, the [ConwayLife](https://conwaylife.com) website offers a comprehensive library of well-documented examples. + +## History + +[The Game of Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life) was created by mathematician John Conway in 1970 as a simple simulation of how life might evolve. It follows a few basic rules where cells live, die, or are born depending on their neighbors. Despite its simplicity, the system can lead to incredibly complex and fascinating patterns. It’s a classic example of how simple rules can create unexpected and beautiful behaviors. + +## Contributing +Feel free to fork the repository, submit issues or pull requests. diff --git a/src/main.rs b/src/main.rs index 4965d1b..43478a5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ impl Cell { let dx = x as i8 + directions_array[i].0; let dy = y as i8 + directions_array[i].1; - if dx > 0 && dy > 0 { + if dx >= 0 && dy >= 0 { cells_array.push(( dx as usize, dy as usize @@ -105,8 +105,10 @@ fn main() { let mut grid: [[bool; WIDTH]; HEIGHT] = [[false; WIDTH]; HEIGHT]; let mut buffer: String = String::new(); + // let glider: Cell = Cell::new(14, 14, "glider", &[(1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]); glider.add_grid(&mut grid); + // loop { display(&grid, &mut buffer);