-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathengine_server.py
69 lines (53 loc) · 1.86 KB
/
engine_server.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
from flask import Flask, request
import os
from checkers.engine import *
"""
Flask-based server for running Kallisto API checkers engines which require Windows 32 bit environment.
Engine is loaded from DLL. DLL name is currently hard-coded in the init() method (see below).
Engine does not support multiple matches at the same time.
Note! If you don't use Kallisto engine(s) then you are NOT required to be on Windows 32 bit.
Author: Evgeny Tyurin, github.com/evg-tyurin
Date: Feb 19, 2018.
"""
app = Flask(__name__)
app.config['ENGINE'] = "None"
@app.route("/")
def hello():
return "Hello World!"
@app.route('/init', methods=['GET'])
def init():
""" Initializes an engine.
"""
if app.config['ENGINE']=="None":
app.config['ENGINE'] = KallistoApiEngine("./checkers/engine/KestoG_1_4_Moscow.dll")
return "OK, "+app.config['ENGINE'].EI_GetName()
else:
return "OK, already initialized "+app.config['ENGINE'].EI_GetName()
@app.route('/reset', methods=['GET'])
def reset():
if check_engine():
app.config['ENGINE'].reset()
return "OK"
else:
return "Engine not initialized"
@app.route('/think', methods=['GET'])
def think():
if check_engine():
return app.config['ENGINE'].think()
else:
return "Engine not initialized"
@app.route('/make_move', methods=['GET'])
def make_move():
# make_move?list=g3:e5,e5:c3
if check_engine():
list = request.args.get('list')
print("make_move?list="+list)
for move in list.split(","):
app.config['ENGINE'].makeMove(move)
return "OK"
else:
return "Engine not initialized"
def check_engine():
return app.config['ENGINE'] != "None"
if __name__ == "__main__":
app.run("0.0.0.0", 8989)