Example #1
0
    def __possible_turns(self, player_name: int,
                         board: Board) -> List[Tuple[int, int]]:
        """
        Returns possible turns with higher hold probability than a trashold.
        (The single turn expectiminimax.)

        :param player_name: A name (ID) of the associated player.
        :param board: The game board.
        :return: Possible turns with higher hold probability than a trashold.
                 (A list of tuples (atacker area; defender area) sorted by
                 a weight in descending order.)
        """
        if board.nb_players_alive() > self.__ATK_PLAYERS_LIMIT_2:
            atk_prob_treshold = self.__ATK_PROB_TRESHOLD_2
            atk_from_larges_reg_weight = self.__ATK_FROM_LARGEST_REG_WEIGHT_2
        else:
            atk_prob_treshold = self.__ATK_PROB_TRESHOLD
            atk_from_larges_reg_weight = self.__ATK_FROM_LARGEST_REG_WEIGHT

        turns = []
        largest_region = self.__largest_region(player_name, board)

        for a, b in possible_attacks(board, player_name):
            a_name = a.get_name()
            b_name = b.get_name()
            atk_power = a.get_dice()

            p = probability_of_successful_attack(board, a_name, b_name)
            p *= probability_of_holding_area(board, b_name, atk_power - 1,
                                             player_name)
            if p >= atk_prob_treshold or atk_power == self.__MAX_DICE:
                if a_name in largest_region:
                    p *= atk_from_larges_reg_weight
                turns.append((a_name, b_name, p))

        turns = sorted(turns, key=lambda t: t[2], reverse=True)
        turns = list(map(lambda t: t[:2], turns))

        return turns
Example #2
0
    def __init__(self, player_name: int, board: Board,
                 players_order: List[int]) -> None:
        """
        Constructs the AI agent for the Dice Wars game.

        :param player_name: A name (ID) of the associated player.
        :param board: A copy of the game board.
        :param players_order: An order in which the players take turn. (A list
               of players IDs.)
        """
        super().__init__()

        self.__player_name = player_name
        self.__board = board
        self.__players_order = players_order
        self.__loger = getLogger(self.__LOGGER_NAME)

        self.__model = self.__load_model()

        nb_players = board.nb_players_alive()
        self.__loger.debug(
            f'An AI agent for the {nb_players}-player game is set up.'
            f' player_name: {player_name}; players_order: {players_order}')