當前位置: 首頁>>代碼示例>>Python>>正文


Python Algorithm.generate_actions方法代碼示例

本文整理匯總了Python中algorithm.Algorithm.generate_actions方法的典型用法代碼示例。如果您正苦於以下問題:Python Algorithm.generate_actions方法的具體用法?Python Algorithm.generate_actions怎麽用?Python Algorithm.generate_actions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在algorithm.Algorithm的用法示例。


在下文中一共展示了Algorithm.generate_actions方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run

# 需要導入模塊: from algorithm import Algorithm [as 別名]
# 或者: from algorithm.Algorithm import generate_actions [as 別名]
    def run(self):
        """
        Runs the game
        """
        print "Starting Battle Tanks Client..."

        connect_command = self.cmd.get_match_connect_command(self.game_info.team_name, self.game_info.match_token,
                                                             self.game_info.team_password)

        print 'Connecting to server...'
        self.comm.set_subscription(opts.match_token)
        self.game_info.client_token = self.comm.send(connect_command, self.cmd.CLIENT_TOKEN)

        print 'Received client token... %s' % self.game_info.client_token
        print 'Starting game...'

        while True:
            algo = Algorithm(self.game_info.team_name, self.game_info.client_token)
            raw_state_message = self.comm.receive(self.comm.Origin.PublishSocket)
            try:
                json_state_message = json.loads(raw_state_message)
                if json_state_message[self.cmd.COMM_TYPE] == command.CommType.GAME_STATE:
                    algo.parse_game_state(json_state_message)
                    actions = algo.generate_actions()
                    for action in actions:
                        self.comm.send(action)
                        """
                        # This never seemed to work, but actions performed fine
                        raw_command_message = self.comm.receive(self.comm.Origin.CommandSocket)
                        try:
                            json_command_message = json.loads(raw_command_message)
                            if json_command_message['resp'] == 'ok':
                                continue
                            else:
                                print "Command did not execute properly!"
                                print raw_command_message
                        except Exception:
                            print "Command did not return valid JSON message!"
                            print raw_command_message
                        """
                    continue
                elif json_state_message[self.cmd.COMM_TYPE] == command.CommType.GAME_START:
                    print "Game Name: %s" % json_state_message['game_name']
                    print "Timestamp: %s" % json_state_message['timestamp']
                    print "Game Number: %s out of %s" % (json_state_message['game_num'], json_state_message ['game_count'])
                    continue
                elif json_state_message[self.cmd.COMM_TYPE] == command.CommType.GAME_END:
                    print "Game Ended! Moving onto the next game..."
                    continue
                elif json_state_message[self.cmd.COMM_TYPE] == command.CommType.MATCH_END:
                    print "Match Ended!"
                    break
                else:
                    print "Something went wrong. No valid comm_type in server response but response is valid json!"
                    print json_state_message
                    continue
            except ValueError:
                # Not valid json, this must the match token string
                self.game_info.match_token = raw_state_message
                continue

        print 'Exiting...'
        exit()
開發者ID:awwong1,項目名稱:2016-pason-coding-contest,代碼行數:65,代碼來源:client.py


注:本文中的algorithm.Algorithm.generate_actions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。