public class Grid
extends java.lang.Object
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.| Modifier and Type | Method and Description |
|---|---|
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,
java.util.List<Path> sol)
Computes the score of the given Solution.
|
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 charactersGrid 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 characterpublic java.lang.String getWord(Path path)
path - - a Path objectpublic int score(Dictionary dict, java.util.List<Path> sol)
dict - - the dictionary of words to use for scoringsol - - the solution to scorepublic void display(Solution sol)
sol - public java.awt.Color intToColor(int id)