import streamlit as st import random from wordle_functions import * ### Page header st.title("Wordle Wizard") ### Loading in official word list official_words = [] with open("data/official_words_processed.txt", "r", encoding = "utf-8") as f: for word in f.read().split("\n"): official_words.append(word) f.close() # closes connection to file ### Examples of words to use sugg_words = [] for i in range(0, 20): ran_int = random.randint(0, len(official_words) - 1) word = official_words[ran_int] sugg_words.append(word) ### Generate Examples Button st.write('Please enter a starting word and a target word, and click the "Abracadabra" button to solve the puzzle.\n') st.write('If you would like some examples of words you can use, click the button below.\n') gen_egs = st.button('Show Me Words', key = str) if gen_egs: st.write(f"There are {len(official_words)} in the official Wordle word list. Here are {len(sugg_words)} of them.") st.write(f"{sugg_words}\n") # user starting word starting_word = st.text_input("Enter starting word here") starting_word = starting_word.strip().replace(" ", "").lower() if len(starting_word) != 5: st.write('Please double check and make sure there are only 5 letters in the starting word.\n') # user target word target_word = st.text_input("Enter target word here") target_word = target_word.strip().replace(" ", "").lower() if len(target_word) != 5: st.write('Please double check and make sure there are only 5 letters in the target word.\n') ### Solving solve_button = st.button('Abracadabra') if solve_button: # button to make everything run if (len(starting_word) and len(target_word)) == 5: # ensure words are the correct lengths if (starting_word.isalpha() and target_word.isalpha()): # checking there's no punctuation # if either of them aren't in the list, temporarily add them to the list. This doesn't impact things much and will save a ton of error headaches if starting_word not in official_words: official_words.append(starting_word) if target_word not in official_words: official_words.append(target_word) # puzzle solution solution = wordle_wizard(word_list = official_words, max_guesses = 6, guess = starting_word, target = target_word, random_guess = False, random_target = False, verbose = True, drama = 0, return_stats = False, record = False, hf_mod = True) # now solve the puzzle with the passed respective start and target words for line in solution: line_clean_str = (line.split("\n"))[0] st.write(f"{line_clean_str}") # st.write("\nThanks for checking out Wordle Wizard! If you have any feedback or requests for additions to this app, you can reach me at kmaurinjones@gmail.com.") else: # if the passed words don't check every criteria st.write("Please check again that the starting word and target word only contain letter and are both 5 letters in length. Once they are, click the 'Abracadabra' button once more.") st.write("\nThanks for checking out Wordle Wizard! If you have any feedback or requests for additions to this app, shoot me at email at kmaurinjones@gmail.com.")