Starting from:

$24.99

IFB104.1 Assignment 1, Part A: Treasure Map Solution

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 image 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 randomly, so your solution must be sufficiently general that it can work correctly for any possible 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.

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 explored 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 tokens 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 legend). Your code will consist of a function called follow_path, and any auxiliary functions you define to support it. This function takes a single argument, which is a list of instructions 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 generates the sequence of instructions, so your code must work correctly for any possible path through the grid!
Data format
The random_path function used to assess your solution returns a list of instructions representing 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 instruction in the path is always of the form
['Start', location, token_number]
['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]
['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 correctly for any path randomly 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!
• 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”

Illustrative example
To illustrate the requirements we developed a solution which uses classic DC Comics superheroes 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 superhero.

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 Token 0, Superman being Token 1, and so on, up to Green Lantern as Token 4. For your solution 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]]
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 Batman. Then we go four squares east and draw Token 2, i.e., Wonder Woman again. We then reverse 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 Token 3, The Flash. The resulting map of the treasure hunt’s discoveries in the grid is shown below.

Notice that each token is of the appropriate style and fits perfectly into the correct square according 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; 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 describes the chosen theme and the meaning of each of the five tokens. This must be placed in the space to the right of the grid but is always the same regardless of the path followed.
The figure overleaf shows a complete treasure map, illustrating both the grid and legend, in this case for the following path:
[['Start', 'Bottom right', 3], ['West', 2, 1],
['North', 5, 2], ['North', 1, 3], ['East', 1, 4],
['East', 1, 2], ['West', 5, 0], ['South', 3, 2],
['East', 1, 0], ['North', 1, 1], ['East', 3, 0], ['West', 4, 4], ['South', 3, 2], ['East', 2, 4]].

To complete this part of the assignment you are required to extend the provided treasure_map.py Python file by completing function follow_path so that it can draw tokens as specified by the data sets generated by the random_path function. Your follow_path function must work correctly for any values returned by the random_path function.
Your submitted solution will consist of a single Python 3 file, and must satisfy the following criteria. Percentage marks available are as shown.
1. Drawing five entirely distinct tokens within a common theme (5%). Your program must be able to draw five clearly distinct tokens, each fitting exactly into a 100
´ 100 pixel square. Each token must be of a reasonable degree of complexity, involving multiple Turtle shapes. It must be easy to distinguish each token from those adjacent to it in the grid.
2. Identifying the theme and tokens (4%). When executed your code must draw a “legend” on the right of the canvas which clearly describes your theme and indicates the meaning/identity of each of the five tokens. The legend must include a visual copy of each token and they should be in the same order as your chosen identity for them from Token 0 to Token 4. You must also put a title at the top of the Turtle drawing canvas describing your theme and tokens.
3. Placing tokens in the grid as per any given path (7%). Your code must be capable of drawing tokens in grid squares, exactly as dictated by any valid data set provided to function follow_path. The tokens must be positioned precisely within the grid squares corresponding to the path described. The drawings of the tokens must preserve their integrity no matter where they are drawn, with no spurious additional or missing lines. Your solution for drawing the tokens must work correctly for any values returned by the random_path function.
4. Code quality and presentation (4%). Your program code, for both Parts A and B of the assignment, must be presented in a professional manner. See the coding guidelines in the IFB104 Code Presentation Guide (on Blackboard under Assessment) for suggestions on how to achieve this. In particular, given the obscure and repetitive nature of the code needed to draw complex images using Turtle graphics, each significant code segment must be clearly commented to say what it does. Similarly, the names of your functions and variables should be indicative of their purpose, not just “i”, “j”, etc. Also, you must use function definitions and loops to avoid unnecessary duplication of similar or identical code segments. To get full marks for this criterion you must provide a significant amount of code to assess.
Finally, you are not required to copy the example shown in this document. Instead you are strongly encouraged to be creative in the design of your solution. Surprise us!
Artistic merit – The Hall of Fame!
Development hints
• Before creating code to draw the individual tokens give careful thought to how you can write the code so that the tokens can be drawn in any square of the grid, and in the legend. In particular, you need to avoid “hardwiring” your drawing to fixed coordinates in the drawing canvas.
• If you are unable to complete the whole task, just submit whatever you can get working. You will receive partial marks for incomplete solutions.
• To help you debug your code we have provided some “fixed” paths. Feel free to use these when developing your program, and add additional ones if you like, but keep in mind that these data sets will not be used for assessing your solution. Your follow_path function must work for any list that can be returned by function random_path.
• Part B of this assignment will require you to change your solution slightly in a short space of time. You are therefore encouraged to keep code maintainability in mind while developing your solution to Part A. Make sure your code is neat and wellcommented so that you will find it easy to modify when the instructions for Part B are released.
Deliverable
You must develop your solution by completing and submitting the provided Python 3 file treasure_map.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!
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 solution with other files or pre-defined images. Do not submit any other files! Submit only a single Python 3 file!
Apart from working correctly your program code must be well-presented and easy to understand, 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.

How to submit your solution

Appendix: Some standard Turtle graphics colours you can use
Source: www.discoveryplayground.com/computer-programming-for-kids/rgb-colors/


More products