• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python sc2reader.load_replay函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sc2reader.load_replay函数的典型用法代码示例。如果您正苦于以下问题:Python load_replay函数的具体用法?Python load_replay怎么用?Python load_replay使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_gameheartnormalizer_plugin

    def test_gameheartnormalizer_plugin(self):
        from sc2reader.engine.plugins import GameHeartNormalizer
        sc2reader.engine.register_plugin(GameHeartNormalizer())

        # Not a GameHeart game!
        replay = sc2reader.load_replay("test_replays/2.0.0.24247/molten.SC2Replay")
        player_pids = set([ player.pid for player in replay.players])
        spawner_pids = set([ event.player.pid for event in replay.events if "TargetUnitCommandEvent" in event.name and event.ability.name == "SpawnLarva"])
        self.assertTrue(spawner_pids.issubset(player_pids))

        replay = sc2reader.load_replay("test_replays/gameheart/gameheart.SC2Replay")
        self.assertEqual(replay.events[0].frame, 0)
        self.assertEqual(replay.game_length.seconds, 636)
        self.assertEqual(len(replay.observers), 5)
        self.assertEqual(replay.players[0].name, 'SjoWBBII')
        self.assertEqual(replay.players[0].play_race, 'Terran')
        self.assertEqual(replay.players[1].name, 'Stardust')
        self.assertEqual(replay.players[1].play_race, 'Protoss')
        self.assertEqual(len(replay.teams), 2)
        self.assertEqual(replay.teams[0].players[0].name, 'SjoWBBII')
        self.assertEqual(replay.teams[1].players[0].name, 'Stardust')
        self.assertEqual(replay.winner, replay.teams[1])

        replay = sc2reader.load_replay("test_replays/gameheart/gh_sameteam.SC2Replay")
        self.assertEqual(replay.events[0].frame, 0)
        self.assertEqual(replay.game_length.seconds, 424)
        self.assertEqual(len(replay.observers), 5)
        self.assertEqual(replay.players[0].name, 'EGJDRC')
        self.assertEqual(replay.players[0].play_race, 'Zerg')
        self.assertEqual(replay.players[1].name, 'LiquidTaeJa')
        self.assertEqual(replay.players[1].play_race, 'Terran')
        self.assertEqual(len(replay.teams), 2)
        self.assertEqual(replay.teams[0].players[0].name, 'EGJDRC')
        self.assertEqual(replay.teams[1].players[0].name, 'LiquidTaeJa')
        self.assertEqual(replay.winner, replay.teams[0])
开发者ID:JunHuang01,项目名称:sc2reader,代码行数:35,代码来源:test_all.py


示例2: main

def main():
	for argument in sys.argv[1:]:
		for path in sc2reader.utils.get_files(argument):
			try:
				replay = sc2reader.load_replay(path, debug=True, verbose=True)
			except sc2reader.exceptions.ReadError as e:
				print e.replay.filename
				print '{build} - {real_type} on {map_name} - Played {start_time}'.format(**e.replay.__dict__)
				print '[ERROR]', e.message
				for event in e.game_events[-5:]:
					print '{0} - {1}'.format(hex(event.type),event.bytes.encode('hex'))
				e.buffer.seek(e.location)
				print e.buffer.peek(50).encode('hex')
				print
			except Exception as e:
				print path
				replay = sc2reader.load_replay(path, debug=True, load_level=1)
				print '{build} - {real_type} on {map_name} - Played {start_time}'.format(**replay.__dict__)
				print '[ERROR]', e.message
				for pid, attributes in replay.attributes.items():
					print pid, attributes
				for pid, info in enumerate(replay.raw_data['replay.details'].players):
					print pid, info
				print replay.raw_data['replay.initData'].player_names
				traceback.print_exc()
				print
开发者ID:SVaid1987,项目名称:sc2reader,代码行数:26,代码来源:sc2parse.py


示例3: test_random_player

    def test_random_player(self):
        replay = sc2reader.load_replay("test_replays/1.2.2.17811/3.SC2Replay")
        gogeta = next(player for player in replay.players if player.name == "Gogeta")
        self.assertEqual(gogeta.pick_race, "Random")
        self.assertEqual(gogeta.play_race, "Terran")

        replay = sc2reader.load_replay("test_replays/1.2.2.17811/6.SC2Replay")
        permafrost = next(player for player in replay.players if player.name == "Permafrost")
        self.assertEqual(permafrost.pick_race, "Random")
        self.assertEqual(permafrost.play_race, "Protoss")
开发者ID:JunHuang01,项目名称:sc2reader,代码行数:10,代码来源:test_all.py


示例4: test_datetimes

def test_datetimes():
    # Ignore seconds in comparisons, because they are off by one what is reported by Windows.
    # This might be a little nuance worth investigating at some point.

    # Played at 20 Feb 2011 22:44:48 UTC+2
    replay = sc2reader.load_replay("test_replays/1.2.2.17811/1.SC2Replay")
    assert replay.end_time == datetime.datetime(2011, 2, 20, 20, 44, 47)

    # Played at 21 Feb 2011 00:42:13 UTC+2
    replay = sc2reader.load_replay("test_replays/1.2.2.17811/2.SC2Replay")
    assert replay.end_time == datetime.datetime(2011, 2, 20, 22, 42, 12)

    # Played at 25 Feb 2011 16:36:28 UTC+2
    replay = sc2reader.load_replay("test_replays/1.2.2.17811/3.SC2Replay")
    assert replay.end_time == datetime.datetime(2011, 2, 25, 14, 36, 26)
开发者ID:JMSerruya,项目名称:sc2reader,代码行数:15,代码来源:test_all.py


示例5: parseData

def parseData(path):
    """
    Returns a list of feature vectors and a list of classes for each replay 
    file in the given path. 
    """
    data = []
    targets = []
    for index, filename in enumerate(os.listdir(path)):
        if os.path.splitext(filename)[-1] == '.SC2Replay':
            fullpath = os.path.join(path, filename)
            try:
                replay = sc2reader.load_replay(fullpath)
                print "Loading replay %s" % replay.filename
                log.loadReplay(replay)
                #Get data from the first 5 minutes of the replay
                frames = 5*framesPerMinute
                if replay.frames >= frames and len(replay.players) == 2:
                    player1race = re.search(pattern, str(replay.players[0]))
                    player2race = re.search(pattern, str(replay.players[1]))
                    if player1race.group(0) in race and player2race.group(0) in race:
                        targets.append(race[player1race.group(0)])
                        targets.append(race[player2race.group(0)])
                        data.append(gamelog(replay, endFrame=frames, classify=abilityID, framesPerRow=frames).getColumn(0))
                        data.append(gamelog(replay, endFrame=frames, classify=abilityID, framesPerRow=frames).getColumn(1))
            except MPQError:
                print "Failed to load replay %s" % fullpath 
    return (data, targets)
开发者ID:jessebwr,项目名称:AISC2,代码行数:27,代码来源:testClassifier.py


示例6: test_3v3

    def test_3v3(self):
        replay = sc2reader.load_replay("test_replays/1.2.2.17811/3.SC2Replay")
        self.assertEqual(replay.type, "3v3")

        # Because it"s a 3v3 and all of the members of Team 2 quit, we should know the winner.
        self.assertEqual(replay.team[1].result, "Win")
        self.assertEqual(replay.team[2].result, "Loss")
开发者ID:JunHuang01,项目名称:sc2reader,代码行数:7,代码来源:test_all.py


示例7: test_canExtractPlayers

 def test_canExtractPlayers(self):
     sc2reader.configure(debug=True)
     print os.getcwd()
     replay = sc2reader.load_replay('data/Akilon Wastes (2).SC2Replay', load_level=4)
     for player in replay.players:
         #if player.is_human:
         print "Player: %s (%s) - %s" % (player.name, player.play_race, player.result)
开发者ID:cdaviduik-va,项目名称:vendladder,代码行数:7,代码来源:test_replay_parsing.py


示例8: test_outmatched_pids

    def test_outmatched_pids(self):
        replay = sc2reader.load_replay('test_replays/2.0.8.25604/issue131_arid_wastes.SC2Replay')
        self.assertEqual(replay.players[0].pid, 1)
        self.assertEqual(replay.players[1].pid, 3)
        self.assertEqual(replay.players[2].pid, 4)

        replay = sc2reader.load_replay('test_replays/2.0.8.25604/issue135.SC2Replay')
        self.assertEqual(replay.players[0].pid, 1)
        self.assertEqual(replay.players[1].pid, 2)
        self.assertEqual(replay.players[2].pid, 4)

        replay = sc2reader.load_replay("test_replays/2.0.8.25604/mlg1.SC2Replay")
        self.assertEqual(replay.players[0].pid, 1)
        self.assertEqual(replay.players[1].pid, 2)
        self.assertEqual(len(replay.players), 2)
        self.assertEqual(len(replay.people), 3)
开发者ID:JunHuang01,项目名称:sc2reader,代码行数:16,代码来源:test_all.py


示例9: test_3v3

def test_3v3():
    replay = sc2reader.load_replay("test_replays/1.2.2.17811/3.SC2Replay")
    assert replay.type == "3v3"

    # Because it's a 3v3 and all of the members of Team 2 quit, we should know the winner.
    assert replay.team[1].result == "Win"
    assert replay.team[2].result == "Loss"
开发者ID:JMSerruya,项目名称:sc2reader,代码行数:7,代码来源:test_all.py


示例10: convertReplay

def convertReplay(path,limit=15000):
	replay=sc2reader.load_replay(path)
	players=[]
	races=[]
	for i in replay.players:
		players.append(i.name)
		races.append(i.pick_race)
	if(len(players)>2):
		print("error: replay not 1v1 "+path)
		return ("error","error")
	hot={}
	frame={}
	hot[players[0]]=[]
	hot[players[1]]=[]
	frame[players[0]]=[]
	frame[players[1]]=[]
	for event in replay.events:
		if event.frame>=limit:
			break
		if event.name=="GetControlGroupEvent" or event.name=="SetControlGroupEvent" or event.name=="AddToControlGroupEvent" :
			hot[event.player.name].append(event.hotkey)
			frame[event.player.name].append(event.frame)
	
#mapsc2="",length="",date=""
	if (len(hot[players[0]])>10):				
		g1=game.game(players[0],players[1],races[0],races[1],hot[players[0]],frame[players[0]],path,replay.map_name,replay.length,replay.date)
	else:
		g1="error"
		print("error, not enough frame")
	if (len(hot[players[1]])>10):
		g2=game.game(players[1],players[0],races[1],races[0],hot[players[1]],frame[players[1]],path)
	else:
		g2="error"
		print("error, not enough frame")		
	return (g1,g2)
开发者ID:NicolasNin,项目名称:sc2-guessplayer,代码行数:35,代码来源:convert.py


示例11: parseData

def parseData(path):
    """
    Returns a list of feature vectors and a list of classes for each replay 
    file in the given path. 
    """
    data = []
    targets = []
    for index, filename in enumerate(os.listdir(path)):
        if os.path.splitext(filename)[-1] == '.SC2Replay':
            fullpath = os.path.join(path, filename)
            try:
                replay = sc2reader.load_replay(fullpath)
                print "Loading replay %s" % replay.filename
                log.loadReplay(replay)
                if len(replay.players) == 2:
                    player1race = re.search(pattern, log.players[0])
                    player2race = re.search(pattern, log.players[1])
                    if player1race.group(0) in race:
                        targets.append(race[player1race.group(0)])
                        data.append(log.actions[0].flatten())
                    if player2race.group(0) in race:
                        targets.append(race[player2race.group(0)])
                        data.append(log.actions[1].flatten())
            except:
                print "Failed to load replay %s" % fullpath 
    return (data, targets)
开发者ID:jessebwr,项目名称:AISC2,代码行数:26,代码来源:wsParser.py


示例12: test_unit_types

 def test_unit_types(self):
     """ sc2reader#136 regression test """
     replay = sc2reader.load_replay('test_replays/2.0.8.25604/issue136.SC2Replay')
     hellion_times = [u.started_at for u in replay.players[0].units if u.name == 'Hellion']
     hellbat_times = [u.started_at for u in replay.players[0].units if u.name == 'BattleHellion']
     self.assertEqual(hellion_times, [5180, 5183])
     self.assertEqual(hellbat_times, [6736, 6741, 7215, 7220, 12004, 12038])
开发者ID:JunHuang01,项目名称:sc2reader,代码行数:7,代码来源:test_all.py


示例13: parseData

def parseData(path):
    """
    Returns a list of feature vectors and a list of classes for each replay 
    file in the given path. 
    """
    data = []
    targets = []
    for index, filename in enumerate(os.listdir(path)):
        if os.path.splitext(filename)[-1] == '.SC2Replay':
            fullpath = os.path.join(path, filename)
            try:
                replay = sc2reader.load_replay(fullpath)
                print "Loading replay %s" % replay.filename
                log.loadReplay(replay)
                if len(replay.players) == 2:
                    player1class, player2class = winner(replay)
                    #For classifying win/loss
                    if not player1class == None and not player2class == None:
                        targets.append(player1class)
                        events1 = log.actions[0].flatten()
                        events2 = log.actions[1].flatten()
                        data.append(np.concatenate((events1,events2)))
                    """ #Use for classifying race
                    if not player1class == None:
                        targets.append(player1class)
                        data.append(log.actions[0].flatten())
                    if not player2class == None:
                        targets.append(player2class)
                        data.append(log.actions[1].flatten())
                    """
            except:
                print "Failed to load replay %s" % fullpath 
    return (data, targets)
开发者ID:jessebwr,项目名称:AISC2,代码行数:33,代码来源:apmParser.py


示例14: main

def main():
    players = {}
    parser = argparse.ArgumentParser(
        description="""Step by step replay of game events; shows only the
        Initialization, Command, and Selection events by default. Press any
        key to advance through the events in sequential order."""
    )

    parser.add_argument('FILE', type=str, help="The file you would like to replay")
    parser.add_argument('--player', default=0, type=int, help="The number of the player you would like to watch. Defaults to 0 (All).")
    parser.add_argument('--bytes', default=False, action="store_true", help="Displays the byte code of the event in hex after each event.")
    parser.add_argument('--hotkeys', default=False, action="store_true", help="Shows the hotkey events in the event stream.")
    parser.add_argument('--cameras', default=False, action="store_true", help="Shows the camera events in the event stream.")
    args = parser.parse_args()

    for filename in sc2reader.utils.get_files(args.FILE):
        replay = sc2reader.load_replay(filename, debug=True)
        r = replay
        print("Release {0}".format(replay.release_string))
        print("{0} on {1} at {2}".format(replay.type, replay.map_name, replay.start_time))
        print("")
        for team in replay.teams:
            print(team)
            for player in team.players:
                print("  {0}".format(player))
                players[player.name] = collections.defaultdict(zeroint)

        print("\n--------------------------\n\n")
开发者ID:nibalizer,项目名称:sc2scripts,代码行数:28,代码来源:sc2analyzer.py


示例15: test_wol_pids

def test_wol_pids():
    replay = sc2reader.load_replay("test_replays/1.5.4.24540/ggtracker_1471849.SC2Replay")

    assert replay.expansion == 'WoL'

    ability_pids = set( [ event.player.pid for event in replay.events if 'AbilityEvent' in event.name ] )
    player_pids = set( [ player.pid for player in replay.players ] )

    assert ability_pids == player_pids
开发者ID:JMSerruya,项目名称:sc2reader,代码行数:9,代码来源:test_all.py


示例16: time_and_players

def time_and_players(path):
	if os.path.exists(path):
		replay = sc2reader.load_replay(path)
		return Game([replay.players[0].name, replay.players[1].name], 
			replay.start_time, 
			replay.end_time, 
			[player.uid for player in replay.players],
			replay.winner.players[0].name
			)
	return None
开发者ID:K4orta,项目名称:izsha,代码行数:10,代码来源:process_replay.py


示例17: test_engine_plugins

    def test_engine_plugins(self):
        from sc2reader.engine.plugins import ContextLoader, APMTracker, SelectionTracker

        replay = sc2reader.load_replay(
            "test_replays/2.0.5.25092/cn1.SC2Replay",
            engine=sc2reader.engine.GameEngine(plugins=[ContextLoader(), APMTracker(), SelectionTracker()]),
        )

        code, details = replay.plugins["ContextLoader"]
        self.assertEqual(code, 0)
        self.assertEqual(details, dict())
开发者ID:BBLN,项目名称:sc2reader,代码行数:11,代码来源:test_all.py


示例18: test_hots_hatchfun

 def test_hots_hatchfun(self):
     replay = sc2reader.load_replay("test_replays/2.0.0.24247/molten.SC2Replay")
     player_pids = set([player.pid for player in replay.players])
     spawner_pids = set(
         [
             event.player.pid
             for event in replay.events
             if "TargetAbilityEvent" in event.name and event.ability.name == "SpawnLarva"
         ]
     )
     self.assertTrue(spawner_pids.issubset(player_pids))
开发者ID:BBLN,项目名称:sc2reader,代码行数:11,代码来源:test_all.py


示例19: handle

 def handle(self):
     path = self.rfile.readline().strip()
     logger.info("Parsing replay file: {}".format(path))
     try:
         json = sc2reader.load_replay(path, load_level=2)
         self.wfile.write(json+"\n\n")
     except Exception as e:
         logger.exception("Error parsing {}".format(path))
         try:
             shutil.copy(path, self.server.replaydir)
         except:
             logger.exception("Error saving {} to {}. Aborting.".format(path, self.server.replaydir))
开发者ID:Aaah,项目名称:erosd,代码行数:12,代码来源:sc2json.py


示例20: main

def main():
    parser = argparse.ArgumentParser(description="StarCraft 2 Replay Analyser")
    parser.add_argument("file_name", help="SC2 Replay file")
    parser.add_argument("--nc", help="No color displayed", action="store_true")
    args = parser.parse_args()
    try:
        replay = sc2reader.load_replay(args.file_name)
    except UnicodeDecodeError:
        print("An error occured while parsing the Replay, please update sc2reader and try again.")
        exit(1)
    init_colors(args.nc)
    display_normal(replay)
开发者ID:DasFranck,项目名称:Python-Mineur,代码行数:12,代码来源:SC2RA.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python hdebug.logText函数代码示例发布时间:2022-05-27
下一篇:
Python utils.walk_json_dict函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap