-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
74 lines (60 loc) · 1.68 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import traceback
from flask import Flask, render_template, request, jsonify, Response
from scripts.chess_game import ChessGame
app = Flask(__name__, template_folder='templates')
chessGame = ChessGame('Minimax', 3)
@app.route('/')
def index():
return render_template('index.html')
# Display Board
@app.route("/board.svg/")
def board():
return Response(chessGame.getBoardSVG(), mimetype='image/svg+xml')
# New Game
@app.route("/game/", methods=['GET', 'POST'])
def newGame():
chessGame.resetBoard()
color = request.args.get('color', default="1")
chessGame.setIsWhitePlayer(color == "1")
return index()
# Human Move
@app.route("/move/", methods=['GET', 'POST'])
def move():
try:
move = request.args.get('move', default="")
gameState = chessGame.humanMove(move)
if gameState == 3:
render_template('index.html')
return index()
except:
traceback.print_exc()
# Bot Move
@app.route("/dev/", methods=['GET', 'POST'])
def dev():
try:
gameState = chessGame.botMove()
# if gameState == 3 & gameState == 4:
if gameState == 3:
render_template('index.html')
return index()
except:
traceback.print_exc()
# Undo move
@app.route("/undo/", methods=['POST'])
def undo():
chessGame.undoMove()
return index()
# Change aimodule
@app.route("/aimodule/", methods=['GET', 'POST'])
def aimodule():
aimodule = request.args.get('aimodule', default="Minimax")
chessGame.setAiModule(aimodule)
return index()
# Change searching depth
@app.route("/depth/", methods=['GET', 'POST'])
def aidepth():
depth = request.args.get('depth', default="3")
chessGame.setDepthSearch(int(depth))
return index()
if __name__ == '__main__':
app.run(debug=False)