X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=qchess%2Fqchess.py;h=1dd8691002816907f2fb979b0ed015a46ff08fc9;hb=068745c990538769b9c4fd48f467a0f938e4c0d6;hp=092a121dedd871abede9903298d324cdf4f247fd;hpb=ef3a2d186de4f86b736dc357948a3ca319ef5423;p=progcomp2013.git diff --git a/qchess/qchess.py b/qchess/qchess.py old mode 100644 new mode 100755 index 092a121..1dd8691 --- a/qchess/qchess.py +++ b/qchess/qchess.py @@ -722,7 +722,15 @@ class FifoPlayer(Player): Player.__init__(self, name, colour) os.mkfifo(self.name+".in") os.mkfifo(self.name+".out") - + + try: + self.fifo_out = open_fifo(self.name+".out","w", FifoPlayer.timeout) + except: + raise Exception("FIFO_TIMEOUT") + else: + self.fifo_out.write("START "+colour+"\n") + self.fifo_out.close() + @@ -890,9 +898,11 @@ class HumanPlayer(Player): sys.stdout.write("SELECTION?\n") try: p = map(int, sys.stdin.readline().strip("\r\n ").split(" ")) + return p except: sys.stderr.write("ILLEGAL GIBBERISH\n") continue + # It's your move captain def get_move(self): if isinstance(graphics, GraphicsThread): @@ -908,6 +918,7 @@ class HumanPlayer(Player): sys.stdout.write("MOVE?\n") try: p = map(int, sys.stdin.readline().strip("\r\n ").split(" ")) + return p except: sys.stderr.write("ILLEGAL GIBBERISH\n") continue @@ -1673,11 +1684,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): @@ -1804,14 +1814,17 @@ class GameThread(StoppableThread): break except Exception,e: #if False: - result = e.message - sys.stderr.write("qchess.py exception: "+result + "\n") - - self.stop() + - with self.lock: - self.final_result = self.state["turn"].colour + " " + e.message - break + 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 @@ -2701,6 +2714,7 @@ def main(argv): global sleep_timeout + retry_illegal = False server_addr = None max_moves = None @@ -2798,7 +2812,8 @@ def main(argv): sleep_timeout = -1 else: sleep_timeout = float(arg[2:].split("=")[1]) - + elif (arg[1] == '-' and arg[2:] == "retry-illegal"): + retry_illegal = not retry_illegal elif (arg[1] == '-' and arg[2:] == "help"): # Help os.system("less data/help.txt") # The best help function @@ -2845,6 +2860,7 @@ def main(argv): board = Board(style) board.max_moves = max_moves game = GameThread(board, players) + game.retry_illegal = retry_illegal @@ -2987,4 +3003,4 @@ if __name__ == "__main__": # --- main.py --- # -# EOF - created from make on Sun May 19 12:36:10 WST 2013 +# EOF - created from make on Friday 21 June 18:15:14 WST 2013