X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=qchess%2Fsrc%2Fmain.py;h=531addec646a2ad8f1b442077b2aa69dfb7711ad;hb=639646adb020e0be9433da7b3d5ef6b987c99f71;hp=cbc07f79db30d13c04de20ac2324e392c100f033;hpb=3decbfd61b59ee2611700e7fa96368e02f643d4d;p=progcomp2013.git diff --git a/qchess/src/main.py b/qchess/src/main.py index cbc07f7..531adde 100644 --- a/qchess/src/main.py +++ b/qchess/src/main.py @@ -16,6 +16,7 @@ import os import time turn_delay = 0.5 +sleep_timeout = None [game, graphics] = [None, None] def make_player(name, colour): @@ -68,6 +69,7 @@ def main(argv): global src_file global graphics_enabled global always_reveal_states + global sleep_timeout max_moves = None src_file = None @@ -109,7 +111,9 @@ def main(argv): elif arg[1] == '-' and arg[2:] == "reveal": always_reveal_states = True elif (arg[1] == '-' and arg[2:] == "graphics"): - graphics_enabled = not graphics_enabled + graphics_enabled = True + elif (arg[1] == '-' and arg[2:] == "no-graphics"): + graphics_enabled = False elif (arg[1] == '-' and arg[2:].split("=")[0] == "file"): # Load game from file if len(arg[2:].split("=")) == 1: @@ -119,7 +123,7 @@ def main(argv): if f[0:7] == "http://": src_file = HttpReplay(f) else: - src_file = open(f.split(":")[0], "r", 0) + src_file = FileReplay(f.split(":")[0]) if len(f.split(":")) == 2: max_moves = int(f.split(":")[1]) @@ -147,6 +151,12 @@ def main(argv): agent_timeout = -1 else: agent_timeout = float(arg[2:].split("=")[1]) + elif (arg[1] == '-' and arg[2:].split("=")[0] == "blackout"): + # Screen saver delay + if len(arg[2:].split("=")) == 1: + sleep_timeout = -1 + else: + sleep_timeout = float(arg[2:].split("=")[1]) elif (arg[1] == '-' and arg[2:] == "help"): # Help @@ -186,6 +196,8 @@ def main(argv): if graphics_enabled == True: try: graphics = GraphicsThread(game.board, grid_sz = [64,64]) # Construct a GraphicsThread! + + graphics.sleep_timeout = sleep_timeout except Exception,e: graphics = None @@ -224,6 +236,10 @@ def main(argv): if graphics != None: graphics.board.display_grid(graphics.window, graphics.grid_sz) graphics.message("Connecting to " + p.colour + " player...") + + # Handle race condition by having clients wait longer than servers to connect + if p.address != None: + time.sleep(0.2) p.connect() @@ -270,6 +286,8 @@ def main(argv): if src_file != None and src_file != sys.stdin: src_file.close() + sys.stdout.write(game.final_result + "\n") + return error # This is how python does a main() function...