def _init_bot(bot_type, game, player_id): """Initializes a bot by type.""" rng = np.random.RandomState(FLAGS.seed) if bot_type == "mcts": evaluator = mcts.RandomRolloutEvaluator(FLAGS.rollout_count, rng) return mcts.MCTSBot( game, FLAGS.uct_c, FLAGS.max_simulations, evaluator, random_state=rng, solve=FLAGS.solve, verbose=FLAGS.verbose) if bot_type == "az": model = az_model.Model.from_checkpoint(FLAGS.az_path) evaluator = az_evaluator.AlphaZeroEvaluator(game, model) return mcts.MCTSBot( game, FLAGS.uct_c, FLAGS.max_simulations, evaluator, random_state=rng, child_selection_fn=mcts.SearchNode.puct_value, solve=FLAGS.solve, verbose=FLAGS.verbose) if bot_type == "random": return uniform_random.UniformRandomBot(player_id, rng) if bot_type == "human": return human.HumanBot() if bot_type == "gtp": bot = gtp.GTPBot(game, FLAGS.gtp_path) for cmd in FLAGS.gtp_cmd: bot.gtp_cmd(cmd) return bot raise ValueError("Invalid bot type: %s" % bot_type)
def _init_bot(bot_type, game, player_id): """Initializes a bot by type.""" if bot_type == "mcts": evaluator = mcts.RandomRolloutEvaluator(FLAGS.rollout_count) return mcts.MCTSBot(game, player_id, FLAGS.uct_c, FLAGS.max_search_nodes, evaluator) if bot_type == "random": return uniform_random.UniformRandomBot(game, player_id, np.random) if bot_type == "human": return human.HumanBot(game, player_id) raise ValueError("Invalid bot type: %s" % bot_type)
def LoadAgent(agent_type, game, player_id, rng): """Return a bot based on the agent type.""" if agent_type == "random": return uniform_random.UniformRandomBot(player_id, rng) elif agent_type == "human": return human.HumanBot() elif agent_type == "check_call": policy = pyspiel.PreferredActionPolicy([1, 0]) return pyspiel.make_policy_bot(game, player_id, FLAGS.seed, policy) elif agent_type == "fold": policy = pyspiel.PreferredActionPolicy([0, 1]) return pyspiel.make_policy_bot(game, player_id, FLAGS.seed, policy) else: raise RuntimeError("Unrecognized agent type: {}".format(agent_type))
def main(unused_argv): game = pyspiel.load_game(FLAGS.game) state = game.new_initial_state() print("Initial state: ") print(str(state)) # Create human bot human_bot = human.HumanBot(game, FLAGS.human_player) # Create random bot random_bot = uniform_random.UniformRandomBot(game, 1 - FLAGS.human_player, np.random) if FLAGS.human_player == 0: bots = [human_bot, random_bot] else: bots = [random_bot, human_bot] while not state.is_terminal(): # The state can be three different types: chance node, # simultaneous node, or decision node if state.is_chance_node(): # Chance node: sample an outcome outcomes = state.chance_outcomes() num_actions = len(outcomes) print("Chance node, got " + str(num_actions) + " outcomes") action_list, prob_list = zip(*outcomes) action = np.random.choice(action_list, p=prob_list) print("Sampled outcome: ", state.action_to_string(state.current_player(), action)) state.apply_action(action) elif state.is_simultaneous_node(): raise ValueError("Game cannot have simultaneous nodes.") else: # Decision node: sample action for the single current player _, action = bots[state.current_player()].step(state) print("Player ", state.current_player(), ", chose action: ", state.action_to_string(state.current_player(), action)) state.apply_action(action) print(str(state)) # Game is now done. Print return for each player returns = state.returns() for pid in range(game.num_players()): print("Return for player {} is {}".format(pid, returns[pid]))
def _init_bot(bot_type, game, player_id): """Initializes a bot by type.""" rng = np.random.RandomState(FLAGS.seed) if bot_type == "mcts": evaluator = mcts.RandomRolloutEvaluator(FLAGS.rollout_count, rng) return mcts.MCTSBot( game, FLAGS.uct_c, FLAGS.max_simulations, evaluator, random_state=rng, solve=FLAGS.solve, verbose=FLAGS.verbose) if bot_type == "random": return uniform_random.UniformRandomBot(player_id, rng) if bot_type == "human": return human.HumanBot() raise ValueError("Invalid bot type: %s" % bot_type)