Initial Commit
[progcomp2013.git] / qchess / main.py
1 #!/usr/bin/python -u
2
3 # Do you know what the -u does? It unbuffers stdin and stdout
4 # I can't remember why, but last year things broke without that
5
6 """
7         UCC::Progcomp 2013 Quantum Chess game
8         @author Sam Moore [SZM] "matches"
9         @copyright The University Computer Club, Incorporated
10                 (ie: You can copy it for not for profit purposes)
11 """
12
13 # system python modules or whatever they are called
14 import sys
15 import os
16 import time
17
18 turn_delay = 0.5
19 [game, graphics] = [None, None]
20
21
22 # The main function! It does the main stuff!
23 def main(argv):
24
25         # Apparently python will silently treat things as local unless you do this
26         # But (here's the fun part), only if you actually modify the variable.
27         # For example, all those 'if graphics_enabled' conditions work in functions that never say it is global
28         # Anyone who says "You should never use a global variable" can die in a fire
29         global game
30         global graphics
31
32         # Magical argument parsing goes here
33         if len(argv) == 1:
34                 players = [HumanPlayer("saruman", "white"), AgentRandom("sabbath", "black")]
35         elif len(argv) == 2:
36                 players = [AgentPlayer(argv[1], "white"), HumanPlayer("shadow", "black"), ]
37         elif len(argv) == 3:
38                 players = [AgentPlayer(argv[1], "white"), AgentPlayer(argv[2], "black")]
39
40         # Construct the board!
41         board = Board(style = "quantum")
42         game = GameThread(board, players) # Construct a GameThread! Make it global! Damn the consequences!
43         #try:
44         if True:
45                 graphics = GraphicsThread(board, grid_sz = [64,64]) # Construct a GraphicsThread! I KNOW WHAT I'M DOING! BEAR WITH ME!
46                 game.start() # This runs in a new thread
47         #except NameError:
48         #       print "Run game in main thread"
49         #       game.run() # Run game in the main thread (no need for joining)
50         #       return game.error
51         #except Exception, e:
52         #       raise e
53         #else:
54         #       print "Normal"
55                 graphics.run()
56                 game.join()
57                 return game.error + graphics.error
58
59
60 # This is how python does a main() function...
61 if __name__ == "__main__":
62         sys.exit(main(sys.argv))

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