Exemplo n.º 1
0
 def _ReadOverworldData(self) -> None:
     self.overworld_caves = []
     for cave_type in Range.VALID_CAVE_TYPES:
         cave_num = cave_type - 0x10
         if cave_type == CaveType.ARMOS_ITEM_VIRTUAL_CAVE:
             self.overworld_caves.append(
                 Cave([0x3F, Item.POWER_BRACELET, 0x7F, 0x00, 0x00, 0x00]))
         elif cave_type == CaveType.COAST_ITEM_VIRTUAL_CAVE:
             self.overworld_caves.append(
                 Cave([0x3F, Item.HEART_CONTAINER, 0x7F, 0x00, 0x00, 0x00]))
         else:
             assert cave_type in Range.VALID_CAVE_TYPES  # Not needed?
             cave_data: List[int] = []
             for position_num in range(0, 3):
                 cave_data.append(self.overworld_raw_data[
                     self._GetOverworldCaveDataIndex(cave_type,
                                                     position_num,
                                                     is_second_byte=False)])
             for position_num in range(0, 3):
                 cave_data.append(self.overworld_raw_data[
                     self._GetOverworldCaveDataIndex(cave_type,
                                                     position_num,
                                                     is_second_byte=True)])
             self.overworld_caves.append(Cave(cave_data))
     assert len(
         self.overworld_caves
     ) == 22  # 0-19 are actual caves, 20-21 are for the armos/coast
Exemplo n.º 2
0
def run():
    data = load_data("Day15.txt")
    cave = Cave(data, 3)
    cave.show()
    outcome, elf_deaths = cave.run()
    print(f"The outcome is {outcome}")
    # part 2
    elf_ap = 4
    elf_deaths = 1
    while elf_deaths:
        cave = Cave(data, elf_ap)
        outcome, elf_deaths = cave.run()
        print(f"The elf ap of {elf_ap} leaves {elf_deaths} elves dead")
        elf_ap += 1
    print(f"The outcome is {outcome}")
Exemplo n.º 3
0
    def create_caves(self):
        """
        Create all the caves for the game.
        """
        random.shuffle(CAVE_NAMES)
        caves = [Cave(name) for name in CAVE_NAMES]
        for connections in CAVE_CONNECTIONS:
            start = connections[0]
            for destination in connections[1:]:
                caves[start].add_connection(caves[destination])

        self.caves = caves
        self.current_cave = caves[0]
Exemplo n.º 4
0
 def updateWorld(self, caveRow, caveCol, isGold, isHole, isWind, isBones,
                 allowDirects, monstersCount, arrowsCount, legsCount):
     self.__isKilledMonster = (monstersCount < self.__monstersCount)
     self.__monstersCount = monstersCount
     caveId = self.getCaveIdFromPos(caveRow, caveCol)
     cave = self.__cavesDict.get(caveId)
     # добавить пещеру в словарь если её там нет
     if (cave == None):
         cave = Cave(self, caveRow, caveCol, isGold, isHole, isWind,
                     isBones, allowDirects)
         self.__cavesDict[caveId] = cave
     # установить пещеру как текущую
     self.__currCave = cave
     # обновить стоимость всех известных пещер
     for caveId in self.__cavesDict.keys():
         self.__cavesDict[caveId].updateCost(monstersCount, arrowsCount,
                                             legsCount)
     # print('World was updated') # !!! TEST !!!
     return
Exemplo n.º 5
0
    def find_wanted_passages_and_cave(self):

        if len(self.current_plan) < 2:
            return [], []

        wanted_passages = []
        wanted_cave = []
        index = 1

        next_action = self.current_plan[0]
        if self.will_move_block_passage_entrance(next_action):

            row, col = next_action.required_free

            explored_entrances = [(row, col)]
            passages_to_explore = [(p, (row, col))
                                   for p in LEVEL.map_of_passages[row][col]]

            while len(passages_to_explore) > 0:

                passage, enter = passages_to_explore.pop()

                next_on_path, new_index = self.is_passage_next_on_path(
                    passage, index)

                #Do I want to enter one of them? -> add to list
                if next_on_path:
                    wanted_passages.append((passage, enter))
                    if new_index is not None:
                        index = new_index + 1
                        entrance = self.current_plan[new_index].required_free

                        if entrance not in explored_entrances:
                            new_passages = [(p, entrance)
                                            for p in LEVEL.map_of_passages[
                                                entrance[0]][entrance[1]]
                                            if p != passage]
                            explored_entrances.append(entrance)
                            passages_to_explore = passages_to_explore + new_passages

        if len(wanted_passages) > 0:
            last_passage, enter = wanted_passages[-1]
            for entrance in last_passage.entrances:
                if entrance == enter:
                    continue
                exit_location = entrance
        else:
            exit_location = next_action.required_free
        caves_to_explore = LEVEL.map_of_caves[exit_location[0]][
            exit_location[1]]
        if caves_to_explore is not None:
            for cave in caves_to_explore:
                if self.is_cave_next_on_path(cave, index)[0]:
                    #log("Agent {} thinks cave {} is the next on the path. index: {}, action self.current_plan[index]: {}".format(self.id_, cave, index, self.current_plan[index]), "TEST", False)
                    wanted_cave.append((cave, exit_location))

        if len(wanted_cave) == 0 and len(wanted_passages) > 0:
            #check if the wanted goal is in the last passage
            last_passage, entrance = wanted_passages[-1]
            location = None

            #get goal location
            if isinstance(self.intentions, Contract):
                if isinstance(self.intentions.performative,
                              CfpMoveSpecificBoxTo):
                    box = self.intentions.performative.box
                    location = self.intentions.performative.location
                else:
                    raise NotImplementedError("Unrecognized performative")
            elif isinstance(self.intentions, AgentGoal):
                location = (self.intentions.row, self.intentions.col)
            elif self.intentions is not None and not isinstance(
                    self.intentions, Request):
                box, goal = self.intentions
                location = (goal.row, goal.col)

            #Check if goal in passage
            if location is not None and location in last_passage.locations:
                #create artificial cave
                artificial_cave = Cave(None, location)
                artificial_cave.entrance = entrance
                end = entrance
                for pos in last_passage.locations:
                    if pos == location:
                        break
                    if is_adjacent(pos, end):
                        end = pos
                        artificial_cave.locations.insert(1, end)
                        if pos in LEVEL.goals_by_pos:
                            artificial_cave.goals.append(
                                LEVEL.goals_by_pos[pos])
                artificial_cave.update_status(self.beliefs)
                wanted_cave = [(artificial_cave, entrance)]
                wanted_passages = wanted_passages[:-1]

        return wanted_passages, wanted_cave
Exemplo n.º 6
0

if __name__ == "__main__":
    # args
    parser = argparse.ArgumentParser()
    parser.add_argument("-m", "--model_path")
    parser.add_argument("-s", "--save", dest="save", action="store_true")
    parser.set_defaults(save=False)
    args = parser.parse_args()
    print('----------------------')
    print('space: moving up')
    print('q:     exit')
    print('----------------------')

    # environmet, agent
    env = Cave(time_limit=False)

    # variables
    past_time = 0
    state_t_1, reward_t, terminal = env.observe()
    action_t = 0

    # animate
    fig = plt.figure(figsize=(env.screen_n_rows / 10, env.screen_n_cols / 10))
    fig.canvas.set_window_title("{}".format(env.name))
    cid = fig.canvas.mpl_connect('key_press_event', onkey)
    cid = fig.canvas.mpl_connect('key_release_event', offkey)
    img = plt.imshow(state_t_1, interpolation="none", cmap="gray")
    ani = animation.FuncAnimation(fig,
                                  animate,
                                  init_func=init,
Exemplo n.º 7
0
# Main Menu Aspects
menu_bg = Background(0, 0, screen_height, screen_width,
                     'resources/menu/menu_bg.png')
start_button = Button(330, 270, 60, 240, 'start_button', 'resources/menu/')
exit_button = Button(330, 360, 60, 240, 'exit_button', 'resources/menu/')


def draw_menu():
    window.blit(menu_bg.image, (menu_bg.x, menu_bg.y))
    window.blit(start_button.image, (start_button.x, start_button.y))
    window.blit(exit_button.image, (exit_button.x, exit_button.y))
    pygame.display.update()


# Generate inital cave
cave = Cave(screen_height // 15, screen_width // 15)
bg = Background(0, 0, screen_height, screen_width)

# Character Creation
# Class definition in entity.py
entities = []
user = Player(450, 350, 13, 30, 100, 5, 3)
entities += [user]


# Main Draw function
def redraw():
    cells_to_redraw = []
    for entity in entities:
        cells_to_redraw += entity.get_cells(cave)
    for cell in cells_to_redraw:
Exemplo n.º 8
0
 def __init__(self):
     self._game_cave = Cave()