Lab 2280 - Life

Description

This is not really a game. It is an implementation of a cellular automata that John H. Conway chose to call "The Game of Life." Once the original organisms are placed on a grid, simple rules determine everything that will happen in future generations. Sometimes the outcome is that all organisms die. Other times they end up in a static or oscillating world. Other times, they may form complex organisms that generate new life forms that glide across the screen.

The original article describing the game can be found in the April 1970 issue of Scientific American on page 120. The game is played on a field of cells, each of which has eight neighbors (adjacent cells). A cell is either occupied (by an organism) or not. The rules for deriving a generation from the previous one are

    Death  
      If an occupied cell has 0, 1, 4, 5, 6, 7, or 8 occupied neighbors, 
      the organism dies (0, 1 neighbors: of loneliness; 4 thru 8: of overcrowding). 
    Survival 
      If an occupied cell has two or three neighbors, the organism survives 
      to the next generation. 
    Birth 
      If an unoccupied cell has three occupied neighbors, it becomes occupied.

You will use these rules to create your own life simulation. For more information, see the interesting and informative discussion of Conway's Game of Life on the math.com site.

Format of the Data Files

You are provided with data files that describe the initial population of the life grid. This is the format of the data files, using blinker.lif as an example:

7
11  11
12  11
11  12
12  12
13  12
11  13
12  13

This data file represents 7 cells initially alive at positions row=11, col=11; row=12, col=12; row=11, col=12; and so forth. It creates an initial world that looks like this:
blinker
This particular initial pattern creates four blinkers after the rules of life have been applied for a few generations.

There are much larger, more interesting patterns on the Internet. Some require a world that has several hundred elements in each direction. For this assignment, your world is constrained to a 60 x 60 grid. If you have computing power for larger grids, the changes are easy to make.

Assignment

This project follows the Model-View-Controller model. You are provided with the Controller, Life.java and the View, LifeView.java. You are also provided with a skeleton Model component, LifeModel.java. Each cell is an object, defined by the LifeCell class. Of these, you need only modify the model component. For file input. this project uses the excellent EasyReader class, which can be downloaded here or from the Litvins' site.

You must write a method to create a new generation from the current generation. In the skeleton code, this is in the private void oneGeneration() method. Your oneGeneration method must implement the rules of Conway's Game of Life as described above. The method oneGeneration will be called automagically over and over once the Run button has been clicked to advance from generation to generation. It can also be paused or resumed under the user's control.

Your program can be tested with any of the included .lif files. blinker.lif, glgun13.lif , penta.lif, or tumbler.lif.


Copyright © 2010 by Asylum Computer Services LLC Return to CS Labs