Git Product home page Git Product logo

game-of-life's Introduction

Game of Life

This library is my attempt at implementing an advanced Conway's Game of Life in Rust. My goal was to optimize and overengineer it in order to learn Rust along the way.

Game of Life demo

Conway's Game of Life (in my advanced version) plays in a grid containing cells (integers) that are either dead (0) or alive (>0). Then, the next generation is calculated with the prior time step following rule:

  1. A cell is alive if its value is state.
  2. Neighbors are either all eight surrounding cell (Moore) or only the four adjacent cells (VonNeumann).
  3. If a cell was dead, it will be revived if it had a number of living neighbors specified in birth.
  4. If a cell was alive, it will stay alive if it had a number of living neighbors specified in survive. If that's not the case, its value will decrease by one.

Usage

You can compile the program with cargo build --release. The binary then takes the following syntax:
gameoflife -{flags} {gif|tui}

  • gif saves the Game of Life as a GIF with plotters,
  • tui plots the Game of Life in the terminal with termion
  • no command starts a dialogue that will ask about all parameters with sane defaults The flags can be:
  • -a: algorithm (std or conv)
  • -n: neighbor algorithm (m or vn)
  • -i: number of iterations
  • -x: number of columns
  • -y: number of rows
  • -p: probability of a cell being alive in the initial field
  • -s: state
  • -h: list all commands

Algorithms

The standard algorithms iterates over every cell, counts its neighbors, and then decides whether it's alive in the next step via normal if statements. This is fairly quick, especially as I used rayon to do this with multiple threads. The convolution algorithm, however, is about 3 faster. It uses ndarray-ndimage to convolve the field with the kernel [[1, 1, 1], [1, 0, 1], [1, 1, 1]] (Moore) or [[0, 1, 0], [1, 0, 1], [0, 1, 0]] (VonNeumann), which is somehow extremely fast with only one thread (props to Nil!) and then calculates the next field with functional-style maps and addition, multiplication, and comparisons.

Licenses

For all licenses, look into license.html.
This file was automatically created using cargo-about (Embark Studios).

game-of-life's People

Contributors

chhecker avatar

Watchers

 avatar

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.