hryanjones / guess-my-word

A word guessing game, where you only know whether my word is before or after your guess. (An unofficial clone of the game previously available on simbase.org)
https://hryanjones.com/guess-my-word/
MIT License
64 stars 26 forks source link

Wrap the index based on the length of the solution word array. #56

Closed powerlanguage closed 2 years ago

powerlanguage commented 2 years ago

On 2021-11-18, getWordIndex returns 939. Both possibleWords.normal and possibleWords.hard have 938 entries. This results in an index-out-of-bounds exception, which returns undefined as the solution. This change wraps the index by the length of the possibleWords arrays, so in this case, a getWordIndex of 939 will be wrapped to 0.

Note, it also appears that the first 3 entries in possibleWords.normal were empty strings. I've removed those to prevent them for being used as solutions but I am not sure if there are implications elsewhere if possibleWords.normal for possibleWords.hard are of different lengths (which they are after this change).

Note, this change assumes that once the end of the possibleWords array is reached, it should start again from the beginning. Which may not be the creators intent.

powerlanguage commented 2 years ago

Closing as it does not sound like this is the creator's intent: https://twitter.com/guessmyword1/status/1461747077306728451

hryanjones commented 2 years ago

Thanks a lot for the fast pull request!

If you happen to have a few minutes and want to put a warning on the site when there are fewer than 5 words left (the warning would be equivalent to "tell Ryan to get his butt in gear and pick some new words!"). I would really appreciate that!

powerlanguage commented 2 years ago

@hryanjones - I am not sure of your process but how much work is it for you to generate solution words? Is there a reason you don't do it in a bigger chunk? E.g. adding multiple years at a time?

hryanjones commented 2 years ago

The way I do it is to look through words that have been guessed for good ones that haven't already been used. You can see some of the process by looking at the guess generator file. I add new words to the center, analyze (which removes previously guessed words and words that are specifically excluded, and then it looks for words that aren't good for the game, e.g. lace is fine, but lacing or laced are a word forms and not as good). Then I sort them into good ones and new ones to exclude. I also added a "Reduce" function so I can pick across the alphabet without having to look through the entire list of guessed words (which is big). I've thought about doing something where I crowd source words, which'd probably use some type of similar process that was public that allowed people to suggest words for the good or exclude lists and then let me know when two or more people had the same word for the list or something, but I don't know if I have the time to implement that. I'd be open to other ideas as well.