Skip to content
Snippets Groups Projects
Commit 2ecb0ccf authored by Bariatti Francesco's avatar Bariatti Francesco
Browse files

Added python wrapper of the program for visualising

parent c4fb6ead
No related branches found
No related tags found
No related merge requests found
...@@ -341,7 +341,7 @@ namespace game ...@@ -341,7 +341,7 @@ namespace game
obstacles |= ((uint64_t) 1) << (state.p3_blue & 63); obstacles |= ((uint64_t) 1) << (state.p3_blue & 63);
obstacles |= ((uint64_t) 1) << (state.p4_blue & 63); obstacles |= ((uint64_t) 1) << (state.p4_blue & 63);
cout << obstacles; cout << obstacles << endl;
state.nb_moves_red = 0; state.nb_moves_red = 0;
state.nb_moves_blue = 0; state.nb_moves_blue = 0;
......
#!/usr/bin/env python3
#-*- encoding: utf-8 -*-
import drawState
import subprocess
import json
import os
if __name__ == "__main__":
programname = os.path.join(os.path.dirname(__file__), "../bin/theturk")
program = subprocess.Popen(programname, stdin = subprocess.PIPE, stdout = subprocess.PIPE, universal_newlines = True, bufsize = 1)
try:
while True:
#READ
readloop = True
comments = []
json_data = []
brackets_count = 0
while readloop:
line = program.stdout.readline()
#print(line)
if line.startswith("{"): #in json or entering json
brackets_count += 1
if brackets_count > 0: #We are in the middle of json data
json_data.append(line)
else:
comments.append(line)
if line.startswith("}"):
brackets_count -= 1
if line == "\n":
readloop = False
#PRINT STATE
print("Comments: {}".format(''.join(comments)))
state = json.loads(''.join(json_data))
drawState.drawBitboard(state["bitboards"]["onefish"],state["bitboards"]["twofish"],state["bitboards"]["threefish"])
print("Red penguins")
for i in range(4):
drawState.drawPenguin(state["penguins"]["red"][i])
print("Blue penguins")
for i in range(4):
drawState.drawPenguin(state["penguins"]["blue"][i])
#PLAY NEXT MOVE
move = input("Enter next move: ")
program.stdin.write(move+"\n")
program.stdin.flush()
except KeyboardInterrupt:
print("\nMay the fish be with you.")
finally:
program.kill()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment