Beispiel #1
0
def main():

    board_size = 5
    game = goboard.GameState.new_game(board_size)

    # temperature == c in w + c*sqrt(log N / n)
    # higher temperatures are more volatile,
    # lower temperaures create a more focused search
    temperature = 1.5

    bots = {
        gotypes.Player.black: mcts.MCTSAgent(3, temperature),
        gotypes.Player.white: mcts.MCTSAgent(3, temperature),
    }

    while not game.is_over():

        time.sleep(0.3)  #

        print(chr(27) + "[2J")
        print_board(game.board)
        bot_move = bots[game.next_player].select_move(game)
        print_move(game.next_player, bot_move)

        game = game.apply_move(bot_move)
Beispiel #2
0
def main():
    board_size = 9
    game = goboard_slow.GameState.new_game(board_size)
    bots = {
        gotypes.Player.black: agent.naive.RandomBot(),
        gotypes.Player.white: agent.naive.RandomBot()
    }
    while not game.is_over():
        time.sleep(1)
        print(chr(27) + "[2J")
        print_board(game.board)
        bot_move = bots[game.next_player].select_move(game)
        print_move(game.next_player, bot_move)
        game = game.apply_move(bot_move)
Beispiel #3
0
def main():

    game = goboard.GameState.new_game(BOARD_SIZE)
    bot = alphabeta.AlphaBetaAgent(3, capture_diff)

    while not game.is_over():

        print_board(game.board)
        if game.next_player == gotypes.Player.black:
            human_move = input('-- ')
            point = point_from_coords(human_move.strip())
            move = goboard.Move.play(point)
        else:
            move = bot.select_move(game)
        print_move(game.next_player, move)
        game = game.apply_move(move)
Beispiel #4
0
def main():
    board_size = 9
    game = goboard.GameState.new_game(board_size)
    bot = agent.RandomBot()

    while not game.is_over():
        print(chr(27) + "[2J")
        print_board(game.board)
        if game.next_player == gotypes.Player.black:
            human_move = input('-- ')
            point = point_from_coords(human_move.strip())
            move = goboard.Move.play(point)
        else:
            move = bot.select_move(game)
        print_move(game.next_player, move)
        game = game.apply_move(move)

    print("Winner: ", game.winner())
def main():
    
    board_size = 5
    game = goboard.GameState.new_game(board_size)
    
    bots = {        
        gotypes.Player.black: depthprune.DepthPrunedAgent(3, pruned_go.capture_diff),
        gotypes.Player.white: depthprune.DepthPrunedAgent(3, pruned_go.capture_diff),
    }

    
    while not game.is_over():
    
        time.sleep(0.3)  #

        print(chr(27) + "[2J")  
        print_board(game.board)
        bot_move = bots[game.next_player].select_move(game)
        print_move(game.next_player, bot_move)
        
        game = game.apply_move(bot_move)
def generate_game(board_size, rounds, max_moves, temperature):
    # initialize encoded board state and encoded moves
    boards, moves = [], []

    # initialize a OnePlaneEncoder by name with given board size
    encoder = get_encoder_by_name('oneplane', board_size)

    # Instantiate a new game with board_size
    game = goboard.GameState.new_game(board_size)

    # MCTS agent bot with specified rounds and temp
    bot = mcts.MCTSAgent(rounds, temperature)

    num_moves = 0
    while not game.is_over():
        print_board(game.board)

        # bot picks next move
        move = bot.select_move(game)
        if move.is_play:
            # append encoded board to board
            boards.append(encoder.encode(game))

            # The one-hot-encoded next move is appended to moves
            move_one_hot = np.zeros(encoder.num_points())
            move_one_hot[encoder.encode_point(move.point)] = 1
            moves.append(move_one_hot)

        # apply bots move to the board
        print_move(game.next_player, move)
        game = game.apply_move(move)
        num_moves += 1

        # keep going until max number of moves is reached.
        if num_moves > max_moves:
            break

    return np.array(boards), np.array(moves)