当前位置: 首页>>代码示例>>Python>>正文


Python Algorithm.client_token方法代码示例

本文整理汇总了Python中algorithm.Algorithm.client_token方法的典型用法代码示例。如果您正苦于以下问题:Python Algorithm.client_token方法的具体用法?Python Algorithm.client_token怎么用?Python Algorithm.client_token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在algorithm.Algorithm的用法示例。


在下文中一共展示了Algorithm.client_token方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: from algorithm import Algorithm [as 别名]
# 或者: from algorithm.Algorithm import client_token [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...'

        map_needs_parsing = True
        algo = Algorithm(self.game_info.team_name, self.game_info.client_token)
        while True:
            raw_state_message = self.comm.receive(self.comm.Origin.PublishSocket)
            algo.client_token = self.game_info.client_token
            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, parse_map=map_needs_parsing)
                    map_needs_parsing = False
                    actions = algo.generate_actions()
                    for action in actions:
                        self.comm.send(action)
                        """
                        # Debugging purposes
                        raw_command_message = ""
                        try:
                            raw_command_message = self.comm.receive(self.comm.Origin.CommandSocket)
                            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..."
                    map_needs_parsing = True
                    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,代码行数:71,代码来源:client.py


注:本文中的algorithm.Algorithm.client_token方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。