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.
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.
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.
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.
src/
directory contains the source codesrc/main.cpp
is the entry point of the programsrc/game.hpp
contains the declarations of the methodssrc/game_of_life.cpp
contains the implementation
stable/
directory contains the stable outputstable/game.life
is the executable
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.