1212
GitHub - AdrielHercules/java-game-of-life: Conway’s Game of Life implemented in Java. · GitHub
Skip to content

AdrielHercules/java-game-of-life

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Java Conway's Game of Life

Conway’s Game of Life implemented in Java with two simulation strategies and two renderers (console and Jaylib/Raylib). Made to explore design choices and performance trade-offs when simulating cellular automata in Java.

About

The Game of Life is a zero-player cellular automaton. The universe is an infinite 2D orthogonal grid of square cells; each cell is either alive or dead. On each tick (generation) every cell transitions according to its 8 neighbors:

  1. A live cell with fewer than two live neighbours dies (underpopulation).
  2. A live cell with two or three live neighbours lives on.
  3. A live cell with more than three live neighbours dies (overpopulation).
  4. A dead cell with exactly three live neighbours becomes alive (reproduction).

More: https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life

Running the project

  1. Download the executable from the latest release.
  2. Run it using one of the following options:

Default (OOP implementation)

java -jar game-of-life-1.0-release.jar

Data-driven / fast implementation

java -jar game-of-life-1.0-release.jar fast

Console renderer

java -jar game-of-life-1.0-release.jar console

Custom simulation size (default: 1024)

java -jar game-of-life-1.0-release.jar console 32

Combine flags

java -jar game-of-life-1.0-release.jar fast console
java -jar game-of-life-1.0-release.jar console 1024

Building from Source

Prerequisites

  • Java Development Kit (JDK) 21 or higher
  • Maven
  • (Optional) VS Code + Java Extension Pack

Steps

git clone https://github.com/AdrielHercules/java-game-of-life.git
cd java-game-of-life
mvn clean install
mvn clean package

# Run after build
java -jar target/game-of-life-1.0-release.jar

Benchmarks

This project includes microbenchmarks written with JMH to compare the performance of the two implementations.

Running benchmarks

mvn clean verify
java -cp .\target\game-of-life-1.0-release.jar org.openjdk.jmh.Main

Architecture

Simulation

The project provides two different approaches to simulating the game, allowing comparison of design and performance trade-offs:

  • gameoflife.simulation.oop — Object-oriented approach. Cells and board modeled as objects; prioritizes clarity and extensibility.
  • gameoflife.simulation.fast — Data-driven / performance focused approach. Uses primitive arrays and cache-friendly algorithms to maximize speed and reduce GC overhead.

Rendering

The project provides two ways of rendering the simulation:

  • ConsoleViewer — ASCII-based rendering in the terminal
  • RaylibVisualizer (Raylib via Jaylib) - 2D renderer using Jaylib (A Java Raylib binding).

Contributing

Feel free to submit issues, pull requests and new features.

About

Conway’s Game of Life implemented in Java.

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages