The main focus of this assignment is designing operations that will efficiently find words that appear in a Boggle board using recursion. Because your focus will be on the back-end logic, you will be provided with a graphical display program, BoggleGUI. This program knows how to generate and render a random Boggle board, interact with a human player, and display results of the game. It will use your code to verify input from the human player, and to obtain the computer player's results.
The program will be due in two parts. In the first part, due next week, you are to write a method to check whether or not words are on the board or not. In the second part, due in two weeks, you are to be able to find all possible words on the board.
In the computer version of the game, the human player gets to go first. (Don't worry, the computer player will still trounce you.) The player proceeds to enter in the text area at the bottom of the window, one at a time, each word that she finds in the game board. A valid word must meet four requirements:
Unlike the original version, there is no time limit here. Instead, the player indicates that she is through entering words by hitting a lone extra carriage return, as if entering an empty word. At this point, the computer gets to take its turn. The computer searches through the board looking for all the valid words it can find. The computer typically beats the human player mercilessly, but the player is free to try again by starting a new game. Scoring is as for the original version of the game, except that words are not removed from the players' lists (if they were, the human player would never have any words left!).
The computer version that I have given you has been handicapped in a few ways (e.g. it doesn't bother with shorter words). Your final version shouldn't be.
In order that you might focus on the most interesting part of the assignment (involving recursion) some of the methods have been written for you, as follows.
public Vector isOnBoard(String wordToCheck) public Vector getAllValidWords(int minimumWordLength)
The hard part is implementing data structures and algorithms to make the computer's search work efficiently. It is easy to get lost in the recursive decomposition and you should think carefully about how to proceed. Bear in mind that you can significantly speed up this algorithm using "pruning" by recognizing when you are going down a dead end, abandoning it, and backtracking to where there are still live alternatives.
For example, if you have built a path starting with "zx", you could use an isPrefix function implemented on your lexicon to determine that there are no words in English beginning with that prefix. If you miss this optimization, you may find yourself taking long coffee breaks while the computer is busy checking out non-existent words like "zxgub" and "zxaep", etc.
Alternatively, if you have traversed your lexicon starting with "ab" and your game board representation is able to tell you there are no paths on the board starting with those letters, you know you don't have to even consider any lexicon words that have "ab" as prefix.
Please note: one implementation of getAllValidWords is to simply run through the dictionary and repeatedly call isOnBoard. This is not a valid solution for this lab (you will get 0 points). Your solution should follow the strategy outlined above.
The file BoggleGUI.java is a GUI application that you can use as a nice interface when testing some things about your Boggle player. Note however that your BogglePlayer class must have the required functionality without the BoggleGUI code present. Also keep in mind that BoggleGUI only knows about 4x4 Boggle boards, and official Boggle dice, while your BogglePlayer needs to be able to handle any square board, and any Strings on the die faces.
The file BoggleGUI.jar is a partially correct solution to the assignment. (It has bugs, and as a player, it it violates the spec by never finding words shorter than 5 or longer than 8 letters, but it lets you find them -- just to give you a fighting chance.)
The BoggleGUI program comes with a main method that will set up the game. You can also pass this method parameters when you run it to set a word file and various game parameters such as minimum word length. Be careful to keep your word file in the same folder as your project because that is where BlueJ will look for it.
Speed matters!
Don't forget that the BoggleGUI is only one possible implementation of a Boggle-style game. Your code must be general. E.g. a "B" program would be able to handle standard boggle dice, but an "A" program should be able to handle any dice. Along those lines, I will use my own program to test your program, so if you alter the BoggleGUI it won't be used when I'm testing your program.
Be aware that where your program runs will make a significant difference in the speed of the program. If you run off the network, for example, your program might take several minutes to run where it might only take a second or two if run off the desktop.
If you test your program in the early stages without using a small lexicon (e.g. 10 words) and a custom board then you are in for trouble. This is also a good time to use BlueJ's ability to run methods individually effectively.
It is virtually essential that you master the debugger on this project. The second part in particular can get very complicated. Once you have your program up and running I will expect that anytime you ask me a question you'll already have the debugger up and will just want me to clarify something or provide a suggestion.
Handing in: As always this is due at the start of the next lab and you should hand in a hard copy in addition to emailing me the java file. Email me only BogglePlayer.java, as an attachment; do not zip or tar. On the hard-copy sign that you followed the honor code for the class.