Uploaded by Estela Luna Chivas

474 ITECH1400 Assignment 2 (1)

advertisement
ITECH 1400 Foundations of Programming
ASSIGNMENT 2. CONWAY'S GAME
35
OF
LIFE
ON
TORUS
MARKS
0. Introduction.
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):
0.1. 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.
Below are two examples of interesting initial patterns:
Fig.1. Glider Gun
Fig 2. Pulsar
0.2. 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.
1. Programming Tasks and Implementation Requirements.
1.1. 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:
board[(i-1+n)%n][(j-1+n)%n],
board[(i-1+n)%n][j],
board[(i-1+n)%n][(j+1)%n],
board[i%n][(j+1)%n],
board[(i+1)%n][(j+1)%n],
board[(i+1)%n][j],
board[(i+1)%n][(j-1+n)%n],
board[i][(j-1+n)%n].
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. See section
0.2.
1.2. Develop GameOfLife class.
The class must have an attribute named board, which should be
defined in the constructor. The board attribute is a twodimensional 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:
neighbourSum(self,i,j) – 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 1.1.
nextPattern(self) – changes the board’s current pattern to the
next one according to the game’s rules. See section 0.1.
printBoard(self) – prints the current pattern, replacing zeros
with white spaces and ones with ‘*’. Similar to the picture
below:
2. 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:
Due Date:
See Course Description
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:
<YOUR-NAME>_<YOUR-STUDENT-ID>.zip,
e.g. John_SMITH_30000000
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.
You might be asked to demonstrate and explain your work.
Submit your assignment (all program source files plus your pdf
document) to the Assignment 1 Upload location on Moodle before
the deadline.
Marking Criteria/Rubric
Student ID:
Student Name:
Tasks
Weight
Marks deducted for badly commented
or badly written code
class GameOfLife

init

neighbourSum

nextPattern

print
main()function

foolproof prompts

Creation of 3 GameOfLife
(-4)
2
8
10
6
2
3
objects

The game’s menu
Total
4
35+(-4)
Awarded
Download