Exemple #1
0
def player_vs_agent(args):
    """Sets up connector to play a player vs agent game.

    Args:
        args: Command-line arguments.

    Returns:
        Game connector.
    """
    weighted_heuristics = _get_weighted_heuristics(args)
    transposition_table = _get_transposition_table(args)
    searcher = _get_searcher(args)
    if args.player == Player.white:
        white_agent = HumanAgent(Player.white)
        black_agent = AutonomousAgent(Player.black, weighted_heuristics,
                                      transposition_table, searcher,
                                      args.max_depth)
    elif args.player == Player.black:
        white_agent = AutonomousAgent(Player.white, weighted_heuristics,
                                      transposition_table, searcher,
                                      args.max_depth)
        black_agent = HumanAgent(Player.black)
    else:
        raise NotImplementedError

    return LocalGameConnector(white_agent, black_agent, args.max_time, False)
Exemple #2
0
def playGameHumanVsComp(game, nn, cpuct, first=True):
    if first:
        a1 = ComputerAgent(game, cpuct, nn)
        a2 = HumanAgent(game)
    else:
        a1 = HumanAgent(game)
        a2 = ComputerAgent(game, cpuct, nn)

    return playGame(game, a1, a2)
Exemple #3
0
def player_vs_player(args):
    """Sets up connector to play a player vs player game.

    Args:
        args: Command-line arguments.

    Returns:
        Game connector.
    """
    white_agent = HumanAgent(Player.white)
    black_agent = HumanAgent(Player.black)
    return LocalGameConnector(white_agent, black_agent, args.max_time, False)
Exemple #4
0
def get_agent(name, properties):
    if name == "random":
        return RandomAgent(world)
    if name == "alphabeta":
        return AlphaBetaAgent(world, properties)
    if name == "human":
        return HumanAgent(world)
    if name == "dls":
        return DLS(world)
Exemple #5
0
def runner(env, settings):

    agent = HumanAgent(settings['fps'] if 'fps' in settings else 60, env)
    base_dir = get_data_base_dir(settings, env)
    data = DataGatheringWithReset(base_dir)

    p = HumanDataGatheringPlay(agent, env, data)

    p.pre_main_loop()

    while not p.done():

        p.before_env_step()
        p.env_step()
        p.post_env_step()
Exemple #6
0
def main():
    parser = argparse.ArgumentParser(description='chat utility')
    parser.add_argument('--model_file', type=str,
        help='model file')
    parser.add_argument('--domain', type=str, default='object_division',
        help='domain for the dialogue')
    parser.add_argument('--context_file', type=str, default='',
        help='context file')
    parser.add_argument('--temperature', type=float, default=1.0,
        help='temperature')
    parser.add_argument('--num_types', type=int, default=3,
        help='number of object types')
    parser.add_argument('--num_objects', type=int, default=6,
        help='total number of objects')
    parser.add_argument('--max_score', type=int, default=10,
        help='max score per object')
    parser.add_argument('--score_threshold', type=int, default=6,
        help='successful dialog should have more than score_threshold in score')
    parser.add_argument('--seed', type=int, default=1,
        help='random seed')
    parser.add_argument('--smart_ai', action='store_true', default=False,
        help='make AI smart again')
    parser.add_argument('--ai_starts', action='store_true', default=False,
        help='allow AI to start the dialog')
    parser.add_argument('--ref_text', type=str,
        help='file with the reference text')
    args = parser.parse_args()

    utils.set_seed(args.seed)

    human = HumanAgent(domain.get_domain(args.domain))

    alice_ty = LstmRolloutAgent if args.smart_ai else LstmAgent
    ai = alice_ty(utils.load_model(args.model_file), args)


    agents = [ai, human] if args.ai_starts else [human, ai]

    dialog = Dialog(agents, args)
    logger = DialogLogger(verbose=True)
    if args.context_file == '':
        ctx_gen = ManualContextGenerator(args.num_types, args.num_objects, args.max_score)
    else:
        ctx_gen = ContextGenerator(args.context_file)

    chat = Chat(dialog, ctx_gen, logger)
    chat.run()
Exemple #7
0
def play_vs_remote(args):
    """Sets up connector to play a game vs a remote agent.

    Args:
        args: Command-line arguments.

    Returns:
        Game connector.
    """
    loop = asyncio.get_event_loop()
    if args.human:
        agent = HumanAgent(args.player)
    else:
        agent = AutonomousAgent(args.player, _get_weighted_heuristics(args),
                                _get_transposition_table(args),
                                _get_searcher(args), args.max_depth)
    return RemoteGameConnector(agent, args.max_time, args.learn, args.id,
                               args.hostname, args.port, loop)
Exemple #8
0
def main(args):
    parser = ArgumentParser(description='')
    
    parser.add_argument('--height', type=int, required=True,
                        help='Heigth of the map')
    parser.add_argument('--width', type=int, required=True,
                        help='Width of the map')
    parser.add_argument('--num-powerups', type=int, required=True,
                        help='Number of powerups to put in the game map')
    parser.add_argument('--num-monsters', type=int, required=True,
                        help='Number of monsters to put in the game map')
    parser.add_argument('--initial-strength', default=100, type=int,
                        help='Initial strength of each agent')
    parser.add_argument('--save-dir', type=str,
                        help='Save directory for saving the map')
    parser.add_argument('--map-file', type=str,
                        help='Path to the map JSON file')
    parser.add_argument('--play-against-human', action='store_true',
                        help='Whether to have a Human player as one of the '
                        'agents in the game')
    parser.add_argument('--play-against-seekers',action='store_true', help='Whether to have a Seeker player as one of the '
                        'agents in the game')
    parser.add_argument('--show-map', action='store_true',
                        help='Whether to display the map in the terminal')
    parser.add_argument('--map-type', choices=MAP_TYPES, default='ascii',
                        help='Select map type. Choices are {' +
                        ', '.join(MAP_TYPES) + '}')
    parser.add_argument('--verbose', action='store_true',
                        help='Whether to be verbose when playing game')

    args = parser.parse_args(args)

    # TODO: Change how agents are populated
    agent = RandomAgent(args.height, args.width, args.initial_strength)

    agents = [agent]
    if args.play_against_human:
        human = HumanAgent(args.height, args.width, args.initial_strength)
        agents.append(human)

    game_driver = GameDriver(
        height=args.height, width=args.width,
        num_powerups=args.num_powerups,
        num_monsters=args.num_monsters,
        agents=agents,
        initial_strength=args.initial_strength,
        show_map=args.show_map, map_type=args.map_type,
        save_dir=args.save_dir, map_file=args.map_file)

    #Play against seekers
    if args.play_against_seekers:
        seeker = SeekerAgent(args.height, args.width, args.initial_strength)
        agents.append(seeker)

    game_driver = GameDriver(
        height=args.height, width=args.width,
        num_powerups=args.num_powerups,
        num_monsters=args.num_monsters,
        agents=agents, initial_strength=args.initial_strength, show_map=args.show_map, map_type=args.map_type, save_dir=args.save_dir, map_file=args.map_file)

    print('Starting game')
    game_driver.play(verbose=args.verbose)
Exemple #9
0
'''
Rock-Paper-Scissors game
Starter code for Stanford CME 193
author: Sven Schmit
'''
from game import Game
from agent import HumanAgent, InstructorAgent, MyAgent

# We can specify which agents we want to play the game here
# Optional: pass this in using the command line
game = Game(HumanAgent(), InstructorAgent())

# How many rounds do we want to play
# Optional: pass this in using the command line
number_rounds = 10
game.play(number_rounds)

# Print summary
game.summary()
Exemple #10
0
 def __init__(self):
     self.env = gym.make("CartPole-v1")
     self.human_agent = HumanAgent()
Exemple #11
0
    font = pygame.font.SysFont(TEXT_FONT, 40)
    label_font = pygame.font.SysFont(TEXT_FONT, 20)
    surface = pygame.display.set_mode((800, 600))
    pygame.display.set_caption("Visualize")
    surface.fill(WHITE)

    computer = None
    if 'ac' in sys.argv[1]:
        computer = AcAgent(Player.black, None)
    elif 'agz' in sys.argv[1]:
        computer = ZeroAgent(Player.black, None)
    else:
        computer = Agent(Player.black, ExpCollector())
    computer.model.load_weights(sys.argv[1])
    human = HumanAgent(Player.red)

    state = GameState(board, Player.red)

    while True:
        surface.fill(WHITE)
        board = state.board
        draw_chess_board(surface)
        draw_pieces(surface, font, board)
        draw_label(surface, label_font)
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
        pygame.display.update()
        if state.player == Player.red: