GithubHelp home page GithubHelp logo

ertyumpx / game-of-life Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 36 KB

Simple simulation of infamous Conway's Game of Life with C++ using SDL2

License: GNU General Public License v3.0

Makefile 10.17% C++ 89.83%
conway-s-game-of-life conways-game-of-life cpp cpp11 game game-of-life makefile sdl2

game-of-life's Introduction

Conway's Game of Life

I believe it was the fastest project I've ever done which took around 1.5 hours.

Infamous Conway's Game of Life implemented in C++ with SDL2.


License

This project is licensed under the GNU GPL-3.0 license.

Feel free to use the source code. Referring to the repository would be very much appreciated.

Setup

Project is currently compiled with GNU G++ 13.2.1.

The only third-party dependency is SDL2. Used version of SDL2 in project is 2.28.5, should work as long as it is SDL2 and not SDL.

For compiling and linking rules GNU Make 4.4.1 was used. After downloading dependencies, make sure to change the include paths inside the Makefile.

# change the paths for '-I' 
CC := g++
CFLAGS := -Wall -std=c++11 -I/usr/include/SDL2           # here
TEST_CFLAGS := -Wall -std=c++11 -Iinclude/SDL2 -Isrc/    # and here
LDFLAGS := -lSDL2 -lSDL2_image
...

After fulfilling dependencies, download or clone the project and use Makefile to easily compile:

> make all
> make run

Since SDL2 is a cross-platform media library, output should work on Windows, MacOS and Linux.

Rules

The simulation goes in a 2D grid where each cell can be either dead or alive. The rules are as follows:

  • Any live cell with fewer than two live neighbors dies, as if by 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, as if by overpopulation.
  • Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.

Directly taken from the Wikipedia page of the Conway's Game of Life.

General Structure

Directory Structure and Files

  • src/ directory contains the source code
    • src/main.cpp is the entry point of the program
    • src/game.hpp contains the declarations of the methods
    • src/game_of_life.cpp contains the implementation
  • stable/ directory contains the stable output
    • stable/game.life is the executable

How It Goes

Current version is not designed specifically to be used anywhere. Without any arguments, it will create a grid according to the WIDTH, HEIGHT and CELL_SIZE constants in main.cpp, randomly fill a grid and start the simulation.

The constant FPS is the frame rate of the simulation. It is set to 15 by default.

game-of-life's People

Contributors

erthium avatar utkub24 avatar

Watchers

 avatar

game-of-life's Issues

Interactive Grid

We can add quite simple mouse events and change the status of the cells by clicking on them.

  • Right click would make the cell alive
  • Left click would make the cell dead

Setting an Image as a Seed

Quite unnecessary concept, but made me say "Why not?"

We could take a random image, convert it to grayscale, size it as our grid and take average of the pixel groups; if the color average is above %50 the cell would be alive.

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.