GillesVandewiele / Wordle-Bot

An entropy-based strategy to wordle
MIT License
27 stars 11 forks source link

Explanation regarding the double call to calculate_entropies() #9

Open woctezuma opened 1 year ago

woctezuma commented 1 year ago

I don't understand the double call to calculate_entropies(). Could you clarify the reason behind it?

https://github.com/GillesVandewiele/Wordle-Bot/blob/f6334959105549745300ff2c1fc7f80e7c8d7a07/wordle.py#L112-L117

Indeed:

So the second call to calculate_entropies() recomputes entropy values which were already computed by the first call.

If the objective is to decrease the number of items fed to max(), it could be done by filtering entropies returned by the first call.

https://github.com/GillesVandewiele/Wordle-Bot/blob/f6334959105549745300ff2c1fc7f80e7c8d7a07/wordle.py#L119-L120

GillesVandewiele commented 1 year ago

Wordle keeps track of two lists: (i) a list of possible correct answers and (ii) a much bigger list of valid words that the user can enter. The first call will try to find a good guess from list (i), but in case there are still many options, it might be better to guess a word from list (ii) to have better outcomes for the next round.

woctezuma commented 1 year ago

There are indeed two lists:

https://github.com/GillesVandewiele/Wordle-Bot/blob/f6334959105549745300ff2c1fc7f80e7c8d7a07/wordle.py#L11-L12

Here:

https://github.com/GillesVandewiele/Wordle-Bot/blob/f6334959105549745300ff2c1fc7f80e7c8d7a07/wordle.py#L71-L77

Here:

https://github.com/GillesVandewiele/Wordle-Bot/blob/f6334959105549745300ff2c1fc7f80e7c8d7a07/wordle.py#L112-L113

And here, we have all_dictionary which corresponds to (ii), not to (i).


Regarding the all_words variable:

https://github.com/GillesVandewiele/Wordle-Bot/blob/f6334959105549745300ff2c1fc7f80e7c8d7a07/wordle.py#L107

https://github.com/GillesVandewiele/Wordle-Bot/blob/f6334959105549745300ff2c1fc7f80e7c8d7a07/wordle.py#L130-L132


Regarding the dictionary variable, it is only used once, in the for-loop to evaluate the bot.

https://github.com/GillesVandewiele/Wordle-Bot/blob/f6334959105549745300ff2c1fc7f80e7c8d7a07/wordle.py#L97

woctezuma commented 1 year ago

I wonder whether what you wanted to do would have been:

candidates = all_words
entropies = calculate_entropies(candidates, all_words, pattern_dict, all_patterns)

if max(entropies.values()) < 0.1:
    candidates = all_dictionary
    entropies = calculate_entropies(candidates, all_words, pattern_dict, all_patterns)

instead of: https://github.com/GillesVandewiele/Wordle-Bot/blob/f6334959105549745300ff2c1fc7f80e7c8d7a07/wordle.py#L112-L117

GillesVandewiele commented 1 year ago

Ok yes, you are correct! This logic seems to indeed be switched up & the calculations in the if-block are redundant. I think it should indeed be switched as you suggested, but we could bench the code to be sure the results are the same (or better)? We could iterate over every possible word and calculate how many guesses the bot needs on average.

I will merge your PRs later this week. Once again, many thanks for your contributions!

woctezuma commented 1 year ago

No problem. I agree it is better to test before merging: