Do another refactoring of frontend

This commit is contained in:
2021-12-11 17:15:50 +01:00
parent b5c252bd4d
commit 7dabb49cd4
4 changed files with 61 additions and 64 deletions

View File

@@ -22,11 +22,10 @@ engine = subprocess.Popen(
def make_piece(piece_str):
piece_type, color, file, rank = piece_str
piece_type, color = piece_str
return {
"who": dict(PIECE_TYPE)[piece_type],
"piece_type": dict(PIECE_TYPE)[piece_type],
"color": dict(COLOR)[color],
"position": f"{file}{rank}",
}
@@ -35,10 +34,10 @@ def get_state():
engine.stdin.write(b"get_state\n")
engine.stdin.flush()
position_str = engine.stdout.readline().decode("ascii").strip()
position = [
make_piece(position_str[i : i + 4])
position = {
position_str[i + 2 : i + 4]: make_piece(position_str[i : i + 2])
for i in range(0, len(position_str), 4)
]
}
return flask.jsonify(position)