Unusual day
today. You only need to create
a directory called lab37
under labs. You are
going to want to copy your source from lab36
into this
directory.
$ cd ~/cs120/labs/lab37 $ cp ../lab36/game_of_life.py . $ ls game_of_life.py
Last week, you wrote code that can read the initial state of a game of life board into a program. Today, you are going to extend that to actually follow the rules of the game of life!
In Conway's game of life, a two dimensional grid represents a petridish. Each cell in the grid is either occupied by a bacteria, 1, or not, 0. In each turn of the game every cell in the grid changes state based on the following rules:
Modify your game_of_life.py
file from the last lab to play
Conway's Game of Life. The program should load a board, a
two-dimensional list of 0s and 1s, from a file and repeatedly print
the result of updating the board according to the above rules. The
program should end when the user kills the program by pressing
ctrl-c.
00000000000 00000000000 00000000000 00000000000 00000100000 00001110000 00000100000 00000000000 00000000000 00000000000 00000000000 00000000000 00000000000 00000000000 00000000000 00001110000 00001010000 00001110000 00000000000 00000000000 00000000000 00000000000 00000000000 00000000000 00000000000 00000100000 00001010000 00010001000 00001010000 00000100000 00000000000 00000000000 00000000000
As you have no doubt seen, watching the game of life through the terminal window is incredibly difficult. The 1's and 0's flying past the screen do very little to aid in your visual of what is going on. Let's layer a Graphical Interface on top of your 2-d list representation, which hopefully will make it easier to visualize.
In the same file as above, create a new function
called draw_game
. This function should take the game
board as a parameter, plus any additional information necessary to
perform the drawing. You should be able to simply
call draw_game
in the same place you have been
calling print_game
, with minimal changes else where.
Your visual should consist of a 2-d grid, where each cell in the grid represents one of the values from the 2-d list of values representing the game board. Cells that are valued 0 will not be filled in, while cells that are valued 1 will be filled in with a color of your choosing (traditionally black).
Your grid should fill as much of the window as possible. As such, you should decide the size of the cells based off the dimensions of the window, as opposed to specifying a default grid size.
When you have finished, create a tar file of your lab37
directory. To create a tar file, execute the following commands:
cd ~/cs120/labs tar czvf lab37.tgz lab37/
To submit your activity, go to cseval.roanoke.edu. You should
see an available assignment called Lab Assignment 37
. Only
one of your pair should submit your activity. Make sure both partners
are listed in the header of your files.
Do not forget to email your partner today's files!