Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
 def __init__(self, dolphin):
     #Dict with key of address, and value of (name, player)
     self.locations = dict()
     path = os.path.dirname(os.path.realpath(__file__))
     with open(path + "/locations.csv") as csvfile:
         reader = csv.DictReader(csvfile)
         for line in reader:
             self.locations[line["Address"]] = (line["Name"],
                                                line["Player"])
     self.player[1] = PlayerState()
     self.player[2] = PlayerState()
     self.player[3] = PlayerState()
     self.player[4] = PlayerState()
     self.player[5] = PlayerState()
     self.player[6] = PlayerState()
     self.player[7] = PlayerState()
     self.player[8] = PlayerState()
     self.newframe = True
     #Helper names to keep track of us and our opponent
     self.ai_state = self.player[dolphin.ai_port]
     self.opponent_state = self.player[dolphin.opponent_port]
     self.ai_port = dolphin.ai_port
     self.opponent_port = dolphin.opponent_port
     #Read in the action data csv
     with open(path + "/actiondata.csv") as csvfile:
         #A list of dicts containing the frame data
         actiondata = list(csv.DictReader(csvfile))
         #Dict of sets
         self.zero_indices = defaultdict(set)
         for line in actiondata:
             if line["zeroindex"] == "True":
                 self.zero_indices[int(line["character"])].add(
                     int(line["action"]))
     #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
     #Creates the socket if it does not exist, and then opens it.
     path = dolphin.get_memory_watcher_socket_path()
     try:
         os.unlink(path)
     except OSError:
         pass
     self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
     self.sock.bind(path)
Exemplo n.º 3
0
    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