cs235.boggle
package.
BogglePlayer
interface (defined in BogglePlayer.java). The Boggle graphical front-end will call your
class to execute the required back-end logic. Although you will probably implement other methods too,
your class that implements the BogglePlayer
interface must have at least the following methods:
public void loadDictionary(String fileName);
public boolean isValidWord(String wordToCheck)
public boolean isValidPrefix(String prefixToCheck)
public void setBoard(String[] letterArray)
public SortedSet getAllValidWords(int minimumWordLength)
public List isOnBoard(String wordToCheck)
public String[] getCustomBoard()
These operations are described in the following sections.
BogglePlayer
interface relate to loading and searching a word dictionary.
If Boggle is to run in a reasonable amount of time, all of these methods must be fast, even for
large dictionaries. For this reason, and to give you experience with binary search, you are required
store your dictionary as a sorted array of strings, and to use the binary search algorithm to search it.
You may assume that the provided dictionary file is already sorted, so creating such an array is easy.
loadDictionary
method loads the dictionary from a file into an array of strings.
isValidWord
method searches the dictionary for a particular word. It returns true
if the word is in the dictionary and false if it is not. This method should be implemented using
a binary search. If loadDictionary
has not yet been called, this method should
throw an IllegalStateException
.isValidPrefix
method accepts a string and determines whether any words in the
dictionary begin with that string. It returns true if at least one word in the dictionary begins
with the string and false if not. This method should be implemented using a modified binary search
(i.e., think about how binary search can be modified a little to determine if any words start with
a given prefix). If loadDictionary
has not yet been called, this method should throw an
IllegalStateException
.
setBoard
method accepts an array of Strings
of length N2 which specifies
the layout of dice on the N-by-N board. (In standard Boggle N is 4; but your BogglePlayer
should
work for any square board.) The elements of the array specify the letters found on dice going from left to
right, and top to bottom of the board. (So the element indexed 0 is a string containing the letter(s) on the
die at the upper left corner; on a 4x4 board, the element indexed 3 is the top right letter, and index 15
gives you the letter at the bottom right.) Each string may be upper or lower case, and may contain one or
more letters. (In official Boggle, these strings will contain one character only, except for the double
letter die face "Qu"; but your BogglePlayer
should work correctly for arbitrary strings.)
From the array of strings to construct a data structure that represents the Boggle board in a way that
lends itself well to your search algorithms.getCustomBoard
method will be called by the GUI when the user requests a custom,
non-random board. This method should return an array of 16 strings representing the desired dice layout based on the usual index from 0 to 15.
loadDictionary
or setBoard
has not yet been called, this
method should throw an IllegalStateException
.isOnBoard
method accepts a string argument and determines whether the string
can be found on the board. The return type of this method is a List
object containing
Integer
elements. If it is possible to find the word on the current board, the method
returns a list of Integers
representing the locations of the dice used to form the word,
in order (using the same mapping from integers to locations required by setBoard
).
If it is NOT possible to form the word, the method returns null
. Again, every effort
should be made to avoid following dead-end paths. If setBoard
has not yet been called,
this method should throw an IllegalStateException
.
BogglePlayer
implementation class,
you will need to modify the BoggleFactory
class to create an object of your class and
return it. The GUI will then call the BoggleFactory
to create the BogglePlayer
object. The BoggleFactory
class is found in BoggleFactory.java.
java cp project-dir cs235.boggle.BoggleGUI word-file board-size min-word-length
\projects\boggle
, the dictionary file is named dictionary.txt
, and you want a 5x5 board with a minimum word size of 3, the command to run Boggle would look like this:java cp \projects\boggle cs235.boggle.BoggleGUI dictionary.txt 5 3
BogglePlayer
. The test driver is designed to test all of the functionality described in the previous sections. However, the test driver should not be viewed as a replacement for doing your own testing. If your code passes the test driver, it is still possible that it will fail at pass off because a different test program is used for pass off (i.e., the pass off driver). It is your responsibility to make sure that your code works.
BogglePlayer
interface. Your implementation class
must be in the cs235.boggle
package.
BoggleFactory
class to return one of your BogglePlayer
objects.