HTW Berlin Medieninformatik HTW Berlin
Fachbereich 4
Internationaler Studiengang
Internationale Medieninformatik (Bachelor)
Info 1: Informatik I
Winter Term 2022/23

Laboratory 8 : The Game of Life

Pre-lab

This week's lab work is intended give you practice working with using two-dimensional arrays.

What to Bring to Lab

Please bring these exercises printed out or written out with you to lab. Please have your name on your page.

P1. Download the Brain project. Create an Environment object and use the GUI controls to create a random initial setup for the automaton. Then either single-step it or run/pause it to obtain a feel for how it behaves. Summarize your findings in your pre-lab.

P2. Read the Wikipedia article on Conway's Game of Life.

P3. Given a 2D array board and a cell board [i][j]. List all of the cells that are its neighbors.

Post-Lab, AKA  What To Turn In

Your completed assignment, submitted in Moodle as a pdf, should include:

Lab assignments are due before your next lab at 22.00. They may, of course, be turned in earlier. You hand them in by preparing the report in PDF and submitting it to Moodle.


Assignment

Conway's Game of Life

  1. In Conway's Game of Life, a cell has only two states, alive or dead. Its next state is determined as follows:

Save a copy of the Brain project as game-of-life and modify the Cell class so that it implements the rules for the Game of Life. It should not be necessary to modify any other classes.

  1. Modify the Environment class in your version of the Game of Life so that the environment is not toroidal. In other words, the next state of a cell at an outer row or column of the environment is determined by assuming that neighbors outside the bounds of the environment are always dead. Is there any difference between this behavior and the toroidal one?
     
  2. Look up the initial patterns on the Wikipedia that oscillate and move. Try them out on your game-of-life. Do they work?
     
  3. Program the rules for this Corona-virus puzzle: Cells now only have 4 neighbors, not 8. What do you have to change? The status of the cells is either infected or not infected. A cell that is not infected becomes infected if two or more of its neighbors are infected. Can you find a state that eventually fills an entire 8x8 board?  
  4. (For the bored) What is the minimum number of cells that need to be infected in the starting state to fill the entire board? How many steps are needed? Can you generate all of the starting sequences that lead to a filled board?  
  5. (For the bored) Can you add colors to your board? A cell has a color that depends on the number of rounds it has stayed alive (or the number of neighbors it has, be creative). What do you have to change to get this to work?
     
  6. (For the very bored) Use a copy of either the brain project or your game-of-life project to implement a new project in which cells can be either alive or dead. Alive cells should appear to wander semi-randomly through the 2D environment. Associate a movement direction with a cell. A cell that is alive should "move" in its associated direction at each step—in other words, a cell that is alive should cause one of its neighbors to be alive at the next step, and itself will become dead. This should give the appearance of movement. When an alive cell at the edge of the environment would try to move beyond the edge, it should instead set its direction randomly and remain alive at the next step. Test using just a single live cell to start. Then think about what you need to do if one cell tries to move into a location just vacated by another cell, or when two cells try to occupy the same neighboring cell.

Writeup

Submit your writeup as your post-lab to the Moodle area.

 


Copyright Prof. Dr. Debora Weber-Wulff
Questions or comments: <weberwu@htw-berlin.de>
Some rights reserved. CC-BY-NC-SA - Copyright and Warranty

The exercises are adapted from Objects First with Java, A Practical Introduction Using BlueJ. David Barnes & Michael Kölling, 2016