X-Git-Url: https://git.ucc.asn.au/?p=progcomp2013.git;a=blobdiff_plain;f=qchess%2Fsrc%2Fgame.py;h=15c53b1315086129fcc8dd21497b1ad7b3393bd9;hp=f1f48bb808f4ee3dfaf0e6f6a5aea33e44b45a43;hb=538a32cb30f21a1a48653d7b639ab0c82db44d83;hpb=573931ea67fa99135eca781ff814933e04df4308 diff --git a/qchess/src/game.py b/qchess/src/game.py index f1f48bb..15c53b1 100644 --- a/qchess/src/game.py +++ b/qchess/src/game.py @@ -15,11 +15,10 @@ class GameThread(StoppableThread): self.cond = threading.Condition() # conditional for some reason, I forgot self.final_result = "" self.server = server + self.retry_illegal = False - - - + # Run the game (run in new thread with start(), run in current thread with run()) def run(self): @@ -29,8 +28,8 @@ class GameThread(StoppableThread): for p in self.players: with self.lock: self.state["turn"] = p.base_player() - #try: - if True: + try: + #if True: [x,y] = p.select() # Player selects a square if self.stopped(): #debug("Quitting in select") @@ -80,10 +79,10 @@ class GameThread(StoppableThread): graphics.state["dest"] = None continue - try: - [x2,y2] = p.get_move() # Player selects a destination - except: - self.stop() + #try: + [x2,y2] = p.get_move() # Player selects a destination + #except: + # self.stop() if self.stopped(): #debug("Quitting in get_move") @@ -132,26 +131,32 @@ class GameThread(StoppableThread): graphics.state["dest"] = None graphics.state["moves"] = None - # Commented out exception stuff for now, because it makes it impossible to tell if I made an IndentationError somewhere - # except Exception,e: - # result = e.message - # #sys.stderr.write(result + "\n") - # - # self.stop() - # with self.lock: - # self.final_result = self.state["turn"].colour + " " + e.message - - end = self.board.end_condition() - if end != None: - with self.lock: - if end == "DRAW": - self.final_result = self.state["turn"].colour + " " + end - else: - self.final_result = end - self.stop() + + end = self.board.end_condition() + if end != None: + with self.lock: + if end == "DRAW": + self.final_result = self.state["turn"].colour + " " + end + else: + self.final_result = end + self.stop() - if self.stopped(): - break + if self.stopped(): + break + except Exception,e: + #if False: + + + result = e.message + if self.retry_illegal: + self.state["turn"].update(result); + else: + sys.stderr.write("qchess.py exception: "+result + "\n") + self.stop() + with self.lock: + self.final_result = self.state["turn"].colour + " " + e.message + break + for p2 in self.players: