The deadline for this lab is Wednesday 09 November 2005, 11:45 hours. Strictly no submissions will be accepted after the deadline.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . T . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The meaning of the characters is:
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . * * * . . . . . . . * T * . . . . . . . * * * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . T . . . . . . . . . . T . . . . . . . . . T . . . . . . . . . T T . . . . . . . . . . . . . . . . T T . . . . . . . . . . . . . . .
A forest is defined as a group of trees that are linked together, either horizontally, vertically, or diagonally. Therefore, there are two forests above; the first forest consists of the trees at (3,4), (4,5), (5,5), (6,5), and (6,6). The second forest consists of the two trees at (8,3) and (8,4).
Suppose we know that Frodo is hiding at (4,5). That means that Frodo is hiding somewhere in the first forest. Aragorn will build walls that completely surround the first forest, as shown below:
. . . . . . . . . . . . . . . . . . . . . . . * * * . . . . . . . * T * * . . . . . . * * T * . . . . . . . * T * * . . . . . . * T T * . . . . . . * * * * . . . . . T T . . . . . . . . . . . . . . .
After building all the walls, Aragorn likes to collect statistics for each wall project. He notes that the number of trees in the forest that Frodo is hiding in is 5, and the number of new walls he has built is 18.
Note that the second forest is not protected by walls since there is no one valuable hiding there.
Supposing that Sam suddenly appears at (8,4); i.e., the second forest. Aragorn then starts to build walls for the second wall project, and the new map becomes:
. . . . . . . . . . . . . . . . . . . . . . . * * * . . . . . . . * T * * . . . . . . * * T * . . . . . . . * T * * . . . . . . * T T * . . . . * * * * * * . . . . * T T * . . . . . . * * * * . . . .
Aragorn notes that the number of trees in Sam's forest is 2, and the number of new walls he has built is 8. Since there are existing walls, Aragorn does not build any new walls if it is unnecessary to do so.
. . . . . . . . . . . . . T T T . . . . . . T . . . T . . . . T . . . . . T . . . T . . . . . T . . . T . . . . . T . . . . T . . . T . . . . . . T T T . . . . . . . . . . . . . . . . . . . . . . . .
and Frodo is hiding at (7,5). Aragorn will build walls as follows:
. . * * * * * . . . . * * T T T * * . . * * T * * * T * * . * T * * . * * T * . * T * . . . * T * . * T * * . * * T * . * * T * * * T * * . . * * T T T * * . . . . * * * * * . . . . . . . . . . . . .
The number of trees is 16, and number of new walls is 48.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . T . . . . . . . . T . . . . . . . . . . T . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The walls are built as shown:
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . * * . . . . . . . * * T . . . . . . . * T * . . . . . . . * * T . . . . . . . . * * . . . . . . . . . . . . . . . . . . . .
The statistics from this project is: 3 trees, 10 walls.
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 0 1 0 0 0 1 0 0 0 1 1 1 0 0 1 0 0 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 1 0 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 4 4 5 8 7 4
The first ten lines of the text file contains the layout of the map. 0 represents a grassy area, and 1 represents a tree.
This is followed by an unknown number of lines which represent the coordinates of Frodo / Sam / group members. Each line consists of two integers which represents the coordinates of the person hiding. In the above text file, someone is hiding at (4,4), and a second person is hiding at (5,8), and a third person is hiding at (7,4). Aragorn builds new walls as necessary to protect each person; and as usual, tree and wall statistics are displayed after each wall project.
You may assume that Frodo / Sam / group members always hide in a forest. They never hide in a grassy area because well... one cannot hide in grass!
Assume also that all the numbers in the file are valid integers. No error checking is required.
Initial map: . . . . . . . . . . . . . . T . . . . . . . . T T T . . . . . . . T . T . . . T . . . T T T . . T . . . . . . T . T T . . . . . . . T . . . . . . . T . . . . . . . . . . . . . . . . . . . . . . . . . Protect person at (4,4), trees in forest: 15, new walls: 33 . . . * * * . . . . . . * * T * * . . . . . * T T T * . * * . . * T * T * * * T . . * T T T * * T * . . * * * T * T T * . . . . * * T * * * . . . . T * * * . . . . . . . . . . . . . . . . . . . . . . Protect person at (5,8), trees in forest: 15, new walls: 0 . . . * * * . . . . . . * * T * * . . . . . * T T T * . * * . . * T * T * * * T . . * T T T * * T * . . * * * T * T T * . . . . * * T * * * . . . . T * * * . . . . . . . . . . . . . . . . . . . . . . Protect person at (7,4), trees in forest: 1, new walls: 5 . . . * * * . . . . . . * * T * * . . . . . * T T T * . * * . . * T * T * * * T . . * T T T * * T * . . * * * T * T T * . . . * * * T * * * . . . * T * * * . . . . . * * * . . . . . . . . . . . . . .Note that we firstly show the initial map, then we show the the map after each wall project, together with the statistics of each wall project.
You are reminded to follow the sample output exactly; else marks will be deducted.
Remember to submit your program using the submit walls.c command, and check your submission using the check command.
All the best!