Spaces:
Sleeping
Sleeping
Commit
·
15408a8
1
Parent(s):
14e2831
Get input from AI
Browse files
app.py
CHANGED
@@ -93,9 +93,9 @@ def aiPlayer(squares: List[str]) -> int:
|
|
93 |
param_3=512,
|
94 |
api_name="/chat"
|
95 |
)
|
96 |
-
print(result)
|
97 |
|
98 |
-
|
|
|
99 |
|
100 |
|
101 |
def botPlayer(squares: List[str]) -> int:
|
@@ -147,7 +147,7 @@ def is_square_empty():
|
|
147 |
return False
|
148 |
|
149 |
|
150 |
-
def on_submit(number):
|
151 |
if not is_square_empty():
|
152 |
reset_squares()
|
153 |
|
@@ -160,13 +160,20 @@ def on_submit(number):
|
|
160 |
gr.Info("Move already made!")
|
161 |
return boardTemplate.format(*squares)
|
162 |
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
|
171 |
if not is_square_empty():
|
172 |
gr.Info("It's a tie!")
|
@@ -192,7 +199,11 @@ with (gr.Blocks(css=css) as demo):
|
|
192 |
maximum=8,
|
193 |
step=1,
|
194 |
)
|
195 |
-
|
|
|
|
|
|
|
|
|
196 |
|
197 |
gr.Markdown(LICENSE)
|
198 |
|
|
|
93 |
param_3=512,
|
94 |
api_name="/chat"
|
95 |
)
|
|
|
96 |
|
97 |
+
print(f"AI's move: {result}")
|
98 |
+
return int(result)
|
99 |
|
100 |
|
101 |
def botPlayer(squares: List[str]) -> int:
|
|
|
147 |
return False
|
148 |
|
149 |
|
150 |
+
def on_submit(number, chk):
|
151 |
if not is_square_empty():
|
152 |
reset_squares()
|
153 |
|
|
|
160 |
gr.Info("Move already made!")
|
161 |
return boardTemplate.format(*squares)
|
162 |
|
163 |
+
if chk:
|
164 |
+
ai_move = aiPlayer(squares)
|
165 |
+
if is_empty(squares, ai_move):
|
166 |
+
squares[ai_move] = " O "
|
167 |
+
if checkWin(False, squares):
|
168 |
+
gr.Info("You lose!")
|
169 |
+
return "<h3>You lose!</h3>"
|
170 |
+
else:
|
171 |
+
bot_move = botPlayer(squares)
|
172 |
+
if is_empty(squares, bot_move):
|
173 |
+
squares[bot_move] = " O "
|
174 |
+
if checkWin(False, squares):
|
175 |
+
gr.Info("You lose!")
|
176 |
+
return "<h3>You lose!</h3>"
|
177 |
|
178 |
if not is_square_empty():
|
179 |
gr.Info("It's a tie!")
|
|
|
199 |
maximum=8,
|
200 |
step=1,
|
201 |
)
|
202 |
+
chk = gr.Checkbox(
|
203 |
+
False,
|
204 |
+
label="AI Component",
|
205 |
+
)
|
206 |
+
num.submit(on_submit, inputs=[num, chk], outputs=[board])
|
207 |
|
208 |
gr.Markdown(LICENSE)
|
209 |
|