alperugurcan commited on
Commit
d14157e
1 Parent(s): d3b026f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -45
app.py CHANGED
@@ -57,7 +57,7 @@ def format_board(board):
57
 
58
  def play_game(board, col, state):
59
  if state["game_over"]:
60
- return board, "Game is over! Click 'New Game' to play again."
61
 
62
  # Convert display format to game logic format
63
  board_array = np.array([[0 if cell == SYMBOLS[EMPTY] else
@@ -68,7 +68,7 @@ def play_game(board, col, state):
68
  board_array = make_move(board_array, col, PLAYER)
69
  if check_winner(board_array):
70
  state["game_over"] = True
71
- return format_board(board_array), "You win! 🎉"
72
 
73
  # AI move
74
  config = Configuration({"rows": BOARD_SIZE[0], "columns": BOARD_SIZE[1], "inarow": WIN_LENGTH})
@@ -79,9 +79,9 @@ def play_game(board, col, state):
79
 
80
  if check_winner(board_array):
81
  state["game_over"] = True
82
- return format_board(board_array), "AI wins! 🤖"
83
 
84
- return format_board(board_array), "Your turn!"
85
 
86
  css = """
87
  #board {
@@ -102,43 +102,8 @@ css = """
102
  width: 14.28%;
103
  height: 40px;
104
  vertical-align: middle;
105
- background: #f0f0f0; /* Light background for cells */
106
- border-radius: 4px; /* Rounded corners */
107
- }
108
- .button-container {
109
- max-width: 400px;
110
- margin: 0 auto 20px auto;
111
- padding: 10px;
112
- }
113
- .button-row {
114
- display: flex;
115
- justify-content: space-between;
116
- gap: 10px;
117
- }
118
- .button-row button {
119
- flex: 1;
120
- min-width: 40px;
121
- height: 40px;
122
- }
123
- """
124
- #board {
125
- max-width: 400px;
126
- margin: 20px auto;
127
- overflow: visible !important;
128
- }
129
- #board table {
130
- width: 100%;
131
- table-layout: fixed;
132
- border-collapse: separate;
133
- border-spacing: 4px;
134
- }
135
- #board td {
136
- text-align: center;
137
- font-size: 28px;
138
- padding: 8px;
139
- width: 14.28%;
140
- height: 40px;
141
- vertical-align: middle;
142
  }
143
  .button-container {
144
  max-width: 400px;
@@ -164,12 +129,10 @@ def create_ui():
164
 
165
  state = gr.State({"game_over": False})
166
 
167
- # Button container
168
  with gr.Row(elem_classes="button-container"):
169
  with gr.Row(elem_classes="button-row"):
170
  buttons = [gr.Button(str(i), size="sm") for i in range(BOARD_SIZE[1])]
171
 
172
- # Updated Dataframe configuration
173
  board = gr.Dataframe(
174
  value=format_board(initialize_game()),
175
  interactive=False,
@@ -201,5 +164,6 @@ def create_ui():
201
 
202
  return demo
203
 
204
- demo = create_ui()
205
- demo.launch()
 
 
57
 
58
  def play_game(board, col, state):
59
  if state["game_over"]:
60
+ return board, "Game is over! Click 'New Game' to play again.", state
61
 
62
  # Convert display format to game logic format
63
  board_array = np.array([[0 if cell == SYMBOLS[EMPTY] else
 
68
  board_array = make_move(board_array, col, PLAYER)
69
  if check_winner(board_array):
70
  state["game_over"] = True
71
+ return format_board(board_array), "You win! 🎉", state
72
 
73
  # AI move
74
  config = Configuration({"rows": BOARD_SIZE[0], "columns": BOARD_SIZE[1], "inarow": WIN_LENGTH})
 
79
 
80
  if check_winner(board_array):
81
  state["game_over"] = True
82
+ return format_board(board_array), "AI wins! 🤖", state
83
 
84
+ return format_board(board_array), "Your turn!", state
85
 
86
  css = """
87
  #board {
 
102
  width: 14.28%;
103
  height: 40px;
104
  vertical-align: middle;
105
+ background: #f0f0f0;
106
+ border-radius: 4px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  }
108
  .button-container {
109
  max-width: 400px;
 
129
 
130
  state = gr.State({"game_over": False})
131
 
 
132
  with gr.Row(elem_classes="button-container"):
133
  with gr.Row(elem_classes="button-row"):
134
  buttons = [gr.Button(str(i), size="sm") for i in range(BOARD_SIZE[1])]
135
 
 
136
  board = gr.Dataframe(
137
  value=format_board(initialize_game()),
138
  interactive=False,
 
164
 
165
  return demo
166
 
167
+ if __name__ == "__main__":
168
+ demo = create_ui()
169
+ demo.launch()