The deadline for this lab is Wednesday 20 April 2005, 12:45 hours. Strictly no submissions will be accepted after the deadline.
....o..... ...o.o.... ..o...o... .o.....o.. oo......o. oo..ooo..o oo..ooo... oo..ooo... ooo....... oooo......
If the square contains a mine, that mine will explode first. It will then cause all other mines around it to explode. All mines that are adjacent to it (one square to the left, right, up, down, and all the four diagonal directions) will explode, causing a chain reaction. In addition, those other mines that are adjacent to the exploded mines will explode until there are no more explosions.
....o..... ...o.o.... ..o...o... .o.....o.. oo......o. oo..ooo..o oo..ooo... oo..ooo... ooo....... oooo......
Suppose we start with the layout shown above.
Supposing a detonation occurs at (7,6). In the following diagrams, we indicate a mine that has just been exploded by a letter x.
Missile at (7,6): Iteration 1: Number exploded: 1 ....o..... ...o.o.... ..o...o... .o.....o.. oo......o. oo..ooo..o The mine at (7,6) has just been exploded by a missile. oo..ooo... This is iteration 1, and 1 mine has been exploded. oo..oox... ooo....... oooo...... Iteration 2: Number exploded: 3 ....o..... ...o.o.... ..o...o... .o.....o.. oo......o. oo..ooo..o All the neighbours of (7,6) are exploded too. oo..oxx... Note that the mine (7,6), once exploded, becomes an empty square. oo..ox.... This is iteration 2, and 3 mines have been exploded. ooo....... oooo...... Iteration 3: Number exploded: 5 ....o..... ...o.o.... ..o...o... .o.....o.. oo......o. oo..xxx..o The chain reaction continues. oo..x..... This is iteration 3, and 5 mines have been exploded. oo..x..... ooo....... oooo...... Iteration 4: Number exploded: 0 ....o..... ...o.o.... ..o...o... .o.....o.. oo......o. oo.......o The chain reaction stops because no more mines oo........ are adjacent to the ones that have been exploded. oo........ This is iteration 4, and 0 mines have been exploded. ooo....... oooo......
0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0 1 1 0 0 0 0 0 0 1 0 1 1 0 0 1 1 1 0 0 1 1 1 0 0 1 1 1 0 0 0 1 1 0 0 1 1 1 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 7 6 5 4 0 5 0 4 9 3
The first ten lines show the initial layout. We use 0 to indicate an empty square and 1 to indicate a mine. The locations of the mines vary from file to file.
The remaining lines in the file (the number of which is unknown) is a list of coordinates that a missile will land on. So the first missile lands at (7,6), the second missile lands at (5,4), 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 blasto.c -o blasto $ ./blasto Missile at (7,6): Iteration 1: Number exploded: 1 ....o..... ...o.o.... ..o...o... .o.....o.. oo......o. oo..ooo..o oo..ooo... oo..oox... ooo....... oooo...... Iteration 2: Number exploded: 3 ....o..... ...o.o.... ..o...o... .o.....o.. oo......o. oo..ooo..o oo..oxx... oo..ox.... ooo....... oooo...... Iteration 3: Number exploded: 5 ....o..... ...o.o.... ..o...o... .o.....o.. oo......o. oo..xxx..o oo..x..... oo..x..... ooo....... oooo...... Iteration 4: Number exploded: 0 ....o..... ...o.o.... ..o...o... .o.....o.. oo......o. oo.......o oo........ oo........ ooo....... oooo...... Missile at (5,4): Iteration 1: Number exploded: 0 ....o..... ...o.o.... ..o...o... .o.....o.. oo......o. oo.......o oo........ oo........ ooo....... oooo...... Missile at (0,5): Iteration 1: Number exploded: 0 ....o..... ...o.o.... ..o...o... .o.....o.. oo......o. oo.......o oo........ oo........ ooo....... oooo...... Missile at (0,4): Iteration 1: Number exploded: 1 ....x..... ...o.o.... ..o...o... .o.....o.. oo......o. oo.......o oo........ oo........ ooo....... oooo...... Iteration 2: Number exploded: 2 .......... ...x.x.... ..o...o... .o.....o.. oo......o. oo.......o oo........ oo........ ooo....... oooo...... Iteration 3: Number exploded: 2 .......... .......... ..x...x... .o.....o.. oo......o. oo.......o oo........ oo........ ooo....... oooo...... Iteration 4: Number exploded: 2 .......... .......... .......... .x.....x.. oo......o. oo.......o oo........ oo........ ooo....... oooo...... Iteration 5: Number exploded: 3 .......... .......... .......... .......... xx......x. oo.......o oo........ oo........ ooo....... oooo...... Iteration 6: Number exploded: 3 .......... .......... .......... .......... .......... xx.......x oo........ oo........ ooo....... oooo...... Iteration 7: Number exploded: 2 .......... .......... .......... .......... .......... .......... xx........ oo........ ooo....... oooo...... Iteration 8: Number exploded: 2 .......... .......... .......... .......... .......... .......... .......... xx........ ooo....... oooo...... Iteration 9: Number exploded: 3 .......... .......... .......... .......... .......... .......... .......... .......... xxx....... oooo...... Iteration 10: Number exploded: 4 .......... .......... .......... .......... .......... .......... .......... .......... .......... xxxx...... Iteration 11: Number exploded: 0 .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... Missile at (9,3): Iteration 1: Number exploded: 0 .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... $
Remember to submit your program using the submit blasto.c command, and check your submission using the check command.
All the best!