The deadline for this lab is Wednesday 13 April 2005, 11:45 hours. Strictly no submissions will be accepted after the deadline.
......O. ......O. .....@.O ......O. ........ ......O. ........ ........
Code | Direction |
---|---|
An unsuccessful move is one in which the man tries to move out of the 8 x 8 board. All unsuccessful moves must be caught and disallowed by your program.
Suppose the first movement code is 3, which means move to the right. The man will move to the right, resulting in the following layout. This is a successful move.
......O. ......O. ......@O ......O. ........ ......O. ........ ........
A push is unsuccessful if the square beyond the block is occupied by another block, or if the square beyond the block is outside of the boundary of the 8 x 8 board. All unsuccessful pushes must be caught and disallowed by your program.
Suppose the next movement code is 4, which means to move down. The man will push the block downwards, resulting in the following layout.
......O. ......O. .......O ......@. ......O. ......O. ........ ........
0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 2 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 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 3 4 2 3 2 1 2 2 2 3 3
The first eight lines show the initial layout. We use 0 to indicate an empty square, 1 to indicate a block, and 2 to indicate a man. The locations of the blocks and the man vary from file to file.
The remaining lines in the file (the number of which is unknown) is a list of moves that the man will execute, shown by the movement code. So the first move is 3 which means move to the right, the second code is 4 which means move down, and so on.
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 blocks.c -o blocks $ ./blocks Final layout: ......@O ......O. .......O ........ ......O. ......O. ........ ........ Total commands: 11 Valid moves: 5 Valid pushes: 2 Invalid moves: 1 Invalid pushes: 3 $
Remember to submit your program using the submit blocks.c command, and check your submission using the check command.
All the best!