diff --git a/cards-client.py b/cards-client.py index ffdbbbb..c10308a 100755 --- a/cards-client.py +++ b/cards-client.py @@ -1,7 +1,5 @@ #!/usr/bin/env python -#An outline of an engine for concept-to-description/category matching card game. - import random import time import pickle @@ -27,11 +25,15 @@ def __repr__(self): def myTurn(self): try: answer = self.server.request_info((self.number,'myturn')) +# print(answer) return answer except socket.error: - return False - except EOFError: - return False + print("socket error") + return (False, None) + except EOFError as e: +# print("EOFError") +# print(e.args) + return (False, None) def __str__(self): return self.name @@ -156,7 +158,7 @@ def update(s): while True: try: myTurn, slowPlayer = me.myTurn() - update("Waiting for {0}...".format(slowPlayer)) + update("Waiting for {0}...".format(slowPlayer if slowPlayer else "others")) if myTurn: print("Your turn!") me.updateTurnInfo() @@ -177,17 +179,17 @@ def update(s): winner, scores, pool = game.scores print("{0} won this round!".format(winner)) for key in pool.keys(): - print("{0} submitted '{1}'".format(pool[key],key)) + print("{0} submitted '{1}'".format(pool[key],key.strip('\n'))) print("==Scores==") for key in scores.keys(): print("{0}: {1}".format(key,scores[key])) print("\n----------------\n----------------\n") break time.sleep(0.5) - update("Waiting for judgement.. ") + update("Waiting for judgement.. ") time.sleep(0.5) time.sleep(0.5) - update("Waiting for {0}.. ".format(slowPlayer)) + update("Waiting for {0}.. ".format(slowPlayer if slowPlayer else "others")) time.sleep(0.5) except KeyboardInterrupt: sys.exit(0) diff --git a/cards-server.py b/cards-server.py index 0b67f0c..4d695bd 100755 --- a/cards-server.py +++ b/cards-server.py @@ -1,6 +1,5 @@ #!/usr/bin/env python #TODO:who are we waiting for? -#An outline of an engine for concept-to-description/category matching card game. import random import socket @@ -125,6 +124,7 @@ def __init__(self, Deck): self.serv = socket.socket(socket.AF_INET,socket.SOCK_STREAM) ##bind our socket to the address + self.serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.serv.bind((ADDR)) #the double parens are to create a tuple with one element self.initPlayers(self.numPlayers) print [player.name for player in self.players] @@ -190,7 +190,7 @@ def newRound(self): conn,addr = self.serv.accept() data = pickle.loads(conn.recv(self.BUFSIZE)) if str(data[1]) == 'myturn': - conn.send(pickle.dumps((hash(player) == data[0],player.name))) + conn.send(pickle.dumps((hash(self.judge) == data[0],self.judge.name))) conn.close() elif str(data[1]) == 'roundEnd': conn.send(pickle.dumps(False))