Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -86,11 +86,13 @@ def minimax(board, depth, is_maximizing):
|
|
86 |
return best_score
|
87 |
|
88 |
def play_tic_tac_toe(evt: gr.SelectData, board, game_over):
|
|
|
|
|
|
|
|
|
89 |
if game_over:
|
90 |
return draw_board(board), "Game already finished! Please reset to play again.", True
|
91 |
|
92 |
-
print(evt.index)
|
93 |
-
|
94 |
r, c = evt.index[1] // 100, evt.index[0] // 100
|
95 |
if board[r][c] != "":
|
96 |
return draw_board(board), "Invalid move! This spot is already taken. Please select an empty square.", False
|
@@ -124,4 +126,4 @@ with gr.Blocks() as app:
|
|
124 |
board_image.select(play_tic_tac_toe, inputs=[board_state, game_over_state], outputs=[board_image, message_display, game_over_state])
|
125 |
reset_button.click(reset_game, inputs=[], outputs=[board_image, board_state, message_display, game_over_state])
|
126 |
|
127 |
-
app.launch(
|
|
|
86 |
return best_score
|
87 |
|
88 |
def play_tic_tac_toe(evt: gr.SelectData, board, game_over):
|
89 |
+
|
90 |
+
if evt.index is None:
|
91 |
+
return draw_board(board), "Invalid action! Please click on the board.", False
|
92 |
+
|
93 |
if game_over:
|
94 |
return draw_board(board), "Game already finished! Please reset to play again.", True
|
95 |
|
|
|
|
|
96 |
r, c = evt.index[1] // 100, evt.index[0] // 100
|
97 |
if board[r][c] != "":
|
98 |
return draw_board(board), "Invalid move! This spot is already taken. Please select an empty square.", False
|
|
|
126 |
board_image.select(play_tic_tac_toe, inputs=[board_state, game_over_state], outputs=[board_image, message_display, game_over_state])
|
127 |
reset_button.click(reset_game, inputs=[], outputs=[board_image, board_state, message_display, game_over_state])
|
128 |
|
129 |
+
app.launch()
|