TCSS 143, Autumn 2004Homework 6: Boggle (Recursion, Data Structures, GUI)

Assigned:Mon 2004/11/29

Due:Fri 2004/12/10, 11:59pm

This assignment is designed to further test your understanding of recursion and data structures, as well as implementing a graphical user interface. This assignment may be completed alone or with a partner. This is a challenging, two-part assignment; start early!

Background Information:

Boggle is a game in which a 4x4 grid of random letters is created, and then players try to connect the letters to form words. Here is an example board:

A word is formed by connecting adjacent letters on the board. Letters that are one square apart (either horizontally, vertically, or diagonally) may be connected. No grid square may be visited twice in the formation of a word. Any word formed must be at least 4 letters long, and must be a valid English word according to Boggle's dictionary. Here is an example of the word "peace" found in the board:

The real Boggle game considers the "Q" square to be a "Qu" so that words such as "queen" can be formed more easily. You may ignore this feature for your assignment.

Part 1 - Boggle Game:

In the first part of this assignment, you will implement the logic to keep track of the Boggle game board and search for words on it. (The next part of the assignment asks you to implement the graphical user interface for the game.)

Your Boggle game class will be called Boggle and will be in the file Boggle.java. The Boggle game class should work with the instructor-provided text user interface, which is in the file BoggleTextUI.java.

Your Boggle class will implement an instructor-provided interface called BoggleInterface. BoggleInterface contains some helpful constants, such as the board size (4), minimum word length (4), and the listing of what letters appear on which side of each of the letter dice.

Your Boggle class must have the following methods:

public Boggle(String filename) throws FileNotFoundException
Initializes the game board and reads the dictionary of legal words from the given file. The dictionary file is a text file with one word per line (the same format as past assignments).
public boolean boardContains(String word)
Returns true if the given word can be formed by connecting squares on the current game board. If the word is null or is too short (less than 4 letters long), return false. (You should write this method recursively. Use a separate recursive helper method if you need to pass more parameters.)
public Set getAllContainedWords()
Returns a Set of all the words that can be formed by connecting squares on the current game board. You should discover the contents of this set by searching the board for every word in the dictionary, to see if it can be formed.
public Set getFoundWords()
Returns a Set of all words that have been found on the board so far by the player; in other words, the set of words passed to the guess method this game, that were contained on the board.
public boolean guess(String word)
This method is called when the player is guessing a word to see if that word is contained on the game board. Returns whether the word was found on the board. If the word is null, is too short (less than 4 letters long), has already been guessed this game, or is not found on the board, return false.
public boolean hasFound(String word)
Returns whether the user has guessed the given word and it was found on the board; in other words, returns whether the word is in the set of found words.
public boolean isInDictionary(String word)
Returns whether the given word is in the dictionary, as read from the dictionary file.
public void newGame()
Starts a new game and re-initializes the game board. The board should pick a random face value (one of the 6 sides) for each of the 16 letter dice. Starting a new game should also clear the set of found words.
public String toString()
Returns a string representation of the game board, with each letter surrounded by [ and ] marks; for example,
[y][v][e][t]
[n][t][t][t]
[k][x][o][e]
[l][n][u][a]

Part 2 - Graphical User Interface (GUI):

After you complete the Boggle game class, you should write a simple graphical user interface (GUI) for the game. The GUI does not have to exactly match any particular appearance, but it must contain some kind of UI that displays the following:

  • The current game board's contents.
  • A way for the user to guess words.
  • An error message of some kind that is displayed if the user guesses a word that is too short, not in the dictionary, has already been found on the board, or is not found on the board at all.
  • A listing of every word that the user has found so far. The listing of words may appear in any order.
  • A way for the user to end the current game, when he/she is done guessing words.
  • A listing of all words that were contained in the board, once the user has ended the game.
  • A way to start a new game.

Here are some screenshots of possible GUIs, to give you ideas of how yours might look.

Submission and Grading:

Submit this assignment online, as with all programming assignments. Turn in ALL of your Java files needed to compile your program, including supporting files. A sample solution will be posted to the course web site. You do not need to match its output exactly, but your game should exhibit similar behavior as described in this writeup. When in doubt or when behavior is otherwise unspecified, match the behavior of the sample solution.

The correctness of your program will be graded by running your Boggle game both with the provided text interface and with your graphical user interface. Exceptions should not occur under normal usage except as specified previously. Your code should not produce any console output, such as System.out.println statements in your code that were not specified. The graphical user interface, in particular, should produce no console output.

The design of your program will be graded on whether you follow the program specification above, whether you implement the interface given, whether you use appropriate collections to implement your Boggle game, and the reasonableness of your code and algorithms. Your style will be graded on the presence of reasonable brief comments in your source code (a short header with your name and course on each class, a header on each method, and a comment on particularly complex code sections), the use of meaningful identifier names, appropriate use of modifiers such as public, private, protected, and static; avoiding redundancy, and general spacing and indentation of your code.

1 of 3