Update app.py
Browse files
app.py
CHANGED
@@ -54,7 +54,7 @@ words = [
|
|
54 |
|
55 |
class WordGame:
|
56 |
|
57 |
-
def __init__(self
|
58 |
self.points = 0
|
59 |
self.target_word = ""
|
60 |
self.attempts = 3
|
@@ -71,6 +71,8 @@ class WordGame:
|
|
71 |
self.generate_task()
|
72 |
self.points -= 1
|
73 |
self.update_status(message="You input the target word yourself, so you lost one point and the game reset.")
|
|
|
|
|
74 |
else:
|
75 |
print(f"The player did not input the target word, so that's good.")
|
76 |
|
@@ -81,23 +83,33 @@ class WordGame:
|
|
81 |
print(f"The player scored {self.attempts} points and has a total of {self.points}.")
|
82 |
score_gained = self.attempts
|
83 |
self.generate_task()
|
84 |
-
|
|
|
85 |
else:
|
86 |
print("The response did not contain the word.")
|
87 |
self.attempts -= 1
|
88 |
print(f"Remaining attempts: {self.attempts}")
|
89 |
if self.attempts <= 0:
|
90 |
self.generate_task()
|
91 |
-
print(f"The player ran out of attempts.")
|
92 |
-
|
|
|
93 |
else:
|
94 |
print(f"The player has attempts left.")
|
95 |
|
96 |
def update_status(self, message=""):
|
97 |
demo.title = f'Current score: {self.points}, remaining attempts: {self.attempts}, target word: "{self.target_word}" {message}'
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
|
100 |
|
|
|
|
|
101 |
|
102 |
|
103 |
|
@@ -113,7 +125,7 @@ def respond(
|
|
113 |
|
114 |
print("message:")
|
115 |
print(message)
|
116 |
-
game.check_input_for_word(message)
|
117 |
|
118 |
for val in history:
|
119 |
if val[0]:
|
@@ -138,7 +150,8 @@ def respond(
|
|
138 |
yield response
|
139 |
print("response:")
|
140 |
print(response)
|
141 |
-
game.check_output_for_word(response)
|
|
|
142 |
|
143 |
|
144 |
"""
|
@@ -161,7 +174,6 @@ demo = gr.ChatInterface(
|
|
161 |
],
|
162 |
)
|
163 |
|
164 |
-
game = WordGame(demo)
|
165 |
|
166 |
|
167 |
if __name__ == "__main__":
|
|
|
54 |
|
55 |
class WordGame:
|
56 |
|
57 |
+
def __init__(self):
|
58 |
self.points = 0
|
59 |
self.target_word = ""
|
60 |
self.attempts = 3
|
|
|
71 |
self.generate_task()
|
72 |
self.points -= 1
|
73 |
self.update_status(message="You input the target word yourself, so you lost one point and the game reset.")
|
74 |
+
return "You input the target word yourself, so you lost one point and the game reset."
|
75 |
+
|
76 |
else:
|
77 |
print(f"The player did not input the target word, so that's good.")
|
78 |
|
|
|
83 |
print(f"The player scored {self.attempts} points and has a total of {self.points}.")
|
84 |
score_gained = self.attempts
|
85 |
self.generate_task()
|
86 |
+
return f"Success! You earned {score_gained} points!"
|
87 |
+
#self.update_status(message=f"Success! You earned {score_gained} points!")
|
88 |
else:
|
89 |
print("The response did not contain the word.")
|
90 |
self.attempts -= 1
|
91 |
print(f"Remaining attempts: {self.attempts}")
|
92 |
if self.attempts <= 0:
|
93 |
self.generate_task()
|
94 |
+
#print(f"The player ran out of attempts.")
|
95 |
+
return f"You did not win in three attempts. Generating new target word."
|
96 |
+
#self.update_status(message=f"You did not win in three attempts. Generating new target word.")
|
97 |
else:
|
98 |
print(f"The player has attempts left.")
|
99 |
|
100 |
def update_status(self, message=""):
|
101 |
demo.title = f'Current score: {self.points}, remaining attempts: {self.attempts}, target word: "{self.target_word}" {message}'
|
102 |
+
|
103 |
+
def analyse_output(self, message, history):
|
104 |
+
print("---message---")
|
105 |
+
print(message)
|
106 |
+
print("---message---")
|
107 |
+
print(history)
|
108 |
|
109 |
|
110 |
|
111 |
+
game = WordGame()
|
112 |
+
|
113 |
|
114 |
|
115 |
|
|
|
125 |
|
126 |
print("message:")
|
127 |
print(message)
|
128 |
+
input_check_result = game.check_input_for_word(message)
|
129 |
|
130 |
for val in history:
|
131 |
if val[0]:
|
|
|
150 |
yield response
|
151 |
print("response:")
|
152 |
print(response)
|
153 |
+
output_check_result = game.check_output_for_word(response)
|
154 |
+
response = response + " " + input_check_result + " " output_check_result
|
155 |
|
156 |
|
157 |
"""
|
|
|
174 |
],
|
175 |
)
|
176 |
|
|
|
177 |
|
178 |
|
179 |
if __name__ == "__main__":
|