Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -54,80 +54,35 @@ def validate_word(word, board):
|
|
54 |
return True
|
55 |
return False
|
56 |
|
57 |
-
def boggle_1(size, time_limit):
|
58 |
-
"""Main function for playing the Boggle game"""
|
59 |
-
st.title("Boggle Game")
|
60 |
-
st.write("Find as many words as possible by connecting adjacent letters on the board.")
|
61 |
-
st.write("Words must be at least three letters long and can only be used once.")
|
62 |
-
board = generate_board(size)
|
63 |
-
board_df = pd.DataFrame(board)
|
64 |
-
st.write(board_df)
|
65 |
-
words = set()
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
st.write("Invalid word. Try again.")
|
77 |
|
78 |
st.write("Here are your words:")
|
79 |
-
st.write(words)
|
80 |
|
81 |
-
|
82 |
-
|
|
|
83 |
st.title("Boggle Game")
|
84 |
st.write("Find as many words as possible by connecting adjacent letters on the board.")
|
85 |
st.write("Words must be at least three letters long and can only be used once.")
|
86 |
-
board = generate_board(size)
|
87 |
-
board_df = pd.DataFrame(board)
|
88 |
-
st.write(board_df)
|
89 |
words = set()
|
|
|
90 |
|
91 |
-
with st.form(key="
|
92 |
-
|
93 |
-
if st.form_submit_button("Submit"):
|
94 |
-
if len(new_word) >= 3 and new_word not in words and validate_word(new_word.upper(), board):
|
95 |
-
words.add(new_word)
|
96 |
-
st.write(f"Added {new_word} to the list of words!")
|
97 |
-
elif new_word in words:
|
98 |
-
st.write("Word already used!")
|
99 |
-
else:
|
100 |
-
st.write("Invalid word. Try again.")
|
101 |
-
|
102 |
-
st.write("Here are your words:")
|
103 |
-
st.write(words)
|
104 |
-
|
105 |
-
return board, words
|
106 |
-
|
107 |
-
def play_boggle(board, words):
|
108 |
-
"""Function for playing the Boggle game"""
|
109 |
-
with st.form(key="new_word"):
|
110 |
-
new_word = st.text_input("Enter a new word:")
|
111 |
-
submit_button = st.form_submit_button("Submit")
|
112 |
-
|
113 |
-
if submit_button:
|
114 |
-
if len(new_word) >= 3 and new_word not in words and validate_word(new_word.upper(), board):
|
115 |
-
words.add(new_word)
|
116 |
-
st.write(f"Added {new_word} to the list of words!")
|
117 |
-
elif new_word in words:
|
118 |
-
st.write("Word already used!")
|
119 |
-
else:
|
120 |
-
st.write("Invalid word. Try again.")
|
121 |
-
st.write("Here are your words:")
|
122 |
-
st.write(words)
|
123 |
-
with st.form(key="new_word"):
|
124 |
-
new_word = st.text_input("Enter a new word:")
|
125 |
-
submit_button = st.form_submit_button("Submit")
|
126 |
|
127 |
|
128 |
if __name__ == "__main__":
|
129 |
-
board
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
# boggle(7, 60)
|
|
|
54 |
return True
|
55 |
return False
|
56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
+
def create_boggle_form(board, words):
|
59 |
+
"""Creates the Boggle form"""
|
60 |
+
new_word = st.text_input("Enter a new word:")
|
61 |
+
submit_button = st.form_submit_button("Submit")
|
62 |
+
|
63 |
+
if submit_button:
|
64 |
+
if len(new_word) >= 3 and new_word not in words and validate_word(new_word.upper(), board):
|
65 |
+
words.add(new_word)
|
66 |
+
st.session_state.words = ", ".join(sorted(words))
|
|
|
67 |
|
68 |
st.write("Here are your words:")
|
69 |
+
st.write(st.session_state.words)
|
70 |
|
71 |
+
|
72 |
+
def play_boggle(board):
|
73 |
+
"""Function for playing the Boggle game"""
|
74 |
st.title("Boggle Game")
|
75 |
st.write("Find as many words as possible by connecting adjacent letters on the board.")
|
76 |
st.write("Words must be at least three letters long and can only be used once.")
|
|
|
|
|
|
|
77 |
words = set()
|
78 |
+
st.session_state.words = ""
|
79 |
|
80 |
+
with st.form(key="boggle_form"):
|
81 |
+
create_boggle_form(board, words)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
|
83 |
|
84 |
if __name__ == "__main__":
|
85 |
+
board = generate_board(7)
|
86 |
+
board_df = pd.DataFrame(board)
|
87 |
+
st.write(board_df)
|
88 |
+
play_boggle(board)
|
|