Class BoggleModel

java.lang.Object
  extended by BoggleModel

public class BoggleModel
extends java.lang.Object


Constructor Summary
BoggleModel(BoggleBoard b, ILexicon lex)
          Construct the model from a board and a lexicon.
 
Method Summary
 int boardSize()
          Returns the size of the model's board, currently all boards are square.
 java.util.List<BoardCell> cellsForWord(java.lang.String word)
          Return a list of BoardCell objects corresponding to a word on the model's board.
 java.lang.String getFace(int row, int col)
          Return a string representing the face of a Boggle cube at the specified position on the model's current board.
 java.util.Iterator<java.lang.String> getLexiconIterator()
          Return an iterator over the model's lexicon.
 int getScore(java.lang.String s)
          Return the score for specific string according to standard rules of Boggle.
 void load(java.util.Scanner s)
          Load the lexicon with words, thus the model will have a potentially new source of words other than the source with which it was constructed.
 void makeBoard(int size)
          Generate a new board of the specified size (boards are square).
 void setFinder(IWordOnBoardFinder finder)
          Supply the model with an object that finds words on the model's board, and thus allows games/players to access the cells of a word on a board via the method cellsForWord
 LexStatus wordStatus(java.lang.String s)
          Return the status of a string, i.e., one of LexStatus.WORD, LexStatus.PREFIX or LexStatus.NOT_WORD.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BoggleModel

public BoggleModel(BoggleBoard b,
                   ILexicon lex)
Construct the model from a board and a lexicon.

Parameters:
b - is the initial board for this model
lex - is the lexicon used by the model
Method Detail

setFinder

public void setFinder(IWordOnBoardFinder finder)
Supply the model with an object that finds words on the model's board, and thus allows games/players to access the cells of a word on a board via the method cellsForWord

Parameters:
finder - is the new word finder used by the model

getFace

public java.lang.String getFace(int row,
                                int col)
Return a string representing the face of a Boggle cube at the specified position on the model's current board. The string is one character unless the corresponding cube stores "Qu" in which case the string is two-characters in length.

Parameters:
row - specifies location on current board
col - specifies column of location on current board
Returns:
string on face specified by row,column
Throws:
java.lang.ArrayIndexOutOfBoundsException - if row and col aren't valid for the model's current board

load

public void load(java.util.Scanner s)
Load the lexicon with words, thus the model will have a potentially new source of words other than the source with which it was constructed.

Parameters:
s - is the source of the words for the model's lexicon

cellsForWord

public java.util.List<BoardCell> cellsForWord(java.lang.String word)
Return a list of BoardCell objects corresponding to a word on the model's board. See IWordOnBoardFinder for complete documentation of the order of the cells returned in the list. This method doesn't check the lexicon, just the board as a source for the word.

Parameters:
word - is the string being checked on the board to see if it can be formed from adjacent board cells
Returns:
a list of BoardCell objects corresponding to the word, or null if the word cannot be formed on the model's board

boardSize

public int boardSize()
Returns the size of the model's board, currently all boards are square.

Returns:
the size, e.g., one dimension like rows, of the model's current board

wordStatus

public LexStatus wordStatus(java.lang.String s)
Return the status of a string, i.e., one of LexStatus.WORD, LexStatus.PREFIX or LexStatus.NOT_WORD. See LexStatus for documentation on these values.

Parameters:
s - is string/word whose status is returned
Returns:
status of s according to the model's lexicon

getLexiconIterator

public java.util.Iterator<java.lang.String> getLexiconIterator()
Return an iterator over the model's lexicon.

Returns:
iterator for model's lexicon

makeBoard

public void makeBoard(int size)
Generate a new board of the specified size (boards are square). The BoggleBoardFactory may only support certain sizes of boards.

Parameters:
size - is number of rows, e.g., the size of one dimension of the board being generated

getScore

public int getScore(java.lang.String s)
Return the score for specific string according to standard rules of Boggle. No check is made to see if the word is in the lexicon or on the board. The score depends on the size of the board in that for 5x5 boards words must be 4-letters or longer wherease for 4x4 boards the minimal length is three.

Parameters:
s - is word whose score is returned
Returns:
score of s according to standard Boggle rules