Add screen blackout to qchess
[progcomp2013.git] / qchess / src / main.py
index 137d1cb..7e862a9 100644 (file)
@@ -16,6 +16,7 @@ import os
 import time
 
 turn_delay = 0.5
+sleep_timeout = None
 [game, graphics] = [None, None]
 
 def make_player(name, colour):
@@ -64,12 +65,13 @@ def main(argv):
        
        global turn_delay
        global agent_timeout
-       global log_file
+       global log_files
        global src_file
        global graphics_enabled
        global always_reveal_states
+       global sleep_timeout
 
-       max_lines = None
+       max_moves = None
        src_file = None
        
        style = "quantum"
@@ -109,23 +111,33 @@ 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:
                                src_file = sys.stdin
                        else:
-                               src_file = open(arg[2:].split("=")[1].split(":")[0])
+                               f = arg[2:].split("=")[1]
+                               if f[0:7] == "http://":
+                                       src_file = HttpReplay(f)
+                               else:
+                                       src_file = FileReplay(f.split(":")[0])
 
-                       if len(arg[2:].split(":")) == 2:
-                               max_lines = int(arg[2:].split(":")[1])
+                                       if len(f.split(":")) == 2:
+                                               max_moves = int(f.split(":")[1])
 
                elif (arg[1] == '-' and arg[2:].split("=")[0] == "log"):
                        # Log file
                        if len(arg[2:].split("=")) == 1:
-                               log_file = sys.stdout
+                               log_files.append(LogFile(sys.stdout))
                        else:
-                               log_file = open(arg[2:].split("=")[1], "w")
+                               f = arg[2:].split("=")[1]
+                               if f[0] == '@':
+                                       log_files.append(ShortLog(f[1:]))
+                               else:
+                                       log_files.append(LogFile(open(f, "w", 0)))
                elif (arg[1] == '-' and arg[2:].split("=")[0] == "delay"):
                        # Delay
                        if len(arg[2:].split("=")) == 1:
@@ -139,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
@@ -165,17 +183,21 @@ def main(argv):
                        if graphics_enabled:
                                sys.stderr.write(sys.argv[0] + " : (You won't get a GUI, because --file was used, and the author is lazy)\n")
                        return 44
-               game = ReplayThread(players, src_file, end=end, max_lines=max_lines)
+               game = ReplayThread(players, src_file, end=end, max_moves=max_moves)
        else:
                board = Board(style)
+               board.max_moves = max_moves
                game = GameThread(board, players) 
 
 
 
+
        # Initialise GUI
        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
@@ -254,13 +276,14 @@ def main(argv):
                error = game.error
        
 
-       if log_file != None and log_file != sys.stdout:
-               log_file.write("# EOF\n")
-               log_file.close()
+       for l in log_files:
+               l.close()
 
        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...

UCC git Repository :: git.ucc.asn.au