from flask import Flask, render_template, request
app = Flask(__name__)
def print_board(board):
# Your print_board function code here
# ...
def check_winner(board, player):
# Your check_winner function code here
# ...
def is_board_full(board):
# Your is_board_full function code here
# ...
@app.route('/')
def index():
board = [[" " for _ in range(3)] for _ in range(3)]
return render_template('index.html', board=board)
@app.route('/play', methods=['POST'])
def play():
board = request.form.getlist('cell[]')
current_player = request.form['current_player']
col = int(request.form['col'])
row = int(request.form['row'])
if board[row][col] == " ":
board[row][col] = current_player
if check_winner(board, current_player):
return "win"
elif is_board_full(board):
return "draw"
else:
return "continue"
else:
return "occupied"
if __name__ == '__main__':
app.run(debug=True)
TICTACTOE
| |
---------
| |
---------
| |
---------
Player X's turn
TICTACTOE
| |
---------
| |
---------
| X |
---------
Player O's turn
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/tmp/ipykernel_1767/1995597895.py in <module>
63
64
---> 65 play_game()
/tmp/ipykernel_1767/1995597895.py in play_game()
32 print(f"Player {current_player}'s turn")
33
---> 34 col = int(input("Enter column (0, 1, 2): "))
35 while True:
36 if col in (0, 1, 2):
ValueError: invalid literal for int() with base 10: ''