Reference no: EM132242369
Programming Assignment: Maps
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. 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.
Learning Outcomes -
- 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.
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).
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:
- Prompt for file name. Read a map file.
- Display the map to screen.
- 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.
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:
- 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).
- Always choose the square which has the lowest value.
- 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 other additional elements for this grade concern code style and layout:
No use of global variables.
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.
- Brackets must line up (and should normally be on a line of their own).
- Indentation must be consistent.
- Appropriate use of white space should be made.
- 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:
- Rotate the map by 90 degrees clockwise.
- Reflect the map vertically.
- 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
|
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.
- 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.
- 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.
- Evaluate not just the immediate locations to your current location, but every possible successor location which you've found.
- Always choose the location which has the highest value.
- 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.
Attachment:- Assignment Files.rar