Write a program to play the word game Boggle®.
The Boggle game. Boggle is a word game designed by Allan Turoff and distributed by Hasbro. It involves a board made up of 16 cubic dice, where each die has a letter printed on each of its sides. At the beginning of the game, the 16 dice are shaken and randomly distributed into a 4-by-4 tray, with only the top sides of the dice visible. The players compete to accumulate points by building valid words out of the dice according to the following rules:
A valid word must be composed by following a sequence of adjacent dice—two dice are adjacent if they are horizontal, vertical, or diagonal neighbors. A valid word can use each die at most once. A valid word must contain at least 3 letters. A valid word must be in the dictionary (which typically does not contain proper nouns).
The Qu special case. In the English language, the letter Q is almost always followed by the letter U. Consequently, the side of one die is printed with the two-letter sequence Qu instead of Q (and this two-letter sequence must be used together when forming words). When scoring, Qu counts as two letters; for example, the word QuEUE scores as a 5-letter word even though it is formed by following a sequence of 4 dice.
public class BoggleSolver { // Initializes the data structure using the given array of strings as the dictionary. // (You can assume each word in the dictionary contains only the uppercase letters A through Z.) public BoggleSolver(String[] dictionary)
// Returns the set of all valid words in the given Boggle board, as an Iterable.
public Iterable<String> getAllValidWords(BoggleBoard board)
// Returns the score of the given word if it is in the dictionary, zero otherwise.
// (You can assume the word contains only the uppercase letters A through Z.)
public int scoreOf(String word)
}
The board data type. An immutable data type BoggleBoard.java for representing Boggle boards. It includes constructors for creating Boggle boards from either the 16 Hasbro dice, the distribution of letters in the English language, a file, or a character array; methods for accessing the individual letters; and a method to print out the board for debugging.
Here is the full API: public class BoggleBoard { // Initializes a random 4-by-4 Boggle board. // (by rolling the Hasbro dice) public BoggleBoard()
// Initializes a random M-by-N Boggle board.
// (using the frequency of letters in the English language)
public BoggleBoard(int M, int N)
// Initializes a Boggle board from the specified filename.
public BoggleBoard(String filename)
// Initializes a Boggle board from the 2d char array.
// (with 'Q' representing the two-letter sequence "Qu")
public BoggleBoard(char[][] a)
// Returns the number of rows.
public int rows()
// Returns the number of columns.
public int cols()
// Returns the letter in row i and column j.
// (with 'Q' representing the two-letter sequence "Qu")
public char getLetter(int i, int j)
// Returns a string representation of the board.
public String toString()
}