The deadline for this lab is Wednesday 13 April 2005, 15:45 hours. Strictly no submissions will be accepted after the deadline.
The entire area is an 8 x 8 board, where an empty square is marked by a full-stop, a tree is marked by a letter X, and Aragon is marked by the character @. The following is an example of an initial layout:
........ ........ ....X... ..@XXX.. ....X... ........ ........ ........
........ ........ ....X... ..@XXX.. ....X... ........ ........ ........ ........ ........ ..@.X... ...XXX.. ....X... ........ ........ ........ ........ ........ ...@X... ...XXX.. ....X... ........ ........ ........ ........ ...@.... ....X... ...XXX.. ....X... ........ ........ ........ ........ ....@... ....X... ...XXX.. ....X... ........ ........ ........ ........ .....@.. ....X... ...XXX.. ....X... ........ ........ ........ ........ ........ ....X@.. ...XXX.. ....X... ........ ........ ........ ........ ........ ....X.@. ...XXX.. ....X... ........ ........ ........ ........ ........ ....X... ...XXX@. ....X... ........ ........ ........ ........ ........ ....X... ...XXX.. ....X.@. ........ ........ ........ ........ ........ ....X... ...XXX.. ....X@.. ........ ........ ........ ........ ........ ....X... ...XXX.. ....X... .....@.. ........ ........ ........ ........ ....X... ...XXX.. ....X... ....@... ........ ........ ........ ........ ....X... ...XXX.. ....X... ...@.... ........ ........ ........ ........ ....X... ...XXX.. ...@X... ........ ........ ........ ........ ........ ....X... ...XXX.. ..@.X... ........ ........ ........ ........ ........ ....X... ..@XXX.. ....X... ........ ........ ........
The following pseudocode is given to help you to ensure that Aragon patrols the trees correctly. It shows the decision that Aragon will make depending on the trees around him. Note that turning left or right keeps Aragon on the same square; only the direction he faces is changed.
if there is a tree in front and there is a tree on the right turn left else if there is a tree on the right go forward one square else turn right go forward one square
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 2 1 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
We use 0 to indicate an empty square, 1 to indicate a tree, and 2 to indicate Aragon. The locations of the trees and Aragon vary from file to file. You may assume that none of the trees will be placed at the board's edges, e.g. there will be no trees at row 0, column 0, row 7, and column 7.
For simplicity, we assume that Aragon always starts with a tree on his right, and he always starts facing upwards. The initial position of Aragon is not fixed.
You can find other text files (walk2.txt) in your practical exam account.
We will test your program with other text files.
Follow the sample run exactly or you will not get any marks for the test cases. The UNIX prompt is shown by the $ sign.
$ gcc -Wall walk.c -o walk $ ./walk ........ ........ ....X... ..@XXX.. ....X... ........ ........ ........ (3,2) (2,2) (2,3) (1,3) (1,4) (1,5) (2,5) (2,6) (3,6) (4,6) (4,5) (5,5) (5,4) (5,3) (4,3) (4,2) (3,2) Moves: 16 $
Remember to submit your program using the submit walk.c command, and check your submission using the check command.
All the best!