RU beehive logo ITEC dept promo banner
ITEC 120
2007fall
ibarland,
jdymacek

homeinfoexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs

lect14c
Conway's Life
2-D arrays

Conway's Game of Life: See rules and an applet. (Try setting speed to 2fps; I started with the pre-configuration "A plus", zoomed in near the lower-left corner.)

Here is some code to start this. Note how we break down the process "process the entire board" into two smaller steps, each just like we've already seen: "process a single row", and "process each row".

It is possible to do both of these at once; see the book for examples of nested loops. Myself, I often like being able to test single-row processing, so I often prefer having two separate loops (one of which calls the other), rather than directly nesting them.

Helpful BlueJ tip: In the console window, select Options > Unlimited Buffering and Options > Clear Screen at Method Call. (Otherwise it's easy to confuse the output with previous runs.)

A starting point: Life.java
A version which is close to working, after talking through the problem in class: Life.java
A version which is does something, but not quite correctly?! Life.java We have reached a version with a fundamental problem: our test cases show that (say) three-cells-in-a-row all die, when in truth they should evolve to three-cells-in-a-column. What's happening? We are updating cells mid-stream, so that later cells are counting some-current-neighbors, and some-neighbors-in-next-generation. The solution is to have two boards: the field holds the current status, and we create a second, new board which gets filled with the next-generation-so-far; at the end of the process we can assign that new board to the field.

homeinfoexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs


©2007, Ian Barland, Radford University
Last modified 2007.Nov.29 (Thu)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme