CS 0401 – Project 5: Boggle

Due: Monday, July 27, 2015 by Midnight

Boggle is a word game where you attempt to make words out of a grid of letters. We will be making a simplified version of the game.

The game

The game is played with a 4x4 grid of random letters. The real game uses the most common letters to make it easy to find words. We will use a purely random approach, and as such, our boards will sometimes be very hard to play.

 

Legal words:

·      Are at least three letters long

·      Have all letters in the word as neighbors in the grid (up/down, left/right, or diagonally)

·      Don’t use a single letter from the grid more than once

·      In the dictionary

·      Haven’t been already guessed

 

After we generate a board and display it, we will prompt the user to enter their first word. Your code must validate the word according to the five rules above.

 

I am providing a dictionary of legal words. The dictionary is a file with over 230,000 words of 3 or more letters that are listed, one per line, in alphabetical order. You will need to read this list in and search it.

 

A valid guess will be scored using the letter point total from Scrabble. Go through each letter and add up that letter’s value according to the table below:

 

A

B

C

D

E

F

G

H

I

J

1

3

3

2

1

4

2

4

1

8

K

L

M

N

O

P

Q

R

S

T

5

1

3

1

1

3

10

1

1

1

U

V

W

X

Y

Z

 

1

4

4

8

4

10

 

The normal boggle game is timed, but our simplified (yet harder) version will not be. Instead, we will end the game when the user enters “q”.

 

At the end of the game, the total score will be compared to a file that contains the ten (at most) top scores ever. If the user’s score is good enough to be in the top ten, ask them for their initials, and save the new top ten scores out to the file.

The program

 

$ java Boggle

O T H U

J X P N

W A W Y

E U Y T

 

way

WAY scored 9 points. Your total score is 9

jaw

JAW scored 13 points. Your total score is 22

yaw

YAW scored 9 points. Your total score is 31

wax

WAX scored 13 points. Your total score is 44

Q

44 points is a new high score! Enter your initials: JRM

 

Requirements and Hints

 

·      Read in the dictionary into an ArrayList. Do not assume the size of the word file in your code.

·      Use Arrays.binarySearch to find if the guess is in the dictionary. You probably want to do this in a case-insensitive way. Look at the overload: http://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html#binarySearch%28T[],%20T,%20java.util.Comparator%29

o   String already has a case insensitive comparator: String.CASE_INSENSITIVE_ORDER

o   Use the toArray() method on your ArrayList to convert it to an array. Use the overload where you pass it the array of the type you want.

·      You might want to consider the MVC pattern since we have a similar setup as with Mastermind. If you decide to forgo the controller, at least have a model that contains the board and can validate the word being connected in the grid of letters along with a toString() method that displays the board.

o   A StringBuilder would be useful for that toString() method

·      I might be a masochist, but I used recursion to validate the word was made from connected letters on the board. I’m sure there’s an iterative way too.

Submission

Create a Boggle.zip file that contains your .java files. Upload it to the submission website as we have been doing with labs. Make sure to do this prior to the deadline. No late work is accepted.

 

If, prior to the deadline, you realize that you need to submit a different version of your code, name it Boggle-2.zip. (You can add new numbers as necessary, but try not to submit many times.)

 

We will grade the last submission that was prior to the deadline.