From 2ecb0ccfe2094b6617f65296af32122bbe6eb90a Mon Sep 17 00:00:00 2001 From: Francesco Bariatti <francesco.bariatti@insa-rennes.fr> Date: Tue, 8 Mar 2016 14:50:39 +0100 Subject: [PATCH] Added python wrapper of the program for visualising --- src/game/penguin.cpp | 2 +- tools/gui.py | 48 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100755 tools/gui.py diff --git a/src/game/penguin.cpp b/src/game/penguin.cpp index 3a5ae00..ef34e59 100644 --- a/src/game/penguin.cpp +++ b/src/game/penguin.cpp @@ -341,7 +341,7 @@ namespace game obstacles |= ((uint64_t) 1) << (state.p3_blue & 63); obstacles |= ((uint64_t) 1) << (state.p4_blue & 63); - cout << obstacles; + cout << obstacles << endl; state.nb_moves_red = 0; state.nb_moves_blue = 0; diff --git a/tools/gui.py b/tools/gui.py new file mode 100755 index 0000000..c2e33ba --- /dev/null +++ b/tools/gui.py @@ -0,0 +1,48 @@ +#!/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() -- GitLab