tisdag 13 augusti 2013

Game of Life

Game of Life

I've just written my first game in Scala, which is a functional/object-oriented programming language built upon Java. John Conway's Game of Life is a game base on simple mathematical rules. The game consists of a collection of cells which can live, die or multiply.

The Rules

A cell that is alive

  • Each cell with one or no neighbors dies by starvation.
  • Each cell with four or more neighbors dies by overpopulation.
  • Each cell with two or three neighbors survives.

A cell that is dead


  • Each cell with three neighbors becomes populated.

My Game of Life

I've made a small change to the game, converting Conway's game into a two player game. Each player starts with 10 points, each point can be turned into a living cell.
The players take turn to place one cell at a time. When they are satisfied or have no more points to spend. Press 'R' and the game runs using the rules described above for ten iterations. The only differences I've made to the rules are that when a player populates a cell that was previously populated by the other player, he scores one point. If both players tries to populate the same cell, the cell remains unpopulated.
After ten iterations, the game pauses, and the scored points can be turned into new living cells.
The players wins who stays alive the longest, or who has the most alive cells when the board remains static and there are no more points to spend. Press 'C' to reset the board.

Applet