Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Assignment1a-TreasureMap IFB104 Building IT Systems Semester 2, 2018 Assignment 1, Part A: Treasure Map (20%, due 11:59pm Sunday, September 9th, end of Week 7) Overview This is the first part of a...

1 answer below »
Assignment1a-TreasureMap


IFB104 Building IT Systems
Semester 2, 2018
Assignment 1, Part A: Treasure Map
(20%, due 11:59pm Sunday, September 9th, 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 most 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 im-
age by following instructions stored in a list. It tests your abilities to:
• Process lists of data values;
• Produce maintainable, reusable code;
• Design a solution to a repetitive computational problem; and
• Display information in a 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
concise and easy to understand and maintain.
Goal
The short-lived Pokémon Go craze temporarily reignited interest in old-fashioned treasure
hunts. In this assignment you are required to use Python’s Turtle graphics module to draw a
map summarising the outcomes of such a treasure hunt. To do so you must follow a given set
of instructions, provided as a Python list, to place “tokens”, representing treasures found, in a
square grid defining the search area. Most importantly, the path followed will be generated
andomly, so your solution must be sufficiently general that it can work co
ectly for any pos-
sible path through the grid.
Resources provided
A template Python 3 program, treasure_map.py, is provided with these instructions.
When run it creates a drawing canvas and displays a simple background image on which you
will follow the instructions to draw tokens in the locations where they are found during the
imaginary treasure hunt. You have a free choice in the design of the individual tokens. The
default image drawn by running the provided Python template appears as shown overleaf. It
consists of a simple grid representing the search field, and space for a legend in which you
will describe the theme and tokens you have designed.


IFB104 Building IT Systems
Semester 2, 2018
Note that in this Turtle canvas the “home” coordinate (0, 0) is at the bottom left, rather than
the usual default of the canvas’ centre. The canvas contains a grid representing the area ex-
plored during the treasure hunt. Each of the grid’s squares measures 100 ´ 100 pixels. The
large blank space on the right is where the legend explaining the meaning of each of your to-
kens will be drawn.
Your task is to extend this template file so that it can draw tokens in the grid to indicate
“treasures” found by following a provided path through the grid. To do so you must design
five entirely distinct tokens, each of which can be drawn in any grid square (and in the leg-
end). Your code will consist of a function called follow_path, and any auxiliary func-
tions you define to support it. This function takes a single argument, which is a list of in-
structions specifying where to start the treasure hunt and which steps to follow. This list of
instructions is created by a provided function called random_path which randomly gener-
ates the sequence of instructions, so your code must work co
ectly for any possible path
through the grid!
Data format
The random_path function used to assess your solution returns a list of instructions repre-
senting the steps taken during the treasure hunt. Each of the instructions is expressed as a
triple (a sublist of length three). The instructions have two different forms. The first instruc-
tion in the path is always of the form
['Start', location, token_number]
This is coordinate (0, 0)


IFB104 Building IT Systems
Semester 2, 2018
where the location may be any one of five character strings, 'Top left', 'Top right',
'Centre', 'Bottom left' or 'Bottom right', and the token_number is an integer
from 0 to 4, inclusive. This instruction tells us in which grid square to begin our treasure
hunt and the token that we find there. (Every square we visit yields a token, including the
first.) For instance, an initial instruction
['Start', 'Bottom right', 3]
tells us that our treasure hunt begins in the grid’s bottom-right square and that we should
draw a token of type 3 there.
The remaining instructions, if any, are all of the form
[direction, number_of_squares, token_number]
where the direction may be 'North', 'South', 'East' or 'West', the num-
er_of_squares is a positive integer, and the token_number is an integer from 0 to 4, inclu-
sive. This instruction tells us where to go from our cu
ent location in the grid and the token
to draw in the target square. For instance, an instruction
['South', 3, 2]
tells us that the next step is to move down by three grid squares and to draw a token of type 2
there.
In addition to the random_path 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 path while debugging your code. However, the “fixed” paths will not be used
for assessing your solution. Your follow_path function must work co
ectly for any path
andomly generated by function random_path.
Designing the tokens
To complete this assignment you must design five entirely distinct tokens representing
“treasures” found during the hunt. The five tokens must each fit precisely in a 100 ´ 100
pixel square, must be drawn using Turtle graphics primitives only, must be of a reasonable
degree of complexity, and must all be part of some common theme. You have a free choice
of theme and are strongly encouraged to be imaginative!
Some possible themes you may consider are:
• 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
• Geographical sites (cities, countries or tourist attractions)
• Vehicles (cars, boats, planes, etc)
• Household objects
• Or anything else suitable for creating five distinct and easily-identifiable “tokens”


IFB104 Building IT Systems
Semester 2, 2018
Illustrative example
To illustrate the requirements we developed a solution which uses classic DC Comics super-
heroes as its theme. (Don’t copy our example! Develop your own idea!) We wrote Turtle
graphics code that could draw the following five tokens, each representing a well-known su-
perhero.
Each of these images is exactly 100 pixels high or wide, so will fit perfectly into one of the
grid squares. In our solution we use these symbols as our “tokens”, with Batman being To-
ken 0, Superman being Token 1, and so on, up to Green Lantern as Token 4. For your solu-
tion you need to similarly design five tokens for use as Token 0 to Token 4, inclusive.
From this basis, our implementation of the follow_path function can follow any plan
generated by function random_path, drawing tokens at each step. For instance, consider
the following short path:
[['Start', 'Top left', 2],
['South', 6, 0],
['East', 4, 2],
['West', 2, 1],
['North', 3, 1],
['West', 1, 3]]


IFB104 Building IT Systems
Semester 2, 2018
This requires us to start in the top-left square of the grid and draw Token 2 there, which in
our case is Wonder Woman. Next we go six squares south and draw Token 0, which is Bat-
man. Then we go four squares east and draw Token 2, i.e., Wonder Woman again. We then
everse direction and go two squares west and draw Token 1, Superman. Next we go three
squares north and draw Token 1 again. The final step is to go one square west and draw To-
ken 3, The Flash. The resulting map of the treasure hunt’s discoveries in the grid is shown
elow.
Notice that each token is of the appropriate style and fits perfectly into the co
ect square ac-
cording to the instructions in the path provided.
As a more complex example, consider the following much longer randomly-generated path.
[['Start', 'Centre', 3], ['North', 2, 1],
['South', 3, 2], ['South', 1, 1],
['West', 2, 0], ['East', 4, 1],
['West', 3, 1], ['West', 2, 4],
['North', 5, 2], ['South', 6, 4],
['East', 2, 0], ['West', 1, 4],
['North', 4, 2], ['East', 3, 3]]
In this case we begin in the centre square with Token 3, The Flash. We then go: two squares
north to draw Token 1, Superman; three squares south to draw Token 2, Wonder Woman;


IFB104 Building IT Systems
Semester 2, 2018
another square south to draw Token 1 again; two squares west to draw Token 0, Batman; and
so on until all the specified tokens are drawn. The resulting image appears below.
As well as drawing tokens in the grid according to a provided path, the final requirement for
this part of the assignment is to complete the treasure map with a legend which clearly de-
scribes the chosen theme and the meaning
Answered Same Day Sep 04, 2020 IFB104

Solution

Snehil answered on Sep 08 2020
120 Votes
#-----Statement of Authorship----------------------------------------#
#
# This is an individual assessment item. By submitting this
# code I agree that it represents my own work. I am aware of
# the University rule that a student must not act in a manne
# which constitutes academic dishonesty as stated and explained
# in QUT's Manual of Policies and Procedures, Section C/5.3
# "Academic Integrity" and Section E/2.1 "Student Code of Conduct".
#
# Student no: PUT YOUR STUDENT NUMBER HERE
# Student name: PUT YOUR NAME HERE
#
# NB: Files submitted without a completed copy of this statement
# will not be marked. All files submitted will be subjected to
# software plagiarism analysis using the MoSS system
# (http:
theory.stanford.edu/~aiken/moss/).
#
#--------------------------------------------------------------------#
#-----Task Description-----------------------------------------------#
#
# TREASURE MAP
#
# This assignment tests your skills at processing data stored in
# lists, creating reusable code and following instructions to display
# a complex visual image. The incomplete Python program below is
# missing a crucial function, "follow_path". You are required to
# complete this function so that when the program is run it traces
# a path on the screen, drawing "tokens" to indicate discoveries made
# along the way, while using data stored in a list to determine the
# steps to be taken. See the instruction sheet accompanying this
# file for full details.
#
# Note that this assignment is in two parts, the second of which
# will be released only just before the final deadline. This
# template file will be used for both parts and you will submit
# your final solution as a single Python 3 file, whether or not you
# complete both parts of the assignment.
#
#--------------------------------------------------------------------#
#-----Preamble-------------------------------------------------------#
#
# This section imports necessary functions and defines constant
# values used for creating the drawing canvas. You should not change
# any of the code in this section.
#
# Import the functions needed to complete this assignment. You
# should not need to use any other modules for your solution. In
# particular, your solution must not rely on any non-standard Python
# modules that need to be downloaded and installed separately,
# because the markers will not have access to such modules.
from turtle import *
from math import *
from random import *
# Define constant values used in the main program that sets up
# the drawing canvas. Do not change any of these values.
grid_size = 100 # pixels
num_squares = 7 # to create a 7x7 map grid
margin = 50 # pixels, the size of the margin around the grid
legend_space = 400 # pixels, the space to leave for the legend
window_height = grid_size * num_squares + margin * 2
window_width = grid_size * num_squares + margin + legend_space
font_size = 18 # size of characters for the coords
starting_points = ['Top left', 'Top right', 'Centre',
'Bottom left', 'Bottom right']
#
#--------------------------------------------------------------------#
#-----Functions for Creating the Drawing Canvas----------------------#
#
# The functions in this section are called by the main program to
# manage the drawing canvas for your image. You should not change
# any of the code in this section. (Very keen students are welcome
# to draw their own background, provided they do not change the map's
# grid or affect the ability to see it.)
#
# Set up the canvas and draw the background for the overall image
def create_drawing_canvas():

# Set up the drawing window with enough space for the grid and
# legend
setup(window_width, window_height)
setworldcoordinates(-margin, -margin, window_width - margin,
window_height - margin)
# Draw as quickly as possible
tracer(False)
# Choose a neutral background colour (if you want to draw you
# own background put the code here, but do not change any of the
# following code that draws the grid)
bgcolor('light grey')
# Get ready to draw the grid
penup()
color('slate grey')
width(2)
# Draw the horizontal grid lines
setheading(0) # face east
for y_coord in range(0, (num_squares + 1) * grid_size, grid_size):
penup()
goto(0, y_coord)
pendown()
forward(num_squares * grid_size)

# Draw the vertical grid lines
setheading(90) # face north
for x_coord in range(0, (num_squares + 1) * grid_size, grid_size):
penup()
goto(x_coord, 0)
pendown()
forward(num_squares * grid_size)
# Draw each of the labels on the x axis
penup()
y_offset = -27 # pixels
for x_coord in range(0, (num_squares + 1) * grid_size, grid_size):
goto(x_coord, y_offset)
write(str(x_coord), align = 'center',
font=('Arial', font_size, 'normal'))
# Draw each of the labels on the y axis
penup()
x_offset, y_offset = -5, -10 # pixels
for y_coord in range(0, (num_squares + 1) * grid_size, grid_size):
goto(x_offset, y_coord + y_offset)
write(str(y_coord), align = 'right',
font=('Arial', font_size, 'normal'))
# Mark the space for drawing the legend
#goto((num_squares * grid_size) + margin, (num_squares * grid_size)
2)
#write(' Put your legend here', align = 'left',
# font=('Arial', 24, 'normal'))
# Reset everything ready for the student's solution
pencolor('black')
width(1)
penup()
home()
tracer(True)
# End the program and release the drawing canvas to the operating
# system. By default the cursor (turtle) is hidden when the
# program ends - call the function with False as the argument to
# prevent this.
def release_drawing_canvas(hide_cursor = True):
tracer(True) # ensure any drawing still in progress is displayed
if hide_cursor:
hideturtle()
done()

#
#--------------------------------------------------------------------#
#-----Test Data for Use During Code Development----------------------#
#
# The "fixed" data sets in this section are provided to help you
# develop and test your code. You can use them as the argument to
# the follow_path function while perfecting your solution. However,
# they will NOT be used to assess your program. Your solution will
# be assessed using the random_path function appearing below. You
# program must work co
ectly for any data set that can be generated
# by the random_path function.
#
# Each of the data sets is a list of instructions expressed as
# triples. The instructions have two different forms. The first
# instruction in the data set is always of the form
#
# ['Start', location, token_number]
#
# where the location may be 'Top left', 'Top right', 'Centre',
# 'Bottom left' or 'Bottom right', and the token_number is an
# integer from 0 to 4, inclusive. This instruction tells us where
# to begin our treasure hunt and the...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here