word guesser word guesser

Image for post is gaining popularity as we continue working remotely. This game is an online Pictionary of sort that I?m really bad at. I can not understand what people draw on the board most of the time. So my strategy is to guess the word by looking at the number of letters in the word.

I thought this could be automated if we knew the words used by I found a corpus of words used in public games, on I downloaded the words.json from their github repo and wrote a Python script to sort the words by the count words appeared in games. I created a dictionary of words with key being the number of letters in the word and value being the corresponding list of words sorted by count.

The function to send the guess word to chat window is simple enough. It takes the guess word as a parameter and fills the word by looking at inputChat and formChat id elements on the document.

The main algorithm is in fillword function where the current word is extracted from currentWord id element which is a string of underscores in most cases. This function obtains the number of letters in the current word and then only look at the list of words with those number of letters in words_dict. Now, it gets the first word from the list and removes it since the word is used for a guess. This is why we need to reassign the word list from copy dictionary when a new current word is seen on the screen.

We also need to narrow the search when there is a hint on the current word. So we obtain all the characters from current word and only send words from the list which contain the hint character at the same index. This improves the performance since we now only send the matching words. For now it only looks at only one character and ignores if there are other hints available.

In the end we need to run the fillword function after certain time intervals. I have set it to 1.2 seconds in setInterval function. A player gets kicked out of the game if the interval is less than 1.2 seconds. I think a good strategy in a real game would be set this interval to 2?3 seconds and look at the drawing as well. If the player can guess by looking at the drawing, they can still type their answer. And the script will still continue in the background, however it becomes hard to type manually when script is running after every 1.2 seconds, hence wait for 2?3 seconds in the script.

This is the link for the repo where I?m using this post in README. As always, I?m open to improvements and looking for suggestions and Pull Requests. Thanks!


No Responses

Write a response