11-Assignment-1-Life

# 11-Assignment-1-Life - CS106X Winter 2008 Handout 11...

This preview shows pages 1–3. Sign up to view the full content.

CS106X Handout 11 Winter 2008 January 16, 2008 Assignment 1: The Game Of Life A brilliant assignment from Julie Zelenski. Let the fun begin! Your first real assignment centers on the use of a two-dimensional grid as a data structure in a cellular simulation. It will give you practice with control structures, functions, templates, and even a bit of string and file processing. More importantly, the program will exercise your ability to decompose a large problem into manageable bits. What’s especially nice about this program is that you can construct a beautiful and elegant solution if you take the time to think through a good design. It can be as lovely to look at the code as it is to watch it run. Due: Wednesday, January 23 rd at 1:15 p.m. The Problem Your mission is to implement a hyped-up version of the game of Life, originally conceived by the British mathematician J.H. Conway in 1970 and popularized by Martin Gardner in his Scientific American column. The game is a simulation that models the life cycle of bacteria. Given an initial pattern, the game simulates the birth and death of future generations using simple rules. Think of it as a Lava Lamp for mathematicians. (Yeah, mathematicians need to get out a little more often – but that's not important right now. ..) The game is played on a two-dimensional grid. Each grid location is either empty or occupied by a single cell (X). A location's neighbors are any cells in the surrounding eight adjacent locations. In the following example, the shaded middle location has three "live" neighbors: X X X

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 The Rules The simulation starts with an initial pattern of cells on the grid and computes successive generations of cells according to the following rules: 1. A location that has one or fewer neighbors will be empty in the next generation. If a cell was in that location, it dies of loneliness. How sad! 2. A location with two neighbors remains "stable"—i.e. if it contained a cell, it still contains a cell. If it was empty, it's still empty. 3. A location with three neighbors will contain a cell in the next generation. If it were unoccupied before, a new cell is born. If it currently contains a cell, the cell remains. Good times. 4. A location with four or more neighbors will be empty in the next generation. If there was a cell in that location, it dies of overcrowding. Bad times. 5. The births and deaths that transform one generation to the next must all take effect simultaneously . Thus, when computing a new generation, new births and deaths in that generation cannot affect other births and deaths in that generation. If this condition is violated, the order that you happen to go through the grid computing the next generation will affect the answer you get. To keep the two generations separate, you will need to work on two versions
This is the end of the preview. Sign up to access the rest of the document.

### Page1 / 8

11-Assignment-1-Life - CS106X Winter 2008 Handout 11...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online