Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -55,11 +55,12 @@ with gr.Blocks(css=".cell-btn {height: 100px; width: 100px; font-size: 2em; text
|
|
55 |
current_player = gr.State("X")
|
56 |
game_status = gr.Textbox(value="Player 1's turn (X)", label="Game Status", interactive=False)
|
57 |
|
58 |
-
# Create grid buttons
|
59 |
buttons = []
|
60 |
for i in range(3):
|
61 |
with gr.Row():
|
62 |
for j in range(3):
|
|
|
63 |
btn = gr.Button(value="", elem_classes=["cell-btn"], elem_id=f"button_{i*3 + j}")
|
64 |
buttons.append(btn)
|
65 |
|
@@ -67,7 +68,7 @@ with gr.Blocks(css=".cell-btn {height: 100px; width: 100px; font-size: 2em; text
|
|
67 |
for idx, btn in enumerate(buttons):
|
68 |
btn.click(
|
69 |
handle_move,
|
70 |
-
inputs=[board_state, current_player, gr.Number(idx)], #
|
71 |
outputs=[board_state, current_player, game_status, *buttons],
|
72 |
)
|
73 |
|
|
|
55 |
current_player = gr.State("X")
|
56 |
game_status = gr.Textbox(value="Player 1's turn (X)", label="Game Status", interactive=False)
|
57 |
|
58 |
+
# Create grid buttons without displaying any Number components
|
59 |
buttons = []
|
60 |
for i in range(3):
|
61 |
with gr.Row():
|
62 |
for j in range(3):
|
63 |
+
# Each button is clickable, the index is passed in hidden and used internally
|
64 |
btn = gr.Button(value="", elem_classes=["cell-btn"], elem_id=f"button_{i*3 + j}")
|
65 |
buttons.append(btn)
|
66 |
|
|
|
68 |
for idx, btn in enumerate(buttons):
|
69 |
btn.click(
|
70 |
handle_move,
|
71 |
+
inputs=[board_state, current_player, gr.Number(idx, visible=False)], # Hide the number input
|
72 |
outputs=[board_state, current_player, game_status, *buttons],
|
73 |
)
|
74 |
|