Spaces:
Runtime error
Runtime error
alperugurcan
commited on
Commit
•
1e4c6d3
1
Parent(s):
c63dd1f
Update app.py
Browse files
app.py
CHANGED
@@ -52,24 +52,28 @@ def play_game(board, col, state):
|
|
52 |
if state["game_over"]:
|
53 |
return board, "Game is over! Click 'New Game' to play again."
|
54 |
|
|
|
|
|
|
|
|
|
55 |
# Player move
|
56 |
-
|
57 |
-
if check_winner(
|
58 |
state["game_over"] = True
|
59 |
-
return format_board(
|
60 |
|
61 |
# AI move
|
62 |
config = Configuration({"rows": 6, "columns": 7, "inarow": 4})
|
63 |
-
obs = Observation({"board":
|
64 |
|
65 |
ai_col = my_agent(obs, config)
|
66 |
-
|
67 |
|
68 |
-
if check_winner(
|
69 |
state["game_over"] = True
|
70 |
-
return format_board(
|
71 |
|
72 |
-
return format_board(
|
73 |
|
74 |
def create_ui():
|
75 |
with gr.Blocks(css=css) as demo:
|
@@ -78,7 +82,11 @@ def create_ui():
|
|
78 |
|
79 |
state = gr.State({"game_over": False})
|
80 |
|
81 |
-
|
|
|
|
|
|
|
|
|
82 |
board = gr.Dataframe(
|
83 |
value=format_board(initialize_game()),
|
84 |
interactive=False,
|
@@ -89,10 +97,6 @@ def create_ui():
|
|
89 |
)
|
90 |
|
91 |
message = gr.Textbox(value="Your turn!", label="Status")
|
92 |
-
|
93 |
-
with gr.Row():
|
94 |
-
buttons = [gr.Button(str(i)) for i in range(7)]
|
95 |
-
|
96 |
new_game = gr.Button("New Game")
|
97 |
|
98 |
def reset_game():
|
|
|
52 |
if state["game_over"]:
|
53 |
return board, "Game is over! Click 'New Game' to play again."
|
54 |
|
55 |
+
# Convert Dataframe to numpy array for game logic
|
56 |
+
board_array = np.array([[0 if cell == "⚪" else 1 if cell == "🔴" else 2 for cell in row]
|
57 |
+
for row in board.values.tolist()])
|
58 |
+
|
59 |
# Player move
|
60 |
+
board_array = make_move(board_array, col, 1)
|
61 |
+
if check_winner(board_array):
|
62 |
state["game_over"] = True
|
63 |
+
return format_board(board_array), "You win! 🎉"
|
64 |
|
65 |
# AI move
|
66 |
config = Configuration({"rows": 6, "columns": 7, "inarow": 4})
|
67 |
+
obs = Observation({"board": board_array.flatten().tolist(), "mark": 2})
|
68 |
|
69 |
ai_col = my_agent(obs, config)
|
70 |
+
board_array = make_move(board_array, ai_col, 2)
|
71 |
|
72 |
+
if check_winner(board_array):
|
73 |
state["game_over"] = True
|
74 |
+
return format_board(board_array), "AI wins! 🤖"
|
75 |
|
76 |
+
return format_board(board_array), "Your turn!"
|
77 |
|
78 |
def create_ui():
|
79 |
with gr.Blocks(css=css) as demo:
|
|
|
82 |
|
83 |
state = gr.State({"game_over": False})
|
84 |
|
85 |
+
with gr.Row():
|
86 |
+
# Add column buttons at the top
|
87 |
+
buttons = [gr.Button(str(i)) for i in range(7)]
|
88 |
+
|
89 |
+
# Board display below the buttons
|
90 |
board = gr.Dataframe(
|
91 |
value=format_board(initialize_game()),
|
92 |
interactive=False,
|
|
|
97 |
)
|
98 |
|
99 |
message = gr.Textbox(value="Your turn!", label="Status")
|
|
|
|
|
|
|
|
|
100 |
new_game = gr.Button("New Game")
|
101 |
|
102 |
def reset_game():
|