Goblins are notorious for both their thieving skills and their riddle games. For example, some days when you came home there's a goblin stealing your ramen noodles. If you catch him at it, he always challenges you to a riddle game for your dinner. Unfortunately, goblins like to cheat! Heres a typical evening discussion:
Goblin: I'm thinking of a six letter word from this list: peanut, slower, packet, faster, parcel. You can guess one letter at a time and Ill tell you if its in the word and where. You can only guess wrong twice.
< The goblin isn't really thinking of a word, hes going to change his answer to win the game. >
You: "l"
Goblin: Nope! One wrong guess left!
< The goblin looked at his list and decided there were more words without an "l". So he's going to use one of the following: peanut, packet, faster >
You: "p"
Goblin: Yeah, there's a "p" here: p - - - - -
< The goblin looked at his list of words and decided that there were more words with p in the first position. So he's going to use one of the following: peanut, packet >
You: "n"
Goblin: Nope! I win! Ramen is mine now.
< The goblin disappears in a puff of smoke with your dinner. >
You have so much fun playing this game that you decide to recreate the experience for others. This is the game we're going to be creating.
Differences between the scenario above and the game you are writing:
1. The virtual goblin will be using a much larger list (he'll be reading words in from a provided dictionary).
2. The virtual goblin will say very specific things during the game which you must make match the sample runs for full credit.
3. In "debug mode" youll be able to see the goblins current list of words, but usually you wont have that.
4. The number of letters in the word and the number of guesses will be set by a command line argument.
5. For simplicity, the goblin will not use words which contain duplicate letters.
Note: In the below examples, user input is shown in green highlight and underlined.
Sample Run
> java GoblinGame ..\dictionary-mini.txt 6 2
Goblin says "Guess a letter": l
Goblin says "No dice! 1 wrong guesses left..."
Goblin says "Guess a letter": p
Goblin says "Yeah, yeah, it's like this: p-----"
Goblin says "Guess a letter": n
Goblin says "No dice! 0 wrong guesses left..."
Goblin says "I win! I was thinking of the word 'packet'
Your stuff is all mine... I'll come back for more soon!"
Sample Run Debug Mode
> java GoblinGame ..\dictionary-mini.txt 6 2 debug
--------------------------------------------------
peanut, slower, packet, faster, parcel
--------------------------------------------------
Goblin says "Guess a letter": l
Goblin says "No dice! 1 wrong guesses left..."
--------------------------------------------------
peanut, packet, faster
--------------------------------------------------
Goblin says "Guess a letter": p
Goblin says "Yeah, yeah, it's like this: p-----"
--------------------------------------------------
peanut, packet
--------------------------------------------------
Goblin says "Guess a letter": n
Goblin says "No dice! 0 wrong guesses left..."
--------------------------------------------------
packet
--------------------------------------------------
Goblin says "I win! I was thinking of the word 'packet'
Your stuff is all mine... I'll come back for more soon!"
Let's say the goblin has the following words in his dictionary ( dictionary-mini.txt ):
one | three | peanut | pepper | slower | packet | pagoda | faster | papers | parcel
And he plays a game where there are 6 letters and 2 guesses. He will choose the following highlighted words:
one | three | peanute | pepper | slower | packet | pagoda | faster | papers | parcel
He will not choose "one" or three because they are not of length 6. He will not choose pepper, pagoda, or papers because they each have duplicate letters.
This is why you see the following in Sample Run Debug Mode:
> java GoblinGame ..\dictionary-mini.txt 6 2 debug
--------------------------------------------------
peanut, slower, packet, faster, parcel
--------------------------------------------------
Let's say the user guesses "l":
Goblin says "Guess a letter": l
Now the Goblin wants to cheat. He's not really thinking of a word, hes thinking of winning the game! The goblin will partition his current list of words (peanut, slower, packet, faster, parcel) into seven categories (number of letters + 1).
Words without the letter "I" | Words with the letter "I" in position 1 | Words with the letter "I" in position 2 | Words with the letter "I" in position 3 | Words with the letter "I" in position 4 | Words with the letter "I" in position 5 | Words with the letter "I" in position 6 |
peanut | slower | parcel |
Now he will choose the biggest "partition", in this case 'Words without the letter l'. So hell respond:
Goblin says "No dice! 1 wrong guesses left..."
But he can't be caught cheating, so he can only use words from that partition later (peanut, packet, faster). So when the user guesses "p":
Goblin says "Guess a letter": p
The goblin does this partition:
Words without the letter "p" | Words with the letter "p" in position 1 | Words with the letter "p" in position 2 | Words with the letter "p" in position 3 | Words with the letter "p" in position 4 | Words with the letter "p" in position 5 | Words with the letter "p" in position 6 |
faster | peanut packet |
And now he picks partition 'Words with the letter "l" in position 1' and says:
Goblin says "Yeah, yeah, it's like this: p-----"
Now that you understand more about the game, let's look at another sample run:
> java GoblinGame ..\dictionary-mini.txt 6 10
Goblin says "Guess a letter": p
Goblin says "Yeah, yeah, it's like this: p-----"
Goblin says "Guess a letter": a
Goblin says "Yeah, yeah, it's like this: pa----"
Goblin says "Guess a letter": e
Goblin says "Yeah, yeah, it's like this: pa--e-"
Goblin says "Guess a letter": e
Goblin says "You already guessed: p, a, e
Guess a new letter": t
Goblin says "No dice! 9 wrong guesses left..."
Goblin says "Guess a letter": c
Goblin says "Yeah, yeah, it's like this: pa-ce-"
Goblin says "Guess a letter": t
Goblin says "You already guessed: p, a, e, t, c
Guess a new letter": banana
Goblin says "One letter! Guess a single letter":
Goblin says "One letter! Guess a single letter": l
Goblin says "Yeah, yeah, it's like this: pa-cel"
Goblin says "Guess a letter": m
Goblin says "No dice! 8 wrong guesses left..."
Goblin says "Guess a letter": 8
Goblin says "No dice! 7 wrong guesses left..."
Goblin says "Guess a letter": r
Goblin says "Yeah, yeah, it's like this: parcel"
Goblin says "You win... here's your stuff. But I'll get you next time!"
Notes:
An overview of the requirements are listed below, please see the grading rubric for more details.
Dictionary files will contain one word per line and only words with alphabetical characters (a-z) and only lower case letters. Two dictionaries have been provided ( dictionary.txt is a Scrabble dictionary, dictionary- mini.txt is for use in debugging and for showing sample runs). You may assume the given dictionary is correctly formatted for this assignment.
This project will be built using a number of classes representing the component pieces of the project. Here we provide a description of these classes. Template files are provided for each class in the project folder and these contain further comments and additional details.
BetterArray< T > (BetterArray.java): This class represents a generic collection of objects in an array whose capacity can grow and shrink as needed. It supports the usual operations of adding and removing objects including add() and delete() . Check the included template file for all required methods and their corresponding big-O requirements. The capacity of a BetterArray may change as items are added or removed and the following rules must be followed in your implementation:
Goblin (Goblin.java): This class implements the goblin game. It must use BetterArray objects for storage and you are not permitted to use any arrays anywhere in this file (the main method which interacts with args[] has already been implemented). You will be implementing a typical "game loop" structure:
The class define multiple methods corresponding to those steps. Some methods include partial implementations to provide a starting point for you. Check the included template file for all required methods and their big-O requirements.
GoblinGame (GoblinGame.java): This class runs the actual game loop and is fully provided (do not edit).