Code Monkey home page Code Monkey logo

gameoflife's Introduction

๐Ÿงซ John Conway's Game of Life

John Conway's Game of Life is a cellular automaton devised by the British mathematician John Horton Conway in 1970. It consists of a grid of cells that can be in one of two states: alive or dead. The state of the grid evolves over time according to a set of simple rules, which lead to complex and often unpredictable behavior.

How does this work?

  1. Initializes a grid of specified width and height with random alive and dead cells based on an optional seed.
  2. Prints the grid to the terminal output.
  3. Updates the grid according to Conway's rules:
    • Any live cell with fewer than two live neighbors dies (underpopulation).
    • Any live cell with two or three live neighbors lives on to the next generation.
    • Any live cell with more than three live neighbors dies (overpopulation).
    • Any dead cell with exactly three live neighbors becomes a live cell (reproduction).
  4. Repeats the process, updating the grid and printing it, to simulate the passage of time in the game.
  5. The simulation stops if all cells are dead or if the pattern repeats twice in a row.
graph LR
    A[๐Ÿ Initialize Grid] --> B[๐Ÿงฎ Print Grid]
    B --> C[๐Ÿ‘พ  Update Grid]
    C --> D{โ˜ ๏ธ All Cells Dead?}
    D -- โœ… Yes --> E[๐Ÿ›‘ Stop Simulation]
    D -- โŒ No --> F{โ™ป๏ธ Pattern Repeats?}
    F -- โœ… Yes --> E
    F -- โŒ No --> B
Loading

Usage

Run the script with optional arguments for width, height, and seed:

./gol.sh [-w width] [-h height] [-s seed]

Arguments

  • -w: Width of the grid (default: 32)
  • -h: Height of the grid (default: 16)
  • -s: Seed for the random number generator (default: a random seed)

Examples

Run with default settings:

./gol.sh

Run with a custom width, height, and seed:

./gol.sh -w 20 -h 10 -s 12345

The simulation stops automatically if all cells are dead or if the pattern repeats.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.