Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 6

CO1401 Programming: 2018-2019

Assignment: Maps

Release Date: 15/02/19 Hand in Date: Sunday 31/03/19, 12 Midnight

Introduction
It is important to acknowledge sources. The initial idea for this assignment was taken from one
created by Baker Franke.

This assignment deals with a height map. This is a map showing height of a geographical area. This
type of map can be used to represent terrain. It depicts the terrain using a grid, with each location of
the grid ascribed a height.

Much of the assignment is based on tracing the path a person should take if they walked over the
map. For example, you are asked to calculate the mountain path across the map. Later parts of the
assignment also include manipulating the map, flooding it with water, and find the best route up a
mountain.

However, the assignment starts with reading a sequence of numbers from a file into an array and
then displaying these numbers.

The assignment is separated into separate grade bands. Complete in full the goals of the lower
grade band before moving onto the next.

This is an individual project and no group work is permitted.

Do not diverge from the assignment specification. If you do not conform to the assignment
specification then you will lose marks.

You must use C++.

You are allowed to ask for help and feedback.

Learning Outcomes Assessed


 To develop the student’s software design skills
 To build on the student’s introductory programming skills to produce solutions to more
complex problems.
 To introduce the student to advanced programming techniques in preparation for study of an
advanced programming module.

Deliverables, Submission and Assessment


 You need to submit your source code and demonstrate your working program in the lab session.
 Submission is electronic, via Blackboard.
o You must upload a text file.
o Upload the code you have written in a single file. (For this assignment, even if you
know how, you are not permitted to have multiple source files.)
o The easiest way to do this is to rename your source code file. The source code is in a file
in your project folder. It has a .cpp extension. Simply change the extension to .txt and
then upload the file to Blackboard.

CO1401 Assignment 2018-19 Gareth Bellaby Page 1


 Assessment will be by demonstration in your usual lab session during the week
immediately after the electronic submission (i.e. the week beginning 01/04/19).

Demonstration
 You must demonstrate your program to your practical tutor.
 You must also show your code to your tutor.
 You will be asked questions about your code. Be prepared to answer them. You may be asked
to explain what is happening, or to describe what a line of code does. If you cannot answer
satisfactorily then you will be asked to attend an interview with the module tutor.

Resources
 This assignment has an associated set of text files. The files can be found inside the assignment
folder Web-CT.

Map Format
 Each of the files represents one height map of a region.
 The numbers are listed on 9 lines, with 9 integers per line.
 In effect the numbers are sorted into a 9 x 9 grid.
 The file will therefore list 81 numbers.
 The maps are always 9 by 9.
 The later parts of the assignment mention coordinates. The coordinates merely identify the
particular square. The coordinates are given in the form: row, column (if it helps you can
alternatively think of them as x and y).
( 0, 0 ) would be the bottom left hand corner.
( 8, 8 ) would be the top right hand corner.
( 8, 0 ) would be the top left hand corner.
( 4, 4 ) would be the centre square.
 Note that we count from 0.
 Hint: counting from 0 will help with the indices in the array. However, if you simply read the
map into an array the indices will not correspond to the coordinates, e.g. index [0][0] in a 2D
array will not correspond to the coordinate (0, 0). My suggestion is to read the map into a
temporary array and then copy it into another array, reversing the map as you do, it will make
later parts of the assignment much easier.

Assignment Requirements

Basic Requirements to get 45%


 The code that you submit must compile without errors.
 Display a welcome message and a menu of operations (see below).
 Prompt the user to select one of the operations:
o Prompt for file name. Read a map file.
o Display the map to screen.
o Quit the program.
 Use "map1.txt" as your map file. For the basic requirements this file will not change.
 You must read the numbers into an array.
 You must comment your code. Your comments must be clear and must describe the operations
of your code.

CO1401 Assignment 2018-19 Gareth Bellaby Page 2


Lower second classification to get 55%
 You must complete the criteria from the lower band.
 For this grade classification the indices of the array must correspond to the coordinates of the
map. However, you must also ensure that when you display the map it is the correct way up.

290 279 274 270 264 271 277 282 290


285 279 274 268 272 274 279 283 291
285 279 276 276 270 275 277 281 290
285 279 275 275 270 273 279 283 291
280 279 265 265 270 275 280 282 292
275 270 265 262 260 265 272 281 285
285 279 270 264 271 276 280 285 291
285 279 270 268 266 275 279 284 291
285 279 270 266 271 276 279 285 290

Note that this version is coloured so that can see the relative heights more clearly. I
am not expecting to see a coloured table!

 Add a new option called mountain pass.


 Imagine using a mountain pass to cross over the map from one side to another. The walker
wants to travel from the top side of the map to the bottom but they also want to take the easiest
route.
 Prompt the user for a staring location on the top hand side. By default start at the middle
location on the top. This would be coordinate (8, 4)
 End anywhere on the bottom of the map.
 The algorithm is quite simple:
o Choose a successor location from a square downwards: either the location directly to the
bottom, or the one down and left or the one down and right (i.e. to the bottom:
diagonally or orthogonally).
o Always choose the square which has the lowest value.
o Carry on until you reach the bottom.
 Print out the height of each square as the walker enters it. For “map1.txt” the output on the
screen would therefore read:
264 268 270 270 265 260 264 266 266

290 279 274 270 264 271 277 282 290


285 279 274 268 272 274 279 283 291
285 279 276 276 270 275 277 281 290
285 279 275 275 270 273 279 283 291
280 279 265 265 270 275 280 282 292
275 270 265 262 260 265 272 281 285
285 279 270 264 271 276 280 285 291
285 279 270 268 266 275 279 284 291
285 279 270 266 271 276 279 285 290
The path taken by the walker on map1

 The other additional elements for this grade concern code style and layout:
 No use of global variables.

CO1401 Assignment 2018-19 Gareth Bellaby Page 3


 Use functions/methods to separate your code into sensible, reusable parts. Comment these
functions appropriately.
 Your code must be properly indented and laid out so that it is readable.
o Brackets must line up (and should normally be on a line of their own).
o Indentation must be consistent.
o Appropriate use of white space should be made.
o Over-long lines of code or comments should be split up
 You should have no "magic numbers" but instead make proper use of constants.
 Variable names should be meaningful.
 Your code should be commented appropriately.
 You should make proper use of arrays, with loops to process them.

Upper second classification to get 65%


 You must complete the criteria from the lower bands.
 A height map has a number of similarities to a bitmap image, such as a .bmp file. A height map
can be considered to be a picture of the landscape. The map therefore lends itself to series of
image manipulations.
 Add new options to your menu perform the following operations on the current map:
o Rotate the map by 90 degrees clockwise.
o Reflect the map vertically.
o Flip the map over the diagonal which runs from top-left to bottom-right. Formally this is
a transpose operation.

First classification to get 75%


 You must complete the criteria from the lower bands.
 Add Create Lake as an option to your menu. Let the user specify the map, starting location and
depth. Include a default for the option. If the user presses “return” rather than entering any
values then a default set of values is used: map2.txt 4 4 300
 Imagine that water is pouring into the default location of the centre square of the map ( 4, 4 ).
 The water will spread out from this location. It will cover any square which is below the
specified depth. However, as soon as the water hits a square higher than the specified depth then
it stops. The water spreads out in all directions: diagonally as well as orthogonally.
 There are a variety of ways that this problem can be tackled. In effect what I’ve asked for is a
flood fill operation so feel free to look up algorithms to implement a flood fill.
 However, for the purposes of this assignment it is also perfectly OK to use a brute force
solution.
 Overwrite water locations with the number 000. Display the map after the lake has been
formed.
 Note that if you use map3.txt and fill anywhere except the centre you can create an island rather
than a lake!
 This is what map2.txt would look like using the default values:

355 355 352 357 351 356 351 357 352


351 351 343 339 000 301 314 339 343
350 350 341 310 305 000 000 310 341
351 351 343 000 000 000 000 000 343
352 352 342 310 000 000 000 000 342
355 355 000 341 314 000 000 000 341

CO1401 Assignment 2018-19 Gareth Bellaby Page 4


351 351 000 000 000 000 000 000 345
351 351 344 310 305 310 305 310 344
360 310 295 290 315 305 315 326 355
The map has been coloured to highlight the effect.

 Note the way that the locations along the bottom haven’t been filled with water even though
they are lower than 300. The reason for this is that they are not directly connected to the lake.
The locations in seventh row act effectively act as a wall.

Mid First classification to get 85%


 You must complete the criteria from the lower bands.
 Full use of object-oriented methods throughout.
 Use classes and methods.

High First classification


 You must complete the criteria from the lower bands.
 Add Steepest Ascent Hill Climbing as an option to your menu. Steepest Ascent Hill Climbing is
a search or pathfinding technique. Steepest Ascent Hill Climbing is a variant of Hill Climbing,
and you might want to look at both of them.
 Let the user specify the map, and starting location. Include a default for the option. If the user
presses “return” rather than entering any values then use default values of: map3.txt 8 4
 Identify the highest location on the map.
o The goal of the walker is to walk to the highest location. The highest location is height
410. You stop searching when the walker reaches this height.
o Choose a successor location from any surrounding locations to the location you are
currently evaluating. In other words a successor can be any of the 8 surrounding
locations.
o Evaluate not just the immediate locations to your current location, but every possible
successor location which you’ve found.
o Always choose the location which has the highest value.
o Carry on until you reach the highest point on the map.
 Do some research yourself on the hill climbing algorithm. It is possible to implement a search
tree in order to solve the problem. However, I would suggest using a brute force method in
which you record all the locations the walker has visited in order to choose the best path.
 Print out the height of each square as the walker enters it. For “map3.txt” the output on the
screen would therefore read:
355 365 373 390 396 395 391 388 410

Hand In Details
 The hand-in deadline is Sunday 31/03/19, Midnight.
 Submissions should be made via the link on the module Blackboard page
 Submissions are automatically checked for plagiarism by TurnItIn
 Ensure your name and student ID is stated at the top of your code.
 You may only submit one file:
o Upload a text file with your code in it. This file should contain all your code for the
assignment.
o Ensure that your code just runs without the need to modify it.
 You will demonstrate the code in your normal lab in the week of the assignment deadline, i.e.
i.e. the week beginning 01/04/19.
CO1401 Assignment 2018-19 Gareth Bellaby Page 5
The same rules of lateness apply to the demonstration as to handing in your work. If you do
not turn up to demonstration then your assignment will be treated as late.

CO1401 Assignment 2018-19 Gareth Bellaby Page 6

You might also like