Boggle
Boggle is a word game, played on a 4 x 4 grid of letters. Players
make works by connecting adjacent letters. To create a
word, start at one cube, and then work through a chain of letters to
form a word that meets the following conditions:
- The word must be at least three letters long.
- The path traced out by the letters in the word must be connected
horizontally, vertically, or diagonally. You can’t skip over
intervening cubes to get the next letter.
- Each cube may be used only once in a given word.
For instance, in the following board layout:
The word "PEACE" can be made as follows:
Note that the word "PLACE" is
not legal, since after the "L" you
would need to jump over the "H" to get to the "A". The same die
cannot be resued in the same word (but can be resused again in a
different word). Words are scored by the following
formula:
Word Length
|
Score
|
3 Letters
|
1
|
4 Letters
|
1
|
5 Letters
|
2
|
6 Letters
|
3
|
7 Letters
|
5
|
8+ Letters
|
11
|
The object is to find as many words as possible to get the highest
possible score.
Computer Boggle
Because the computer has a complete dictionary and you do not, we’ve
tried to make the game a little more interesting by letting you find as
many words as you can and then turning the computer loose to find the
rest. If you’re thorough, you can beat the computer because it is
not allowed to count words you’ve already found. Most games,
however, still end up as a rout.
Implementation Details
- Unlike your last assignemnt, you will not have to write any GUI
code. Most of the "main loop" has been coded for you, in the
provided BoardGUI.java. You just need to write a class Board.java
(plus any supporting classes you need to implement the board), that
complies to the interface described in the documentation.
- The initial board should not be shuffled! It should appear
as it does in the input file. That is, your inital board should
always be:
P
|
O
|
L
|
V
|
E
|
S
|
A
|
I
|
M
|
A
|
X
|
E
|
Y
|
Z
|
N
|
O
|
This will help us with grading
- To shuffle the dice, you will need to both rearrange the dice in
the grid, and flip each die to a random side. Flipping each die
to a random side is easy, rearranging the dice could be done with the
pseudocode:
for (row =
0; row < numRows; row++)
for (col = 0; col < numCols; col++)
swap elements board[row][col] and
board[random.nextInt(numRows)][random.nextInt(numCols)]
Note that this pseudocode will not do a perfectly random shuffle, but
it is good enough for this assignment
- To check if a word is legal:
- Make sure it has at least 3 letters (many words in the provided
dictionary have 2 or fewer letters!)
- Make sure it is in the dictionary
- Make sure it can be formed on the board
- To find all possible words:
- Start with a letter, and start searching, keeping track of the
word you are building up
- When you create a word, add it to a set of all generated words,
and go on.
- If the word so far is not a prefix of any valid word
(Dictionary method checkPrefix is your friend here), you can stop
- Keep track of which positions you have used, so you don't reuse
them. Note that only the tiles in the current word you are
buiding up should be marked as used -- as you backtrack, you will need
to modify your markings of which tiles are used (this is a little
different from the maze assignment)
- Note that you will likely need to create extra classes beyond the
board, and extra private functions in the Board class beyond the ones
listed in the documentation
Assignment
Your assignment is to write the class Board.java, as defined by the
JavaDoc files found here.
Provided java files: