Question
Tasks VII - [30 points] - Play the Game This is the most open-ended task of the program and encompasses the bulk of the game
Tasks VII - [30 points] - Play the Game
This is the most open-ended task of the program and encompasses the bulk of the game play. At this point, a thorough review of the sample outputs above and playing the game using demo.exe is a good idea in order to understand all of the nuances of the game. In summary, the game should proceed as follows:
Input a character from the the user as their guess. If the input character is not a lower-case letter OR the input lower-case letter has already been guessed, then prompt the user for another input until a valid guess has been input. One exception is that if the user enters '#', then terminate the game immediately.
Build a dynamic array of unique Pattern structs, where a Pattern struct is defined in the starter code and contains a heap-allocated C-string representing the current status of the final word, with a '–' for each unsettled character; for each word in the current word list, produce an updated pattern by replacing '–'s with the current guessed letter wherever that letter appears in the word. Then, append the pattern to the dynamic array of Patterns as a new element if it is a unique pattern (i.e. does not match any of the patterns already in the array). Otherwise, locate the Pattern already in the array that it matches and increment the count subitem for that Pattern. The array of Patterns should dynamically grow, beginning with a capacity of 4 Patterns and doubling whenever more space is needed. As an example, suppose in the midst of a game play, the current word list and final word pattern are as follows:Possible words are now: bowed boxed foxed jowed joyed moved mowed vowed wowed yowed The word pattern is: -o-ed
Then, the user guesses letter 'w'. The resulting Pattern array contains 3 elements, because there are only 3 unique patterns in the word list made by adding the instances of 'w' to the current final word pattern –o–ed:
All patterns for letter w: -owed count = 5 changes = 1 -o-ed count = 4 changes = 0 wowed count = 1 changes = 2
Note that the patterns are printed in the order they first appear in the word list. Also, the patterns are printed with their frequencies in the word list (i.e. count) and how many changes there are to the final word pattern for that pattern (i.e. number of occurrences of the current letter guess, 'w' here). In this case, the pattern that will be chosen is –owed, since it has the highest count.
Find the most common pattern in the word list, but analyzing the dynamic Pattern struct array. Ties between pattern family sizes are broken by first checking which pattern has the least changes due to the guessed letter, i.e. the pattern with the least number of occurrences of the guessed letter is chosen. If multiple patterns are still tied, the pattern where the guessed letter appears earliest is chosen; if the first occurrence of the guessed letter is at the same index, then the second occurrence is checked; etc., until a single pattern is chosen. For example, consider the following set of patterns & counts:
All patterns for letter e: -----s count = 2 changes = 0 --e-es count = 3 changes = 2
--ee-s count = 3 changes = 2 -e---s count = 1 changes = 1 -e-e-s count = 3 changes = 2 -e--es count = 3 changes = 2
-e-ees count = 3 changes = 3 e----s count = 2 changes = 1
To select the pattern, first find the highest count(s). Here, there is a 5-way tie:
--e-es count = 3 changes = 2 --ee-s count = 3 changes = 2 -e-e-s count = 3 changes = 2 -e--es count = 3 changes = 2 -e-ees count = 3 changes = 3
The first tiebreaker is to go to the smallest number of changes (i.e. instances of the guessed letter). But, we still have a 4-way tie to break:
--e-es count = 3 changes = 2 --ee-s count = 3 changes = 2 -e-e-s count = 3 changes = 2 -e--es count = 3 changes = 2
Next, we look for the earliest instance of the guessed letter, but we still have a 2-way tie:
-e-e-s count = 3 changes = 2 -e--es count = 3 changes = 2
So, we continue comparing instances of the guessed letter, until we find one pattern with an earlier instance, leaving us with the final chosen pattern as: –e–e–s.
Once the most common pattern is found (with tiebreakers), update and print out the final word pattern after notifying the player whether their guessed letter is in the final word or not. If their letter is not in the final word pattern, then there guess was wrong and they just used up one of their valuable wrong guesses. At this point, end the game if the player has used up all of the allowed wrong guesses or has solved the final word by revealing all letters. Otherwise, repeat the process by inputting another letter guess from the user.
Throughout the game play, produce print statements matching the format of the sample gameplay outputs and demo.exe; only print the statistics [-s], word lists [-w], letter list [-l], and patter list [-p] if the proper command-line argument flags are turned ON
20: Tasks VII - pattern list and word list, n = 21, single guess 's'keyboard_arrow_up
0 / 2
Your Output
Expected output ends with
Welcome to the (Evil) Word Guessing Game!
Game Settings:
Word Size = 21
Number of Guesses = 26
View Stats Mode = OFF
View Word Lis View Word List Mode = ON
View Letter List Mod View Letter List Mode = OFF
View Pattern List Mode = ON
Number of guesses remaining: 26
Guess a letter (# to end game):
All patterns for letter s:
--------------------s ⇥count = 2 ⇥changes = 1
------------------s-s ⇥count = 1 ⇥changes = 2
-s-----s-----------s- ⇥count = 1 ⇥changes = 3
-----------s--------s ⇥count = 1 ⇥changes = 2
----s------s-------ss ⇥count = 1 ⇥changes = 4
Good guess! The word has at least one s.
Possible words are now:
compartmentalizations
ultraminiaturizations
The word pattern is: --------------------s
Number of guesses remaining: 26
Guess a letter (# to end game):
Terminating game...
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started