-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
66 lines (45 loc) · 1.54 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
import chess
import base64
from flask import Flask, Response, request, render_template, redirect, url_for
from state import State
from valuator import Valuator
from treesearch import minimax_root
app = Flask(__name__)
# Instatitate chess board.
s = State()
v = Valuator()
max_depth = 4
@app.route('/')
def index():
return render_template("test-page.html")
@app.route("/move_coordinates")
def move_coordinates():
if not s.board.is_game_over():
source = int(request.args.get('from', default=''))
target = int(request.args.get('to', default=''))
promotion = True if request.args.get('promotion', default='') == 'true' else False
move = s.board.san(chess.Move(source, target, promotion=chess.QUEEN if promotion else None))
if move is not None and move != "":
print("Human moves", move)
print("Computing... ")
s.board.push_san(move)
#print(s.board.fen())
computer_move = minimax_root(s, v, max_depth, pruning=True)
#print("computer moves", computer_move)
s.board.push(computer_move)
#print(s.board.fen())
response = app.response_class(
response=s.board.fen(),
status=200
)
return response
print("GAME IS OVER")
response = app.response_class(
response="game over",
status=200
)
return response
def main():
app.run(debug=True)
if __name__ == '__main__':
main()