|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcmsc433.p3.Grid
public class Grid
The Grid class is a matrix of letters which are intended
to form words. Words are constructed as paths through the matrix. A
solution to a grid is simply a list of (nonoverlapping) paths that
correspond to words in a dictionary. The score of a solution depends
on the length of the word, and the frequency of words of that length
in the given dictionary.
This class is immutable, and so is thread-safe.
| Method Summary | |
|---|---|
void |
display(Solution sol)
This method displays the grid using the Swing GUI library, along with a depiction of the given solution. |
char |
get(int row,
int col)
Provides the character at the given row,col coordinates |
java.lang.String |
getWord(Path path)
Returns the word corresponding to the given path. |
java.awt.Color |
intToColor(int id)
|
static Grid |
makeGrid(java.lang.String file)
This factory method constructs a Grid object from the
contents of the given file. |
int |
numCols()
Provides the number of columns in this grid |
int |
numRows()
Provides the number of rows in this grid. |
int |
score(Dictionary dict,
Solution sol)
Computes the score of the given Solution. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static Grid makeGrid(java.lang.String file)
Grid object from the
contents of the given file. The file is expected to formatted as a series of
rows of characters; each row in the file corresponds to a row in the
grid.
file - - a text file containing (equal-length) rows of characters
Grid object representing the contents of the filepublic int numRows()
public int numCols()
public char get(int row,
int col)
row - - the row of the charactercol - - the column of the character
public java.lang.String getWord(Path path)
path - - a Path object
public int score(Dictionary dict,
Solution sol)
dict - - the dictionary of words to use for scoringsol - - the solution to score
public void display(Solution sol)
sol - public java.awt.Color intToColor(int id)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||