Created
November 2, 2017 14:52
-
-
Save highfestiva/64cd22d952f5ce73c03750e51ed1bed4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Server for remote naughts and crosses playing. | |
from flask import Flask, jsonify, request | |
map = [[' ' for _ in range(20)] for _ in range(20)] | |
map[10][10] = 'X' | |
turn = 2 | |
webapp = Flask(__name__) | |
def check_winner(): | |
return | |
@webapp.route('/map') | |
def getmap(): | |
strmap = [''.join(row) for row in map] | |
return jsonify(strmap) | |
@webapp.route('/marker', methods=['PUT']) | |
def marker(): | |
global turn | |
x = int(request.form['x']) | |
y = int(request.form['y']) | |
t = int(request.form['turn']) | |
assert 0 <= x <= len(map) | |
assert 0 <= y <= len(map) | |
if t == turn: | |
map[y][x] = 'X' if t==1 else 'O' | |
turn = 3-t | |
check_winner() | |
return jsonify('ack') | |
r = jsonify('nak') | |
r.status_code = 409 | |
return r | |
webapp.run(host='0.0.0.0', port=9002, threaded=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment