def __get_adjacent_rooms_ordered_by_preference(
            character: Character, available_paths: List[Path],
            game: Game) -> List[List[Room]]:
        inhabiting_room: Room = game.get_map().get_list_of_rooms()[
            character.get_current_position()]
        efficient_move: List[Room] = []
        neutral_move: List[Room] = []
        inefficient_move: List[Room] = []

        for available_path in available_paths:
            adjacent_room: Room = available_path.get_adjacent_room(
                inhabiting_room)
            inhabitant_adjacent_room: List[
                Character] = adjacent_room.get_inhabitant()

            if adjacent_room.get_id() != game.get_map().get_dark_room().get_id(
            ):
                neutral_move.append(adjacent_room)
            elif len(inhabitant_adjacent_room) == 1:
                efficient_move.append(adjacent_room)
            elif len(inhabitant_adjacent_room) > 1:
                inefficient_move.append(adjacent_room)
            else:
                inefficient_move.append(adjacent_room)

        return [efficient_move, neutral_move, inefficient_move]
Ejemplo n.º 2
0
class Starter:
    def __init__(self, player_id):
        self.__textFileManager = TextFileManager(player_id)
        self.__parser = Parser()
        self.__game = Game()

    def initialize(self):
        pass

    def run(self, ai: AI):

        previous_line: str = None

        while self.__textFileManager.game_is_ongoing():
            print("running")

            # Get history
            history: List[MoveHistory] = self.__parser\
                .translate_history(self.__textFileManager.get_history_from_info_file())

            if len(history) > 0:

                if self.__game.get_map() is None:
                    self.__game.set_default_state(history[0])
                print("history size :", len(history))

                # Update current game state
                self.__game.update_game_state(history)

                # Get current question
                line = self.__textFileManager.get_question()

                if line == "" and line == previous_line:
                    print("Question is either empty or already treated.")
                else:
                    question = self.__parser.parse_question(line)
                    print("question :", line, "| understood :",
                          question.server_asking, question.option_available)

                    # If current question is invalid
                    if question is None:
                        print("Question couldn't be parsed.")
                    # Else, we let our IA process data and give us a response
                    else:
                        # IA process data to give us a response
                        response = ai.process(self.__game, question, history)
                        # We write the response in the 'reponses.txt'
                        self.__textFileManager.write_response(response)
                        # We make define current question as treated (to be omitted if nothing happen until next loop)
                        previous_line = line
                        print("Question processed. Given response : ",
                              response)
Ejemplo n.º 3
0
    def get_character_available_paths(character: Character,
                                      game: Game) -> List[Path]:
        inhabiting_room: Room = game.get_map().get_list_of_rooms()[
            character.get_current_position()]
        paths: List[Path] = game.get_map().get_list_of_paths()
        available_paths: List[Path] = []

        for path in paths:
            if path.get_id() != game.get_map().get_blocked_path(
            ) and path.match_room_id(inhabiting_room.get_id()):
                if not path.is_rose_special() and not path.is_secret_stairs():
                    available_paths.append(path)
        return available_paths
Ejemplo n.º 4
0
    def get_remaining_characters_in_dark_room(
            remaining_characters: List[Character],
            game: Game) -> List[Character]:
        dark_room: Room = game.get_map().get_dark_room()
        remaining_characters_color: List[
            str] = CharacterSelector.get_characters_color(remaining_characters)
        remaining_characters_in_dark_room: List[Character] = []

        for inhabitant in dark_room.get_inhabitant():
            if inhabitant.get_color() in remaining_characters_color:
                remaining_characters_in_dark_room.append(inhabitant)
        return remaining_characters_in_dark_room
Ejemplo n.º 5
0
    def get_remaining_characters_in_group(
            remaining_characters: List[Character],
            game: Game) -> List[Character]:
        characters_in_group: List[Character] = CharacterSelector.\
            get_characters_in_group(game.get_map().get_list_of_rooms())
        remaining_characters_color: List[
            str] = CharacterSelector.get_characters_color(remaining_characters)
        remaining_characters_alone: List[Character] = []

        for character_in_group in characters_in_group:
            if character_in_group.get_color() in remaining_characters_color:
                remaining_characters.append(character_in_group)
        return remaining_characters_alone
Ejemplo n.º 6
0
 def __init__(self, player_id):
     self.__textFileManager = TextFileManager(player_id)
     self.__parser = Parser()
     self.__game = Game()