You will be implementing the Game of Life, originally conceived by British mathematician J. H. Conway in 1970. Contrary to its name, the Game of Life is not an actual “game” in the traditional sense per se, but rather a zero-player cellular automaton simulation.
The game board is a 2-D grid. The game has an initial state specified, then proceeds by evolving the grid through “generations”. Each cell in the grid can be either “live” or “dead”. Given an initial state of the board, the next generation of the board is determined by the status of each cell’s neighbors which include cells directly horizontally, vertically, and diagonally adjacent. In other words, an internal cell has 8 total neighbors.
The evolution of the board is created by applying the following rules to all cells simultaneously:
- A live cell with fewer than 2 live neighbors dies.
- A live cell with more than 3 live neighbors dies.
- A live cell with 2 or 3 live neighbors lives on to the next generation.
- A dead cell with exactly 3 neighbors becomes a live cell.
There are examples of this simulation on the Internet such as ConwaysLife.com.
For this project, you will be asked to create a graphic user interface (GUI) in Java Swing similar to the image on the right. The text area has a width of 30 characters and height of 15. This will represent a 15 x 15 game board, in which you use 2-character wide spacing. The black square ██ is created using Alt+219 twice.
You will use a multidimensional array to store and manipulate the grid data, i.e.
boolean currentGeneration = new boolean;
You need to implement all the buttons with the following features:
- Next: This button will evolve the grid to the next generation based on the rules.
- Random: This button will randomly bring dead cells back to life based on the specified probability. By default (p = 0.25), dead cells have 25% chance of becoming live. (Note: Good idea to deal with exceptions but they will not be explicitly tested.)
- Pulsar: This button will insert a Pulsar pattern (see picture, right) in middle of the grid and serve as a test case of expected behavior.
- Beehive, Blinker, Beacon and Glider: These buttons will insert their respective patterns (see hyperlink) onto the grid and serve as test cases of expected behavior.
- Clear: This button will clear all the cells.
Bonus: Implement Play/Stop and Back buttons.
- The Play and Stop buttons control a Timer that automatically displays the next generation after 0.25 seconds.
- The back button shows the grid from the previous generation (up to the initial generation). To do this, you need to create a three dimensional array such that the third dimension stores the ‘history’ of generations.
Evaluation: The project is out of 25 marks.
- Graphical UI: 2 marks
- Buttons and Functions
- Next: 10 marks
- Random: 5 marks
- Clear: 2 mark
- Patterns: 5 marks (1 mark each)
- Play/Stop and Back: 2 marks (bonus)
- Display of Generation: 1 mark
This is a major term project worth 25% of the term mark. It is recommended that you complete this project and then return to work on the other Swing assignments.