Exemple #1
0
 def preprocess_input(self, gamestate, ai_state, opponent_state):
     df = pd.DataFrame({
         'Frame': [gamestate.frame],
         'Opponent_x': [(opponent_state.x)],
         'Opponent_y': [(opponent_state.y)],
         'AI_x': [(ai_state.x)],
         'AI_y': [(ai_state.y)],
         'Opponent_Facing': [(opponent_state.facing)],
         'AI_Facing': [(ai_state.facing)],
         'Opponent_Action_Num': [(Action(opponent_state.action).value)],
         'AI_Action_Num': [(Action(ai_state.action).value)],
         'Opponent_Action_Frame': [(opponent_state.action_frame)],
         'AI_Action_Frame': [(ai_state.action_frame)],
         'Opponent_Jumps_Left': [(opponent_state.jumps_left)],
         'AI_Jumps_Left': [(ai_state.jumps_left)],
         'Opponent_Stock': [(opponent_state.stock)],
         'AI_Stock': [(ai_state.stock)],
         'Opponent_Percent': [(opponent_state.percent)],
         'AI_Percent': [(ai_state.percent)]
     })
     df[["Opponent_Facing", "AI_Facing"]] *= 1
     df_test = df.head(1)
     result = df.head(1).astype(float).values
     result = np.tile(result, (149, 1))
     return result, np.array(range(149))
 def cleanupcsv(self):
     #Make a list of all the attacking action names
     attacks = []
     for row in self.rows:
         if row['hitbox_1_status'] or row['hitbox_2_status'] or \
                 row['hitbox_3_status'] or row['hitbox_4_status'] or \
                 row['projectile']:
             attacks.append(row['action'])
     #remove duplicates
     attacks = list(set(attacks))
     #Make a second pass, removing anything not in the list
     for row in list(self.rows):
         if row['action'] not in attacks and not self.isroll(Character(row['character']), Action(row['action'])) \
                 and not self.isbmove(Character(row['character']), Action(row['action'])):
             self.rows.remove(row)
Exemple #3
0
    def log_frame(self, gamestate):
        if gamestate.menu_state not in [Menu.IN_GAME, Menu.SUDDEN_DEATH]:
            self.past_opponent_percent = 0
            self.past_ai_percent = 0
            self.past_opponent_stock = 3
            self.past_ai_stock = 3
        ai_state = gamestate.ai_state
        opponent_state = gamestate.opponent_state

        self.log('Frame', gamestate.frame)
        self.log('Opponent_x', str(opponent_state.x))
        self.log('Opponent_y', str(opponent_state.y))
        self.log('AI_x', str(ai_state.x))
        self.log('AI_y', str(ai_state.y))
        self.log('Opponent_Facing', opponent_state.facing)
        self.log('AI_Facing', ai_state.facing)
        self.log('Opponent_Action', str(opponent_state.action))
        self.log('Opponent_Action_Num', str(Action(opponent_state.action).value))
        self.log('AI_Action', str(ai_state.action))
        self.log('AI_Action_Num', str(Action(ai_state.action).value))
        self.log('Opponent_Action_Frame', str(opponent_state.action_frame))
        self.log('AI_Action_Frame', str(ai_state.action_frame))
        self.log('Opponent_Jumps_Left', str(opponent_state.jumps_left))
        self.log('AI_Jumps_Left', str(ai_state.jumps_left))
        self.log('Opponent_Stock', str(opponent_state.stock))
        self.log('AI_Stock', str(ai_state.stock))
        self.log('Opponent_Percent', str(opponent_state.percent))
        self.log('AI_Percent', str(ai_state.percent))
        self.log('Opponent_Percent_Change', str(opponent_state.percent-self.past_opponent_percent))
        self.log('AI_Percent_Change', str(ai_state.percent-self.past_ai_percent))
        self.log('Opponent_Stock_Change', opponent_state.stock-self.past_opponent_stock)
        self.log('AI_Stock_Change', ai_state.stock-self.past_ai_stock)
        self.past_opponent_percent=opponent_state.percent
        self.past_ai_percent=ai_state.percent
        self.past_opponent_stock=opponent_state.stock
        self.past_ai_stock=ai_state.stock
    def __init__(self, write=False):
        if write:
            self.csvfile = open('framedata.csv', 'a')
            fieldnames = [
                'character', 'action', 'frame', 'hitbox_1_status',
                'hitbox_1_size', 'hitbox_1_x', 'hitbox_1_y', 'hitbox_2_status',
                'hitbox_2_size', 'hitbox_2_x', 'hitbox_2_y', 'hitbox_3_status',
                'hitbox_3_size', 'hitbox_3_x', 'hitbox_3_y', 'hitbox_4_status',
                'hitbox_4_size', 'hitbox_4_x', 'hitbox_4_y', 'locomotion_x',
                'locomotion_y', 'iasa', 'facing_changed', 'projectile'
            ]
            self.writer = csv.DictWriter(self.csvfile, fieldnames=fieldnames)
            self.writer.writeheader()
            self.rows = []

            self.actionfile = open("actiondata.csv", "a")
            fieldnames = ["character", "action", "zeroindex"]
            self.actionwriter = csv.DictWriter(self.actionfile,
                                               fieldnames=fieldnames)
            self.actionwriter.writeheader()
            self.actionrows = []

            self.prevfacing = {}
            self.prevprojectilecount = {}

        #Read the existing framedata
        path = os.path.dirname(os.path.realpath(__file__))
        self.framedata = defaultdict(
            lambda: defaultdict(lambda: defaultdict(dict)))
        with open(path + "/framedata.csv") as csvfile:
            # A list of dicts containing the frame data
            csvreader = list(csv.DictReader(csvfile))
            # Build a series of nested dicts for faster read access
            for frame in csvreader:
                # Pull out the character, action, and frame
                character = Character(int(frame["character"]))
                action = Action(int(frame["action"]))
                action_frame = int(frame["frame"])
                self.framedata[character][action][action_frame] = \
                    {"hitbox_1_status": frame["hitbox_1_status"] == "True", \
                    "hitbox_1_size": float(frame["hitbox_1_size"]), \
                    "hitbox_1_x": float(frame["hitbox_1_x"]), \
                    "hitbox_1_y": float(frame["hitbox_1_y"]), \
                    "hitbox_2_status": frame["hitbox_2_status"] == "True", \
                    "hitbox_2_size": float(frame["hitbox_2_size"]), \
                    "hitbox_2_x": float(frame["hitbox_2_x"]), \
                    "hitbox_2_y": float(frame["hitbox_2_y"]), \
                    "hitbox_3_status": frame["hitbox_3_status"] == "True", \
                    "hitbox_3_size": float(frame["hitbox_3_size"]), \
                    "hitbox_3_x": float(frame["hitbox_3_x"]), \
                    "hitbox_3_y": float(frame["hitbox_3_y"]), \
                    "hitbox_4_status": frame["hitbox_4_status"] == "True", \
                    "hitbox_4_size": float(frame["hitbox_4_size"]), \
                    "hitbox_4_x": float(frame["hitbox_4_x"]), \
                    "hitbox_4_y": float(frame["hitbox_4_y"]), \
                    "locomotion_x": float(frame["locomotion_x"]), \
                    "locomotion_y": float(frame["locomotion_y"]), \
                    "iasa": frame["iasa"] == "True", \
                    "facing_changed": frame["facing_changed"] == "True", \
                    "projectile": frame["projectile"] == "True"}

        #read the character data csv
        self.characterdata = dict()
        path = os.path.dirname(os.path.realpath(__file__))
        with open(path + "/characterdata.csv") as csvfile:
            reader = csv.DictReader(csvfile)
            for line in reader:
                del line["Character"]
                #Convert all fields to numbers
                for key, value in line.items():
                    line[key] = float(value)
                self.characterdata[Character(line["CharacterIndex"])] = line