Docsity

Homework Assignment for EECS12: Implementing the Rules of Conway's Game of Life, Assignments of Electrical and Electronics Engineering

Toggle sidebar
bg1
EECS12 Homework #6 Due: 11:59 PM, Friday, March 5, 2005
In this assignment you will write several functions that will be used to play a ā€œgameā€ called Life that
was invented by the mathematician John Horton Conway in 1970.1In reality, Life is not a game
at all, but an entertaining example of cellular automata; that is, a collection of simple rules that
determine how a binary pattern defined on a regular grid evolves with time. There are no winners,
losers, payoffs, or even strategies in this game; but it is very captivating to sit back and watch what
happens.
Rules of the Game
Conceptually, Life is played on an infinite regular grid (checkerboard), each square, called a cel l ,is
either alive or dead. The collection of all ā€œlivingā€ cells is called a colony. The colony of living cells
changes in discrete time steps called generations, each generation being completely determined by
the previous generation. The cells obey four simple rules, which determine the fate of the colony
in the next generation. Each rule is based solely on the number of living neighbors that a cell has
among the eight adjacent cells (including diagonally adjacent cells), and whether the cell is currently
alive or dead. Here are the rules:
1. A living cell with either two or three living neighbors is stable; it lives into the next generation.
2. A living cell that has more than three living neightbors dies of overpopulation in the next
generation.
3. A living cell that has fewer than two living neighbors dies of isolation in the next generation.
4. A dead cell becomes alive (or is bor n) in the next generation if the cell has exactly three living
neighbors.
All four rules are applied simultaneously, and (conceptually) to each cell of the entire infinite grid to
determine the colony of the next generation. See Figure for an example of four successive generations
of a simple colony.
You might wonder where these rules came from. The answer is experimentation. Computer scientists
had been exploring the behavior of rules such as these for a long time, with an eye toward exploiting
massive computational parallelism. Conway discovered that the rules above had a very appealing
balance: cells were born and died off in such a way that the resulting colonies exhibited very complex
and unpredictable behavior. While these rules may not be the most intrinsically valuable in terms
of computation, they are nonetheless the best known, for their entertainment valu e.
uuu
u
u
uu
u
u
u
u
u
u
u
u
u
u
u
u
u
Figure 1: A simple il lustration of the rules of Life. Reading left-to-right, the four configurations
represent four successive generations. You should be able to try this pattern on paper, applying the
rules yourself. Notice that one cell dies and one is born in the in moving from the first to the second
generation. In the fourth generation a stable pattern called a ā€œhiveā€ is reached. There will be no
further births or deaths.
1This is a two-part assignment; in part two you will complete the progtram that plays the game of Life.
1
pf3

Partial preview of the text

Download Homework Assignment for EECS12: Implementing the Rules of Conway's Game of Life and more Assignments Electrical and Electronics Engineering in PDF only on Docsity!

EECS12 Homework #6 Due: 11:59 PM, Friday, March 5, 2005

In this assignment you will write several functions that will be used to play a ā€œgameā€ called Life that was invented by the mathematician John Horton Conway in 1970.^1 In reality, Life is not a game at all, but an entertaining example of cellular automata; that is, a collection of simple rules that determine how a binary pattern defined on a regular grid evolves with time. There are no winners, losers, payoffs, or even strategies in this game; but it is very captivating to sit back and watch what happens.

Rules of the Game

Conceptually, Life is played on an infinite regular grid (checkerboard), each square, called a cell, is either alive or dead. The collection of all ā€œlivingā€ cells is called a colony. The colony of living cells changes in discrete time steps called generations, each generation being completely determined by the previous generation. The cells obey four simple rules, which determine the fate of the colony in the next generation. Each rule is based solely on the number of living neighbors that a cell has among the eight adjacent cells (including diagonally adjacent cells), and whether the cell is currently alive or dead. Here are the rules:

  1. A living cell with either two or three living neighbors is stable; it lives into the next generation.
  2. A living cell that has more than three living neightbors dies of overpopulation in the next generation.
  3. A living cell that has fewer than two living neighbors dies of isolation in the next generation.
  4. A dead cell becomes alive (or is born) in the next generation if the cell has exactly three living neighbors.

All four rules are applied simultaneously, and (conceptually) to each cell of the entire infinite grid to determine the colony of the next generation. See Figure for an example of four successive generations of a simple colony.

You might wonder where these rules came from. The answer is experimentation. Computer scientists had been exploring the behavior of rules such as these for a long time, with an eye toward exploiting massive computational parallelism. Conway discovered that the rules above had a very appealing balance: cells were born and died off in such a way that the resulting colonies exhibited very complex and unpredictable behavior. While these rules may not be the most intrinsically valuable in terms of computation, they are nonetheless the best known, for their entertainment value.

Figure 1: A simple illustration of the rules of Life. Reading left-to-right, the four configurations represent four successive generations. You should be able to try this pattern on paper, applying the rules yourself. Notice that one cell dies and one is born in the in moving from the first to the second generation. In the fourth generation a stable pattern called a ā€œhiveā€ is reached. There will be no further births or deaths.

(^1) This is a two-part assignment; in part two you will complete the progtram that plays the game of Life.

Figure 2: Shown here is the simplest repeating pattern, called a ā€œblinker.ā€ This configuration con- stantly changes, but repeats with a period of two generations (as shown).

Figure 3: Here are three patterns that you should try out once you think your complete program is working in the next assignment. From left to right these are called (or turn into) a ā€œpulsar,ā€ a ā€œglider,ā€ and an ā€œr-pentomino.ā€ The configuration on the left ultimately leads to a pulsar, a pattern that looks like a blinking star as it cycles through three different shapes. The glider is the simplest shape that moves. The r-pentomino grows into a massively complex colony, shooting off several gliders in the process. The configuration in Figure is only one cell away from being an r-pentomino (aside from rotation).

What You Need to Do

This is a two-part assignment; you will only implement three of the necessary components of a working Life program in this assignment, and you will complete the program in the following as- signment. You are to create and submit a Python module named ā€œhw6.pyā€ containing definitions for the following functions (with precisely these spellings, including case):

  1. CellNeighbors( coords )
  2. AdjacencyDictionary( colony )
  3. Births and Deaths( colony )

Be sure to submit only working Python code and comments. If your Python module cannot be loaded as-is, points will be deducted. Also, be sure to text these functions thorougly so that you are confident that they behave as they should. (Test functions will be supplied for you.) Here is what the functions should do:

  1. CellNeighbors should accept a single coordinate of a cell, encoded as a tuple with two integer components: an x-coordinate and a y-coordinate of a cell, such as (10,123), or (-33,5). It is to return a list of the coordinates of the eight neighboring cells. For example, given the coordinate (10,-5), this function should return the list

[( 9 , āˆ’ 6 ), ( 9 , āˆ’ 5 ), ( 9 , āˆ’ 4 ), ( 10 , āˆ’ 6 ), ( 10 , āˆ’ 4 ), ( 11 , āˆ’ 6 ), ( 11 , āˆ’ 5 ), ( 11 , āˆ’ 4 )],

although the ordering is unimportant. Notice that the coordinate passed in to the function is not in the list; just the coordinates of the surrounding cells.