コード例 #1
0
            self._update_prev_rounds(state,board_card,rround,r,a)

            #Execute self bet in +Training
            bet = self.state_controller.bet()

            #Determine action type
            action_type = self._get_action_type(game, bet)

            print("  Bet:",bet,"Type:",action_type)

            #Set action (+amount) for server
            if action_type == acpc.ActionType.RAISE and game.get_betting_type() == acpc.BettingType.NO_LIMIT:
                self.set_next_action(action_type, bet + self.contrib[self.player][-1])
            else:
                self.set_next_action(action_type)

        self.player = 1 - self.player

    def on_game_finished(self, game, match_state):
        print("==========")
        print()
        
if __name__ == "__main__":
    if len(sys.argv) < 4:
        print("Usage {game_file_path} {dealer_hostname} {dealer_port}")
        sys.exit(1)

    client = acpc.Client(sys.argv[1], sys.argv[2], sys.argv[3])
    L = Libratus()
    client.play(L)
def _run_agent(args):
    client = acpc.Client(args[0], '127.0.1.1', args[1])
    client.play(StrategyAgent(args[2]))
コード例 #3
0
                strategy[line_split[0]] = [
                    float(probStr) for probStr in line_split[1:4]
                ]
        self.strategy = strategy

    def on_game_start(self, game):
        pass

    def on_next_turn(self, game, match_state, is_acting_player):
        if not is_acting_player:
            return

        info_set = _get_info_set(game, match_state)
        node_strategy = self.strategy[info_set]
        selected_action = select_action(node_strategy)
        self.set_next_action(selected_action)

    def on_game_finished(self, game, match_state):
        pass


if __name__ == "__main__":
    if len(sys.argv) < 5:
        print(
            "Usage {game_file_path} {strategy_file_path} {dealer_hostname} {dealer_port}"
        )
        sys.exit(1)

    client = acpc.Client(sys.argv[1], sys.argv[3], sys.argv[4])
    client.play(StrategyAgent(sys.argv[2]))
コード例 #4
0
    def evaluate_agent(self, test_spec):
        portfolio_name = test_spec['portfolio_name']
        portfolio_directory = '%s/%s' % (PORTFOLIOS_DIRECTORY, portfolio_name)

        game_file_path = test_spec['game_file_path']
        game = acpc.read_game_file(game_file_path)
        if game.get_num_players() != 2:
            raise AttributeError('Only games with 2 players are supported')

        response_strategy_paths = []
        opponent_names = []
        opponent_script_paths = []
        for file in os.listdir(portfolio_directory):
            if file.endswith('-response.strategy'):
                response_strategy_paths += [file]
            elif file.endswith('.sh') and not file.startswith(portfolio_name):
                opponent_names += [file[:-len('.sh')]]
                opponent_script_paths += [
                    '%s/%s' % (portfolio_directory, file)
                ]

        portfolio_size = len(response_strategy_paths)

        logs_dir = '/'.join([GAME_LOGS_DIRECTORY, portfolio_name])
        if os.path.exists(logs_dir):
            shutil.rmtree(logs_dir)
        os.makedirs(logs_dir)

        big_blind_size = get_big_blind_size(game)

        env = os.environ.copy()
        env['PATH'] = os.path.dirname(sys.executable) + ':' + env['PATH']

        print()
        for i in range(portfolio_size):
            opponent_name = opponent_names[i]
            logs_path = '%s/%s' % (logs_dir, opponent_name)

            proc = subprocess.Popen([
                START_DEALER_AND_OPPONENT_SCRIPT_PATH, game_file_path,
                logs_path, opponent_name, opponent_script_paths[i],
                portfolio_name
            ],
                                    env=env,
                                    stdout=subprocess.PIPE)
            port_number = proc.stdout.readline().decode('utf-8').strip()

            client = acpc.Client(game_file_path, '127.0.1.1', port_number)

            full_response_strategy_paths = [
                '%s/%s' % (portfolio_directory, s)
                for s in response_strategy_paths
            ]

            utility_estimator_args = test_spec[
                'utility_estimator_args'] if 'utility_estimator_args' in test_spec else None

            client.play(
                ImplicitModellingAgent(
                    game_file_path,
                    full_response_strategy_paths,
                    utility_estimator_class=test_spec[
                        'utility_estimator_class'],
                    utility_estimator_args=utility_estimator_args))

            scores_line = proc.stdout.readline().decode('utf-8').strip()
            agent_score = float(scores_line.split(':')[1].split('|')[1])
            agent_score_mbb_per_game = (agent_score /
                                        NUM_EVAL_HANDS) * big_blind_size
            print('%s vs %s: %s' %
                  (portfolio_name, opponent_name, agent_score_mbb_per_game))