CPE 103

Boggle Checker

Overview

Imagine you are part of a team developing a computer-based variation of the board game Boggle (Weiss exercise 10.12).  Boggle is a word game consisting of NxN grid of six-sided die where each side of a die has a different upper case letter on it.  By shaking up the grid of die you end of with a random NxN grid of letters something like this:

X Q A E
Z O T S
I N D L
Y R U K

Next the players write down all of the words they find in the grid subject to the constraint that two adjacent letters in the word must be adjacent in the grid (i.e., north, south, east, or west of each other).  Each letter in the grid can be used at most once per word. The goal is to find the most words that no other player has found. A word must have more than one letter.
 
Your assignment on the team is to develop the word verification routine.  When a player guesses word, you have to determine if the word they guessed actually exists in the board.

Write a boolean function called checkWord that has a single String parameter representing the word to look for in the Boggle board.  Return true if the word is found in the board (doesn't have to be an actual English word). You may write private helper methods if you choose.

Problem Requirements

Write a program to perform word verification for a Boggle game. 

You must follow this Java class definition:


public class BoggleChecker
{

/** Set the board for this checker.
 * @param board a String containing the letters in a 4x4 or 5x5 board
 * in row-major order. 

 * @pre board.length() is 16 or 25.
 * @pre board contains only upper case letters.
 */
public void setBoard(String board)

/** Determine if the given word exists in the current Boggle board.
 * @param word is a player's guess
 * @pre word contains only letters
 * @pre word.length() > 1
 * @pre a board has been set for this checker.
 */

public boolean checkWord(String word)

}

Note: Please design your own solution. While this algorithm is easy to find on the Web or in textbooks, please write your own algorithm from scratch.  Do not use the internet or other resources for any purpose related to games.  

Design constraints

There must be no redundant code in your solution.

Unit Testing

Write a JUnit test class for BoggleChecker that demonstrates at least the following test cases.

Given this 4x4 board,

X Q A E
Z O T S
I N D L
Y R U K

checkWord()
should be able to find XQAESLKURYIZ, DNOT, NIZOTS, KUDL, STONI, SEAT, ONIYR, ZONIY
but fail to find MY, SEAN, SETS, TOO, DOT

Given this 5x5 board,

X Q A D E 
Z O T I S
I N D O L
Y R U N B
F A E H K

checkWord() should be able to find ZOTIS, SIT, LOIS
but fail to find DOT, SLOB