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:
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!
The program should be written in a single, static class. Do not define multiple classes or create objects from your own non-static classes.
You will need to use (and should use) classes defined by Java itself, particularly for reading and writing files. The Java API documentation will be useful for using these classes.
The program should take two command-line arguments:
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 -+-- --+- +--- ----
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.init .
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.
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 project-1 Life.javaA 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.