Your assignment is to code a version of the game "Boggle".
Here is how Boggle is played, in case you haven't ever experienced the Joy of Boggle.
X := Boggle start "execute this with print it menu option"This will start the game and print out the 4x4 grid of letters in the workspace. The (global variable)
startis an object creation protocol.
Boggleobjects is thus going to have to print the grid.
X wordGuess: 'ware'which will add 'ware' to the list of guessed words.
X correctGuessesafter the game is over to return the number of correct guesses. In the middle of a game this method can return anything you want. Also, to be doubly nice, please add a method
Boggle startWithGrid: 'aefnwrpoiymsvexk'to start the game, but with the grid letters as above instead of a random grid. (10-2 clarification: this method is a variation on
start-- it does the same thing but starts with a fixed grid. You could make your start method generate a randon string and call startWithGrid:).
DictFileName. This variable will probably contain just 'dict', but you can make it a full path such as 'b:\oos\assignment2\dict' if you desire.
aStream nextPut: Character cr.will be helpful for printing the Boggle grid: this will put a newline on
[ (Delay forSeconds: 10) wait. Transcript show: 'beep!'; cr ] fork. Transcript show: 'notice how things right after the fork immediately run.';crPaste and execute this code to see what it does. Instead of beeping, you should send a message which ends the game and returns the number of correct guesses.
initializeis executed when that class is filed in. You can do any initialization you want to do there.
dictFileName := 'dict' asFilename. dictStream := dictFileName readStream.opens the filename "dict" as a stream for reading (of class
ReadStream). Note, for this code to work, the filename must be in the same directory/folder as where visualworks was launched from.
dictStream upTo: (Character cr)then returns a string of all the characters up to the next cr on the stream, and
dictStream nextadvances the stream one character.
97 asCharacterreturns the character
$a. The code
97.0 asIntegerreturns 97.
An initial grid of random characters must be generated. A list of word guesses must be maintained during the game play, and both checked against the 4x4 grid to make sure the word occurs, and checked against a dictionary, at the end of the game. Checking a word against the grid will require finding all possible starting points for the word and traversing from there in all possible next directions to see if there is any direction to proceed for match. . . .Try to keep your design and final code as close to the object-spirit of the informal English as you can. For instance,
nextDirectionscould be a method which returned
aListof all the
gridLocation's that can be reached from the
currentGridLocation. Also, make
Gridbe unique classes -- it is good not to overload the "main" class (
Bogglehere) with too much functionality.
At this point in your Smalltalk coding career, it is good to go overboard with keeping to the spirit of the high-level description -- make method names as evocative as possible, and make a class for every different possible object-concept.
Please use hashing to implement a fast word dictionary lookup (big hint:
Sets use hashing for lookup...).
See the coding style suggestions in lecture. You will be expected to follow those points.
For your code, use the file out as.. menu option on the class
category list to file out
your class category as
Assignment2.st, and then submit
this file from hops via the precise (no exceptions in names,
please) hops command
~scott/bin/submit Assignment2 Assignment2.st(The general format for this command is the name of the assignment followed by the file(s) submitted)
You will need to ftp your files to hops first if you are working on some other machine.
Don't submit a
.im file, they are too
big! Use the file in/out tool instead.
You can check what files you submitted via
~scott/bin/queryAll of your solutions should work in VisualWorks Smalltalk 3.0.