Overview | Schedule | Resources | Assignments | Home |
Stores a two-dimensional grid of characters for use in a word search game. The grid may be generated randomly or read from a file.
Constructor Summary | |
Grid(Infile in)
Construct a Grid by reading lines from a text file. |
|
Grid(int rows,
int cols) Construct a randomly-generated Grid of the given size. |
Method Summary | |
java.lang.String |
chars(int row,
int col, int dir) Extract characters from this Grid starting at the given row and column and heading in the given direction: 0 is right, 1 is down-right, 2 is down, 3 is down-left, 4 is left, 5 is up-left, 6 is up, and 7 is up-right. |
int |
cols()
Get the number of columns in this Grid. |
void |
display() Print this Grid on the system console. |
int |
rows()
Get the number of rows in this Grid. |
Constructor Detail |
public Grid(Infile in)
in
- The Infile from which to read. The
number of rows will be the number of lines read from the
file; the number of columns will be the number of
characters in the shortest line (longer lines will be
truncated).public Grid(int rows, int cols)
rows
-cols
-Method Detail |
public java.lang.String chars(int row, int col, int dir)
row
- The starting row (0 ..
rows()-1)col
- The starting column (0 ..
cols()-1)dir
- The direction (0 .. 7)public int cols()
public void display()
public int rows()
Word list format:
http://wordlist.sourceforge.net/
,
which provides a variety of word lists (American,
British, and Canadian variants, plus a common English
core) over a range of levels (starting from a small list
of the 5000 most common words up to the "insane" list of
more than 600,000). The word list we are using is a
concatenation of 16 of these lists (so the file is
actually made up of 16 sorted blocks of varying sizes),
with about 112,000 words (including American variants);
it has been processed to remove words shorter than four
letters (since there would be too many matches for the
shortest words in a letter grid), as well as words with
apostrophes or accented characters.The suggested algorithm:
chars
method of the Grid object to extract
all of the characters in that direction.substring
method), check whether it is a
word in the word list (again, with the sizes involved,
you will not want to use a linear search). If it is,
print it out on the console.The WordSearch project:
http://www.armoredpenguin.com/wordsearch/
,
using words from the chapter headings of the textbook).
If my model solution is correct (and I believe it is),
you should find 341 words (some will be duplicates, since
a word such as "noon" will be found twice, and several
words actually occur several times at different places in
the grid).pecnyscdgbaeeelvokfe aetiylgneeageioorpml selhfdoiniciursniriv tmmdromngrengdcaevgh etirzbieeatennnhrgio hxitntphsnsempqihrdh agaeyetrsetcfseidrio raeihwlcvbsruoypoers pabratbhognasrlnnatv coohaentolssaonzddsn srutomsitbcnacsrpklk ietrretealdlnastseei strevekmfaavnvlasnul oeaulsttihvveneeaius idnnbsceiayncawrtiue aancyrescorlnerbeegs dnjacibtmmcnsinlsegg esnaiincrogailgnrhat rnyiuttrmhsplraereun hronlirenzleoiondvse past paste sync lone nine gigs arris viol rite zoon eaten enol nide herm ohos harp ends dirt tend tends dies read bots ours your yours ordo pour brat bout sang rand outran hues slot rete toms tret mare stob blah nary scan tels rete rete read teal slew stre else vest ever evert asks sate sates seem test earl ewes ates sues deter tass ewes etas gere cite come nape silo seta nays glia tahr homo soms earl rear lire linnOne potential enhancement is to collect the list of found words and sort it before printing it out, but this is not required (though it should be easy to reuse the WordList class for this purpose).
Standards:
Your project should be well-written, neatly-formatted, modular, and well-documented.
Grading:
Overview | Schedule | Resources | Assignments | Home |
DePauw
University, Computer Science
Department, Spring 2005
Maintained by Brian Howard (bhoward@depauw.edu
).
Last updated