The Game of Life probably isn't what you think, it's a program that simulates how cells might grow or die based on a small set of rules. It was created by a British mathematician named John Conway and is sometimes called "Conway's Game of Life." This description and the image above are from Wikipedia:
Every cell interacts with its eight neighbours, which are the cells that are horizontally, vertically, or diagonally adjacent. At each step in time, the following transitions occur:
- Any live cell with fewer than two live neighbours dies, as if by underpopulation.
- Any live cell with two or three live neighbours lives on to the next generation.
- Any live cell with more than three live neighbours dies, as if by overpopulation.
- Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
These rules, which compare the behavior of the automaton to real life, can be condensed into the following:
- Any live cell with two or three live neighbours survives.
- Any dead cell with three live neighbours becomes a live cell.
- All other live cells die in the next generation. Similarly, all other dead cells stay dead.
You can find examples and descriptions of the Game of Life at the following websites:
Play the Game of Life online
What is the Game of Life?
Conway's Game of Life on Wikipedia
The Game of Life is well suited to using a two dimensional array of buttons. We'll be using a GUI library called Guido to create the buttons. To install it, start Processing and choose Sketch | Import Library | Add Library. Type Guido in the search box, the click on Guido by Florian Jenett and then click Install.
- Your Game of Life will be a two dimensional array of buttons
- If the user clicks on a button it should turn that cell on and off
- Make sure all class member variables and methods are labeled appropriately as either
publicorprivate - The finished program should correctly implement the rules of the Game of Life
- Fork and clone down this repository. As you work through the following steps, make sure that your program runs correctly before going to the next step.
- On line 2, delete the comment and create two integer constants
NUM_ROWSandNUM_COLSand initialize them each with the value 20 - Go to line 13, use the constants to initialize the 2d array
buttonsto have 20 rows and 20 columns - Use nested loops to create a
new Lifefor each row column pair - Use the constants initialize
bufferto be a new 2d array of typeboolean - Uncomment the first two lines in the Life constructor (around line 62)
- In
drawwrite nested loops to draw each button to the screen. You should now see a grid of buttons. If you click on the button it should turn off and on.
More to come
none yet!
