2014-11-25 HW (vacation)

posted Nov 24, 2014, 5:57 PM by Samuel Konstantinovich   [ updated Nov 24, 2014, 8:41 PM ]
This documents the final required revisions to your WordSearch. 

-The deadline is Tuesday December 2nd 11:59pm. (That what due by Wednesday means)
-You have a lot of time to complete this, please do not slack off. 
-I expect to see your git commits and pushes regularly. Lack of commits can and will be used to reduce points of the project... so don't just do it without github and commit a working version. I am not trying to hurt your grade, I am trying to encourage you to use github properly.


Overview of new main behavior:
java Driver rows cols randomSeed answers
1. rows and cols are the dimension of the puzzle.
2. The randomSeed can be changed to force the same puzzle to occur again.
3. Only if the randomSeed is provided, should you be able to trigger answer mode by passing the value 1 into the answers parameter. All other values will be a normal puzzle, and not show the answer.

so:

java Driver 20 30 124850 0 would print the 20x30 puzzle seeded by 124850, including which words are inside the puzzle. 
java Driver 20 30 124850 1 would print the answer key for the 20x30  puzzle seeded by 124850    (both of these will match)

java Driver 10 20 8230 123 would print the 10x20  puzzle seeded by 8230
java Driver 10 20 8230     would print the 10x20  puzzle seeded by 8230  (both of these will match)

Changing the dimensions or wordlist, even by a single number or word, will cause a completely different puzzle. 

Example: 

(because of outdated terminal limitations, I try to keep the lines < 80 characters long. Clearly we can make our terminals wider, but this avoids the requirement to resize. You should keep things from getting too wide.)

$ java Driver 12 18 42308
Find these words:
      zonae           zymurgy          zinckier            zither
    zouaves             zooms           zorilla           zipless
    zigzags            zizzes         zoologist            zooeas
    zooming             zoeal             zitty            zinebs
     zorros            zygoma           zoccolo           zoysias
     zonked            zipped           zechins            zoccos
    zoecium             zooey             zorch             zupas
r g n i m o o z r e h t i z e h v y
x l e z o r c h i l e o l o c c o z
e s t y i z e z s n a a z o e a l i
z z z t z y w i g a n z e c h i n s
o i o t o m d p k z o e c i u m f d
o p y i r u e p h c z f s e z z i z
m l s z r r k e c g n l q b h m o t
s e i u o g n d t k m i s a e o o z
l s a p s y o s o c c o z q b n r f
z s s a l d z z o o l o g i s t i g
g d z s e v a u o z i g z a g s n z
z o o e y a l l i r o z a m o g y z


Now with the same seed (42308) I can generate an answer:
$ java Driver 12 18 42308 1  
Findd these words:
      zonae           zymurgy          zinckier            zither
    zouaves             zooms           zorilla           zipless
    zigzags            zizzes         zoologist            zooeas
    zooming             zoeal             zitty            zinebs
     zorros            zygoma           zoccolo           zoysias
     zonked            zipped           zechins            zoccos
    zoecium             zooey             zorch             zupas
_ g n i m o o z r e h t i z _ _ _ _
_ _ _ z o r c h _ _ e o l o c c o z
_ _ _ y _ z e z _ _ a _ z o e a l _
z z z t z y _ i _ _ n z e c h i n s
o i o t o m d p k z o e c i u m _ _
o p y i r u e p _ c z _ s e z z i z
m l s z r r k e _ _ n _ _ b _ _ _ _
s e i u o g n d _ _ _ i s a e o o z
_ s a p s y o s o c c o z _ _ n _ _
_ s s a _ _ z z o o l o g i s t i _
_ _ _ s e v a u o z i g z a g s _ z
z o o e y a l l i r o z a m o g y z

4. The main will pass the fileName of the list of words into the constructor as well. 

Your main will look like this:

public static void main(String[]args){
   /*this is the "NEW SECTION" 
    *
    *This is where you need to write something in order
    *to get the values from args, OR decide to use default values 
    */
    WordGrid w = new WordGrid( /*some stuff from NEW SECTION*/ );
    if(you need to change the random seed){  /*see more notes on this later*/
      w.setSeed( ??? );  
    }
    w.loadWordsFromFile("fileNameYouMade.txt", /*something from NEW SECTION*/ );
    System.out.println( "Find these words:\n"+ w.wordsInPuzzle() );
    System.out.println( w );
}
That is all! So easy. But wait... how does that load the words? This means your main is merely to handle parameter passing from the terminal to the constructor. All logic should be handled internal to your class!!!

THINGS YOU ARE WRITING:

New Instance Variables:
1. Make a Random as part of your WordGrid class. This will make it really easy to reproduce things, just use that random anytime you need to generate random numbers. 
2. Make something to store the words you successfully added to your WordGrid.

New Constructor Parts: 
3. Make sure your constructor initializes the new instance variables


New Required Methods:
4.
public void loadWordsFromFile(String fileName, boolean fillRandomLetters)
    -filename is used to tell the WordGrid from which file to read all of the words.
    -fillRandomLetters is used to determine if you need to fill it up or not. If there are 4 arguments, look at the 4th one to determine this boolean. A '1' means this should be false, otherwise If the value is not '1' or there aren't enough parameters you assume that you DO want to fill in the letters, and default the value to true

5. public String wordsInPuzzle()
    -Return a formatted string of text that has several words per line. This will require you to keep track of the added words.

6. public void setSeed(long seed)
    -Mutator that changes the random seed of your Random object. Call this method before you add words to predict the way they are added!

Regarding Randoms and seeds:
 Random rng = new Random(seed);

Is equivalent to:

 Random rng = new Random();
 rng.setSeed(seed);
The 2nd method allows you to only set the seed in some instances, and not others. This allows the default behavior of different seeds all the time to be used unless a seed is specified. 


Methods that would be very useful:
7. addManyWordsToList ( ArrayList<String> allWords )









Comments