コード例 #1
0
 def get_stats(self, map):
     map_locations = get_tile_locations(map, self.get_tile_types())
     map_stats = {
         "player":
         calc_certain_tile(map_locations, ["player"]),
         "dist-floor":
         get_floor_dist(map, ["player"], ["solid"]),
         "exit":
         calc_certain_tile(map_locations, ["exit"]),
         "diamonds":
         calc_certain_tile(map_locations, ["diamond"]),
         "key":
         calc_certain_tile(map_locations, ["key"]),
         "spikes":
         calc_certain_tile(map_locations, ["spike"]),
         "regions":
         calc_num_regions(map, map_locations,
                          ["empty", "player", "diamond", "key", "exit"]),
         "num-jumps":
         0,
         "col-diamonds":
         0,
         "dist-win":
         self._width * self._height,
         "sol-length":
         0
     }
     if map_stats["player"] == 1:
         if map_stats["exit"] == 1 and map_stats["key"] == 1 and map_stats[
                 "regions"] == 1:
             map_stats["dist-win"], map_stats[
                 "sol-length"], play_stats = self._run_game(map)
             map_stats["num-jumps"] = play_stats["num_jumps"]
             map_stats["col-diamonds"] = play_stats["col_diamonds"]
     return map_stats
コード例 #2
0
    def get_stats(self, map):
        self.path = []
        map_locations = get_tile_locations(map, self.get_tile_types())
        map_stats = {
            "player":
            calc_certain_tile(map_locations, ["player"]),
            "key":
            calc_certain_tile(map_locations, ["key"]),
            "door":
            calc_certain_tile(map_locations, ["door"]),
            "enemies":
            calc_certain_tile(map_locations, ["bat", "spider", "scorpion"]),
            "regions":
            calc_num_regions(
                map, map_locations,
                ["empty", "player", "key", "bat", "spider", "scorpion"]),
            "nearest-enemy":
            0,
            "path-length":
            0
        }
        if map_stats["player"] == 1 and map_stats["regions"] == 1:
            p_x, p_y = map_locations["player"][0]
            enemies = []
            enemies.extend(map_locations["spider"])
            enemies.extend(map_locations["bat"])
            enemies.extend(map_locations["scorpion"])
            if len(enemies) > 0:
                # NOTE: for evo-pcgrl, we don't want these super-high nearest-enemy scores from when
                # the player is cornered behind a key (it distorts our map of elites), so we make key passable
                dikjstra, _ = run_dikjstra(
                    p_x, p_y, map,
                    ["key", "empty", "player", "bat", "spider", "scorpion"])
                #               dikjstra,_ = run_dikjstra(p_x, p_y, map, ["empty", "player", "bat", "spider", "scorpion"])
                min_dist = self._width * self._height
                for e_x, e_y in enemies:
                    if dikjstra[e_y][e_x] > 0 and dikjstra[e_y][e_x] < min_dist:
                        min_dist = dikjstra[e_y][e_x]
                map_stats["nearest-enemy"] = min_dist
            if map_stats["key"] == 1 and map_stats["door"] == 1:
                k_x, k_y = map_locations["key"][0]
                d_x, d_y = map_locations["door"][0]
                dikjstra_k, _ = run_dikjstra(
                    p_x, p_y, map,
                    ["empty", "key", "player", "bat", "spider", "scorpion"])
                map_stats["path-length"] += dikjstra_k[k_y][k_x]
                dikjstra_d, _ = run_dikjstra(k_x, k_y, map, [
                    "empty", "player", "key", "door", "bat", "spider",
                    "scorpion"
                ])
                map_stats["path-length"] += dikjstra_d[d_y][d_x]
                if self.render_path:
                    self.path = np.hstack(
                        (get_path_coords(dikjstra_k, init_coords=(k_x, k_y)),
                         get_path_coords(dikjstra_d, init_coords=(d_x, d_y))))

        return map_stats
コード例 #3
0
    def get_stats(self, map):
        map_locations = get_tile_locations(map, self.get_tile_types())
        map_stats = {
            "player":
            calc_certain_tile(map_locations, ["player"]),
            "key":
            calc_certain_tile(map_locations, ["key"]),
            "door":
            calc_certain_tile(map_locations, ["door"]),
            "enemies":
            calc_certain_tile(map_locations, ["bat", "spider", "scorpion"]),
            "regions":
            calc_num_regions(
                map, map_locations,
                ["empty", "player", "key", "bat", "spider", "scorpion"]),
            "nearest-enemy":
            0,
            "path-length":
            0
        }
        if map_stats["player"] == 1 and map_stats["regions"] == 1:
            p_x, p_y = map_locations["player"][0]
            enemies = []
            enemies.extend(map_locations["spider"])
            enemies.extend(map_locations["bat"])
            enemies.extend(map_locations["scorpion"])
            if len(enemies) > 0:
                dikjstra, _ = run_dikjstra(
                    p_x, p_y, map,
                    ["empty", "player", "bat", "spider", "scorpion"])
                min_dist = self._width * self._height
                for e_x, e_y in enemies:
                    if dikjstra[e_y][e_x] > 0 and dikjstra[e_y][e_x] < min_dist:
                        min_dist = dikjstra[e_y][e_x]
                map_stats["nearest-enemy"] = min_dist
            if map_stats["key"] == 1 and map_stats["door"] == 1:
                k_x, k_y = map_locations["key"][0]
                d_x, d_y = map_locations["door"][0]
                dikjstra, _ = run_dikjstra(
                    p_x, p_y, map,
                    ["empty", "key", "player", "bat", "spider", "scorpion"])
                map_stats["path-length"] += dikjstra[k_y][k_x]
                dikjstra, _ = run_dikjstra(k_x, k_y, map, [
                    "empty", "player", "key", "door", "bat", "spider",
                    "scorpion"
                ])
                map_stats["path-length"] += dikjstra[d_y][d_x]

        return map_stats
コード例 #4
0
ファイル: tmp_rts_prob.py プロジェクト: poi233/pcgrl_rts
 def get_stats(self, map):
     map_locations = get_tile_locations(map, self.get_tile_types())
     map_stats = {
         "base_count":
         calc_certain_tile(map_locations, ["base"]),
         "resource_count":
         calc_certain_tile(map_locations, ["resource"]),
         "chock_point":
         calc_certain_tile(map_locations, ["chock_point"]),
         "base_distance":
         0,
         # "base_space": 0,
         # "asymmetry": 0,
         "resource_distance":
         0,
         # "resource_clustering": 0,
         # "path_overlapping": 0,
         "region":
         calc_num_regions(map, map_locations, ["empty", "base", "resource"])
     }
     if map_stats["base_count"] == 2:
         # calculate distance
         b1_x, b1_y = map_locations["base"][0]
         b2_x, b2_y = map_locations["base"][1]
         dikjstra1, _ = run_dikjstra(b1_x, b1_y, map,
                                     ["empty", "base", "resource"])
         map_stats["base_distance"] = max(map_stats["base_distance"],
                                          dikjstra1[b2_y][b2_x])
         # calculate resource distance
         if map_stats["resource_count"] >= self._min_resource and map_stats[
                 "resource_count"] <= self._max_resource:
             dikjstra2, _ = run_dikjstra(b2_x, b2_y, map,
                                         ["empty", "base", "resource"])
             resources = []
             resources.extend(map_locations["resource"])
             dist1 = 10000
             dist2 = 10000
             for r_x, r_y in resources:
                 if dikjstra1[r_y][r_x] > 0:
                     dist1 = min(dist1, dikjstra1[r_y][r_x])
                 if dikjstra2[r_y][r_x] > 0:
                     dist2 = min(dist2, dikjstra2[r_y][r_x])
             map_stats["resource_distance"] = 1 - abs(dist1 - dist2)
     return map_stats
コード例 #5
0
 def get_stats(self, map):
     map_locations = get_tile_locations(map, self.get_tile_types())
     map_stats = {
         "player":
         calc_certain_tile(map_locations, ["player"]),
         "crate":
         calc_certain_tile(map_locations, ["crate"]),
         "target":
         calc_certain_tile(map_locations, ["target"]),
         "regions":
         calc_num_regions(map, map_locations,
                          ["empty", "player", "crate", "target"]),
         "dist-win":
         self._width * self._height * (self._width + self._height),
         "solution": []
     }
     if map_stats["player"] == 1 and map_stats["crate"] == map_stats[
             "target"] and map_stats["crate"] > 0 and map_stats[
                 "regions"] == 1:
         map_stats["dist-win"], map_stats["solution"] = self._run_game(map)
     return map_stats
コード例 #6
0
ファイル: smb_prob.py プロジェクト: sts-sadr/gym-pcgrl
 def get_stats(self, map):
     map_locations = get_tile_locations(map, self.get_tile_types())
     map_stats = {
         "dist-floor": get_floor_dist(map, ["enemy"], ["solid", "brick", "question", "tube_left", "tube_right"]),
         "disjoint-tubes": get_type_grouping(map, ["tube"], [(-1,0),(1,0)],1,1),
         "enemies": calc_certain_tile(map_locations, ["enemy"]),
         "empty": calc_certain_tile(map_locations, ["empty"]),
         "noise": get_changes(map, False) + get_changes(map, True),
         "jumps": 0,
         "jumps-dist": 0,
         "dist-win": 0
     }
     map_stats["dist-win"], play_stats = self._run_game(map)
     map_stats["jumps"] = play_stats["jumps"]
     prev_jump = 0
     value = 0
     for l in play_stats["jump_locs"]:
         value = max(value, l[0] - prev_jump)
         prev_jump = l[0]
     value = max(value, self._width - prev_jump)
     map_stats["jumps-dist"] = value
     return map_stats
コード例 #7
0
 def get_stats(self, map):
     map_locations = get_tile_locations(map, self.get_tile_types())
     map_stats = {
         "player":
         calc_certain_tile(map_locations, ["player"]),
         "exit":
         calc_certain_tile(map_locations, ["exit"]),
         "potions":
         calc_certain_tile(map_locations, ["potion"]),
         "treasures":
         calc_certain_tile(map_locations, ["treasure"]),
         "enemies":
         calc_certain_tile(map_locations, ["goblin", "ogre"]),
         "regions":
         calc_num_regions(map, map_locations, [
             "empty", "player", "exit", "potion", "treasure", "goblin",
             "ogre"
         ]),
         "col-potions":
         0,
         "col-treasures":
         0,
         "col-enemies":
         0,
         "dist-win":
         self._width * self._height,
         "sol-length":
         0
     }
     if map_stats["player"] == 1 and map_stats["exit"] == 1 and map_stats[
             "regions"] == 1:
         map_stats["dist-win"], map_stats[
             "sol-length"], play_stats = self._run_game(map)
         map_stats["col-potions"] = play_stats["col_potions"]
         map_stats["col-treasures"] = play_stats["col_treasures"]
         map_stats["col-enemies"] = play_stats["col_enemies"]
     return map_stats
コード例 #8
0
 def get_stats(self, map):
     map_locations = get_tile_locations(map, self.get_tile_types())
     map_stats = {
         "base_count":
         calc_certain_tile(map_locations, ["base"]),
         "resource_count":
         calc_certain_tile(map_locations, ["resource"]),
         "obstacle":
         calc_certain_tile(map_locations, ["obstacle"]),
         "base_distance":
         -500,
         "resource_distance":
         -500,
         "resource_balance":
         -500,
         "area_control":
         -500,
         "region":
         calc_num_regions(map, map_locations, ["empty", "base", "resource"])
     }
     if map_stats["base_count"] == 2:
         # general parameter
         b1_x, b1_y = map_locations["base"][0]
         b2_x, b2_y = map_locations["base"][1]
         dikjstra1, _ = run_dikjstra(b1_x, b1_y, map,
                                     ["empty", "base", "resource"])
         dikjstra2, _ = run_dikjstra(b2_x, b2_y, map,
                                     ["empty", "base", "resource"])
         # calculate distance
         map_stats["base_distance"] = int(
             self._base_distance_diff -
             abs(self._width / 2 -
                 max(map_stats["base_distance"], dikjstra1[b2_y][b2_x])))
         # calculate resource distance
         if self._min_resource <= map_stats[
                 "resource_count"] <= self._max_resource:  # and map_stats["resource_count"] <= self._max_resource:
             resources = []
             resources.extend(map_locations["resource"])
             sum1 = 0
             sum2 = 0
             dist1 = 100000
             dist2 = 100000
             for r_x, r_y in resources:
                 if dikjstra1[r_y][r_x] > 0:
                     sum1 += dikjstra1[r_y][r_x]
                     dist1 = min(dist1, dikjstra1[r_y][r_x])
                 if dikjstra2[r_y][r_x] > 0:
                     sum2 += dikjstra2[r_y][r_x]
                     dist2 = min(dist2, dikjstra2[r_y][r_x])
             map_stats["resource_distance"] = int(
                 self._resource_distance_diff - abs(dist1 - dist2))
             map_stats["resource_balance"] = int(
                 self._resource_balance_diff - abs(sum1 - sum2))
         # calculate area control
         base1 = 0
         base2 = 0
         for x in range(self._width):
             for y in range(self._height):
                 if dikjstra1[y][x] > dikjstra2[y][x]:
                     base2 += 1
                 elif dikjstra1[y][x] < dikjstra2[y][x]:
                     base1 += 1
         map_stats["area_control"] = self._area_control_diff - abs(base1 -
                                                                   base2)
     return map_stats
コード例 #9
0
    def get_stats(self, map):
        self.path = []
        map_locations = get_tile_locations(map, self.get_tile_types())
        map_stats = {
            "player":
            calc_certain_tile(map_locations, ["player"]),
            "key":
            calc_certain_tile(map_locations, ["key"]),
            "door":
            calc_certain_tile(map_locations, ["door"]),
            "enemies":
            calc_certain_tile(map_locations, ["bat", "spider", "scorpion"]),
            "regions":
            calc_num_regions(
                map,
                map_locations,
                ["empty", "player", "key", "bat", "spider", "scorpion"],
            ),
            "nearest-enemy":
            0,
            "path-length":
            0,
        }

        if map_stats["player"] == 1:  # and map_stats["regions"] == 1:
            # NOTE: super whack, just taking random player. The RL agent may learn some weird bias about this but the alternatives seem worse.
            p_x, p_y = map_locations["player"][0]
            enemies = []
            enemies.extend(map_locations["spider"])
            enemies.extend(map_locations["bat"])
            enemies.extend(map_locations["scorpion"])
            # Added this bit
            UPPER_DIST = self._width * self._height * 100

            if len(enemies) > 0:
                dikjstra, _ = run_dikjstra(
                    p_x,
                    p_y,
                    map,
                    ["empty", "player", "key", "bat", "spider", "scorpion"],
                )
                min_dist = UPPER_DIST

                for e_x, e_y in enemies:
                    if dikjstra[e_y][e_x] > 0 and dikjstra[e_y][e_x] < min_dist:
                        min_dist = dikjstra[e_y][e_x]

                if min_dist == UPPER_DIST:
                    # And this
                    min_dist = 0
                map_stats["nearest-enemy"] = min_dist

            if map_stats["key"] == 1 and map_stats["door"] == 1:
                k_x, k_y = map_locations["key"][0]
                d_x, d_y = map_locations["door"][0]
                dikjstra_k, _ = run_dikjstra(
                    p_x,
                    p_y,
                    map,
                    ["empty", "key", "player", "bat", "spider", "scorpion"],
                )
                map_stats["path-length"] += dikjstra_k[k_y][k_x]
                dikjstra_d, _ = run_dikjstra(
                    k_x,
                    k_y,
                    map,
                    [
                        "empty", "player", "key", "door", "bat", "spider",
                        "scorpion"
                    ],
                )
                map_stats["path-length"] += dikjstra_d[d_y][d_x]

                if self.render_path and map_stats["regions"] == 1:
                    self.path = np.vstack(
                        (get_path_coords(dikjstra_k,
                                         init_coords=(k_y, k_x))[1:-1],
                         get_path_coords(dikjstra_d,
                                         init_coords=(d_y, d_x))[1:-1]))
                    front_tiles = set(((k_x, k_y), (d_x, d_y), (p_x, p_y)))
                    i = 0
                    render_path = self.path.copy()
                    # slice out any tiles that need to be visualized "in front of" the path (then trim the path as needed)
                    for (x, y) in self.path:
                        if (x, y) in front_tiles:
                            continue
                        render_path[i] = [x, y]
                        i += 1
                    self.path = render_path[:i]
        self.path_length = map_stats['path-length']

        return map_stats