kmaurinjones commited on
Commit
202c68f
1 Parent(s): 0c9757e

Update wordle_functions.py

Browse files
Files changed (1) hide show
  1. wordle_functions.py +39 -39
wordle_functions.py CHANGED
@@ -200,9 +200,9 @@ def count_vows_cons(word: str, y_vow = True):
200
 
201
  return counts
202
 
203
- def get_word_meaning(words_to_rate: list, word_list: list, normalized: bool = True, ascending: bool = False):
204
  """
205
- Given a word and a word list, calculates meaning each word as a measure of its impact to the next possible guesses in Wordle, ordered according to `reverse` parameter.
206
 
207
  ------
208
  Parameters:
@@ -393,15 +393,15 @@ def wordle_wizard(word_list: list, max_guesses: int = None,
393
  stats_dict['target_vowels'] = float(count_vows_cons(target, y_vow = True)['vows'])
394
  stats_dict['target_consonants'] = float(count_vows_cons(target, y_vow = True)['cons'])
395
 
396
- # get meaning of the first guess word and target word in the entire word_list
397
- for tup in get_word_meaning(word_list, word_list, normalized = True):
398
  if tup[0] == guess:
399
- stats_dict['first_guess_meaning'] = tup[1]
400
  if tup[0] == target:
401
- stats_dict['target_meaning'] = tup[1]
402
 
403
  guess_entropies = []
404
- guess_entropies.append(stats_dict['first_guess_meaning'])
405
 
406
  # luck_guess_1 = round(1 - ((1 / len(word_list)) * guess_entropies[0] / 100), 2) * 100
407
 
@@ -654,13 +654,13 @@ def wordle_wizard(word_list: list, max_guesses: int = None,
654
  st.write(f"The only remaining possible word is:\n\t'{list(potential_next_guesses)[0]}'\n")
655
 
656
  guess = list(potential_next_guesses)[0]
657
- guess_entropies.append(get_word_meaning([guess], word_list, normalized = False, ascending = False)[0][1])
658
 
659
  else:
660
 
661
  best_next_guesses = list(potential_next_guesses)
662
  # print (best_next_guesses)
663
- word_ratings = get_word_meaning(best_next_guesses, word_list, normalized = False, ascending = False) # "internal" ratings
664
 
665
  # Get max rating of all words
666
  max_rating = -np.inf
@@ -668,7 +668,7 @@ def wordle_wizard(word_list: list, max_guesses: int = None,
668
  if rating > max_rating:
669
  max_rating = rating
670
 
671
- # add best rated words (all equally best meaning in next guess list) to set
672
  best_of_the_best_1 = []
673
  for word, rating in word_ratings:
674
  if rating == max_rating:
@@ -691,7 +691,7 @@ def wordle_wizard(word_list: list, max_guesses: int = None,
691
  else:
692
  guess = best_of_the_best_1[0] # they're all equally the best of the best possible guesses so just pick the first
693
 
694
- # guess_entropies.append(get_word_meaning([guess], word_list, normalized = False, ascending = False)[0][1])
695
 
696
  if return_stats == False:
697
  if verbose == True:
@@ -702,7 +702,7 @@ def wordle_wizard(word_list: list, max_guesses: int = None,
702
  st.write(f"The top 40 potential next guesses are:\n\t{word_ratings[:40]}\n")
703
  st.write(f"Words guessed so far:\n\t{guessed_words}.\n")
704
 
705
- guess_entropies.append(get_word_meaning([guess], word_list, normalized = False, ascending = False)[0][1])
706
 
707
  #### Guess has now been made -- what to do next
708
  if guess_num == max_guesses: # if at max guesses allowed
@@ -771,22 +771,22 @@ def wordle_wizard(word_list: list, max_guesses: int = None,
771
  # average number of words remaining after each guess -- the higher this is, the luckier the person got (the lower, the more guesses it took)
772
  stats_dict['avg_remaining'] = float(round(np.mean(reduction_per_guess), 2))
773
 
774
- # avg meaning of each guessed word relative to all other words possible at that moment -- this should consistently be 100 for the algorithm, but will be different for user
775
  if len(guess_entropies) > 1: # in case of guessing it correctly on the first try
776
  sum_entropies = 0
777
- for meaning in guess_entropies:
778
- sum_entropies += meaning
779
 
780
- average_meaning = float(round(sum_entropies / len(guess_entropies), 2))
781
- stats_dict['avg_intermediate_guess_meaning'] = average_meaning
782
  else:
783
- stats_dict['avg_intermediate_guess_meaning'] = float(100)
784
 
785
  expected_guesses = 3.85
786
 
787
  # guess_num = 3
788
- # average_meaning = 95
789
- luck = round(1 - ((((guess_num / expected_guesses) * (stats_dict['avg_intermediate_guess_meaning'] / 100)) / max_guesses) * 5), 2)
790
  stats_dict['luck'] = luck
791
 
792
  if record == True:
@@ -915,15 +915,15 @@ def get_gram_freq(word_list: list, letters_length: int = 2, position: bool = "st
915
  # stats_dict['target_vowels'] = float(count_vows_cons(target, y_vow = True)['vows'])
916
  # stats_dict['target_consonants'] = float(count_vows_cons(target, y_vow = True)['cons'])
917
 
918
- # # get meaning of the first guess word and target word in the entire word_list
919
- # for tup in get_word_meaning(word_list, word_list, normalized = True):
920
  # if tup[0] == guess:
921
- # stats_dict['first_guess_meaning'] = tup[1]
922
  # if tup[0] == target:
923
- # stats_dict['target_meaning'] = tup[1]
924
 
925
  # guess_entropies = []
926
- # guess_entropies.append(stats_dict['first_guess_meaning'])
927
 
928
  # english_alphabet = "abcdefghijklmnopqrstuvwxyz"
929
 
@@ -1172,18 +1172,18 @@ def get_gram_freq(word_list: list, letters_length: int = 2, position: bool = "st
1172
  # del guess_list[0]
1173
  # # print (guess_list)
1174
  # guess = guess_list[0]
1175
- # guess_entropies.append(get_word_meaning([guess], word_list, normalized = True, ascending = False)[0][1])
1176
 
1177
  # else:
1178
 
1179
  # best_next_guesses = list(potential_next_guesses)
1180
- # word_ratings = get_word_meaning(best_next_guesses, word_list, normalized = True, ascending = False) # "internal" ratings
1181
 
1182
  # del guess_list[0]
1183
  # # print (guess_list)
1184
  # guess = guess_list[0]
1185
 
1186
- # guess_entropies.append(get_word_meaning([guess], word_list, normalized = True, ascending = False)[0][1])
1187
 
1188
  # if return_stats == False:
1189
  # if verbose == True:
@@ -1278,16 +1278,16 @@ def get_gram_freq(word_list: list, letters_length: int = 2, position: bool = "st
1278
  # # average number of words remaining after each guess -- the higher this is, the luckier the person got (the lower, the more guesses it took)
1279
  # stats_dict['avg_remaining'] = float(round(np.mean(reduction_per_guess), 2))
1280
 
1281
- # # avg meaning of each guessed word relative to all other words possible at that moment -- this should consistently be 100 for the algorithm, but will be different for user
1282
  # if len(guess_entropies) > 1: # in case of guessing it correctly on the first try
1283
  # sum_entropies = 0
1284
- # for meaning in guess_entropies:
1285
- # sum_entropies += meaning
1286
 
1287
- # average_meaning = float(round(sum_entropies / len(guess_entropies), 2))
1288
- # stats_dict['avg_intermediate_guess_meaning'] = average_meaning
1289
  # else:
1290
- # stats_dict['avg_intermediate_guess_meaning'] = float(100)
1291
 
1292
  # # stats_dict['bias'] = bias
1293
 
@@ -1312,7 +1312,7 @@ def get_gram_freq(word_list: list, letters_length: int = 2, position: bool = "st
1312
  # stats_dict['num_guesses'] = float(guess_num)
1313
 
1314
  # wizard_dict = wordle_wizard(word_list = word_list, max_guesses = max_guesses,
1315
- # guess = first_guess, target = target, bias = 'meaning',
1316
  # random_guess = False, random_target = False,
1317
  # verbose = False, drama = 0, return_stats = return_stats, record = False)
1318
 
@@ -1324,8 +1324,8 @@ def get_gram_freq(word_list: list, letters_length: int = 2, position: bool = "st
1324
  # stats_dict['expected_guesses'] = wizard_dict['num_guesses']
1325
 
1326
  # expected_guesses = wizard_dict['num_guesses']
1327
- # # stats_dict['luck'] = round((1 - (guess_num / expected_guesses)) * (stats_dict['avg_intermediate_guess_meaning'] / 100), 2)
1328
- # stats_dict['luck'] = round((1 - ((guess_num / expected_guesses)) * (stats_dict['avg_intermediate_guess_meaning'] / 100)), 2)
1329
 
1330
  # stats_master = {}
1331
  # for metric, result in stats_dict.items():
@@ -1440,9 +1440,9 @@ def get_gram_freq(word_list: list, letters_length: int = 2, position: bool = "st
1440
 
1441
  # # Re-organizing columns to a more logical order (for viewing)
1442
  # df_master = df_master[['first_guess', 'target_word', 'player', 'num_guesses', 'expected_guesses', 'luck', 'first_guess_vowels', 'first_guess_consonants',
1443
- # 'target_vowels', 'target_consonants', 'first_guess_meaning', 'target_meaning',
1444
  # 'target_guessed', 'mid_guesses_avg_vows', 'mid_guesses_avg_cons', 'avg_perf_letters',
1445
- # 'avg_wrong_pos_letters', 'avg_wrong_letters', 'avg_remaining', 'avg_intermediate_guess_meaning',
1446
  # 'valid_success']]
1447
 
1448
  # # print(excepts)
 
200
 
201
  return counts
202
 
203
+ def get_word_rating(words_to_rate: list, word_list: list, normalized: bool = True, ascending: bool = False):
204
  """
205
+ Given a word and a word list, calculates rating each word as a measure of its impact to the next possible guesses in Wordle, ordered according to `reverse` parameter.
206
 
207
  ------
208
  Parameters:
 
393
  stats_dict['target_vowels'] = float(count_vows_cons(target, y_vow = True)['vows'])
394
  stats_dict['target_consonants'] = float(count_vows_cons(target, y_vow = True)['cons'])
395
 
396
+ # get rating of the first guess word and target word in the entire word_list
397
+ for tup in get_word_rating(word_list, word_list, normalized = True):
398
  if tup[0] == guess:
399
+ stats_dict['first_guess_rating'] = tup[1]
400
  if tup[0] == target:
401
+ stats_dict['target_rating'] = tup[1]
402
 
403
  guess_entropies = []
404
+ guess_entropies.append(stats_dict['first_guess_rating'])
405
 
406
  # luck_guess_1 = round(1 - ((1 / len(word_list)) * guess_entropies[0] / 100), 2) * 100
407
 
 
654
  st.write(f"The only remaining possible word is:\n\t'{list(potential_next_guesses)[0]}'\n")
655
 
656
  guess = list(potential_next_guesses)[0]
657
+ guess_entropies.append(get_word_rating([guess], word_list, normalized = False, ascending = False)[0][1])
658
 
659
  else:
660
 
661
  best_next_guesses = list(potential_next_guesses)
662
  # print (best_next_guesses)
663
+ word_ratings = get_word_rating(best_next_guesses, word_list, normalized = False, ascending = False) # "internal" ratings
664
 
665
  # Get max rating of all words
666
  max_rating = -np.inf
 
668
  if rating > max_rating:
669
  max_rating = rating
670
 
671
+ # add best rated words (all equally best rating in next guess list) to set
672
  best_of_the_best_1 = []
673
  for word, rating in word_ratings:
674
  if rating == max_rating:
 
691
  else:
692
  guess = best_of_the_best_1[0] # they're all equally the best of the best possible guesses so just pick the first
693
 
694
+ # guess_entropies.append(get_word_rating([guess], word_list, normalized = False, ascending = False)[0][1])
695
 
696
  if return_stats == False:
697
  if verbose == True:
 
702
  st.write(f"The top 40 potential next guesses are:\n\t{word_ratings[:40]}\n")
703
  st.write(f"Words guessed so far:\n\t{guessed_words}.\n")
704
 
705
+ guess_entropies.append(get_word_rating([guess], word_list, normalized = False, ascending = False)[0][1])
706
 
707
  #### Guess has now been made -- what to do next
708
  if guess_num == max_guesses: # if at max guesses allowed
 
771
  # average number of words remaining after each guess -- the higher this is, the luckier the person got (the lower, the more guesses it took)
772
  stats_dict['avg_remaining'] = float(round(np.mean(reduction_per_guess), 2))
773
 
774
+ # avg rating of each guessed word relative to all other words possible at that moment -- this should consistently be 100 for the algorithm, but will be different for user
775
  if len(guess_entropies) > 1: # in case of guessing it correctly on the first try
776
  sum_entropies = 0
777
+ for rating in guess_entropies:
778
+ sum_entropies += rating
779
 
780
+ average_rating = float(round(sum_entropies / len(guess_entropies), 2))
781
+ stats_dict['avg_intermediate_guess_rating'] = average_rating
782
  else:
783
+ stats_dict['avg_intermediate_guess_rating'] = float(100)
784
 
785
  expected_guesses = 3.85
786
 
787
  # guess_num = 3
788
+ # average_rating = 95
789
+ luck = round(1 - ((((guess_num / expected_guesses) * (stats_dict['avg_intermediate_guess_rating'] / 100)) / max_guesses) * 5), 2)
790
  stats_dict['luck'] = luck
791
 
792
  if record == True:
 
915
  # stats_dict['target_vowels'] = float(count_vows_cons(target, y_vow = True)['vows'])
916
  # stats_dict['target_consonants'] = float(count_vows_cons(target, y_vow = True)['cons'])
917
 
918
+ # # get rating of the first guess word and target word in the entire word_list
919
+ # for tup in get_word_rating(word_list, word_list, normalized = True):
920
  # if tup[0] == guess:
921
+ # stats_dict['first_guess_rating'] = tup[1]
922
  # if tup[0] == target:
923
+ # stats_dict['target_rating'] = tup[1]
924
 
925
  # guess_entropies = []
926
+ # guess_entropies.append(stats_dict['first_guess_rating'])
927
 
928
  # english_alphabet = "abcdefghijklmnopqrstuvwxyz"
929
 
 
1172
  # del guess_list[0]
1173
  # # print (guess_list)
1174
  # guess = guess_list[0]
1175
+ # guess_entropies.append(get_word_rating([guess], word_list, normalized = True, ascending = False)[0][1])
1176
 
1177
  # else:
1178
 
1179
  # best_next_guesses = list(potential_next_guesses)
1180
+ # word_ratings = get_word_rating(best_next_guesses, word_list, normalized = True, ascending = False) # "internal" ratings
1181
 
1182
  # del guess_list[0]
1183
  # # print (guess_list)
1184
  # guess = guess_list[0]
1185
 
1186
+ # guess_entropies.append(get_word_rating([guess], word_list, normalized = True, ascending = False)[0][1])
1187
 
1188
  # if return_stats == False:
1189
  # if verbose == True:
 
1278
  # # average number of words remaining after each guess -- the higher this is, the luckier the person got (the lower, the more guesses it took)
1279
  # stats_dict['avg_remaining'] = float(round(np.mean(reduction_per_guess), 2))
1280
 
1281
+ # # avg rating of each guessed word relative to all other words possible at that moment -- this should consistently be 100 for the algorithm, but will be different for user
1282
  # if len(guess_entropies) > 1: # in case of guessing it correctly on the first try
1283
  # sum_entropies = 0
1284
+ # for rating in guess_entropies:
1285
+ # sum_entropies += rating
1286
 
1287
+ # average_rating = float(round(sum_entropies / len(guess_entropies), 2))
1288
+ # stats_dict['avg_intermediate_guess_rating'] = average_rating
1289
  # else:
1290
+ # stats_dict['avg_intermediate_guess_rating'] = float(100)
1291
 
1292
  # # stats_dict['bias'] = bias
1293
 
 
1312
  # stats_dict['num_guesses'] = float(guess_num)
1313
 
1314
  # wizard_dict = wordle_wizard(word_list = word_list, max_guesses = max_guesses,
1315
+ # guess = first_guess, target = target, bias = 'rating',
1316
  # random_guess = False, random_target = False,
1317
  # verbose = False, drama = 0, return_stats = return_stats, record = False)
1318
 
 
1324
  # stats_dict['expected_guesses'] = wizard_dict['num_guesses']
1325
 
1326
  # expected_guesses = wizard_dict['num_guesses']
1327
+ # # stats_dict['luck'] = round((1 - (guess_num / expected_guesses)) * (stats_dict['avg_intermediate_guess_rating'] / 100), 2)
1328
+ # stats_dict['luck'] = round((1 - ((guess_num / expected_guesses)) * (stats_dict['avg_intermediate_guess_rating'] / 100)), 2)
1329
 
1330
  # stats_master = {}
1331
  # for metric, result in stats_dict.items():
 
1440
 
1441
  # # Re-organizing columns to a more logical order (for viewing)
1442
  # df_master = df_master[['first_guess', 'target_word', 'player', 'num_guesses', 'expected_guesses', 'luck', 'first_guess_vowels', 'first_guess_consonants',
1443
+ # 'target_vowels', 'target_consonants', 'first_guess_rating', 'target_rating',
1444
  # 'target_guessed', 'mid_guesses_avg_vows', 'mid_guesses_avg_cons', 'avg_perf_letters',
1445
+ # 'avg_wrong_pos_letters', 'avg_wrong_letters', 'avg_remaining', 'avg_intermediate_guess_rating',
1446
  # 'valid_success']]
1447
 
1448
  # # print(excepts)