Assignment1 - Part B Instructions
Assignment1 - Part B Instructions
Semester 1, 2020
Motivation
One of the most common tasks in “Building IT Systems” is modifying some existing code.
In practice, computer programs are written only once but are subsequently modified and ex-
tended many times during their operational lifetime. Code changes may be required in re-
sponse to internal factors, such as the need to correct design flaws or coding errors, or exter-
nal factors, such as changes in consumer requirements.
A common situation is where some new feature must be added to an existing program. This
is the scenario simulated in this part of the assignment. This task requires you to modify your
solution to Part A of the assignment by adding a new capability. It tests:
• Your ability to work under time pressure; and
• The quality and clarity of your code for Part A, because a well-written solution to
Part A will make completing this part of the assignment easy.
Goal
In Part A of this assignment you were required to develop a program which could follow a
randomly-generated list of coded moves to simulate a game called “Not Connect Four”, but
we did not specify how the winner of the game is chosen. In the real game “Connect Four”
the winner is the first player to get four tokens in a row, either vertically, horizontally or
diagonally. However, this rule is considered too hard to implement for the assignment1, so
our “Not Connect Four” game uses a simpler rule. The winner of “Not Connect Four” is the
first player to get four of their tokens topmost on four separate columns.
In this part of the assignment you will modify your solution to Part A to identify the winner
of the game. Specifically:
• You must stop drawing tokens as soon as a player has won the game (or the list of
moves is exhausted if there is no winner); and
• You must indicate visually which player has won (or whether the game was a tie in
which case all players are considered equal winners).
1
To see why, consider how much information about the state of the game is needed to recognise that a game of
Connect Four has been won …
IFB104 Building IT Systems
Semester 1, 2020
To complete this additional task you must modify your play_game function from Part A.
No additional Python template file is supplied for this part of the assignment. Also, as per
Part A, your Part B solution must work for any randomly-generated list of moves that can be
returned by the provided function random_game.
Illustrative example
To illustrate the requirement we continue our example from the Part A instructions. Recall
that we developed a solution which drew four kinds of tokens celebrating the first moon land-
ing. To meet the extended requirements of Part B we therefore developed additional code to
recognise when a player has four tokens on the top of four different columns. As soon as this
happens we stop drawing tokens, even if there are still some moves left in the list given to
function play_game. For instance, consider the following short data set, generated by call-
ing function random_game.
In this case 14 moves have been generated. The first is to drop a token of type 4 into column
‘f’. The second is token type 2 in column ‘d’, and so on. Importantly, however, tokens of
type 3 are dropped into columns ‘c’, ‘f’, ‘g’ and ‘b’ early in the game. Although not im-
mediately obvious from looking at the data set above, this results in tokens of type 3 occupy-
ing the topmost position of those four columns. This occurs after the ninth move. At this
point the player using token type 3 has won the game because this is the first time the same
type of token has been at the top of four columns. Our random_game function therefore
stops drawing tokens at this point, because the game already has a winner, even though there
are another five moves in the list above.
As well as stopping the game, the random_game function must also indicate visually who
won. In our solution we have placed a gold star on the description of token 3, in this case the
Apollo 11 Command Module. The resulting game drawn is as shown overleaf.
IFB104 Building IT Systems
Semester 1, 2020
In the game above a player won after making only four moves, but this is not always the case.
It’s possible for a player to drop many tokens into the board without ever having four on top
of different columns. As a longer game, consider the following sequence of moves.
In this case 20 moves were generated. The resulting game is shown overleaf. It is eventually
won after the 17th move when token 4, the Lunar Module, becomes the first token to appear
at the top of four different columns. However, it took five moves by token 4 to achieve this
winning position. By contrast, token 3, the Command Module, was played six times, but still
didn’t win because there was never a state in which this token was topmost in four columns.
IFB104 Building IT Systems
Semester 1, 2020
Most games generated by function random_game involve a large number of moves and
typically end with a player in a winning position. As another example, the following game
has 38 moves but it isn’t until the 23rd move that token 2 appears at the top of four columns.
IFB104 Building IT Systems
Semester 1, 2020
Nonetheless, it’s possible that no token ever appears at the top of four columns at the same
time. In this case the game will be played until the list of moves is exhausted. In such a
situation we consider the game a tie and declare all four players equal winners.
This can happen, for instance, when only a small number of moves are generated by function
random_game. Consider the following short sequence.
In this case no token ever appears at the top of four columns before the list of moves ends.
Token 1 is played four times, but never manages to appear on top of four different columns.
Our play_game function therefore declares the game a tie. In this situation we award a sil-
ver star to all four players as shown below. (Player 4 was lucky enough to get an “equal-
winner” silver star without even making a move!)
IFB104 Building IT Systems
Semester 1, 2020
It’s rare, but nonetheless possible, for the entire game board to fill with tokens without any
player winning. The following sequence of 41 moves ends without any player achieving a
winning situation, so the game is declared a tie after all 41 moves have been made as shown
below.
Resources provided
The Python template file accompanying the Part A instructions included a number of “fixed”
data sets to help you debug your code during development. Although they can also be used
for Part A, some of these data sets are specifically designed to help with Part B.
§ Data sets fixed_game_b0_0, fixed_game_b0_1 and fixed_game_b0_2 all
end in a tie.
§ Data sets fixed_game_b1_0, fixed_game_b1_1 and fixed_game_b1_2 all
reach states in which token 1 wins.
§ Data sets fixed_game_b2_0, fixed_game_b2_1 and fixed_game_b2_2 all
reach states in which token 2 wins.
IFB104 Building IT Systems
Semester 1, 2020
Development hints
• It should be possible to complete this task merely by adding code to your existing so-
lution, with little or no change to the code you have already completed.
• If you are unable to complete the whole task, just submit whatever part you can get
working. You will receive partial marks for incomplete solutions. Try to ensure that
your program runs when submitted, even if it is incomplete.
Portability
An important aspect of software development is to ensure that your solution will work cor-
rectly on all computing platforms (or at least as many as possible). For this reason you must
complete the assignment using standard Turtle graphics, random number and maths
functions only. You may not import any additional modules or files into your program other
than those already imported by the given template file. In particular, you may not import any
image files to help create your drawings or use non-standard image processing modules such
as Pillow.
IFB104 Building IT Systems
Semester 1, 2020
Deliverable
You must develop your solution by completing and submitting the provided Python 3 file
not_connect_4.py as follows.
1. Complete the “statement” at the beginning of the Python file to confirm that this is
your own individual work by inserting your name and student number in the places
indicated. We will assume that submissions without a completed statement are not
your own work!
2. Complete your solution by developing Python code to replace the dummy
play_game function. You must complete your solution using only the standard Py-
thon 3 modules already imported by the provided template. In particular, you must
not use any Python modules that must be downloaded and installed separately because
the markers will not have access to these modules. Furthermore, you may not import
any image files into your solution; the entire image must be drawn using Turtle graph-
ics drawing primitives only, as we did in our sample solution.
3. Submit a single Python file containing your solution for marking. Do not submit
multiple files. Only a single file will be accepted, so you cannot accompany your so-
lution with other files or pre-defined images. Do not submit any other files! Sub-
mit only a single Python 3 file!
Apart from working correctly your program code must be well-presented and easy to under-
stand, thanks to (sparse) commenting that explains the purpose of significant code segments
and helpful choices of variable and function names. Professional presentation of your code
will be taken into account when marking this assignment.
If you are unable to solve the whole problem, submit whatever parts you can get working.
You will receive partial marks for incomplete solutions.
IFB104 Building IT Systems
Semester 1, 2020