Example #1
0
def parse_replay(replay_player_path, sampled_action_path, reward):
    if os.path.isfile(os.path.join(FLAGS.parsed_replay_path, 'GlobalFeatures', replay_player_path)):
        return

    # Global Info
    with open(os.path.join(FLAGS.parsed_replay_path, 'GlobalInfos', replay_player_path)) as f:
        global_info = json.load(f)
    units_info = static_data.StaticData(Parse(global_info['data_raw'], sc_pb.ResponseData())).units
    feat = features.Features(Parse(global_info['game_info'], sc_pb.ResponseGameInfo()))

    # Sampled Actions
    with open(sampled_action_path) as f:
        sampled_action = json.load(f)
    sampled_action_id = [id // FLAGS.step_mul + 1 for id in sampled_action]

    # Actions
    with open(os.path.join(FLAGS.parsed_replay_path, 'Actions', replay_player_path)) as f:
        actions = json.load(f)
    actions = [None if len(actions[idx]) == 0 else Parse(actions[idx][0], sc_pb.Action())
                for idx in sampled_action_id]

    # Observations
    observations =  [obs for obs in stream.parse(os.path.join(FLAGS.parsed_replay_path,
                            'SampledObservations', replay_player_path), sc_pb.ResponseObservation)]

    assert len(sampled_action) == len(sampled_action_id) == len(actions) == len(observations)

    states = process_replay(sampled_action, actions, observations, feat, units_info, reward)

    with open(os.path.join(FLAGS.parsed_replay_path, 'GlobalFeatures', replay_player_path), 'w') as f:
        json.dump(states, f)
Example #2
0
def parse_replay(replay_player_path, sampled_frame_path, reward):
    if os.path.isfile(os.path.join(FLAGS.parsed_replay_path, 'GlobalFeatures', replay_player_path)):
        return

    # Global Info
    with open(os.path.join(FLAGS.parsed_replay_path, 'GlobalInfos', replay_player_path)) as f:
        global_info = json.load(f)
    units_info = static_data.StaticData(Parse(global_info['data_raw'], sc_pb.ResponseData())).units
    feat = features.features_from_game_info(Parse(global_info['game_info'], sc_pb.ResponseGameInfo()))

    # Sampled Frames
    with open(sampled_frame_path) as f:
        sampled_frames = json.load(f)
    sampled_actions_idx = [frame // FLAGS.step_mul - 1 for frame in sampled_frames] # Create index to retrieve actions corresponding to sampled frames

    # Actions
    with open(os.path.join(FLAGS.parsed_replay_path, 'Actions', replay_player_path)) as f:
        actions = json.load(f)
    sampled_actions = [None if len(actions[idx]) == 0 else Parse(actions[idx][0], sc_pb.Action()) 
                for idx in sampled_actions_idx] # Get first action executed after each sampled frame

    # Observations
    observations =  [obs for obs in stream.parse(os.path.join(FLAGS.parsed_replay_path,
                            'SampledObservations', replay_player_path), sc_pb.ResponseObservation)]

    assert len(sampled_frames) == len(sampled_actions_idx) == len(sampled_actions) == len(observations)

    states = process_replay(sampled_frames, sampled_actions, observations, feat, units_info, reward)

    with open(os.path.join(FLAGS.parsed_replay_path, 'GlobalFeatures', replay_player_path), 'w') as f:
        json.dump(states, f)
def get_data_raw(version):
    data_raw = sc_pb.ResponseData()
    if distutils.version.LooseVersion(
            version) >= distutils.version.LooseVersion('4.7.1'):
        data = pkgutil.get_data('pysc2',
                                f'lib/data/data_raw_{version}.serialized')
        data_raw.ParseFromString(data)
    elif distutils.version.LooseVersion(
            version) >= distutils.version.LooseVersion('4.0'):
        data_4_0 = pkgutil.get_data('pysc2',
                                    'lib/data/data_raw_4_0.serialized')
        data_raw.ParseFromString(data_4_0)
    else:
        data_3_16 = pkgutil.get_data('pysc2',
                                     'lib/data/data_raw_3_16.serialized')
        data_raw.ParseFromString(data_3_16)
    return data_raw
import json
from google.protobuf.json_format import Parse
from s2clientprotocol import sc2api_pb2 as sc_pb

Name = '1@04dc996078fde09d89b18de27d7570e6077b13483f69611fbb7a93ad8e3a29e8.SC2Replay'

GLOBAL_INFO_PATH = '/parsed_replays/GlobalInfos/Terran_vs_Terran/Terran/'+Name

PATH2 = 'parsed_replays/GlobalInfos/Terran_vs_Terran/Terran/1@0553abd0df0ead191d279074ded6c426dedd5d371dded691bf44e380b92cd359.SC2Replay'


with open(PATH2) as f:
    global_info = json.load(f)
GAME_INFO = Parse(global_info['game_info'], sc_pb.ResponseGameInfo())
DATA_RAW  = Parse(global_info['data_raw'], sc_pb.ResponseData())

print(GAME_INFO)
#print(DATA_RAW)
from s2clientprotocol import  sc2api_pb2 as sc_pb
import pkgutil

data_raw_3_16 = sc_pb.ResponseData()
data_3_16 = pkgutil.get_data('pysc2', 'lib/data/data_raw_3_16.serialized')
data_raw_3_16.ParseFromString(data_3_16)
#print(data_raw_3_16)

data_raw_4_0 = sc_pb.ResponseData()
data_4_0 = pkgutil.get_data('pysc2', 'lib/data/data_raw_4_0.serialized')
data_raw_4_0.ParseFromString(data_4_0)
#print(data_raw_4_0)