game-of-life-modern-java

用现代工具和语言构造以 Java 实现的《人生游戏》。「Game Of Life implemented in Java with modern tools and language constructs」

  • Owner: giorgiosironi/game-of-life-java-2016
  • Platform: BSD, Cross-platform, Linux, Mac, Solaris, Unix-like, Windows
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

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.

Main metrics

Overview
Name With Ownergiorgiosironi/game-of-life-java-2016
Primary LanguageJava
Program languageJava (Language Count: 3)
PlatformBSD, Cross-platform, Linux, Mac, Solaris, Unix-like, Windows
License:MIT License
所有者活动
Created At2015-12-20 10:13:44
Pushed At2016-01-26 13:22:57
Last Commit At2016-01-25 14:35:12
Release Count0
用户参与
Stargazers Count57
Watchers Count10
Fork Count23
Commits Count109
Has Issues Enabled
Issues Count0
Issue Open Count0
Pull Requests Count1
Pull Requests Open Count0
Pull Requests Close Count1
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private