diff --git a/Konane.py b/Konane.py index ffd9f4c..7e6b6eb 100644 --- a/Konane.py +++ b/Konane.py @@ -6,22 +6,30 @@ # Top level class that has the client and the state class Konane: - def __init__(self): - self.client = client.ArtemisClient("artemis.engr.uconn.edu", 4705) + def __init__(self, pretty=False): + self.client = client.ArtemisClient("artemis.engr.uconn.edu", 4705, pretty) self.state = state.State() + self.playerNumber = None self.color = None self.player = None + self.pretty = pretty + def stringToCoords(self, string): coords = [] coords.append(int(string[string.find("[")+1:string.find(":")])) coords.append(int(string[string.find(":")+1:string.find("]")])) - return coords + # convert from BOTTOM-lowest to TOP-lowest + newCoords = [17-coords[0], coords[1]] + + return newCoords def coordsToString(self, coords): - return "[{0}:{1}]".format(coords[0], coords[1]) + #convert from TOP-lowest to BOTTOM-lowest + newCoords = [17-coords[0], coords[1]] + return "[{0}:{1}]".format(newCoords[0], newCoords[1]) def start(self): firstMove = self.coordsToString(self.state.first_moves_set()[0]) @@ -57,8 +65,6 @@ def start(self): myTurn = False finished = False - #print(self.state) - turns = 0 while(not finished): if(myTurn): moveCoords = self.state.makeMove(self.color) @@ -88,7 +94,8 @@ def start(self): break myTurn = not myTurn - print(self.state) + if(self.pretty): + print(self.state) self.client.close() diff --git a/__pycache__/client.cpython-36.pyc b/__pycache__/client.cpython-36.pyc index dec3fe6..b68e817 100644 Binary files a/__pycache__/client.cpython-36.pyc and b/__pycache__/client.cpython-36.pyc differ diff --git a/client.py b/client.py index 98fa29f..55340b7 100644 --- a/client.py +++ b/client.py @@ -3,7 +3,7 @@ import time class ArtemisClient: - def __init__(self, server_host, server_port): + def __init__(self, server_host, server_port, pretty=False): self.server_host = server_host self.server_port = server_port self.username = None @@ -13,6 +13,8 @@ def __init__(self, server_host, server_port): self.color = None self.server_sock = None + self.pretty = pretty + self.gameOver = False def extractREMOVED(self, string): @@ -53,9 +55,8 @@ def send(self, string): return "GAME OVER" formatted_string = string.rstrip() + "\r\n" - print("**********************\n" + formatted_string + "**********************") - #formatted_string = string - #print(formatted_string, end="") + if(self.pretty): + print("**********************\n" + formatted_string + "**********************") self.server_sock.send(formatted_string.encode()) def sendREMOVE(self, piece): @@ -73,8 +74,7 @@ def waitREMOVE(self): def waitMOVE(self, myTurn): response = dummyResponse = self.waitForResponse() # wait til i receive '?Move', so I know can transmit once it's my turn - while(not myTurn and dummyResponse.find("?Move") == -1): - #print("hit") + while(not myTurn and dummyResponse.find("?Move") == -1 and (not self.gameOver)): dummyResponse = self.waitForResponse()