Java Boggle Code Sample
I wrote this code sample after a recent interview question, to test if the quickly
thought out solution I came up with during the interview would work.
The interview problem was to import a large dictionary of words, and then play the
game "Boggle" with it. Given a specified (or randomly generated) Boggle board, how
many words from the dictionary can be generated using the rules of Boggle
(walking from one character to the next, snaking through the board without
crossing an already used character).
Get the full source code for it here:
Boggle_DPL.zip (209 Kb)
The zip file contains 5 java classes, 2 interfaces, and a large text file
containing the dictionary, contained in 5 java packages.
I came up with the basic idea and pseudo-coded it out in about 30 minutes for the
interview test. Since I wanted to be able to load in the dictionary once, and then
run multiple boggle boards through it, I used a tree structure to store the
dictionary.
After the interview, I coded up the first version as a single java class with
sub-classes, and output to the console, which took about 4 hours. This final
version took another 4 or 5 hours to build, and splits the code into several
separate classes and interfaces. This version shows ideas such as using interfaces
to create delegate classes, and also uses some quick Java Swing UI. It can be run
as either a stand-alone application (through the "main" method in the
"BoggleGameWithMain" class, or a web browser applet (through the
"BoggleGameAsApplet" class).
Though this app is set for 4x4 Boggle boards, that is configurable. There is a
constant (BOARD_SIZE in the BoggleGame class) that sets the board size. If the
board size is set to 4, you will notice a second button for playing a test
board. This runs Boggle on a pre-set board that can spell out a word using
all 16 characters in the board.
The applet version is deployed here below, though most modern browsers will block
it unless you go in to your Java security settings and allow unblocking of applets
from "http://opusgames.com"....
To learn more about the games I've worked on, go to
my Games Page.
To go to my website, go to
OpusGames.com.