Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
|
4 |
def check_winner(board):
|
5 |
# Check rows, columns, and diagonals for a win
|
6 |
for i in range(3):
|
@@ -67,7 +66,8 @@ def update_buttons(board, game_active):
|
|
67 |
return updates
|
68 |
|
69 |
def reset_game():
|
70 |
-
|
|
|
71 |
|
72 |
with gr.Blocks(css="""
|
73 |
.tic-btn {
|
@@ -78,7 +78,7 @@ with gr.Blocks(css="""
|
|
78 |
""") as demo:
|
79 |
board_state = gr.State([['', '', ''], ['', '', ''], ['', '', '']])
|
80 |
current_player_state = gr.State('X')
|
81 |
-
game_over_state = gr.State(False)
|
82 |
status = gr.Markdown(value="Player X's turn")
|
83 |
|
84 |
buttons = []
|
@@ -94,8 +94,8 @@ with gr.Blocks(css="""
|
|
94 |
for idx, btn in enumerate(buttons):
|
95 |
btn.click(
|
96 |
fn=handle_move,
|
97 |
-
inputs=[gr.State(idx), board_state, current_player_state, game_over_state],
|
98 |
-
outputs=[board_state, status, current_player_state, game_over_state] + buttons
|
99 |
)
|
100 |
|
101 |
new_game_btn = gr.Button("New Game")
|
|
|
1 |
import gradio as gr
|
2 |
|
|
|
3 |
def check_winner(board):
|
4 |
# Check rows, columns, and diagonals for a win
|
5 |
for i in range(3):
|
|
|
66 |
return updates
|
67 |
|
68 |
def reset_game():
|
69 |
+
board = [['', '', ''], ['', '', ''], ['', '', '']] # Corrected the board initialization
|
70 |
+
return (board, "Player X's turn", 'X', False, *update_buttons(board, True))
|
71 |
|
72 |
with gr.Blocks(css="""
|
73 |
.tic-btn {
|
|
|
78 |
""") as demo:
|
79 |
board_state = gr.State([['', '', ''], ['', '', ''], ['', '', '']])
|
80 |
current_player_state = gr.State('X')
|
81 |
+
game_over_state = gr.State(False)
|
82 |
status = gr.Markdown(value="Player X's turn")
|
83 |
|
84 |
buttons = []
|
|
|
94 |
for idx, btn in enumerate(buttons):
|
95 |
btn.click(
|
96 |
fn=handle_move,
|
97 |
+
inputs=[gr.State(idx), board_state, current_player_state, game_over_state],
|
98 |
+
outputs=[board_state, status, current_player_state, game_over_state] + buttons
|
99 |
)
|
100 |
|
101 |
new_game_btn = gr.Button("New Game")
|