CS 12 -- Lab 2


The Game of Life

The Game of Life is not really a game (you don't play it), but is rather an instance of a cellular automaton. That is, there are a group of cells whose behavior is determined by a set of simple rules. While the behavior of the cell isn't particularly interesting, the behavior of the group and how they interact can be.

Specifically, the Game of Life involves cells on a two-dimensional grid that are either alive or dead. There are rules for when cells are born, when the continue to live, and when they die. This section will describe the details of the Game. Below you will find your specific assignment for implementing this game.

Details of the game:


Your assignment

In short, you must write a program that plays the Game of Life. There are some specifications to how you should write this program. Be sure to following them carefully!

Initial state files: This kind of file has a specific format. An initial state file contains integer pairs, one per line of text, separated by a space character. The first line of the file indicates the dimensions of the grid. All subsequent lines of the file contain the coordinates, given in (row, column) pairs of initially live cells.

For example, this initial state file...

4 4
0 1
1 2
2 0
    

...describes a 4-by-4 grid where cells at (0,1), (1,2), and (2,0) are alive in the 0th generation.

Output format: The output of this program must follow exactly the format given here. The program should produce the following output for each generation computed, including the 0th:

Generation = 0, Population = 3
-+--
--+-
+---
----

Generation = 1, Population = 0
----
----
----
----
    

The example corresponds to the 0th generation described by the example initial state file above. The data for each generation should begin with the output of the generation and population numbers, exactly as shown, followed by a textual representation of the grid, where a minus sign (-) denotes a dead cell and a plus sign (+) denotes a live cell.

Sample initial state files: I've provided initial files for you to use during the development of your program. Along with each initial state file is a results file, which contains the output that your program should generate on these samples. To obtain these files, you can copy them from my public CS 12 directory on romulus, like so:

cp ~sfkaplan/public/cs12/simple.init .
cp ~sfkaplan/public/cs12/simple.results .
cp ~sfkaplan/public/cs12/X-pattern.init .
cp ~sfkaplan/public/cs12/X-pattern.results .

The simple case is a small grid where the pattern will repeat every two generations. The X-pattern case is a medium-sized grid that resolves to a static state after a number of (somewhat interesting) steps.


Submitting your work

Use the cs12-submit program to submit only your source code, which should have been written as a single file. Submit your work as project-1, like so:

cs12-submit lab-2 Life.java
A WARNING: If you try, you can find Java code to play the Game of Life. DO NOT try to find such code. Don't look at such code. Most certainly do not copy such code. Not only would you be cheating yourself and failing to learn this material, but you are putting yourself at risk. I, too, can find this code. If I find that you've plagiarized your work, the consequences will be severe. Steer clear of this problem, and we'll all be happy.
This assigment is due on Tuesday, February 24th at 11:59 pm!

Scott F. Kaplan
Last modified: Wed Feb 11 09:21:50 EST 2004