Do another refactoring of frontend
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user