Renecto commited on
Commit
b75074b
·
verified ·
1 Parent(s): a2ba12e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -2
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  from PIL import Image, ImageDraw
3
-
 
4
  def initialize_board():
5
  board = [[0 for _ in range(8)] for _ in range(8)]
6
  board[3][3], board[4][4] = 1, 1
@@ -77,7 +78,20 @@ def main():
77
  status = gr.Text(value="Black: 2 | White: 2 | Black to move", interactive=False)
78
 
79
  def click_handler(evt: gr.SelectData, state):
80
- return play_move(evt.index[0], evt.index[1], state)
 
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
  image_box.select(click_handler, inputs=[state], outputs=[image_box, status, state])
83
  demo.launch()
 
1
  import gradio as gr
2
  from PIL import Image, ImageDraw
3
+ from ai import choose_move
4
+
5
  def initialize_board():
6
  board = [[0 for _ in range(8)] for _ in range(8)]
7
  board[3][3], board[4][4] = 1, 1
 
78
  status = gr.Text(value="Black: 2 | White: 2 | Black to move", interactive=False)
79
 
80
  def click_handler(evt: gr.SelectData, state):
81
+ # ユーザーの手
82
+ board_img, status_text, state = play_move(evt.index[0], evt.index[1], state)
83
+ board, player = state
84
+ # AI(White)が動く
85
+ if player == 1:
86
+ ai_move = choose_move(board, player)
87
+ if ai_move:
88
+ apply_move(board, ai_move[0], ai_move[1], player)
89
+ player = -player
90
+ black_score, white_score = count_score(board)
91
+ status_text = f"Black: {black_score} | White: {white_score} | {'Black' if player == -1 else 'White'} to move"
92
+ board_img = board_to_image(board)
93
+ state = (board, player)
94
+ return board_img, status_text, state
95
 
96
  image_box.select(click_handler, inputs=[state], outputs=[image_box, status, state])
97
  demo.launch()