Mostly networking
[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
41         board = Board(style = "quantum")
42         # Construct the board!
43         if len(argv) == 1:
44                 players = [NetworkSender(HumanPlayer("saruman", "white"), board), NetworkReceiver("black", board, 'localhost')]
45                 
46         else:
47                 players = [NetworkReceiver("white", board, 'localhost'), NetworkSender(HumanPlayer("sabbath", "black"), board)]
48                 
49         
50         
51
52         graphics = GraphicsThread(board, grid_sz = [64,64]) # Construct a GraphicsThread! I KNOW WHAT I'M DOING! BEAR WITH ME!
53         
54
55
56
57         game = GameThread(board, players) # Construct a GameThread! Make it global! Damn the consequences!
58         game.start() # This runs in a new thread
59
60         graphics.run()
61         game.join()
62         return game.error + graphics.error
63
64
65 # This is how python does a main() function...
66 if __name__ == "__main__":
67         sys.exit(main(sys.argv))

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