Exemple #1
0
frames = 5*framesPerMinute #Frames in the first five minutes of the game 

def ability_id(event):
    """
    Helper function which returns the pid of an event. Returns -1 if the event
    does not have a pid member.
    """
    if hasattr(event, 'ability_id'):
        return u'%i' % event.ability_id
    else:
        return 0
        
#Parse the event log
with open('workersupply.txt') as infile:
    labels = json.load(infile) 
parser = eventParser(labels, ability_id) #Classify worker and supply build events
log = gamelog(parser,3,start=0,end=frames,framesPerRow=fpr)

#Load and parse the training data
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)
Exemple #2
0
    Returns a label for each player in the replay. Returns 1 if the player is
    the winner of the replay and false otherwise. 
    """
    gameWinner = str(replay.winner.players[0])
    isPlayer1Winner = 0
    isPlayer2Winner = 0
    if gameWinner == str(replay.players[0]):
        isPlayer1Winner = 1
    if gameWinner == str(replay.players[1]):
        isPlayer2Winner = 1
    return (isPlayer1Winner, isPlayer2Winner)

#Classify worker and supply build events
with open('workersupply.txt') as infile:
    labels = json.load(infile) 
parser_ws = eventParser(labels, ability_id) 
log_ws = gamelog(parser_ws,2,start=0,end=frames,framesPerRow=fpr)

#Classify micro and macro
with open('micromacro.txt') as infile:
    labels = json.load(infile)
parser_mm = eventParser(labels, ability_id)
log_mm = gamelog(parser_mm,2,start=0,end=frames,framesPerRow=fpr)

#Load and parse the training data
def parseData(path):
    """
    Returns a list of feature vectors and a list of classes for each replay 
    file in the given path. 
    """
    data = []
Exemple #3
0
def ability_id(event):
    """
    Helper function which returns the pid of an event. Returns -1 if the event
    does not have a pid member.
    """
    if hasattr(event, 'ability_id'):
        return u'%i' % event.ability_id
    else:
        return 0
        
#Parse the event log
with open('micromacro.txt') as infile:
    labels = json.load(infile) 
#parser = eventParser() #Default uses APM as features
parser = eventParser(labels, ability_id) #Classify micro/macro
log = gamelog(parser,1,start=0,end=frames,framesPerRow=fpr)

def winner(replay):
    """
    Returns a label for each player in the replay. Returns 1 if the player is
    the winner of the replay and false otherwise. 
    """
    gameWinner = str(replay.winner.players[0])
    isPlayer1Winner = 0
    isPlayer2Winner = 0
    if gameWinner == str(replay.players[0]):
        isPlayer1Winner = 1
    if gameWinner == str(replay.players[1]):
        isPlayer2Winner = 1
    return (isPlayer1Winner, isPlayer2Winner)