Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import random
|
|
| 2 |
import numpy as np
|
| 3 |
import gradio as gr
|
| 4 |
|
|
|
|
| 5 |
class TicTacToe:
|
| 6 |
def __init__(self):
|
| 7 |
self.board = [' '] * 9
|
|
@@ -161,8 +162,9 @@ def render_board():
|
|
| 161 |
board.append(row)
|
| 162 |
return board
|
| 163 |
|
| 164 |
-
def make_move(
|
| 165 |
"""Handle player moves and AI responses"""
|
|
|
|
| 166 |
position = row * 3 + col
|
| 167 |
status = ""
|
| 168 |
|
|
@@ -225,6 +227,7 @@ def create_gui():
|
|
| 225 |
|
| 226 |
board = gr.DataFrame(
|
| 227 |
render_board(),
|
|
|
|
| 228 |
interactive=True,
|
| 229 |
col_count=(3, "fixed"),
|
| 230 |
row_count=(3, "fixed")
|
|
@@ -233,10 +236,10 @@ def create_gui():
|
|
| 233 |
status = gr.Textbox(value="Current player: X", label="Status")
|
| 234 |
reset_btn = gr.Button("Reset Game")
|
| 235 |
|
| 236 |
-
# Event handlers
|
| 237 |
board.select(
|
| 238 |
make_move,
|
| 239 |
-
[
|
| 240 |
[board, status]
|
| 241 |
)
|
| 242 |
reset_btn.click(
|
|
@@ -250,4 +253,4 @@ def create_gui():
|
|
| 250 |
# Launch the interface
|
| 251 |
if __name__ == "__main__":
|
| 252 |
interface = create_gui()
|
| 253 |
-
interface.launch()
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
+
# [All classes remain exactly the same - TicTacToe, MinimaxPlayer, QLearningPlayer]
|
| 6 |
class TicTacToe:
|
| 7 |
def __init__(self):
|
| 8 |
self.board = [' '] * 9
|
|
|
|
| 162 |
board.append(row)
|
| 163 |
return board
|
| 164 |
|
| 165 |
+
def make_move(evt: gr.SelectData, game_mode, difficulty): # Changed the parameters here
|
| 166 |
"""Handle player moves and AI responses"""
|
| 167 |
+
row, col = evt.index # Get row and col from the event
|
| 168 |
position = row * 3 + col
|
| 169 |
status = ""
|
| 170 |
|
|
|
|
| 227 |
|
| 228 |
board = gr.DataFrame(
|
| 229 |
render_board(),
|
| 230 |
+
headers=False,
|
| 231 |
interactive=True,
|
| 232 |
col_count=(3, "fixed"),
|
| 233 |
row_count=(3, "fixed")
|
|
|
|
| 236 |
status = gr.Textbox(value="Current player: X", label="Status")
|
| 237 |
reset_btn = gr.Button("Reset Game")
|
| 238 |
|
| 239 |
+
# Event handlers - Fixed the event handling here
|
| 240 |
board.select(
|
| 241 |
make_move,
|
| 242 |
+
[game_mode, difficulty],
|
| 243 |
[board, status]
|
| 244 |
)
|
| 245 |
reset_btn.click(
|
|
|
|
| 253 |
# Launch the interface
|
| 254 |
if __name__ == "__main__":
|
| 255 |
interface = create_gui()
|
| 256 |
+
interface.launch()
|