Home » Featured, Java

Boggle

8 February 2008 2,181 views No Comment

The Game

Boggle is a word game designed by Allan Turoff. The objective of the game is to construct as many different words as you can from a grid of letters. You can use letters (in positions) that are next to each other – above, below, left, right, diagonal but you can not use the same letter more than once. Each word must be defined in a dictionary. Points are assigned according to the length of the word.

The source code attached here is an implementation of this game in Java. It demonstrates recursion to solve problems like this game. The program attempts to construct words as defined in dic.txt from puzzle.txt. Points are assigned according to the length of the word.

Instructions

To run this program you need JDK 5 or better installed. You can get JDK from here.

  1. Unzip the file. This creates a folder called Boggle
  2. Compile the code: javac src\*.java -d bin
  3. Run the program: java -classpath bin Boggle
C:\Boggle>javac src\*.java  -d bin
 
C:\Boggle>java -classpath bin Boggle
Enter boggle file:
puzzle.txt
Opened puzzle.txt
Enter dictionary name:
dic.txt
Opened dic.txt
Reading files...
Solving...
Word            | Points | Path
----------------+--------+-----------------------
            APR |      1 | [(0,0), (0,1), (0,2)]
      APRTOCFED |     15 | [(0,0), (0,1), (0,2), (1,2), (1,1), (1,0), (2,0), (2,1), (2,2)]
            COT |      1 | [(1,0), (1,1), (1,2)]
            FED |      1 | [(2,0), (2,1), (2,2)]

Attachments

Source code

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.