Add array reply parsing to the adapter
This commit is contained in:
@@ -34,7 +34,7 @@ def ask_engine(command):
|
|||||||
engine.stdin.write(f"{command}\n".encode("ascii"))
|
engine.stdin.write(f"{command}\n".encode("ascii"))
|
||||||
engine.stdin.flush()
|
engine.stdin.flush()
|
||||||
reply = engine.stdout.readline().decode("ascii").strip()
|
reply = engine.stdout.readline().decode("ascii").strip()
|
||||||
status, result = reply.split(",")
|
status, *result = reply.split(",")
|
||||||
if status != "ok":
|
if status != "ok":
|
||||||
flask.abort(400)
|
flask.abort(400)
|
||||||
return result
|
return result
|
||||||
@@ -49,14 +49,14 @@ def parse_state(state_str):
|
|||||||
|
|
||||||
@app.route("/get_state/")
|
@app.route("/get_state/")
|
||||||
def get_state():
|
def get_state():
|
||||||
state_str = ask_engine("get_state")
|
(state_str,) = ask_engine("get_state")
|
||||||
return flask.jsonify(parse_state(state_str))
|
return flask.jsonify(parse_state(state_str))
|
||||||
|
|
||||||
|
|
||||||
@app.route("/get_moves/", methods=["POST"])
|
@app.route("/get_moves/", methods=["POST"])
|
||||||
def get_moves():
|
def get_moves():
|
||||||
position_str = flask.request.json
|
position_str = flask.request.json
|
||||||
moves_str = ask_engine(f"get_moves,{position_str}")
|
(moves_str,) = ask_engine(f"get_moves,{position_str}")
|
||||||
moves = [moves_str[i : i + 2] for i in range(0, len(moves_str), 2)]
|
moves = [moves_str[i : i + 2] for i in range(0, len(moves_str), 2)]
|
||||||
return flask.jsonify(moves)
|
return flask.jsonify(moves)
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ def get_moves():
|
|||||||
@app.route("/make_move/", methods=["POST"])
|
@app.route("/make_move/", methods=["POST"])
|
||||||
def make_move():
|
def make_move():
|
||||||
source, target = flask.request.json
|
source, target = flask.request.json
|
||||||
state_str = ask_engine(f"make_move,{source},{target}")
|
(state_str,) = ask_engine(f"make_move,{source},{target}")
|
||||||
return flask.jsonify(parse_state(state_str))
|
return flask.jsonify(parse_state(state_str))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user