예제 #1
0
def main():
    board_size = 3
    game = GameState.new_game(board_size)
    bots = {
        Player.black: MCTSAgent(362000, 1., 128),
        Player.white: MCTSAgent(362000, 1., 128),

        #    Player.black : MinimaxAgent(5, None),
        #    Player.white : MinimaxAgent(5, None),
    }
    while not game.is_over():
        time.sleep(0.1)

        print_board(game.board)
        bot_move = bots[game.nplayer].select_move(game)
        print_move(game.nplayer, bot_move)
        game = game.apply_move(bot_move)
    print_board(game.board)
    winner = game.winner()
    if winner is None:
        print("Tie")
    elif winner == Player.black:
        print("Black won")
    else:
        print("White won")
예제 #2
0
def main():
    args = parse_args()
    agent = load_agent(args)
    board_size = args.board_size
    game = GameState.new_game(board_size)
    if args.playas == 'black':
        human_play = Player.black
    elif args.playas == 'white':
        human_play = Player.white
    else:
        raise ValueError('Unknown option for playas: {}'.format(args.playas))
    while not game.is_over():
        print_board(game.board)
        if game.nplayer == human_play:
            human_move = input('-- ')
            if len(human_move) > 1:
                point = point_from_coord(human_move.strip())
                move = Move.play(point)
            else:
                move = Move.pass_turn()
        else:
            move = agent.select_move(game)
        print_move(game.nplayer, move)
        game = game.apply_move(move)
    winner = game.winner()
    if winner is None:
        print("Tie")
    elif winner == Player.black:
        print("Black win")
    else:
        print("White win")
예제 #3
0
def main():
    board_size = 9
    game = GameState.new_game(board_size)
    bots = {
        #    Player.black : RandomAgent(),
        #    Player.white : RandomAgent(),
        Player.black:
        FastRandomAgent(board_size),
        Player.white:
        FastRandomAgent(board_size),
    }
    while not game.is_over():
        time.sleep(0.1)  # slow down so we can observe

        #print(chr(27) + "[2J") #clear screen
        print_board(game.board)
        bot_move = bots[game.nplayer].select_move(game)
        print_move(game.nplayer, bot_move)
        game = game.apply_move(bot_move)
    winner = game.winner()
    if winner is None:
        print("Tie")
    elif winner == Player.black:
        print("Black win")
    else:
        print("White win")
예제 #4
0
def main():
    args = parse_args()
    board_size = args.size
    game = GameState.new_game(board_size)
    #bot = RandomAgent()
    bot = MCTSAgent(100, 1., 64)
    while not game.is_over():
        print_board(game.board)
        if game.nplayer == Player.black:
            human_move = input('-- ')
            if len(human_move) > 1:
                point = point_from_coord(human_move.strip())
                move = Move.play(point)
            else:
                move = Move.pass_turn()
        else:
            move = bot.select_move(game)
        print_move(game.nplayer, move)
        game = game.apply_move(move)
    winner = game.winner()
    if winner is None:
        print("Tie")
    elif winner == Player.black:
        print("Black win")
    else:
        print("White win")
예제 #5
0
def generate_game(board_size, rounds, max_moves, temperature):
  boards, moves = [], []
  encoder = get_encoder_by_name('oneplane', board_size)
  game = GameState.new_game(board_size)
  bot = MCTSAgent(100, 1., 1)
  num_moves = 0
  while not game.is_over():
    print_board(game.board)
    move = bot.select_move(game)
    if move.is_play:
      boards.append(encoder.encode(game))
      move_one_hot = np.zeros(encoder.num_points())
      move_one_hot[encoder.encode_point(move.pt)] = 1
      moves.append(move_one_hot)
    print_move(game.nplayer, move)
    game = game.apply_move(move)
    num_moves += 1
    if num_moves > max_moves:
      break
  return np.array(boards), np.array(moves)
예제 #6
0
def main():
    board_size = 3
    game = GameState.new_game(board_size)
    #bot = MinimaxAgent(5, None)
    bot = MCTSAgent(362000, 0.1, 64)
    while not game.is_over():
        print_board(game.board)
        if game.nplayer == Player.black:
            human_move = input('-- ')
            point = point_from_coord(human_move.strip())
            move = Move.play(point)
        else:
            move = bot.select_move(game)
        print_move(game.nplayer, move)
        game = game.apply_move(move)
    print_board(game.board)
    winner = game.winner()
    if winner is None:
        print("Tie")
    elif winner == Player.black:
        print("Human won")
    else:
        print("Bot won")