CS 307 - Fall 2001 - Assignment 7
Final Project
Boggle

Placed Online: November 19, 2001    
Due:
   Decemebr 10, 2001

Purpose:
To write non trivial recursive methods and work with data structure
Provided classes: FileHandler.java, WordLoader.java, Lexicon.java, LetterDice.java, BoggleBoard.java, ConsoleInput.java, BoggleMain.java, words.txt, Boggle Sample output

Part 1 - Introduction

What is Boggle?  The game of boggle is played with a set of sixteen letter cubes, which are standard six-sided dice except that they are marked with letters of the alphabet instead of numbers.  The cubes are arranged into a 4X4 square that might look like this:

e e c a
a l e p
h n b o
q t t y

The object of the game is to form words by starting at one cube and then work through a chain of letters to form a word that meets the following conditions

  1. the word must be at least 4 letters long
  2. the path traced out by the letters in the word must be connected horizontally, vertically, or diagonally in the order of the word. You may not skip over intervening cubes to get to a letter.
  3. each cube may be used only once in a given word
  4. the word is contained in the game's lexicon or word list

In the above arrangement the word "peace" would be formed by going from 1,3 to 1,2 to 0,3 to 0,2 to 0,1.

e E C A
a l E P
h n b o
q t t y

For scoring a 4 letter word is worth 1 point, a f5 letter word is worth 2 points, a 6 letter word is worth 3 points and so forth.

You will create a game that allows a human player to play against the computer.  The human player goes first and has as much time as they wish to find as many words as they can. When the human player gives up and signals they are done the computer gets its turn. The computer is not allowed to use any words the human player has already found. The computer does an exhaustive search of the board and finds all words in the lexicon that are on the board that have not been used. The computer gets all of these words. Due to the power of recursion and a rather large lexicon the computer will win most games in a rout.

Part 2 - Overview of the Classes

This assignment will use multiple classes to implement Boggle. The classes that are provided to you are:

  1. FileHandler: This is used to read information from the word list
  2. WordLoader: Its job is to read words from the file via the FileHandler and put them into the Lexicon
  3. Lexicon: A very important class. The lexicon is set up for you and loaded at the beginning of the game. Lexicon contains 2 important methods for you to use:

    public boolean wordIsPresent(String word)
    returns true if word is in the Lexicon. Note all words in the lexicon are lower case

    public boolean isValidPrefix(String pre)
    returns true if there is a word in the lexicon equal to pre or if there is a word in the lexicon that starts with pre

  4. LetterDice: Represent the dice cubes in the game of Boggle. You construct a LetterDice by sending in a String representing the letters on the die. There is a roll method that returns the new char showing and a charShowing method.
  5. BoggleBoard: You are only given the shell of this class and the information for the letters on the dice. This class represents the board with its dice. You can either have a matrix of LetterDice or an array of LetterDice and a matrix of chars.  I suggest the latter method.  There may be additional instance and class variables you need.
  6. BoggleGame: You will write this class in its entirety. This is a controller class that runs most of the game. It acts as an intermediary between the Display class and the Board class. Most of the rules of the game will be embedded in this class. This class shall have instance variables of objects of type Lexicon, BoggleBoard, and Display.  You may also find other necessary instance variables. The BoggleGame will keep track of what words the human player has entered, determine if a word is valid other than actually being on the board, and keep track of the human and computer score.
  7. Display: You will write this class in its entirety. This class will do all of the input and output. It shall not keep track of any information, merely implement methods required by the BoggleGame to display information.
  8. ConsoleInput: Display will use the static readString method from this class when required to get input from the user via the keyboard.
  9. BoggleMain: This class must be sent a command line parameter with the name of the file where the words are stored. The main method will simply instantiate a BoggleGame object and tell it to run the game. The words.txt file contains over 100,000 words from the official Scrabbletm first edition dictionary.

Part 3 - Requirements

The BoggleGame class will act as the controller for the whole game. The basic sequence of actions is to initialize the board via some method in BoggleBoard that will pick a random die from the 16 LetterDice for each slot on the board and roll each die so a random letter is showing. Display the board (get string version via toString method in BoggleBoard class and send it to the Display class), show the player what words they have so far, and there score and then ask for their next word.

You will want to use some signal, an all uppercase word or the string "1" to allow the human player to tell you they are done. After the human player enters a word it must be checked. Possible errors are the word is too short, the word has already been used, or the word is not in the Lexicon. If all of these tests are passed then the word is sent to the BoggleBoard class to see if it is actually present on the board. If it is the BoggleBoard should highlight so when the toString method is called next the word shows up in uppercase letters. If the word is found the BoggleGame must update the list of words so far and the human score. If the word is not on the board or any of the previous errors occur the user is informed of the error and the board should be redisplayed (with all letters now in lower case) along with words so far and the score. The human player is then asked to try again or quit.

Finding if a word is on the board will involve a challenging recursive method. You will have to think very carefully about the base cases and what the recursive step should be. Essentially the recursive step is to perform an exhaustive search of all cells around the current one.

When the human player gives up the BoggleGame will ask the BoggleBoard to find all words on the board, 4 letters or more in length, in the Lexicon, and were not found by the human user. This will require an exhaustive search of the board. No highlighting of letters is necessary. Instead after all words are found and passed back to the BoggleGame it will determine the computer's score and send the list of words the computer found and the computer's score to its Display object to show the human. The board should e redisplayed so the human can compare the computer's word list to the words on the board. Finally the BoggleGame declares the winner and asks the human if they want to play again. If they do then the BoggleBoard should be reset as well as the scores and the words used list.

Unless you want your running time to be very long for the computer's search you must use the isValidPrefix method from the lexicon to cut short any searches when it is impossible to form a word out of the letters so far. For example no word in English begins with "zx". Thus if you are searching through the board and have built a path starting with "zx" you can stop right there with no more recursive calls because it doesn't matter what additional letters you add to the end, it is impossible to form a valid word starting with "zx".

A Word of advice: Start now! Do this program in small chunks. Get a little bit working at a time.  Don't code too much, no more than a method or two, before testing what you have completed to be sure it works. It would be much better to turn in only a partially functioning program rather than a bunch of code that does not even compile and therefore does nothing. You may use the ArrayList class if you wish.  You may also find the Point class from the java.awt package useful for tracking cell coordinates.  Point objects have 2 public instance integer variables, x and y.

When you are finished turn in you BoggleGame.java, Display.java, and BoggleBoard.java files.