Preparation for project on "Game of Life".
The "Game of Life" was invented by John H. Conway to simulate the
birth and death of cells in a society. It really isn't a "game", but a
simulation of population growth that is displayed over time.
Game Rules:
-
The game is played on the rectangular board. Each square at time T could
contain 1 that indicates the presence of the organism (life) or 0 that
indicates the absence of the organism (death).
- The following rules govern the birth and/or death of these organisms
between two consecutive time periods. At time T, for each square:
-
Birth: An organism is born if there was none at time T-1 and
exactly three of its neighbors were alive.
- Survival: An existing organism remains alive if at time T-1 there
were either two or three neighbors.
- Death: An organism dies from isolation if at time T-1 there were
fewer than two neighbors.
- Death: An organism dies from overcrowding if at time T-1 there
were more than three neighbors.
- At time T the situation on the board is called configuration.
- The Game is over when there is no change in configuration between two
consecutive time periods
-
In this lab you will write and test the following functions
- def build_board_random(row, col) - this function fills the
board with random numbers 0 and 1. A live organism is represented by 1 and
a dead organism is represented by 0. The sizes of the board will be user
input and determine in main
- def build_board_user(row, col) this function fills the
board with user input: 0 and 1. A live organism is represented by 1 and
a dead organism is represented by 0.
- def printBoard(board, row, col) - prints the board (prints 2-d list in
matrix form) - we wrote this function already
- def copyBoard(board, row, col) - creates and returns the copy of the
board
- def change(oldBoard, newBoard, row, col) - returns 1 if both 2-d
lists,
oldBoard and newBoard, are the same, and 0 otherwise
- def count(board, row, col) - counts and returns the number of live
organisms
- def neigh(board, row, col, i, j) - finds and returns the
number of live
organisms around
the cell position i, j
- def all_neigh(board, row, col) - this function creates a 2-d list, with each
element
equals to the number of live organisms of 2-d list scores. The function returns a new list.