from flask import Flask, jsonify, request from tictactoe import TicTacToe app = Flask(__name__) game = TicTacToe() @app.route("/make_move", methods=["POST"]) def make_move(): data = request.get_json() move = data.get("move") player = data.get("player") if not move or not player: return jsonify({"error": "Invalid input. 'move' and 'player' are required."}), 400 try: valid_move, board_state = game.make_move(move, player) if valid_move: return jsonify({"board": board_state, "message": "Move successful."}), 200 else: return jsonify({"error": "Invalid move. Try again."}), 400 except Exception as e: return jsonify({"error": str(e)}), 500 @app.route("/get_board", methods=["GET"]) def get_board(): return jsonify({"board": game.get_board()}), 200 if __name__ == "__main__": app.run(debug=True)