def __init__(self): #initialize and start the game self.board = Board() self.userHandler = UserHandler() """ ******** You can control the search broadth for each layer here, the default is 20""" self.searchHandler = SearchHandler(self.board,20) self.uiHandler = UIHandler(self.board) self.run()
class Game: """ whole game object maintain some game status including a game board ( class Board ) delegate work to different handlers """ def __init__(self): #initialize and start the game self.board = Board() self.userHandler = UserHandler() """ ******** You can control the search broadth for each layer here, the default is 20""" self.searchHandler = SearchHandler(self.board,20) self.uiHandler = UIHandler(self.board) self.run() def run(self): self.uiHandler.printInit() self.uiHandler.printBoard() #the initial board state while True: # (OldCoord,newCoord) in the form of ((0,1),(4,3)),illegal intentions are dealt with by userHandler (oldCoord,newCoord) = self.userHandler.askLegalMove(self.board) self.board.makeMove((oldCoord,newCoord)) #player move, board state updated self.uiHandler.printBoard() if self.checkOver(): exit() (oldCoord,newCoord) = self.searchHandler.getBestMove(4) print "*************Computer's move ",(oldCoord,newCoord),"****************" self.board.makeMove((oldCoord,newCoord)) # computer move, board state updated self.uiHandler.printBoard() if self.checkOver(): exit() def checkOver(self): winner = self.board.checkWinner() if winner: print "Game over!", winner, "Won !" return True else: return False
app.debug = True #daos and objects userDao=UserDAO() containerDao=ContainerDAO() authDao = AuthDao() locationDao=LocationDao() appinfoDao=appInfoDAO() relationshipDao = RelationshipDAO() emailServer = EmailManager() notificationHelper = NotificationHelper() #handlers helperHandler = HelperHandler(emailServer) authHandler = AuthHandler(helperHandler) userHandler = UserHandler(helperHandler) containerHandler = ContainerHandler(helperHandler, notificationHelper) locationHandler = LocationHandler(helperHandler) #SSL/HTTPS config context = ssl.SSLContext() context.load_cert_chain('fullchain.pem', 'privkey.pem') #----------------------------User Methods -------------------------------- @app.route('/getUser', methods=['GET']) def getUser(): return userHandler.getUser(request, userDao, True) @app.route('/getAllUsers', methods=['GET']) def getAllUsers(): return userHandler.getAllUsers(request, userDao, True)