I’m writing a console-environment Hangman game for my introductory programming class. The player chooses the word length and number of guesses they would like. ‘Easy mode’ is simple enough… generate a random number to use as the list’s index and check that the chosen word is the right length. However, ‘hard mode’ requires the list to be refined as the game progresses, choosing the largest list of possibilities given the letters guessed.
I should note, we are not using the C# List class but instead, creating array-based structs:
struct ListType
{
public type[] items;
public int count;
}
//defined as:
ListType myList = new ListType();
myList.items = new type[max value];
myList.count = 0;
Anyway, here’s an example of the way ‘hard mode’ should go:
Word List:
hole
airplane
lame
photos
cart
mole
(player chooses word length of 4)
Word List (refined):
hole
lame
cart
mole
(player guesses "l", then "e")
Word List (refined):
hole
mole
“Lame” is omitted because more words have the “…le…” pattern. The technique that makes sense to me (but isn’t working the way I’d like) is storing each word’s pattern to an array (ie: “mole” and “hole” = 0011, and “lame” = 1001), and counting up the duplicates to determine the larger list.
Is this the way I should be doing it? I’m new to programming and have just under a year’s worth of experience, so I guess answer as such.
Thanks!!
There are a few ways of approaching this. A simple way would be to keep track of a list for all candidate words and calculate the amount of matching sequences for that word as well as log the best matching sequence. This way you can both sort on the best sequence and the amount of sequences when the best sequence alone is not a good enough measurement tool. I hope it becomes obvious how to modify this code in order to only sort on the best sequence.
Firstly i setup a test case like:
After which i filter the wordList and calculate the best matches which i finally group together to produce the desired result:
Pay attention to the comments in the code