Skip to content

giorgiosironi/game-of-life-modern-java

Repository files navigation

Pure Java Game Of Life

This is an implementation of Conway's Game Of Life, a zero-player game featuring an infinite plane of square cells which evolve their state as alive or dead according to a finite set of rules:

  • Any live cell with fewer than two live neighbours dies, as if caused by under-population.
  • Any live cell with two or three live neighbours lives on to the next generation.
  • Any live cell with more than three live neighbours dies, as if by over-population.
  • Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.

Sample screen from this application

(Game Of Life on Wikipedia)

The Game Of Life is a common kata to exercise in a code retreat, or to get your feet wet with a different technology. Keep the problem the same and change the conditions around it to cover new ground.

Technologies used

This project tries to take a modern approach to Java software development, producing a self-contained application which embeds everything needed to run on any JVM in a development, CI or production environment.

  • Java 8 with lambdas support
  • Gradle for build automation and dependency resolution (substitutes both Ant and Maven)
  • Jetty as an embedded server to respond to HTTP requests
  • Jersey for building the RESTful web service calculating new generations of a plane, using JAX-RS
  • Freemarker templating engine to build HTML
  • Log4j 2 for logging, encapsulated behind the interface slf4j.

On the testing side of things:

How to run

Clone the project, then run:

./gradlew

The Gradle Wrapper will install itself.

Run

./gradlew test

to run unit, property-based and Selenium tests.

Standalone

Then run

./gradlew installDist
cd build/install/game-of-life
bin/game-of-life

to install an instance in the build/ subfolder. Load [http://localhost:8080/planes/a-block-and-bar] in your browser to see the evolution of a test plane. The patterns featured in the sample are a stable block and a rotating bar, along with a lone cell vanishing after the first generation.

The plane shown is a configurable window of 10x10 cells having the plane origin as the top corner, but the underlying engine is capable of extending the plane dimensions automatically to use all available memory.

Inside a server

./gradlew war

will generate a WAR file at build/libs/game-of-life-*.war. This WAR file can be deployed inside a servlet container.

To check how the WAR file is working, run:

./gradlew jettyRunWar -i

which will spin up a temporary Jetty 6.x (very old) container and deploy the WAR inside it.

About

Game Of Life implemented in Java with modern tools and language constructs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published