|
|
HTW Berlin
Fachbereich 4
Internationaler Studiengang
Internationale Medieninformatik (Bachelor)
Info 1: Informatik I
Winter Term 2022/23
|
Laboratory 8 : The
Game of Life
|
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:
- A description of what you did during the lab, including a
record of what worked, what problems you encountered, and
answers to the questions asked in the pre-lab. The focus is on
the process!
- Include the final version of the source code.
- The names and roles of any collaborators in any parts of
the exercise.
- A record of how long you needed for this lab and what you
learned.
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
- In Conway's Game of Life, a cell has
only two states, alive or dead. Its next state is determined as
follows:
- A count is taken of the number of its neighbors that are
alive.
- if the cell is dead and has exactly three live neighbors,
then its next state will be alive, otherwise its next state
will be dead.
- If the cell is alive , then its next state also depends on
the number of live neighbors. If there are fewer than two or
more than three, then the next state will be dead, otherwise
alive.
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.
- 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?
- Look up the initial patterns on the
Wikipedia that oscillate and move. Try them out on your game-of-life.
Do they work?
- 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?
- (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?
- (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?
- (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