ashish-001 commited on
Commit
f29f094
·
verified ·
1 Parent(s): 6b49530

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -13
app.py CHANGED
@@ -58,18 +58,21 @@ def play_nn(curr_fen, model):
58
 
59
  def make_move(move):
60
  global board
61
- if not board.outcome():
62
- if len(move) > 3:
63
- turn = "White"
64
- new_turn = "Black"
65
- if chess.Move.from_uci(move) in board.legal_moves:
66
- board.push(chess.Move.from_uci(move))
67
- ai_move = str(play_nn(board.fen(), model))
68
- board.push(chess.Move.from_uci(ai_move))
69
- message = f"{turn} move: {move},move accepted\nAI moved: {ai_move}\n\n{turn}'s move."
70
- else:
71
- message = f"{turn} move: Illegal move. Please try again."
72
- return message, display_board(board)
 
 
 
73
  else:
74
  winner = "White" if board.outcome() == chess.WHITE else "Black"
75
  return f"{winner} won", display_board(board)
@@ -86,7 +89,7 @@ with gr.Blocks() as demo:
86
  gr.Markdown("## Chess board game")
87
  with gr.Row():
88
  with gr.Column():
89
- move_input = gr.Textbox(placeholder="Enter your move in UCI format", lines=1)
90
  move_button = gr.Button("Make move")
91
  reset_button = gr.Button("Reset Board")
92
  status_output = gr.Textbox(label='Status', interactive=False)
 
58
 
59
  def make_move(move):
60
  global board
61
+ if len(move) > 3:
62
+ turn = "White"
63
+ new_turn = "Black"
64
+ if chess.Move.from_uci(move) in board.legal_moves:
65
+ board.push(chess.Move.from_uci(move))
66
+ if board.outcome():
67
+ return f"White won", display_board(board)
68
+ ai_move = str(play_nn(board.fen(), model))
69
+ board.push(chess.Move.from_uci(ai_move))
70
+ if board.outcome():
71
+ return f"Black won", display_board(board)
72
+ message = f"{turn} move: {move},move accepted\nAI moved: {ai_move}\n\n{turn}'s move."
73
+ else:
74
+ message = f"{turn} move: Illegal move. Please try again."
75
+ return message, display_board(board)
76
  else:
77
  winner = "White" if board.outcome() == chess.WHITE else "Black"
78
  return f"{winner} won", display_board(board)
 
89
  gr.Markdown("## Chess board game")
90
  with gr.Row():
91
  with gr.Column():
92
+ move_input = gr.Textbox(placeholder="Enter your move in UCI format (e.g. e2e3)", lines=1)
93
  move_button = gr.Button("Make move")
94
  reset_button = gr.Button("Reset Board")
95
  status_output = gr.Textbox(label='Status', interactive=False)