WeChat:lovexc60
IFB104!Building!IT!Systems
Each token is exactly 100 pixels wide and high, so they all fit perfectly into one of the game
Semester!1,!2020
Assignment 1, Part A: “Not Connect Four”
(20%, due 11:59pm Sunday, April 12th, end of Week 7)
Overview
This is the first part of a two-part assignment. This part is worth 20% of your final grade for
IFB104. Part B will be worth a further 5%. Part B is intended as a last-minute extension to
the assignment, thereby testing the maintainability of your code, and the instructions for
completing it will not be released until Week 7. Whether or not you complete Part B you will
submit only one file, and receive only one assessment, for the whole 25% assignment.
Motivation
One of the basic functions of any IT system is to process a given data set to produce some
form of human-readable output. This assignment requires you to produce a visual image by
following instructions stored in a list. It tests your abilities to:
• Process lists of data values;
• Produce maintainable, reusable code;
• Design a general solution to a non-trivial computational problem; and
• Display information in an attractive visual form.
In particular, you will need to think carefully about how to design reusable code segments,
via well-planned function definitions and the use of repetition, to make the resulting program
as concise as possible and easy to understand and maintain.
Goal
Connect Four (also known as Connect-4 and by many other names) is a popular children’s
game in which players take turns dropping coloured tokens into a vertical game board. The
first player to complete a vertical, horizontal or diagonal row of four tokens is the winner.
IFB104!Building!IT!Systems
Semester!1,!2020
In this assignment you will visually simulate a similar game, but with a number of differences. Our “Not Connect Four” game has:
four players instead of two;
random choices of which player gets to drop the next token;
illustrated square tokens instead of plain round ones; and
a different way of choosing the winner, which will be revealed only in Part B of the
assignment.
To draw the game you must follow a set of instructions, provided as a list of moves, to place
the tokens in various cells of the playing board. The tokens must be stacked in columns as in
the real game. Most importantly, the sequence of moves to be followed is generated randomly, so your solution must be sufficiently general that it can work correctly for any possible sequence of moves.
Resources provided
A template Python 3 program, not_connect_4.py, is provided with these instructions.
When run it creates a drawing canvas and displays a simple image of the playing board on
which you will draw specific types of tokens in specific columns. You have a free choice in
the design of the four token types, but they must all be related by a common theme. The default image drawn by running the provided Python template appears as shown below. It consists of a numbered grid representing the playing board, with spaces on either side for descriptions of the tokens you have designed.
For convenience, the “home” coordinate (0, 0) is marked by a dot. The board is a 7 × 6 grid
of square cells. Each of the board’s cells measures 100 × 100 pixels. The spaces to the left
and right are where the descriptions of each of your token types will be drawn.
This is coordinate (0, 0)
IFB104!Building!IT!Systems
Semester!1,!2020
Your task is to extend this template file so that it can draw games of “Not Connect Four” by
following a provided list of moves. To do so you must design four entirely distinct tokens,
each of which can be drawn in any square on the board. Your code will consist of a function
called play_game and any auxiliary functions you define to support it. This function takes
a single argument, which is a list of moves specifying in which column to place each type of
token. The moves are created by a provided function called random_game which randomly
generates the sequence of moves, so your code must work correctly for any possible game
that could be played!
Designing the tokens
To complete this assignment you must design four entirely distinct types of game tokens.
Each token must fit exactly into a 100 × 100 pixel square. Each token must contain a single
image, different from the other tokens, and which fills its whole area. They must be drawn
using Turtle graphics primitives only, must be easily recognisable, must be of a reasonable
degree of complexity involving multiple shapes, and must all be part of some common theme.
(Simply drawing the same image in different colours or with some other trivial difference is
not considered acceptable.)
You have a free choice of theme and are encouraged to be imaginative! Some possible
themes you may consider are:
• Geographical sites (cities, countries or tourist attractions)
• Vehicles (cars, boats, planes, etc)
• Household objects
• Cartoon or comic characters
• TV or movie characters
• Sporting teams
• Businesses (banks, restaurants, IT companies, etc)
• Computer or board games (e.g., Monopoly tokens)
• Internet or cloud service providers
• Or anything else suitable for creating four distinct, related and easily-identifiable tokens
Data format
The random_game function used to assess your solution returns a list of moves each representing the action of a player dropping one of their tokens into the board. Each of the moves
is expressed as a pair of values with the following general form.
[column, token_type]
The column values are letters ranging from ‘a’ to ‘g’ and the token types are integers ranging
from 1 to 4. For instance,
[‘c’, 2]
IFB104!Building!IT!Systems
Semester!1,!2020
tells us to draw a token of type 2 in column ‘c’. Note, however, that we are not told in which
row to draw the token! As in the real Connect Four game, this depends on how many tokens
have already been dropped into this column, if any. Tokens cannot be drawn on top of one
another. For instance, if there have already been two tokens placed in column ‘c’ then this
new token must be drawn in row 3.
The random_game function generates a list of anywhere between zero and 42 (i.e., 7 × 6)
moves. When choosing which player makes the next move, no attempt is made by the function to be “fair”. The next player is chosen at random; we assume some other mechanism,
such as rolling a die, is used to choose who moves next. However, the game generated will
always be a valid one within the rules of “Not Connect Four”. In particular, the moves generated will never overfill a column.
In addition to the random_game function, the template file also contains a number of
“fixed” data sets. These are provided to help you develop your code, so that you can work
with a known sequence of moves, rather than a random one, while debugging your code.
However, these “fixed” patterns will not be used for assessing your solution. Your
play_game function must work correctly for any sequence of moves randomly generated
by function random_game.
Illustrative example
To illustrate the requirements we developed a solution whose four tokens follow the theme
“Apollo 11”, in recognition of last year’s 50th anniversary of the first moon landing. (Don’t
copy our example! Come up with your own idea!) We wrote Turtle graphics code that can
draw the following four tokens, each representing an aspect of the historic mission.
board’s cells. All of these images were drawn using basic Turtle graphics drawing steps; no
separate image files are used to display the tokens. Your images do not need to be as complicated as these examples, but they must still be recognisable and non-trivial.
The first requirement for the assignment is to clearly identify your four tokens and their
common theme. To do so you must put an appropriate title on the drawing window and a description of each token in the spaces indicated to the left and right of the game board. Our
sample solution is shown overleaf.
IFB104!Building!IT!Systems
Semester!1,!2020
The next requirement is for your implementation of the random_game function to draw
these tokens in appropriate places on the game board, as per the moves in the list provided as
its parameter. To do so you need to take into account the column and token type specified in
each move, as well as the number of tokens already placed in that column.
For instance, consider the following list of 13 moves returned by function random_game.
The first move requires us to drop a token of type 4 into column ‘d’, so our random_game
function draws the Lunar Module token in row 1 of this column. The next move is a token of
type 2 in column ‘e’, so we draw the Apollo 11 mission patch in row 1 of that column.
However, the third move requires us to put another token of the same type in the same column. Since there is already a token in column ‘e’ we draw the next Lunar Module in row 2.
The fourth move is token type 3 in column ‘f’. There are no other tokens in this column so
IFB104!Building!IT!Systems
Semester!1,!2020
we draw the Command Module in row 1. The fifth move is another token 2 in column ‘a’,
and again this is the first token to appear in that column. The sixth move is token 2 in column ‘f’ and because this is the second token to appear in that column we draw the mission
patch in row 2. This process continues for all the moves in the list, taking care to stack tokens placed in the same column on top of one another. The resulting image, showing all the
tokens drawn in this case, is as follows.
Each time we call function random_game it produces a different list of drawing instructions. As another example, consider the following longer list returned by the function.
In this case we begin with token 3 in column ‘f’, followed by tokens of type 1 and 4, both in
column ‘e’, and so on. The resulting image once all 29 moves have been drawn appears below. Notice in the data set above that the only token ever placed in column ‘b’ is of type 4,
which is why we see only Lunar Module tokens in that column.
IFB104!Building!IT!Systems
Semester!1,!2020