Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
finished
  • Loading branch information
john.wohl@uconn.edu committed Dec 13, 2019
1 parent bbe2182 commit badced4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
21 changes: 14 additions & 7 deletions Konane.py
Expand Up @@ -6,22 +6,30 @@ import math
# 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])
Expand Down Expand Up @@ -57,8 +65,6 @@ class Konane:
myTurn = False

finished = False
#print(self.state)
turns = 0
while(not finished):
if(myTurn):
moveCoords = self.state.makeMove(self.color)
Expand Down Expand Up @@ -88,7 +94,8 @@ class Konane:
break

myTurn = not myTurn
print(self.state)
if(self.pretty):
print(self.state)

self.client.close()

Expand Down
Binary file modified __pycache__/client.cpython-36.pyc
Binary file not shown.
12 changes: 6 additions & 6 deletions client.py
Expand Up @@ -3,7 +3,7 @@ import sys
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
Expand All @@ -13,6 +13,8 @@ class ArtemisClient:
self.color = None
self.server_sock = None

self.pretty = pretty

self.gameOver = False

def extractREMOVED(self, string):
Expand Down Expand Up @@ -53,9 +55,8 @@ class ArtemisClient:
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):
Expand All @@ -73,8 +74,7 @@ class ArtemisClient:
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()


Expand Down

0 comments on commit badced4

Please sign in to comment.