Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -86,6 +86,47 @@ minimax_player = MinimaxPlayer('O')
|
|
| 86 |
def render_board():
|
| 87 |
return [[game.board[i * 3 + j] for j in range(3)] for i in range(3)]
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
def make_move(row, col):
|
| 90 |
position = row * 3 + col
|
| 91 |
if game.board[position] == ' ':
|
|
|
|
| 86 |
def render_board():
|
| 87 |
return [[game.board[i * 3 + j] for j in range(3)] for i in range(3)]
|
| 88 |
|
| 89 |
+
def create_gui():
|
| 90 |
+
"""Create the Gradio interface"""
|
| 91 |
+
with gr.Blocks() as interface:
|
| 92 |
+
gr.Markdown("# Tic Tac Toe with AI")
|
| 93 |
+
|
| 94 |
+
with gr.Row():
|
| 95 |
+
game_mode = gr.Radio(
|
| 96 |
+
["human_vs_human", "minimax", "q_learning"],
|
| 97 |
+
label="Game Mode",
|
| 98 |
+
value="human_vs_human"
|
| 99 |
+
)
|
| 100 |
+
difficulty = gr.Radio(
|
| 101 |
+
["easy", "medium", "hard"],
|
| 102 |
+
label="AI Difficulty",
|
| 103 |
+
value="medium"
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
board = gr.DataFrame(
|
| 107 |
+
render_board(),
|
| 108 |
+
interactive=True,
|
| 109 |
+
col_count=(3, "fixed"),
|
| 110 |
+
row_count=(3, "fixed")
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
status = gr.Textbox(value="Current player: X", label="Status")
|
| 114 |
+
reset_btn = gr.Button("Reset Game")
|
| 115 |
+
|
| 116 |
+
# Event handlers
|
| 117 |
+
board.select(
|
| 118 |
+
make_move,
|
| 119 |
+
[board.select_data["row"], board.select_data["column"], game_mode, difficulty],
|
| 120 |
+
[board, status]
|
| 121 |
+
)
|
| 122 |
+
reset_btn.click(
|
| 123 |
+
reset_game,
|
| 124 |
+
[game_mode, difficulty],
|
| 125 |
+
[board, status]
|
| 126 |
+
)
|
| 127 |
+
|
| 128 |
+
return interface
|
| 129 |
+
|
| 130 |
def make_move(row, col):
|
| 131 |
position = row * 3 + col
|
| 132 |
if game.board[position] == ' ':
|