Coder Social home page Coder Social logo

game_of_life's Introduction

Game of Life by petya0927

Simple Game of Life simulation in Pyhton 3., based on the work of John Horton Conway. It is a cellular automaton, means each cell on the screen is generated by the state of other cells. We can create a lot of generated structures. More on Conway's Game of Life - Wikipedia

User manual

Dependencies:

Once you installed everything and started the game_of_life.pyw script, you can place squares in the grid where every black cell is alive, every white cell is dead. By hitting the space key, you can start the simulation, where every frame is generated based on the rules below. You can restart the game and the simulation by hitting the r key any time.

Rules:

  1. Any live cell with two or three live neighbours survives.
  2. Any dead cell with three live neighbours becomes a live cell.
  3. All other live cells die in the next generation. Similarly, all other dead cells stay dead.

Basic keybindings:

  • space : switch mode between Editing and Playing. Default is Editing.
  • r : delete every alive cell, and restart the game.
  • m : show more cells on the screen
  • l : show less cells on the screen
  • g : toggle grid display

Versions:

  • v1: Computes the next step by iterating through the cells and check if the cell is alive or dead. With that information, creates a new matrix based on the rules of the game. Problems: iterating through the array for each frame takes a long time; stores the cells in an array (that could be really large); the new step computation is not smart (means for every generation it checks all the alive and dead cells).

  • v2: Faster than v1. Computes the next step by filtering the alive cells and iterates through them. Checks the alive cells and their neighbours. (The logic behind is that every dead cell becomes only if there're enough alive cells around, so we don't need to check cells that are not surrounded by a living cell.) Problems: it still stores the cells in an array and not only the alive cells;

  • v3: It stores only the alive cells and directly render those on the specific coordinates. It uses the same algorythm as the v2 for every alive cell, but the simulation has no borders, because we do not use a specificly shaped array, but create the coordinates of the next living cells from the prevoius ones. Unfortunately, as the simulation goes on, it becames slower. Problems: sometimes it checks a dead cell multiple times.

game_of_life's People

Contributors

petya0927 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

remarci225

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.