CS1101C Practical Exam
Session 3 (1200 - 1345 hours)
Bubble Breaker
The name of your C program file must be called bubbles.c, files
with any other name will not be marked.
The deadline for this lab is Wednesday 14 November 2007, 13:45:59
hours. Strictly no submissions will be accepted after the
deadline.
Background
Bubble Breaker is a game where players select a Bubble of a particular colour to break it.
This Bubble and all other Bubbles that are "linked" to it will then be removed from the board.
A Bubble is considered "linked" to its adjacent neighbour(s) if they are of the same colour.
Playing Rules
The game occurs in a square board of size 8 by 8 and each cell is
initially occupied by a Bubble. The top-left cell has coordinates (0,0);
the top-right cell has coordinates (0,7).
The Bubbles have 5 colours namely Blue, Green, Red, Violet and Yellow,
denoted by the characters 'b', 'g', 'r', 'v' and 'y' respectively.
A Bubble can be removed from the board.
The underscore character '_' is used to denote a blank in the board when
a Bubble is removed from the board.
A Bubble is a neighbour of another Bubble if it is in a cell to the left
of, or to the right of, or below or above it, i.e. adjacent to it, but
not diagonally.
A Bubble is "linked" to its neighbour if they are of the same colour.
A Bubble is then "linked" to another Bubble if they are linked through
connecting neighbours.
A Bubble is first selected to be deleted and all Bubbles that are linked
to it are established. The Bubbles and all Bubbles that are linked to it
are then removed.
Objective
Print to screen the number of Bubbles that have been deleted and the resultant board. You must follow the format given below.
Text File
Your program must read in a text file called
bubbles.txt which has been copied into your directory by
the pesetup command. There are 9 lines in total. The first 8
lines have 8 characters each, which gives the board layout with the
various coloured Bubbles while the last line contains 2 integers,
denoting the coordinates of the Bubble to be selected. The following is
a sample text file.
b r g v y b r g
b r g v y b r g
b r g v y b r g
b r g v y b r g
b r g v y b r g
b r g v y b r g
b r g v y b r g
b r g v y b r g
2 3
Here, the Bubble selected to be deleted is at (2,3), which is a 'v'.
We will test your program with other text files.
Sample Run 1
The following shows a sample run when using the file
bubbles.txt as shown above.
Follow the sample run exactly or you will lose marks for the test
cases.
Initial Board:
b r g v y b r g
b r g v y b r g
b r g v y b r g
b r g v y b r g
b r g v y b r g
b r g v y b r g
b r g v y b r g
b r g v y b r g
Bubble selected at (2,3) is violet.
Number of bubbles deleted: 8.
Final Board:
b r g _ y b r g
b r g _ y b r g
b r g _ y b r g
b r g _ y b r g
b r g _ y b r g
b r g _ y b r g
b r g _ y b r g
b r g _ y b r g
Sample Run 2
The following shows a sample run when using the file
bubbles2.txt (which has also been copied into your
directory by the pesetup command) as shown below.
Initial Board:
b r g v y b r g
v r v v y b r v
b r v v y b r g
b v v v y b v g
b v v v v v v g
v r g v y b v g
b r g v y v r v
b r g v y b r g
Bubble selected at (2,3) is violet.
Number of bubbles deleted: 19.
Final Board:
b r g _ y b r g
v r _ _ y b r v
b r _ _ y b r g
b _ _ _ y b _ g
b _ _ _ _ _ _ g
v r g _ y b _ g
b r g _ y v r v
b r g _ y b r g
You may assume that the text file will always contain valid information.
No error checking is required.
Do not use any structures or any form of dynamic memory allocation
(using malloc or calloc) in your program, else no
credit will be given.
Remember to submit your program using the submit bubbles.c
command, and check your submission using the check command.
All the best!
UNIX commands
Some useful UNIX commands (in case you forgot what you did in Lab 0):
- “dir”: lists all the files in the directory.
- “cp a.txt b.txt”: copies a.txt to b.txt.
- “mv a.txt b.txt”: moves / renames a.txt to b.txt.
- “cat a.txt”: shows the contents of a.txt.