Assignment Intro James Wei Professor Peck March 26 2014 Slides by James Wei Outline A look at Boggle Classes of Boggle Understanding the design Implementing a word finder Implementing a lexicon ID: 176146
Download Presentation The PPT/PDF document "Boggle" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
BoggleAssignment Intro
James WeiProfessor PeckMarch 26, 2014
Slides by James WeiSlide2
Outline
A look at BoggleClasses of BoggleUnderstanding the designImplementing a word finder
Implementing a lexicon
Implementing an
autoplayer
Analysis
Grading
SummarySlide3
A look at Boggle
We are creating AI to play the game BoggleThe AI will make use of three main tools to find words on a boggle board:A lexicon
for knowing which words are valid
A
word finder
for searching for a specific word on the board
An
autoplayer
for searching the board for words
We will also analyze different implementations of these tools to see which ones are better
Sample
playthroughSlide4
Classes of Boggle
The (more important) classes of Boggle:BoggleMain – runs Boggle
IWordOnBoardFinder
– interface for finding the position of a single word on a Boggle board
ILexicon
– interface for a
list of
all valid words and the ability to query for them
IAutoPlayer
– interface for an AI Boggle player
LexiconBenchmark
– performs stress and correctness tests on Lexicon implementations
BoggleStats
– compares performance for different lexicon/
autoplayer
combinations
TestLexicon
/
TestWordFinder
– test your codeSlide5
Understanding the Design
Boggle is a great example of the uses of inheritance! You will write multiple implementations for various interfaces.As mentioned before, these interfaces include:ILexicon
IWordOnBoardFinder
IAutoPlayerSlide6
Understanding the Design
Steps to Boggle:Player enters a guessComputer looks for word and highlights if foundWhen time runs out, computer looks for all
valid words
on board
Computer lists out
all valid wordsSlide7
Understanding the Design
Break it down—what tasks must we be able to handle (and what’s handled for us)?Given a String, determine if it is a wordGiven a word, determine its exists
on the board
Given a board, find all valid words in it
Framework for playing the game is givenSlide8
Understanding the Design
Break it down—what tools will handle each individual task?We determine if a String is a valid word using a lexicon, as defined by ILexicon
We search boards for individual words and obtain the positions of those words with a word finder, as defined by
IWordOnBoardFinder
We determine the entire list of words on a board by using an
autoplayer
, as defined by
IAutoPlayerSlide9
Understanding the Design
What are we given? What will we write?Lexicons: we start with SimpleLexicon, which holds a dictionary as a list of Strings,
and
TrieLexicon
, which uses tries (a variant of a tree) to organize
words
We will write
BinarySearchLexicon
, which uses binary search to make querying the lexicon faster
For
extra credit
, you may also write
CompressedTrieLexicon
, which is a more optimized implementation of
TrieLexiconSlide10
Understanding the DesignSlide11
Understanding the Design
What are we given? What will we write?Word Finders: we start with our so-called BadWordOnBoardFinder, which employs the beautiful strategy of always returning nothing
We will write
GoodWordOnBoardFinder
, which uses recursive backtracking to find the cells at which a word can be found on the boardSlide12
Understanding the Design
What are we given? What will we write?AutoPlayers: we have LexiconFirstAutoPlayer, which relies on a working implementation of
IWordOnBoardFinder
to search the board for every possible word in the lexicon
We will write
BoardFirstAutoPlayer
, which uses recursive backtracking to search the board for all of valid words, instead of searching the board for each word in the lexicon specificallySlide13
Understanding the DesignSlide14
Implementation – Lexicon
Look at BinarySearchLexicon. Most methods are already implemented for you, but you must complete one:
LexStatus
wordStatus
(String)
wordStatus
must
:
Use binary search to see if the string exists in the
lexicon (use
Collections.binarySearch
, check online for documentation on its usage)
Determine
if a string that is not found is a PREFIX by finding the word in the lexicon which would succeed it if inserted and seeing if the string is a prefix to that wordSlide15
Implementation – Lexicon
What’s a LexStatus?It’s an
enum
, aka a special data type which must take one of several predefined constants
Our
enum
has three values:
LexStatus.WORD
LexStatus.PREFIX
LexStatus.NOT_WORD
More on
enums
:
http
://docs.oracle.com/javase/tutorial/java/javaOO/enum.htmlSlide16
Implementation – Word Finder
Look at IWordOnBoardFinder—there is one method to implement in this interface
List<
BoardCell
>
cellsForWord
(
BoggleBoard
, String)
cellsForWord
must:
Use recursive backtracking to find the cells in which a word on the board is found
Return a
List
of
BoardCell
objects which represent
the position of each letter
on the board in order
Hints to get started: what is the base case? What about the recursive step?Slide17
Implementation – Word Finder
Two other classes to consider here, BoggleBoard and
BoardCell
, which are java objects representing the board and cell
BoggleBoard
is implemented as a String array showing the faces of the board
So this board to the right is
represented by the String array:
[“LORE”, “LTSR”, “AOSP”,
“MOTG”]
BoardCell
represents the position
of one cell on the board—does not
store the cell’s value!Slide18
Implementation – AutoPlayer
Look at BoardFirstAutoPlayer. Most methods are already implemented for you, but you must complete one:
void
findAllValidWords
(
BoggleBoard
,
ILexicon
,
int
)
findAllValidWords
must:
Iterate over all cells on a board for use as a “start”
For each starting cell, use recursive backtracking to find every word starting at that cell
Use an
ILexicon
to determine hits and base cases
Use the
IPlayer
add method to mark found wordsSlide19
Analysis
When you finish coding the assignment, you will have three (four with extra credit) lexicon implementations and two autoplayersNow the question is—which ones are better?
You will analyze your different implementations using the
BoggleStats
class we have provided for youSlide20
Analysis
How to use BoggleStats? Pretty easy…
main method calls
runTests
, which calls
doTests
doTests
will create two
autoplayers
, a
LexiconFirst
and a
BoardFirst
, then it will use each
autoplayer
to find all valid words on a series of randomly generated boards
The Lexicon used by
BoggleStats
is passed in to
doTests
as an argument
You may change the instance variable NUM_TRIALS as appropriate
You will need to modify
doTests
to return the highest scoring board for part of the analysisSlide21
Analysis
Your analysis has a few parts:Compare running different autoplayers
with different lexicons (with at least 500 trials per combination). Include both empirical data AND code analysis!
Play lots of auto-games—start with 100, then 1,000, 10,000, 50,000. Use your findings to predict how long it’d take for 100,000 and 1,000,000 games
In your 10,000 auto-games, print out the Boggle board you find with the highest score (and the score)
Run these tests for both 4x4 and 5x5 boardsSlide22
Grading
Your grade is based on:Code (16 pts
+ 1 E.C.):
Word finder code passes tests
Lexicon code passes tests
Functional
autoplayer
CompressedTrieLexicon
implementation (extra credit)
Analysis (4
pts
):
All combinations of
autoplayers
and lexicons
Sufficient number of trials per combination (500 bare minimum, likely need more for other parts of analysis)
High scores for 4x4 and 5x5 board sizes, and the boards corresponding to those scoresSlide23
Wrap-Up
Recommended plan of attack?Start by looking over everything, understanding the classes and the program design
Implement
BinarySearchLexicon
;
test with
TestLexicon
which is provided
Implement
GoodWordOnBoardFinder
(you need to make this class yourself); test with
TestWordFinder
Modify
BoggleMain
to use your new word finder and try playing Boggle
Implement
BoardFirstAutoPlayer
; try playing Boggle with this
autoplayerSlide24
Wrap-Up
Recommended plan of attack?Check your BoardFirstAutoPlayer
by running
BoggleStats
with 100+ trials; your
autoplayer
should find the same number of words in every board as
LexiconFirstAutoPlayer
Using
BoggleStats
, try running large numbers of
autoplayer
games using all combinations of lexicons and
autoplayers
In your analysis, compare performance of different lexicon/
autoplayer
combinations; make sure to include both empirical data and code analysis
For
extra credit
, implement
CompressedTrieLexicon
and include it in your analysisSlide25
One Last Thing…
Start early! Seriously. Or you’ll be sadder than this woman:Slide26
Good luck!
Start early!