Course Home | Homework | Lab Hours | Programming | Schedule & Lecture Notes | Submit

Saint Louis University

Computer Science 150
Introduction to Computer Science

Michael Goldwasser

Fall 2005

Dept. of Math & Computer Science

Programming Assignment 08

Boggle

Due: 8:00pm, Monday 12 December 2005


Contents:


Overview

Our goal is to design a program to simulate a game of Boggle. The program will display a randomly chosen board, allow the user to enter as many words as he or she can find. The software will check that each entered word is legitimate. When the user is done entering words, the software should also produce a list of all other words which could have been found on that board.

Newly Introduced Techniques


Collaboration Policy

For this assignment, you are allowed to work with one other student if you wish (in fact, we suggest that you do so). If any student wishes to have a partner but has not been able to locate one, please let the instructor know so that we can match up partners.

Please make sure you adhere to the policies on academic integrity in this regard.


Files You Will Need

To get the needed files, type the following from your working directory for this assignment:
ln -s /home/home0/goldwasser/lib/boggleUtil.py .
ln -s /home/home0/goldwasser/lib/bogshort.txt .
ln -s /home/home0/goldwasser/lib/boglong.txt .

The first of these are some utilties we have written to generate new boards and to display them (details below). The last two of these files are dictionaries. bogshort.txt contains 19912 words (most common words, but not plurals of nouns, or varying tenses of verbs). boglong.txt contains 117661 words and is much more complete (this is purported to be the official scrabble dictionary).


Rules

A Boggle board is comprised of 16 dice. Each side of a die is typically marked with a single letter from the English alphabet, though one dice has a side marked with 'Qu' (more about this later). To start the game, the dice are shaken up and then placed in a 4x4 grid. An example of such a game board is shown here.

A player is then asked to find as many words as possible on the game board. A word can be find by stepping from die to neighboring die, where this step can either be horizontal, vertical or diagonal. Such a path must be found so as to spell the word from beginning to end. Moreso, you may not use the same die twice when spelling a single word.

For example, the word WALK can be found as shown in the following figure.

The word CRIER could also be formed, by starting at the top-right corner. Note that the letter 'R' is used twice, yet this is legal so long as we use two different dice (thus using the top-left corner of the board for the final 'R' in this example). Notice that we cannot form the word DAD in this puzzle, as that would require us to use the same die twice.

The goal of the player is to list as many words as possible which can be found on the board. More formally, for a player to get credit for a word, the following conditions must be satisfied:

In the multiplayer version of Boggle, players only get credit for words which they find that are not found by any other players. In our one-player version, we will let the human player take the first turn, getting credit for all words he or she finds; then we let the computer take the second turn, taking credit for all remaining words not used by the player. The scoring for the official game gives more points for longer words, based upon the following formula:

Number of letters 3 4 5 6 7 8 or more
Points awarded 1 1 2 3 5 11


Sample Round

Here is a sample run of our program. Note that your program does not need to match the precise formatting shown here, but this should demonstrate the spirit of the game and the expected interactions.

Welcome to Boggle.
What is the name of the wordlist file? [default: bogsmall.txt] 
What board number? [default: random] 180
R  Qu I  C 
U  E  R  O 
I  W  Y  K 
T  D  A  L 

Please enter words, one per line.  When you are done enter a blank line.

walk
lad
tie
die
or
  -- Words must use at least three letters.
ore
core
rice
  -- Sorry.  That word cannot be formed on the gameboard.
york
  -- Sorry.  That word is not in the wordfile.
cork
quirk
rock
  -- Sorry.  That word cannot be formed on the gameboard.
lawyer
law
yore
ore
  -- You already used that word.
year
  -- Sorry.  That word cannot be formed on the gameboard.
daddy
  -- Sorry.  That word cannot be formed on the gameboard.
day
way
tie
  -- You already used that word.
wit

------------------------------------------
Player used 598.168277 seconds.
You found 14 words worth a total of 17 points.
core
cork
day
die
lad
law
lawyer
ore
quirk
tie
walk
way
wit
yore

Now it is the computer's turn...
------------------------------------------
Computer used 0.487780 seconds.
The computer found 32 additional words for 39 points.
adieu
awe
awry
aye
coy
crew
cry
dye
dyer
ire
irk
kayo
lady
lay
lye
lyric
okay
query
quirky
royal
rue
rye
tid
tidal
tidy
tier
wad
wadi
weir
wry
yak
yaw

------------------------------------------
Would you like to play again? [default: Y] n
Okay. Thanks for playing!

Data Structures

We will be starting you off with some utilities for generating and representing a game board. The game board is viewed as a two-dimensional structure. This can be naturally modeled in Python as a list of lists That is the board can be thought of as a list of columns, where each column is then a list of dice. For example, on the board diagramed earlier in this description, the first column can be viewed as a list ['R','U','I','T'], the next column as ['Qu','E','W','D'], and so on. The overall board is then a list comprised of the four columns.

Syntactically, if we have a variable board representing such a list of lists, then we can refer to an individual die using a syntax such as board[2][3] which is the die 'A' in our example. Namely, the simpler expression, board[2] would represent the column ['I', 'R', 'Y', 'A'] (as the columns are indexed starting with zero). Given that board[2] evaluates to this list, we can then index into that list, so that board[2][3] results in the 'A'.

Given such a representation of a board, I have provided three utility functions for you to use:

Rather than representing the board directly as such a two-dimensional list of strings, we have created a class Die to represent each of the dice. The operations supported by a die are:


Advice

The major challenges are:


Submitting Your Assignment

You should submit your new file, boggle.py, which contains all of your own code. This file must be submitted electronically.

You should also submit a separate 'readme' text file, as outlined in the general webpage on programming assignments.

Please see details regarding the submission process from the general programming web page, as well as a discussion of the late policy.


Extra Credit (1 point)

Write the efficient version of the software for finding all possible words on the board, using the path-based search rather than the word-based search, as described above.


Michael Goldwasser
Last modified: Wednesday, 07 December 2005