I have to write a hangman program, Only the “house” is evil and changes the word so the player (hopefully) loses.
I will create a set of all the words at the start of the game when they player chooses a letter i will create a set that matches the pattern, and continue creating the optimal subset.
for example
Assuming the user selects 3 letter words, and for this examples sake we will say there are only the following 3 letter words in the english language; Dog Fog And Fox Cat Not Bus
If the user Guesses “o” the program will compile a list of words with out “o” in them, I will sort this list in to sets one set would be “and” the other “bus” and an other “cat”
However I was wondering what the best method would be to store these sets.
As a suggestion, think about what operation you need to efficiently support. You will need to be able to take a word, map it to its word family, and from there to distribute the word into the collection of words matching that family. For this, consider using something like a
Mapthat will associate the word family (represented however you wish) with the collection of words matching that family. You can represent the collection in many ways – as aSet, as aList, etc. That way, you can easily take the string, convert it to a word family, and then map the word family to the set of all words in that family.Hope this helps!