コード例 #1
0
 def test_hots_vs_ai(self):
     replay = sc2reader.load_replay(
         "test_replays/2.0.0.24247/Cloud Kingdom LE (13).SC2Replay")
     self.assertEqual(replay.expansion, "HotS")
     replay = sc2reader.load_replay(
         "test_replays/2.0.0.24247/Korhal City (19).SC2Replay")
     self.assertEqual(replay.expansion, "HotS")
コード例 #2
0
ファイル: test_all.py プロジェクト: JunHuang01/sc2reader
    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])
コード例 #3
0
def test_hots_vs_ai():
    replay = sc2reader.load_replay(
        "test_replays/2.0.0.24247/Cloud Kingdom LE (13).SC2Replay")
    assert replay.expansion == 'HotS'
    replay = sc2reader.load_replay(
        "test_replays/2.0.0.24247/Korhal City (19).SC2Replay")
    assert replay.expansion == 'HotS'
コード例 #4
0
ファイル: test_all.py プロジェクト: joanSolCom/sc2reader
    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 "TargetAbilityEvent" 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])
コード例 #5
0
ファイル: sc2parse.py プロジェクト: SVaid1987/sc2reader
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
コード例 #6
0
    def test_teams(self):
        replay = sc2reader.load_replay("test_replays/1.2.2.17811/13.SC2Replay")
        self.assertNotEqual(replay.player[1].team.number,
                            replay.player[2].team.number)

        replay = sc2reader.load_replay(
            "test_replays/2.0.8.25604/mlg1.SC2Replay")
        self.assertNotEqual(replay.player[1].team.number,
                            replay.player[2].team.number)
コード例 #7
0
ファイル: test_all.py プロジェクト: JunHuang01/sc2reader
    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")
コード例 #8
0
ファイル: test_all.py プロジェクト: joanSolCom/sc2reader
    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")
コード例 #9
0
ファイル: parse_replay.py プロジェクト: halloikama/LyingSoup
    def parse_replay(cls, replay=None, replay_file=None, file_object=None):

        replay_data = ReplayData(replay_file)
        try:
            # This is the engine that holds some required plugins for parsing
            engine = sc2reader.engine.GameEngine(
                plugins=[ContextLoader(),
                         APMTracker(),
                         SelectionTracker()])

            if replay:
                pass
            elif replay_file and not file_object:
                # Then we are not using ObjectStorage for accessing replay files
                replay = sc2reader.load_replay(replay_file, engine=engine)
            elif file_object:
                # We are using ObjectStorage to access replay files
                replay = sc2reader.load_replay(file_object, engine=engine)
            else:
                pass

            # Get the number of frames (one frame is 1/16 of a second)
            replay_data.frames = replay.frames
            # Gets the game mode (if available)
            replay_data.game_mode = replay.real_type
            # Gets the map hash (if we want to download the map, or do map-based analysis)
            replay_data.map_hash = replay.map_hash

            # Use the parsers to get data
            for event in replay.events:
                for parser in cls.__parsers__:
                    parser(replay_data, event)

            # Check if there was a winner
            if replay.winner is not None:
                replay_data.winners = replay.winner.players
                replay_data.losers = [
                    p for p in replay.players if p not in replay.winner.players
                ]
            else:
                replay_data.winners = []
                replay_data.losers = []
            # Check to see if expansion data is available
            replay_data.expansion = replay.expansion
            return replay_data
        except:
            # print our error and return NoneType object
            print_exc()
            return None, None
コード例 #10
0
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)
コード例 #11
0
ファイル: test_all.py プロジェクト: JMSerruya/sc2reader
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)
コード例 #12
0
def main():
    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.")
    args = parser.parse_args()

    for filename in sc2reader.utils.get_files(args.FILE):
        replay = sc2reader.load_replay(filename, debug=True)
        parseReplay(replay)
コード例 #13
0
    def test_metrics_exist(self):
        replay = sc2reader.load_replay(
            os.path.join(REPLAY_DIR, "standard_1v1.SC2Replay"))
        p1_met = None

        # Test first metrics is part of the player
        try:
            p1_met = replay.player[1].metrics
        except:
            self.fail("metrics is not a member of the player object.")

        # Test that the instance was created
        self.assertIsNotNone(p1_met)

        # Test that data was put into the class properties
        if p1_met is not None:
            self.assertNotEqual(len(p1_met.army_created), 0)
            self.assertNotEqual(len(p1_met.workers_created), 0)
            self.assertNotEqual(len(p1_met.supply_created), 0)
            self.assertNotEqual(len(p1_met.bases_created), 0)
            #self.assertNotEqual(len(p1_met.current_food_used), 0)
            #self.assertNotEqual(len(p1_met.current_food_made), 0)
            self.assertNotEqual(len(p1_met.supply), 0)
            self.assertNotEqual(len(p1_met.resources), 0)
            self.assertNotEqual(p1_met.avg_apm, 0)
コード例 #14
0
    def test_time_to_supply_created_max_workers_with_more_than_total_supply(
            self):
        replay = sc2reader.load_replay(
            os.path.join(REPLAY_DIR, "standard_1v1.SC2Replay"))
        p1_met = replay.player[1].metrics

        self.assertIsNone(p1_met.time_to_supply_created_max_workers(1000, 75))
コード例 #15
0
ファイル: wsParser.py プロジェクト: jessebwr/AISC2
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)
コード例 #16
0
ファイル: convert.py プロジェクト: NicolasNin/sc2-guessplayer
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)
コード例 #17
0
ファイル: testClassifier.py プロジェクト: jessebwr/AISC2
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)
コード例 #18
0
ファイル: sc2analyzer.py プロジェクト: nibalizer/sc2scripts
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")
コード例 #19
0
 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)
コード例 #20
0
def test_worker_milestones():
    replay = sc2reader.load_replay(
        'replays/Nerchio vs Neeb ZvP  Newkirk Precinct TE (Void) WCS Austin.SC2Replay',
        engine=sc2reader.engine.GameEngine(plugins=[
            APMTracker(),
            SelectionTracker(),
            ContextLoader(),
            GameHeartNormalizer(),
            workers_analysis(),
        ]),
        load_map=False)
    if replay.players[0].name == "Neeb":
        neeb = replay.players[0]
        nerchio = replay.players[1]
    else:
        nerchio = replay.players[0]
        neeb = replay.players[1]

    assert neeb.worker_milestones[40] == 5493
    assert nerchio.worker_milestones[40] == 5213

    assert neeb.worker_milestones[50] == 7466
    assert nerchio.worker_milestones[50] == 7247

    assert neeb.worker_milestones[60] == 8668
    assert nerchio.worker_milestones[60] == 11838

    assert neeb.worker_milestones[70] == 14631
    assert nerchio.worker_milestones[70] == 17087
コード例 #21
0
def test_alive_at_this_time():

    replay = sc2reader.load_replay(
        'replays/Nerchio vs Neeb ZvP  Newkirk Precinct TE (Void) WCS Austin.SC2Replay',
        engine=sc2reader.engine.GameEngine(plugins=[
            APMTracker(),
            SelectionTracker(),
            ContextLoader(),
            GameHeartNormalizer(),
            workers_analysis(),
        ]),
        load_map=False)
    if replay.players[0].name == "Neeb":
        neeb = replay.players[0]
        nerchio = replay.players[1]
    else:
        nerchio = replay.players[0]
        neeb = replay.players[1]

    probe = neeb.units[54]

    assert alive_at_this_time(probe, 0, replay.frames) is False
    assert alive_at_this_time(probe, 28870, replay.frames) is False
    assert alive_at_this_time(probe, 26000, replay.frames) is False
    assert alive_at_this_time(probe, 4500, replay.frames) is True
    assert alive_at_this_time(probe, 2000, replay.frames) is False
コード例 #22
0
 def parse_replay(cls, replay=None, replay_file=None):
     if (replay is not None):
         replay_data = cls(replay)
     elif (replay_file is not None):
         replay = sc2reader.load_replay(replay_file)
         replay_data = cls(replay)
     else:
         print("Error! No valid replay or replay_file given")
         return None
     
     # Parse events in replay with parsers
     try:
         # Metadata
         replay_data.frames = replay.frames
         for event in replay.events:
             for parser in cls.__parsers__:
                 parser(replay_data, event)
         if replay.winner is not None:
             replay_data.winners = replay.winner.players
             replay_data.losers = [p for p in replay.players if p not in replay.winner.players]
         # Maybe the GAME expansion (version)? e.g. wol/hots/lotv
         replay_data.expansion = replay.expansion
         return replay_data
     except Exception as e:
         print(e)
         return None
コード例 #23
0
ファイル: apmParser.py プロジェクト: jessebwr/AISC2
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)
コード例 #24
0
    def test_time_to_workers_created_with_more_than_total_workers_created(
            self):
        replay = sc2reader.load_replay(
            os.path.join(REPLAY_DIR, "pvt_macro1.SC2Replay"))
        p1_met = replay.player[1].metrics

        self.assertIsNone(p1_met.time_to_workers_created(200))
コード例 #25
0
    def test_time_to_X_workers(self):
        replay = sc2reader.load_replay(
            os.path.join(REPLAY_DIR, "pvt_macro1.SC2Replay"))
        p1_met = replay.player[1].metrics

        self.assertEqual(p1_met.time_to_workers_created(66), 478)
        self.assertEqual(p1_met.time_to_workers_created(75), 547)
コード例 #26
0
def extract(in_path, out_path):
    replay = sc2reader.load_replay(in_path)
    created = []
    deaths = []

    for event in replay.events:
        # Unit created
        if type(event) is sc2reader.events.tracker.UnitBornEvent:
            if event.unit_type_name in ['Marine']:
                created_data = {
                    'x_coordinate:': event.location[0],
                    'y_coordinate:': event.location[1],
                    'unit_type:': event.unit_type_name,
                    'game_second:': event.second,
                    #'player': event.unit_controller.toon_id,
                    'unit_id:': event.unit_id
                }

                created.append(created_data)

        if type(event) is sc2reader.events.tracker.UnitDiedEvent:
            death_data = {
                'killing_unit_id:': event.killing_unit_id,
                'x_coordinate:': event.location[0],
                'y_coordinate:': event.location[1],
                'game_second:': event.second,
                #'unit_type:': event.unit_type_name,                    'game_second': event.second,
                #'player': event.unit_controller.toon_id,
                'unit_id:': event.unit_id
            }

            deaths.append(death_data)
    getData(created, deaths, out_path)
コード例 #27
0
def test_workers_at_frame():

    replay = sc2reader.load_replay(
        'replays/Nerchio vs Neeb ZvP  Newkirk Precinct TE (Void) WCS Austin.SC2Replay',
        engine=sc2reader.engine.GameEngine(plugins=[
            APMTracker(),
            SelectionTracker(),
            ContextLoader(),
            GameHeartNormalizer(),
            workers_analysis(),
        ]),
        load_map=False)
    if replay.players[0].name == "Neeb":
        neeb = replay.players[0]
        nerchio = replay.players[1]
    else:
        nerchio = replay.players[0]
        neeb = replay.players[1]

    assert workers_at_frame(neeb, time_to_frame('4:06')) == 40
    assert workers_at_frame(nerchio, time_to_frame('4:31')) == 40
    assert workers_at_frame(nerchio, time_to_frame('5:25')) == 50
    assert workers_at_frame(neeb, time_to_frame('5:34')) == 50
    assert workers_at_frame(neeb, time_to_frame('6:28')) == 60
    assert workers_at_frame(neeb, time_to_frame('10:56')) == 70
    assert workers_at_frame(nerchio, time_to_frame('12:22')) == 58
    assert workers_at_frame(nerchio, time_to_frame('12:23')) == 61
コード例 #28
0
ファイル: test_all.py プロジェクト: joanSolCom/sc2reader
    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)
コード例 #29
0
ファイル: test_all.py プロジェクト: JMSerruya/sc2reader
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"
コード例 #30
0
    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")
コード例 #31
0
    def test_supply_created_tracker(self):
        #:TODO
        rep = sc2reader.load_replay("test_replays\\standard_1v1.SC2Replay")
        sup = rep.player[1].metrics.supply_created
        wor = rep.player[1].metrics.workers_created
        arm = rep.player[1].metrics.army_created

        # check that the correct supply counts were counted
        self.assertEqual(len(sup), 120)
        self.assertEqual(len(wor), 75)
        self.assertEqual(len(arm), 45)

        # check that individual units data is correct
        self.assertEqual(wor[0].unit_supply, 1)
        self.assertEqual(wor[0].supply, 1)
        self.assertEqual(wor[0].second, 0)
        self.assertTrue(wor[0].is_worker)
        self.assertEqual(wor[25].unit_supply, 1)
        self.assertEqual(wor[50].unit_supply, 1)
        self.assertEqual(wor[74].unit_supply, 1)

        self.assertEqual(arm[0].unit_supply, 2)
        self.assertEqual(arm[0].supply, 40)
        self.assertEqual(arm[0].second, 300)
        self.assertFalse(arm[0].is_worker)

        self.assertEqual(sup[0].unit_supply, 1)
        self.assertEqual(sup[0].supply, 1)
        self.assertEqual(sup[0].second, 0)
        self.assertTrue(sup[0].is_worker)
コード例 #32
0
def test_random_player():
    replay = sc2reader.load_replay("test_replays/1.2.2.17811/3.SC2Replay")

    gogeta = next(player for player in replay.players
                  if player.name == 'Gogeta')
    assert gogeta.pick_race == "Random"
    assert gogeta.play_race == "Terran"
コード例 #33
0
ファイル: test_all.py プロジェクト: JunHuang01/sc2reader
    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")
def main():

    path_to_replay_file = ""
    if len(sys.argv) < 2:
        path_to_replay_file = _get_path_to_most_recent_replay()
    else:
        path_to_replay_file = sys.argv[1]

    print("Path: ", path_to_replay_file)

    replay = sc2reader.load_replay(path_to_replay_file)

    print("\nAnalyzing replay: {}".format(replay.filename))

    analysis_cutoff_time_in_seconds = 600

    for player in replay.players:
        if player.play_race != "Zerg":
            continue

        print("\n{}".format(player))

        num_creep_tumors = techlabreactor.creep_tumours_built_before_second(
            analysis_cutoff_time_in_seconds, player, replay)
        print("\tNum creep tumors produced in first {} seconds: {}".format(
            analysis_cutoff_time_in_seconds, num_creep_tumors))

        avg_larvae_lifetime = average_larvae_lifetime(player, replay)
        print("\tAverage larva lifetime: {}s".format(avg_larvae_lifetime))

        larvae_efficiency(player, replay)

        print_larvae_timeline(player, replay)

    return 0
コード例 #35
0
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"
コード例 #36
0
ファイル: test_all.py プロジェクト: JunHuang01/sc2reader
 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])
コード例 #37
0
ファイル: test_all.py プロジェクト: JunHuang01/sc2reader
    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)
コード例 #38
0
def processReplays():
    global currentReplay
    copyRecentReplaysFromSource()
    replayNames = os.listdir(path)
    for index in range(len(replayNames)):
        try:
            currentReplay = replayNames[index]
            replay = sc2reader.load_replay(path + currentReplay)
            getPlayerInfo(replay)
            getRatings(players[0], players[1], races[0], races[1])
            newName = createReplayString(
                str(replay.date).replace(":", "."), str(replay.map_name))
            print(newName)
            renameFile(newName)
            clear()
        except Exception as err:
            print("A non 1v1 can't be processed.", str(err))
    try:
        zipname = "Rob ReplayPack " + str(
            datetime.datetime.now().month) + '-' + str(
                datetime.datetime.now().day) + '-' + str(
                    datetime.datetime.now().year) + ".zip"
        zipf = zipfile.ZipFile(zipname, 'w', zipfile.ZIP_DEFLATED)
        zipdir(path, zipf)
        zipf.close()
        print(os.getcwd() + '/' + zipname)
        shutil.move(os.getcwd() + "\\" + zipname,
                    os.environ['USERPROFILE'] + '\Desktop')
        print('zipped')
    except Exception as err:
        print(err)
コード例 #39
0
def classify_by_type(path):
    counter = Counter()
    replay_races = dict()
    for file in os.listdir(path):
        try:
            replay = sc2reader.load_replay(path + '/' + file,
                                           load_level=4,
                                           debug=True)
            if len(replay.players) == 2 and replay.winner is not None:
                player1_race = replay.players[0].attribute_data['Race']
                player2_race = replay.players[1].attribute_data['Race']
                if player1_race == "Random":
                    p1_unit = replay.players[0].units[25].name
                    if p1_unit in zergHeaders:
                        player1_race = "Zerg"
                    elif p1_unit in terranHeaders:
                        player1_race = "Terran"
                    elif p1_unit in protossHeaders:
                        player1_race = "Protoss"
                if player2_race == "Random":
                    p2_unit = replay.players[1].units[25].name
                    if p2_unit in zergHeaders:
                        player2_race = "Zerg"
                    elif p2_unit in terranHeaders:
                        player2_race = "Terran"
                    elif p2_unit in protossHeaders:
                        player2_race = "Protoss"

                replay_races[file] = get_race_class(player1_race, player2_race)
        except Exception:
            print(file)
    with open("replay_races.txt", 'wb') as fp:
        pickle.dump(replay_races, fp)
コード例 #40
0
ファイル: test_all.py プロジェクト: joanSolCom/sc2reader
 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])
コード例 #41
0
def upload():
    """Process the uploaded file"""
    uploaded_file = request.files.get('file')

    if not uploaded_file:
        return 'No file uploaded.', 400

    replay = sc2reader.load_replay(uploaded_file, load_map=True)
    player1 = replay.players[0]
    player2 = replay.players[1]

    build1 = []
    build2 = []

    for event in replay.events:
        if event.name == "UnitInitEvent":
            if event.unit_controller == player1:
                build1.append(floor(event.second / 60))
                build1.append(event.second % 60)
                if event.unit.name == "SupplyDepotLowered":
                    build1.append("SupplyDepot")
                else:
                    build1.append(event.unit.name)
            else:
                build2.append(floor(event.second / 60))
                build2.append(event.second % 60)
                if event.unit.name == "SupplyDepotLowered":
                    build2.append("SupplyDepot")
                else:
                    build2.append(event.unit.name)
    text = "<html><body><p>" + dumps(build1) + "</p><hr><p>" + dumps(
        build2) + "</p></body></html>"
    return text
コード例 #42
0
def test_us_realm():
    replay = sc2reader.load_replay("test_replays/1.2.2.17811/5.SC2Replay")
    shadesofgray = next(player for player in replay.players
                        if player.name == 'ShadesofGray')
    reddawn = next(player for player in replay.players
                   if player.name == 'reddawn')
    assert shadesofgray.url == "http://us.battle.net/sc2/en/profile/2358439/1/ShadesofGray/"
    assert reddawn.url == "http://us.battle.net/sc2/en/profile/2198663/1/reddawn/"
コード例 #43
0
def test_oracle_parsing():
    replay = sc2reader.load_replay(
        "test_replays/2.0.3.24764/ggtracker_1571740.SC2Replay")
    assert replay.expansion == 'HotS'
    oracles = [
        unit for unit in replay.objects.values() if unit.name == 'Oracle'
    ]
    assert len(oracles) == 2
コード例 #44
0
 def test_oracle_parsing(self):
     replay = sc2reader.load_replay(
         "test_replays/2.0.3.24764/ggtracker_1571740.SC2Replay")
     self.assertEqual(replay.expansion, "HotS")
     oracles = [
         unit for unit in replay.objects.values() if unit.name == "Oracle"
     ]
     self.assertEqual(len(oracles), 2)
コード例 #45
0
ファイル: test_all.py プロジェクト: JMSerruya/sc2reader
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
コード例 #46
0
ファイル: process_replay.py プロジェクト: K4orta/izsha
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
コード例 #47
0
ファイル: test_all.py プロジェクト: BBLN/sc2reader
 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))
コード例 #48
0
ファイル: test_all.py プロジェクト: BBLN/sc2reader
    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())
コード例 #49
0
ファイル: sc2json.py プロジェクト: Aaah/erosd
 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))
コード例 #50
0
ファイル: test_all.py プロジェクト: JunHuang01/sc2reader
 def test_map_info(self):
     replay = sc2reader.load_replay("test_replays/1.5.3.23260/ggtracker_109233.SC2Replay", load_map=True)
     self.assertEqual(replay.map.map_info.tile_set, 'Avernus')
     self.assertEqual(replay.map.map_info.fog_type, 'Dark')
     self.assertEqual(replay.map.map_info.width, 176)
     self.assertEqual(replay.map.map_info.height, 160)
     self.assertEqual(replay.map.map_info.camera_top, 134)
     self.assertEqual(replay.map.map_info.camera_left, 14)
     self.assertEqual(replay.map.map_info.camera_right, 162)
     self.assertEqual(replay.map.map_info.camera_bottom, 14)
     controllers = [(p.pid, p.control) for p in replay.map.map_info.players]
     self.assertEqual(controllers, [(0, 3), (1, 1), (2, 1), (15, 4)])
コード例 #51
0
ファイル: SC2RA.py プロジェクト: DasFranck/Python-Mineur
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)
コード例 #52
0
def main():
    for argument in sys.argv[1:]:
        for path in sc2reader.utils.get_files(argument,extension='SC2Replay'):
            try:
              print "doing {}".format(path)
              rs = sc2reader.load_replay(path, load_level=0).release_string
              versdir = '/Users/david/Dropbox/Public/sc2replays/{}'.format(rs)
              if not os.path.exists(versdir):
                os.mkdir(versdir)
              shutil.copy(path, versdir)
            except Exception as e:
              print "bah", e
              pass
コード例 #53
0
ファイル: test_all.py プロジェクト: JunHuang01/sc2reader
    def test_hots_pids(self):
        for replayfilename in [
            "test_replays/2.0.3.24764/Akilon Wastes (10).SC2Replay",
            "test_replays/2.0.3.24764/Antiga Shipyard (3).SC2Replay",
            "test_replays/2.0.0.24247/molten.SC2Replay",
            "test_replays/2.0.0.23925/Akilon Wastes.SC2Replay",
            ]:

            replay = sc2reader.load_replay(replayfilename)
            self.assertEqual(replay.expansion, "HotS")
            player_pids = set([player.pid for player in replay.players if player.is_human])
            ability_pids = set([event.player.pid for event in replay.events if "CommandEvent" in event.name])
            self.assertEqual(ability_pids, player_pids)
コード例 #54
0
ファイル: test_all.py プロジェクト: JunHuang01/sc2reader
 def test_kr_realm_and_tampered_messages(self):
     """
     # TODO: Current problem.. both players are set as the recording players
     # Waiting for response https://github.com/arkx/mpyq/issues/closed#issue/7
     """
     replay = sc2reader.load_replay("test_replays/1.1.3.16939/11.SC2Replay")
     self.assertEqual(replay.expansion, "WoL")
     first = [player for player in replay.players if player.name == "명지대학교"][0]
     second = [player for player in replay.players if player.name == "티에스엘사기수"][0]
     self.assertEqual(first.url, "http://kr.battle.net/sc2/en/profile/258945/1/명지대학교/")
     self.assertEqual(second.url, "http://kr.battle.net/sc2/en/profile/102472/1/티에스엘사기수/")
     self.assertEqual(replay.messages[0].text, "sc2.replays.net")
     self.assertEqual(replay.messages[5].text, "sc2.replays.net")
コード例 #55
0
ファイル: sc2printer.py プロジェクト: 30to1/sc2reader
def doFile(filename, arguments):
    '''Prints summary information about SC2 replay file'''
    try:
        replay = sc2reader.load_replay(filename, debug=True)
    except ReadError as e:
        raise
        return
        prev = e.game_events[-1]
        print "\nVersion {0} replay:\n\t{1}".format(e.replay.release_string, e.replay.filename)
        print "\t{0}, Type={1:X}, Code={2:X}".format(e.msg, e.type,e.code)
        print "\tPrevious Event: {0}".format(prev.name)
        print "\t\t"+prev.bytes.encode('hex')
        print "\tFollowing Bytes:"
        print "\t\t"+e.buffer.read_range(e.location,e.location+30).encode('hex')
        print "Error with '{0}': ".format(filename)
        print e
        return
    except TypeError as e:
        raise
        print "Error with '%s': " % filename,
        print e
        return
    except ValueError as e:
        print "Error with '%s': " % filename,
        print e
        return

    if arguments.map:
        print "   Map:      {0}".format(replay.map)
    if arguments.length:
        print "   Length:   {0}".format(replay.length)
    if arguments.date:
        print "   Date:     {0}".format(replay.date)
    if arguments.teams:
        races = list()
        for team in replay.teams:
            races.append(''.join([player.pick_race[0] for player in team.players]))
        print "   Teams:    {0}".format("v".join(races))

        for team in replay.teams:
            print "      Team {0}\t{1} ({2})".format(team.number,team.players[0].name,team.players[0].pick_race[0])
            for player in team.players[1:]:
                print "              \t{0} ({1})".format(player.name,player.pick_race[0])
    if arguments.messages:
        print "   Messages:"
        for message in replay.messages:
            print "   {0}".format(message)
    if arguments.version:
        print "   Version:  {0}".format(replay.release_string)

    print
コード例 #56
0
ファイル: parser.py プロジェクト: GraylinKim/spawningtool
def parse_replay(replay_file, cutoff_time=None):
    """
    Parse replay for build order related events
    """
    try:
        replay = sc2reader.load_replay(replay_file)
    except sc2reader.exceptions.ReadError as error:
        raise ReadError(error.message)
    except Exception as error:  # Maybe a MPQError
        raise ReadError(error.message)

    parsed_data = {
        'buildOrderExtracted': False,
        'message': '',
        'build': replay.build,
        'baseBuild': replay.versions[5],
        'category': replay.category,
        'expansion': replay.expansion,
        'unix_timestamp': replay.unix_timestamp,  # time completed
        'frames': replay.frames,
        'game_type': replay.real_type,
        'region': replay.region,
        'map': replay.map_name,
        'map_hash': replay.map_hash,
    }

    parsed_data['players'] = dict(
        (key,
            {
                'name': player.name,
                'pick_race': player.pick_race,  # can be random
                'race': player.play_race,
                'league': player.highest_league if player.is_human else None,
                'level': player.combined_race_levels if player.is_human else None,
                'is_winner': player.team.result == 'Win',
                'result': player.team.result,
                'is_human': player.is_human,
                'handicap': player.handicap,
                'color': player.color.hex,
                'uid': player.toon_id,  # naming change from sc2reader
                'region': player.region,
                'supply': [[0, 6]],
                'team': player.team.number,
            }) for key, player in replay.player.iteritems()
    )

    return parse_events(
        replay,
        cutoff_time,
        parsed_data,
    )
コード例 #57
0
ファイル: drop_to_debug.py プロジェクト: nibalizer/sc2scripts
def main():
    players = {}
    parser = argparse.ArgumentParser(
        description="""Parse replay and drop immediately to a debug shell"""
    )

    parser.add_argument('FILE', type=str, help="The file you would like to replay")
    args = parser.parse_args()

    for filename in sc2reader.utils.get_files(args.FILE):
        replay = sc2reader.load_replay(filename, debug=True)
        r = replay
        from pdb import set_trace; set_trace()
        print("\n--------------------------\n\n")
コード例 #58
0
def main(files, maxSecondsToConsider, windowCutInSeconds):
    actions_dic = collections.OrderedDict()  # id: action
    next_global_d = 1 # start to count action id at 1

    for filename in sc2reader.utils.get_files(files):
        replay = sc2reader.load_replay(filename, load_level=4, debug=True) # reads a folder
        #get all players
        players = [t.players for t in replay.teams]
        players = [y for x in players for y in x] # Not sure what this means?
        #get the matchup as a unique string (sorted by letters): e.g., ZZ TZ TTP and not ZT as Z>T in lex. ordering.
        matchup = [p.play_race[0:1] for p in players]
        matchup.sort()
        matchup= "".join(matchup)
        # get basics replays info
        replay_info = [matchup, replay.release_string, replay.type, replay.map_name, replay.start_time]

        if len(players) !=2: continue
        sec = 0
        for event in replay.events:
            if (event.second > maxSecondsToConsider): break
            if (isinstance(event, TargetPointCommandEvent) and event.has_ability):
                if (event.ability_name.startswith("Build")):

                    actionpos  = event.ability_name + "+"
                    actionneg  = event.ability_name + "-"
                    actiondone = actionpos if event.player.result[:1]=="W" else actionneg

                    if actionpos not in actions_dic:
                        actions_dic[actionneg] = next_global_d
                        next_global_d = next_global_d + 1
                        actions_dic[actionpos] = next_global_d
                        next_global_d = next_global_d + 1
                    
                    print(actions_dic[actiondone], end = " ")

                    hasChangedItemset = False
                    if (event.second - sec > windowCutInSeconds):
                        sec = event.second
                        print("-1", end=" ")
                        hasChangedItemset=True
                        
        if (not hasChangedItemset): print ("-1", end=" ")
        print("\t".join([str(s) for s in ["-2"]+replay_info]))

    # write the dico,  mapping integer -> action/build_order
    f = open("dico.txt", "w")
    for a in actions_dic:
        f.write("{1}\t{0}\n".format(actions_dic[a], a))
    f.close()
コード例 #59
0
def printReplay(filepath, analysis, arguments):
    """ Prints summary information about SC2 replay file """
    replay = sc2reader.load_replay(filepath, debug=True)

    if arguments.displayreplays:
        print("\n--------------------------------------\n{0}\n".format(filepath))
        print("   Map:      {0}".format(replay.map_name))
        print("   Date:     {0}".format(replay.start_time))
        print("   Version:  {0}".format(replay.release_string))
        print("   Length:   {0} minutes".format(replay.game_length))
        lineups = [team.lineup for team in replay.teams]
        print("   Teams:    {0}".format("v".join(lineups)))
        if len(replay.observers) > 0:
            print("   Observers:")
            for observer in replay.observers:
                print("      {0}".format(observer.name))
    for team in replay.teams:
        if arguments.displayreplays:
            print("      Team {0}".format(team.number))
        for player in team.players:
            if player.is_human:
                if arguments.displayreplays:
                    print("      \t{0} ({1})".format(player.name, player.pick_race[0]))
                    print("      \t\tPPM: {0:>6.2f}".format(player.PACStats.ppm))
                    print("      \t\tPAL: {0:>6.2f}".format(player.PACStats.pal))
                    print("      \t\tAPP: {0:>6.2f}".format(player.PACStats.app))
                    print("      \t\tGAP: {0:>6.2f}".format(player.PACStats.gap))
                if player.toon_id in analysis:
                    analysis[player.toon_id].ppm = (analysis[player.toon_id].count * analysis[player.toon_id].ppm +
                                                    player.PACStats.ppm) / (analysis[player.toon_id].count + 1)
                    analysis[player.toon_id].pal = (analysis[player.toon_id].count * analysis[player.toon_id].pal +
                                                    player.PACStats.pal) / (analysis[player.toon_id].count + 1)
                    analysis[player.toon_id].app = (analysis[player.toon_id].count * analysis[player.toon_id].app +
                                                    player.PACStats.app) / (analysis[player.toon_id].count + 1)
                    analysis[player.toon_id].gap = (analysis[player.toon_id].count * analysis[player.toon_id].gap +
                                                    player.PACStats.gap) / (analysis[player.toon_id].count + 1)
                    analysis[player.toon_id].count += 1
                else:
                    analysis[player.toon_id] = PACStats()
                    analysis[player.toon_id].name = player.name
                    analysis[player.toon_id].count = 1
                    analysis[player.toon_id].ppm = player.PACStats.ppm
                    analysis[player.toon_id].pal = player.PACStats.pal
                    analysis[player.toon_id].app = player.PACStats.app
                    analysis[player.toon_id].gap = player.PACStats.gap
            else:
                if arguments.displayreplays:
                    print("      \t{0} ({1})".format(player.name, player.pick_race[0]))
    print
コード例 #60
0
ファイル: sc2replayer.py プロジェクト: JMSerruya/sc2reader
def main():
    args = get_args()
    for filename in sc2reader.utils.get_files(args.FILE):
        replay = sc2reader.load_replay(filename, debug=True)
        print "Release {0}".format(replay.release_string)
        print "{0} on {1}".format(replay.type, replay.map)
        for player in replay.players:
            print player
        print "\n--------------------------\n\n"

        # Allow picking of the player to 'watch'
        if args.player:
            events = replay.player[args.player].events
        else:
            events = replay.events

        # Loop through the events
        # data = sc2reader.config.build_data[replay.build]
        for event in events:
            try:
                pass
                # event.apply(data)
            except ValueError as e:
                if str(e) == "Using invalid abilitiy matchup.":
                    myGetch()
                else:
                    raise e

            # Use their options to filter the event stream

            if (
                isinstance(event, AbilityEvent)
                or isinstance(event, SelectionEvent)
                or isinstance(event, PlayerJoinEvent)
                or isinstance(event, PlayerLeaveEvent)
                or isinstance(event, GameStartEvent)
                or (args.hotkeys and isinstance(event, HotkeyEvent))
                or (args.cameras and isinstance(event, CameraEvent))
            ):
                """
                if isinstance(event, SelectionEvent) or isinstance(event, HotkeyEvent):
                """
                print event
                # myGetch()
                if args.bytes:
                    print "\t" + event.bytes.encode("hex")

                if re.search("UNKNOWN|ERROR", str(event)):
                    myGetch()