Beispiel #1
0
 def callback2(valid):
     """called when move is executed and validated in the engine"""
     if valid:
         self._moves.play(move)
         self.broadcast(ClientGameCommand.play(self.id, color, move))
         if self._moves.finished():
             self.engine.final_score(callback3)
         else:
             if ((color == "black") and (self._config.white == "GNUGo")) or\
                ((color == "white") and (self._config.black == "GNUGo")):
                     self.play(None, lambda: None, genmove=True)
     
     callback1(valid)
Beispiel #2
0
    def callIntoGame(self, sender, game_id, sender_callback):
        """another user may use this to request a game with
        this user

        sender:  ConnectedUser instance that wants to play
        game_id: Game instance created by the sender
        sender_callback: function to be called when a response
                         is obtained from the user, accepts one
                         parameter 'accepted' as True or False"""
        def response_callback(response):
            """expects response to be a dict with a key 'accepted'
            and boolean value"""
            if response['accepted']:
                #self.enterGame(sender.getGameById(game_id))
                self.enterGame(Game.__games__.get(game_id))
            sender_callback(response['accepted'])

        command = ClientGameCommand.call_into(sender.db_tuple.name, game_id)

        self.conn.addResponseCallback(response_callback, command['trans'])
        self.conn.send(command)
Beispiel #3
0
 def callback2_genmove(move):
     """called when move is executed using genmove"""
     self._moves.play(move)
     self.broadcast(ClientGameCommand.play(self.id, color, move))
     if self._moves.finished():
         self.engine.final_score(callback3)
Beispiel #4
0
 def addSpectator(self, user):
     user.conn.send(ClientGameCommand.initialize(self))
     self.broadcast_to.add(user)