Note: This exercise is based on a practice programming problem used at the ACM Southeast Regional programming contest a few years ago.
Bingo is a popular game played on a 5 by 5 grid, called a card. Normally we associate each column of the card with the letters B-I-N-G-O from left to right. Each square on the grid has a number in it. As numbers are selected, they are marked off the card. When a line of five squares, horizontal, vertical or diagonal, is marked out, the card is a winner. When a player gets a winning card, he or she shouts BINGO!
A sample bingo card is shown below:
B |
I |
N |
G |
O |
12 |
28 |
31 |
49 |
66 |
3 |
26 |
45 |
53 |
75 |
10 |
17 |
33 |
59 |
67 |
7 |
19 |
42 |
55 |
74 |
2 |
23 |
37 |
46 |
70 |
If the numbers 3, 45, 53, 75, and 26 are picked, then there will be a horizontal bingo on the second row.
The five entries in a column are random integers in the range selected from the ranges indicated below:
The goal of this assignment is to design and implement a Scala program to play a game of bingo.
BingoCard
ADT (e.g., Scala
trait or class) to represent a bingo card. A concrete instance of the
ADT should include appropriate internal state and operations to
manipulate that state during a bingo game. By default, a
BingoCard
should be initialized to a valid set of random
values. (You likely will want to provide the ability to initialize
the card to specific values as an aid in debugging and testing.)
You will, of course, need operations to mark the card appropriately when numbers are called, determine whether the card is a winner, to "print" the card (e.g., return the card as a string so that it can be printed), and so forth.
GameCards
ADT (trait or
class) to represent a collection of bingo cards being played at the
same time. A concrete instance of the ADT should create the number of
desired cards and then accept a sequence of random values in the range
1 to 75 that are played on the cards. It should detect a winner and
make that information available through an appropriate feature of its
interface. It should also be possible to print the winning card(s)
and/or the entire collection.
Constructing your own iterator to work on the GameCards
collection might be a good idea.
scala PlayBingo
n
where n is the number of cards to include in the game.
The program should display the numbers called during the game. At the completion of the game, the program should display the winning card and give other information useful in evaluation of your program. (It would be helpful in debugging if this output went to a file instead of just to the screen.) It is not necessary to do a GUI!
This is not a particularly difficult assignment. My purposes are:
Note that I do want the classes and methods specified using preconditions, postconditions, and invariants.
If any of you are looking for more of a challenge, you might think
about developing the program, in particular the BingoCard
and GameCards
classes, as an "application framework" for
a whole class of Bingo-like games. By application framework, I mean a
set of abstract base classes, interfaces, and concrete library classes
that can be extended, implemented, or used to provide different
specific games. The set of classes making up the framework represent
the common aspects of the family of programs. The extensions
represent the variable aspects of the family. Here are some
ideas--perhaps all cannot coexist within the same design.
You might want to investigate the Template Method, Strategy, Decorator, Visitor, and other design patterns for ideas on how to implement this (and other of the possible enhancements).
Int
s. Since an equality operation
is needed you will need to define an appropriate base class or
interface to represent this hierarchy of labels.
BingoCard
class but
should be a separate class that gets its information from a
BingoCard
instance. You would probably need to be able
to selectively choose cards to display, since all in a
GameCards
class will not likely fit on a screen at once.
Finally, if you have a programming problem you would like to tackle, then let me know. I could perhaps substitute it for this one, but more likely I might consider it for future individual or group programming exercises.
UP to Engr 692 Assignments page?