Exemplo n.º 1
0
    def predict(self):
        n_coin = bank_get_value("n_coin")
        n_player = bank_get_value("n_player")
        chessboard = self._chessboard.get_value()
        choice = self._choice
        history = self._game
        history_action = []
        if history._total_round > 0:
            for idx_round in range(history._total_round):
                history_action.append(
                    history.get_round(idx_round)._action.get_value())
            history_action = np.asarray(history_action)
            history_action = np.sum(history_action, axis=0)
            idx_player = np.nonzero(self._player.get_value())[0][0]

            history_action[idx_player].fill(0)

            # improved value
            for idx in range(n_player):
                if idx != idx_player:
                    curr_count = history_action[idx]
                    history_action[idx] = np.eye(n_coin)[np.argmax(curr_count)]

            history_action = np.sum(history_action, axis=0)
            estimation = np.multiply(history_action, choice)
            estimation[estimation == 0] = 3
            estimation = np.subtract(3, estimation)
            benefit = np.multiply(estimation, chessboard)
            self._target = np.eye(n_coin)[np.argmax(estimation)]

        else:
            benefit = np.multiply(choice, chessboard)
            self._target = np.eye(n_coin)[np.argmax(benefit)]
Exemplo n.º 2
0
    def run(self):
        temp_action = self._action.get_value()
        temp_chessboard = self._chessboard.get_value()

        result = np.sum(temp_action, axis=0)
        n_coin = bank_get_value("n_coin")
        n_player = bank_get_value("n_player")
        for i in range(n_coin):
            if result[i] > 1:
                temp_action[:, i] = np.zeros(n_player)
        current_coin = np.dot(temp_action, temp_chessboard)
        return A2F_Coin(current_coin)
Exemplo n.º 3
0
def show_player_ID(player_list):
    n_player = bank_get_value("n_player")
    player_ID = []
    for idx in range(n_player):
        player_ID.append(player_list[idx].__name__)

    return player_ID
Exemplo n.º 4
0
    def winner(self):
        total_game = bank_get_value("total_game")
        n_player = bank_get_value("n_player")
        if self._total_round < total_game - 1:
            raise A2F_Error("The game is not over")
        else:
            init_coin = A2F_Coin(np.zeros(n_player))
            for idx_round in range(total_game):
                curr_coin = self._process[idx_round].run()
                init_coin.set_value(init_coin.get_value() +
                                    curr_coin.get_value())

            final_coin = init_coin.get_value()
            best_player = init_coin.get_value()
            best_profit = np.max(final_coin)
            best_player[best_player < best_profit] = 0
            best_player[best_player == best_profit] = 1
            return final_coin, best_player
Exemplo n.º 5
0
 def decide(self):
     # check validity and generate the willing
     valid_table = self._valid_table
     temp_target = self._target
     temp_player = self._player.get_value()
     validity = valid_table.dot(temp_target).dot(temp_player)
     n_coin = bank_get_value("n_coin")
     if np.sum(validity) > 0:
         self._target = np.zeros(n_coin)
     return self._target
Exemplo n.º 6
0
    def predict(self):
        n_coin = bank_get_value("n_coin")
        choice = self._choice
        action_list = self.para
        chessboard = self._chessboard.get_value()

        other_action = np.sum(action_list, axis=0)
        possible_choice = np.subtract(choice, other_action)
        possible_choice[possible_choice < 0] = 0
        benefits = np.multiply(possible_choice, chessboard)
        self._target = np.eye(n_coin)[np.argmax(benefits)]
Exemplo n.º 7
0
 def __init__(self, game: A2F_Game, chessboard: A2F_Chessboard,
              player: A2F_Player, para: list):
     n_coin = bank_get_value("n_coin")
     self._game = game
     self._chessboard = chessboard
     self._player = player
     self._target = np.zeros(n_coin)
     # in valid table, 0 is possible and 1 is impossible
     valid_table = [[0, 0, 0, 1, 1], [0, 1, 0, 0, 1], [1, 0, 0, 1, 0],
                    [1, 1, 0, 0, 0]]
     self._valid_table = np.asarray(valid_table)
     temp_player = self._player.get_value()
     # 1*D vector to express possible choice
     self._choice = np.dot(temp_player, np.subtract(1, self._valid_table))
Exemplo n.º 8
0
def invite_players(player_list, game:A2F_Game, chessboard:A2F_Chessboard, para_list):
    n_player = bank_get_value("n_player")
    action_list = []
    for idx in range(n_player):
        if player_list[idx].__name__ != "A2FP_Cheat":
            curr_player = player_list[idx](game=game,
                                           chessboard=chessboard,
                                           player=A2F_Player(np.eye(n_player)[idx]),
                                           para=para_list[idx])
            curr_player.predict()
            action_list.append(curr_player.decide())
        else:
            curr_player = player_list[idx](game=game,
                                           chessboard=chessboard,
                                           player=A2F_Player(np.eye(n_player)[idx]),
                                           para=action_list)
            curr_player.predict()
            action_list.append(curr_player.decide())
    return A2F_Action(action_list)
Exemplo n.º 9
0
 def predict(self):
     n_coin = bank_get_value("n_coin")
     choice = self._choice
     possible_target = np.where(choice == 1)[0]
     random_choice = np.random.choice(possible_target, p=self.para)
     self._target = np.eye(n_coin)[random_choice]
Exemplo n.º 10
0
 def predict(self):
     choice = self._choice
     n_coin = bank_get_value("n_coin")
     random_choice = np.random.choice(np.nonzero(choice)[0])
     self._target = np.eye(n_coin)[random_choice]
Exemplo n.º 11
0
 def predict(self):
     n_coin = bank_get_value("n_coin")
     self._target = np.zeros(n_coin)
Exemplo n.º 12
0
 def predict(self):
     choice = self._choice
     chessboard = self._chessboard.get_value()
     benefit = np.multiply(choice, chessboard)
     n_coin = bank_get_value("n_coin")
     self._target = np.eye(n_coin)[np.argmax(benefit)]