Foundations of Programming



Here is Your Sample Download Sample 📩


In this assignment you are required to develop a Python program to run Conway’s Game of Life on a finite board. Here are the definitions (from Wikipedia):

The Classical Game of Life

The Game of Life was invented by British mathematician John Horton Conway in 1970. The universe of the Classical Game of Life is an infinite twodimensional grid of square cells, each of which is in one of two possible states, alive or dead (1 or 0). Every cell interacts with its eight neighbours, which are the cells that are horizontally, vertically or diagonally adjacent. At each step, the following transitions occur

1. Any live cell with fewer than two live neighbours dies, as if caused by under-population.

2. Any live cell with two or three live neighbours lives on to the next generation.

3. Any live cell with more than three live neighbours dies, as if by overcrowding.

4. Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.

The initial pattern constitutes the seed of the system. The first generation is created by applying the above rules simultaneously to every cell in the seed — births and deaths occur simultaneously. The rules continue to be applied repeatedly to create further generations.

The Game of Life on Torus (GLT)

In the assignment you are required to develop a Python program for the Game of Life restricted to a finite board (n ✕ n). It is same as the classical game of life except that we assume that the left border of the board is glued to the right border, and the top border of the board is glued to the bottom border. So, there are no borders, and the game is played on a torus. See the details in the next section.

Programming Tasks and Implementation Requirements.

The board of GLT

• The board of GLT should be implemented as a two-dimensional (𝒏𝒏 × 𝒏𝒏)list of integers that contains only zeros and ones.

• Elements of the list represent cells of GLT’s universe: Zero elements represent dead cells, elements that are equal to one represent live cells.

• Transition rules (1-4) of the restricted game are the same as those of the classical game.

• Eight neighbours of the cell board[i][j] should be computed by the following rules









Where n is the length of the board’s side. The modulus (%) operator is used in the formulas for neighbours because the game will be played on a torus, not on a plane.

Develop GameOfLife class

The class must have an attribute named board, which should be defined in the constructor. The board attribute is a two dimensional square list as described in the previous section. You may define other attributes in your class, if required. Also, the class should define the following methods:


the method computes and returns the number of live neighbours of the cell board[i][j]. The neighbours of board[i][j] are listed in section


changes the board’s current pattern to the next one according to the game’s rules. See section 


prints the current pattern, replacing zeros with white spaces and ones with ‘*’. Similar to the picture below:

Write main() function

This is a driver program where you test your implementations as follows:

• Create three initial patterns (2D-lists) for the game. You may search the Internet for interesting patterns.

• Games should be played on the bord with dimensions 20×20.

• Print the patterns on the screen and ask the user which one they would like to play with.

• Once the pattern is chosen, the game starts.

• During the game, after printing a new pattern, you should always ask if the user wants the next pattern to be printed or end the game.

• The game ends only when the user decides so

Allocated Marks

See Course Description

Due Date

See Course Description

Please refer to the Course Description for information relating to late assignments and special consideration.

Assignment Submission

You must supply your program source code files and your documentation as a single zip file named as follows

Support documentation should be in PDF format. Assignments will be marked on the basis of fulfilment of the requirements and the quality of the work. In addition to the marking criteria, marks may be deducted for failure to comply with the assignment requirements, including (but not limited to):

• Incomplete implementation(s), and

• Incomplete submissions (e.g. missing files), and

• Poor spelling and grammar