def head_to_portal_decision(api, my_player, logger):
    my_position = my_player.get_position()
    nearest_portal_pos = api.find_closest_portal(my_player.get_position())
    if nearest_portal_pos.x == my_position.x and nearest_portal_pos.y == my_position.y:
        return CharacterDecision(decision_type="TRAVEL",
                                 action_position=None,
                                 action_index=0)
    else:
        return CharacterDecision(decision_type="MOVE",
                                 action_position=helpers.find_position_to_move(
                                     api, my_player, nearest_portal_pos),
                                 action_index=None)
Esempio n. 2
0
    def make_decision(self, player_name: str,
                      game_state: GameState) -> CharacterDecision:
        """
        Parameters:
        player_name (string): The name of your player
        game_state (GameState): The current game state
        """
        self.api = API(game_state, player_name)
        self.my_player = game_state.get_all_players()[player_name]
        self.board = game_state.get_pvp_board()
        self.curr_pos = self.my_player.get_position()

        self.logger.info("In make_decision")

        last_action, type = self.memory.get_value("last_action", str)
        if last_action is not None and last_action == "PICKUP":
            self.memory.set_value("last_action", "EQUIP")
            return CharacterDecision(
                decision_type="EQUIP",
                action_position=None,
                action_index=self.my_player.get_free_inventory_index())

        tile_items = self.board.get_tile_at(self.curr_pos).items
        if tile_items is not None or len(tile_items) > 0:
            self.memory.set_value("last_action", "PICKUP")
            return CharacterDecision(decision_type="PICKUP",
                                     action_position=None,
                                     action_index=0)

        weapon = self.my_player.get_weapon()
        enemies = self.api.find_enemies(self.curr_pos)
        if enemies is None or len(enemies) > 0:
            self.memory.set_value("last_action", "MOVE")
            return CharacterDecision(
                decision_type="MOVE",
                action_position=self.my_player.get_spawn_point(),
                action_index=None)

        enemy_pos = enemies[0].get_position()
        if self.curr_pos.manhattan_distance(enemy_pos) <= weapon.get_range():
            self.memory.set_value("last_action", "ATTACK")
            return CharacterDecision(decision_type="ATTACK",
                                     action_position=enemy_pos,
                                     action_index=None)

        self.memory.set_value("last_action", "MOVE")
        decision = CharacterDecision(decision_type="MOVE",
                                     action_position=find_position_to_move(
                                         self.my_player, enemy_pos),
                                     action_index=None)
        return decision
def loot_items(api, my_player, logger, board, item_tiles):
    #### grab one based on closeness ####
    current_tile_items = board.get_tile_at(my_player.get_position()).items
    if current_tile_items is not None and len(current_tile_items) > 0:
        return CharacterDecision(decision_type="PICKUP",
                                 action_position=None,
                                 action_index=0)

    item_tiles.sort(key=lambda x: Position(x[1], x[2],
                                           my_player.get_position().board_id).
                    manhattan_distance(my_player.get_position()))
    return CharacterDecision(decision_type="MOVE",
                             action_position=item_tiles[0],
                             action_index=0)
def pickup(player, item, board):
    current_position = player.get_position()
    x = current_position.x
    y = current_position.y
    tile = board.grid[x][y]
    items = tile.items
    return CharacterDecision(decision_type="PICKUP",
                             action_position=None,
                             action_index=items.index(item))
def make_our_combat_decision(api, my_player, logger, monsters,
                             searching_graph):
    curr_pos = my_player.get_position()
    target_enemy = find_ideal_monster(api, my_player, monsters)
    enemy_pos = target_enemy.get_position()

    if curr_pos.manhattan_distance(
            enemy_pos) <= my_player.get_weapon().get_range():
        return CharacterDecision(decision_type="ATTACK",
                                 action_position=enemy_pos,
                                 action_index=None), target_enemy
    else:
        pos = Position(my_player.get_position())
        pos.y = my_player.get_position().y + my_player.get_speed()
        return CharacterDecision(decision_type="MOVE",
                                 action_position=helpers.find_position_to_move(
                                     api, my_player, enemy_pos, logger,
                                     searching_graph),
                                 action_index=None), target_enemy
Esempio n. 6
0
def move(pos: Position):
    return CharacterDecision(decision_type="MOVE",
                             action_position=pos,
                             action_index=0)
Esempio n. 7
0
def drop_item(ind=0):
    return CharacterDecision(decision_type="DROP",
                             action_position=None,
                             action_index=ind)
Esempio n. 8
0
def equip_item(ind=0):
    return CharacterDecision(decision_type="EQUIP",
                             action_position=None,
                             action_index=ind)
Esempio n. 9
0
def pick_up_item(item_index=0):
    return CharacterDecision(decision_type="PICKUP",
                             action_position=None,
                             action_index=item_index)
Esempio n. 10
0
def attack_monster(monster: Monster, item_index=0):
    return CharacterDecision(decision_type="ATTACK",
                             action_position=monster.position,
                             action_index=item_index)
def head_to(given_position):
    return CharacterDecision(decision_type="MOVE",
                             action_position=given_position,
                             action_index=None)
def equip_given_item(inventory_index):
    return CharacterDecision(decision_type="EQUIP",
                             action_position=None,
                             action_index=inventory_index)
Esempio n. 13
0
    def make_decision(self, player_name: str,
                      game_state: GameState) -> CharacterDecision:
        """
        Parameters:
        player_name (string): The name of your player
        game_state (GameState): The current game state
        """
        self.api = API(game_state, player_name)
        self.my_player = game_state.get_all_players()[player_name]
        self.board = game_state.get_pvp_board()
        self.curr_pos = self.my_player.get_position()

        self.logger.info("In make_decision")

        self.logger.info(
            f"Currently at position: ({self.curr_pos.x},{self.curr_pos.y}) on board '{self.curr_pos.board_id}'"
        )

        last_action, type = self.memory.get_value("last_action", str)
        self.logger.info(f"last_action: '{last_action}'")

        if last_action is not None and last_action == "PICKUP":
            self.logger.info(
                "Last action was picking up, equipping picked up object")
            self.memory.set_value("last_action", "EQUIP")
            return CharacterDecision(
                decision_type="EQUIP",
                action_position=None,
                action_index=0  # self.my_player.get_free_inventory_index()
            )

        tile_items = self.board.get_tile_at(self.curr_pos).get_items()
        if tile_items is not None and len(tile_items) > 0:
            self.logger.info("There are items on my tile, picking up item")
            self.memory.set_value("last_action", "PICKUP")
            return CharacterDecision(decision_type="PICKUP",
                                     action_position=None,
                                     action_index=0)

        weapon = self.my_player.get_weapon()
        enemies = self.api.find_enemies_by_distance(self.curr_pos)
        if enemies is None or len(enemies) == 0:
            self.logger.info(
                "There is no enemies in range, moving to spawn point")
            self.memory.set_value("last_action", "MOVE")
            return CharacterDecision(
                decision_type="MOVE",
                action_position=self.my_player.get_spawn_point(),
                action_index=None)

        enemy_pos = enemies[0].get_position()
        if self.curr_pos.manhattan_distance(enemy_pos) <= weapon.get_range():
            self.logger.info(
                "There is an enemy within weapon range, attacking")
            self.memory.set_value("last_action", "ATTACK")
            return CharacterDecision(decision_type="ATTACK",
                                     action_position=enemy_pos,
                                     action_index=None)

        self.memory.set_value("last_action", "MOVE")
        self.logger.info("Moving towards the nearest enemy")
        decision = CharacterDecision(
            decision_type="MOVE",
            action_position=self.find_position_to_move(self.my_player,
                                                       enemy_pos),
            action_index=None)
        return decision
Esempio n. 14
0
    def make_decision(self, player_name: str,
                      game_state: GameState) -> CharacterDecision:
        """
        Parameters:
        player_name (string): The name of your player
        game_state (GameState): The current game state
        """
        self.logger.info(
            "==========================NEW TURN==========================")
        self.api = API(game_state, player_name)
        self.character = game_state.get_character(player_name)
        self.my_player = game_state.get_all_players()[player_name]
        #self.pvpboard = game_state.get_pvp_board()
        self.board = game_state.get_board(self.board_id)
        self.curr_pos = self.my_player.get_position()
        self.monsters = game_state.get_monsters_on_board(self.board_id)

        self.obstacles = self.get_obstacles(game_state)
        self.bad_monster_squares = self.get_monsters(game_state, self.board_id)
        # cycle through items
        items = self.my_player.get_inventory()
        self.logger.info("items: {}".format(items))
        cur_weapon = self.my_player.get_weapon
        self.logger.info('performing inventory check')
        try:
            if self.character.clothes is not None:
                self.print_stats(self.character.clothes)
        except:
            self.logger.info("no clothes to print")
            pass
        try:
            if self.character.hat is not None:
                self.print_stats(self.character.hat)
        except:
            self.logger.info("no hat to print")
            pass
        try:
            if self.character.weapon is not None:
                self.print_stats(self.character.weapon)
        except:
            self.logger.info("no weapon to print")
            pass
        try:
            if self.character.shoes is not None:
                self.print_stats(self.character.shoes)
        except:
            self.logger.info("no shoes to print")
            pass
        try:
            if self.character.accessory is not None:
                self.print_stats(self.character.accessory)
        except:
            self.logger.info("no accessory to print")
            pass
        for i, item in reversed(list(enumerate(items))):
            # self.logger.info('exp change: {}, {}'.format(item.get_flat_experience_change(), item.get_percent_experience_change()))
            # self.logger.info('atk change: {}, {}'.format(item.get_flat_attack_change(), item.get_percent_attack_change()))
            # if item.get_flat_attack_change() > cur_weapon.get_flat_attack_change():
            #     self.logger.info('equiping item')
            #     return CharacterDecision(
            #         decision_type="EQUIP",
            #         action_position=None,
            #         action_index=i
            #     )
            try:
                self.logger.info("grading index {} in the inventory".format(i))
                # self.logger.info(type(item))

                item_type = item.__class__.__name__
                # self.logger.info(item_type)

                if "Consumable" in item_type:
                    #idk do we equip the consumable before we fite the guy
                    #but also if its a health potion do it now
                    self.logger.info(
                        'index {} is a consumable, eating!'.format(i))
                    #actually drop consumables f**k em (no wee eat them right there)
                    return CharacterDecision(decision_type="EQUIP",
                                             action_position=None,
                                             action_index=i)
                    # continue
                self.logger.info(self.print_stats(item))
                stat_mod = item.get_stats()
                new_stats = 0
                try:
                    new_stats += stat_mod.get_flat_speed_change() * 0
                except:
                    new_stats += 0
                try:
                    new_stats += stat_mod.get_percent_speed_change() * 0
                except:
                    new_stats += 0
                try:
                    new_stats += stat_mod.get_flat_health_change() * .1
                except:
                    new_stats += 0
                try:
                    new_stats += stat_mod.get_percent_health_change() * 30
                except:
                    new_stats += 0
                try:
                    new_stats += stat_mod.get_flat_experience_change() * 10
                except:
                    new_stats += 0
                try:
                    new_stats += stat_mod.get_percent_experience_change() * 200
                except:
                    new_stats += 0
                try:
                    new_stats += stat_mod.get_flat_attack_change() * 10
                except:
                    new_stats += 0
                try:
                    new_stats += stat_mod.get_percent_attack_change() * 70
                except:
                    new_stats += 0
                try:
                    new_stats += stat_mod.get_flat_defense_change() * 2
                except:
                    new_stats += 0
                try:
                    new_stats += stat_mod.get_percent_defense_change() * 30
                except:
                    new_stats += 0
                try:
                    new_stats += stat_mod.get_flat_regen_per_turn() * 0
                except:
                    new_stats += 0
                self.logger.info("got stats for index {}".format(i))
                # new_stats = stat_mods.get_flat_speed_change() + stat_mods.get_percent_speed_change() + stat_mods.get_flat_health_change() + stat_mods.get_percent_health_change() + stat_mods.get_flat_defense_change() + stat_mods.get_flat_attack_change() + stat_mods.get_percent_attack_change()
                self.logger.info("stat check for index {} is {}".format(
                    i, new_stats))
                for typ in ["Clothes", "Hat", "Shoes", "Weapon", "Accessory"]:

                    if typ in item_type:
                        self.logger.info('index {} is a {}'.format(i, typ))
                        current_stats = self.stats[typ]
                        self.logger.info(
                            'old stats: {} , new stats: {}'.format(
                                current_stats, new_stats))
                        if new_stats > current_stats:
                            self.logger.info("equipping")
                            self.stats[typ] = new_stats
                            return CharacterDecision(decision_type="EQUIP",
                                                     action_position=None,
                                                     action_index=i)
                        else:
                            self.logger.info(
                                "this {} sucks, dropping it".format(typ))
                            return CharacterDecision(decision_type="DROP",
                                                     action_position=None,
                                                     action_index=i)
            except Exception as e:

                self.logger.error(e)
                return CharacterDecision(decision_type="DROP",
                                         action_position=None,
                                         action_index=0)

        # item pick up
        tile_items = self.board.get_tile_at(self.curr_pos).items
        if len(tile_items) > 0:
            self.memory.set_value("last_action", "PICKUP")
            self.logger.info("picking up item: {}".format(tile_items))
            try:
                for i in range(len(tile_items)):
                    self.logger.info("grading new item index {}".format(i))
                    if "Consumable" in tile_items[i].__class__.__name__:
                        return CharacterDecision(decision_type="PICKUP",
                                                 action_position=self.curr_pos,
                                                 action_index=i)
                    stat_mods = tile_items[i].get_stats()
                    stat_sum = stat_mods.get_flat_speed_change(
                    ) * 0 + stat_mods.get_percent_speed_change(
                    ) * 0 + stat_mods.get_flat_health_change(
                    ) * .1 + stat_mods.get_percent_health_change(
                    ) * 30 + stat_mods.get_flat_defense_change(
                    ) * 2 + stat_mods.get_flat_attack_change(
                    ) * 10 + stat_mods.get_percent_attack_change(
                    ) * 70 + stat_mods.get_percent_defense_change(
                    ) * 30 + stat_mods.get_flat_regen_per_turn(
                    ) * 0 + stat_mods.get_flat_experience_change(
                    ) * 10 + stat_mods.get_percent_experience_change() * 200
                    self.logger.info("new item stat: " + str(stat_sum))
                    self.logger.info(
                        "curr stat item: " +
                        str(self.stats[tile_items[i].__class__.__name__]))
                    if stat_sum > self.stats[tile_items[i].__class__.__name__]:
                        self.logger.info(
                            "picking up item at index {}".format(i))
                        return CharacterDecision(decision_type="PICKUP",
                                                 action_position=self.curr_pos,
                                                 action_index=i)
                    else:
                        self.logger.info(
                            "skipping index {}, shitty item".format(i))
            except Exception as e:
                self.logger.error(e)
                self.logger.info("picking up item at index 0")
                return CharacterDecision(decision_type="PICKUP",
                                         action_position=self.curr_pos,
                                         action_index=i)
        for d in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
            target_pos = Position.create(self.curr_pos.x + d[0],
                                         self.curr_pos.y + d[1],
                                         self.curr_pos.get_board_id())
            tile_items = self.board.get_tile_at(target_pos).items
            if len(tile_items) > 0:
                for i in range(len(tile_items)):
                    self.logger.info("grading new item index {}".format(i))
                    if "Consumable" in tile_items[i].__class__.__name__:
                        self.memory.set_value("last_action", "MOVE")
                        self.logger.info("moving to item")
                        return CharacterDecision(decision_type="MOVE",
                                                 action_position=target_pos,
                                                 action_index=0)
                    stat_mods = tile_items[i].get_stats()
                    stat_sum = stat_mods.get_flat_speed_change(
                    ) * 0 + stat_mods.get_percent_speed_change(
                    ) * 0 + stat_mods.get_flat_health_change(
                    ) * .1 + stat_mods.get_percent_health_change(
                    ) * 30 + stat_mods.get_flat_defense_change(
                    ) * 2 + stat_mods.get_flat_attack_change(
                    ) * 10 + stat_mods.get_percent_attack_change(
                    ) * 70 + stat_mods.get_percent_defense_change(
                    ) * 30 + stat_mods.get_flat_regen_per_turn(
                    ) * 0 + stat_mods.get_flat_experience_change(
                    ) * 10 + stat_mods.get_percent_experience_change() * 200
                    self.logger.info("new item stat: " + str(stat_sum))
                    self.logger.info(
                        "curr stat item: " +
                        str(self.stats[tile_items[i].__class__.__name__]))
                    if stat_sum > self.stats[tile_items[i].__class__.__name__]:
                        self.memory.set_value("last_action", "MOVE")
                        self.logger.info("moving to item")
                        return CharacterDecision(decision_type="MOVE",
                                                 action_position=target_pos,
                                                 action_index=0)
                    else:
                        self.logger.info(
                            "skipping index {}, shitty item".format(i))

        ## Choose weakest monster
        weakestMonster = self.findWeakest(self.monsters, self.curr_pos)
        weapon = self.my_player.get_weapon()
        ## Check if weakest monster is in attack range
        if self.curr_pos.manhattan_distance(
                weakestMonster.position) <= weapon.get_range():
            self.logger.info("Attacking monster: " +
                             str(weakestMonster.get_name()) + " with health " +
                             str(weakestMonster.get_current_health()) + "/" +
                             str(weakestMonster.get_max_health()))
            return CharacterDecision(
                decision_type="ATTACK",
                action_position=weakestMonster.get_position(),
                action_index=0)
        ## Move to weakest monster!
        self.logger.info("Chosen weakest monster: " +
                         str(weakestMonster.get_name()) + " || location: (" +
                         str(weakestMonster.get_position().x) + "," +
                         str(weakestMonster.get_position().y) + ")")

        positionToMove = self.zhou_astar_path_to_move(
            self.my_player, weakestMonster.get_position())
        # hard code walk back
        if positionToMove[0] >= 6:
            positionToMove[0] = 4
        positionObjectToMove = self.curr_pos
        newPos = positionObjectToMove.create(positionToMove[0],
                                             positionToMove[1], self.board_id)
        self.logger.info("Location to move now: (" + str(newPos.x) + ", " +
                         str(newPos.y) + ")")
        return CharacterDecision(decision_type="MOVE",
                                 action_position=newPos,
                                 action_index=0)