Ejemplo n.º 1
0
def main():

    # Define board size
    board_size = 9
    # Start a new game and store it in the game variable
    game = goboard.GameState.new_game(board_size)
    # Declare the players from the naive bot agent
    bot = RandomBot()

    # Game loop
    while not game.is_over():

        # Before each move, we clear the screen. This way the board is always
        # printed to the same position on the line command
        print(chr(27) + "[2J")
        # Print the board
        print_board(game.board)

        # Tell the bot to select a move
        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 the next move
        print_move(game.next_player, move)
        # Apply the move
        game = game.apply_move(move)
Ejemplo n.º 2
0
    def simulate_random_game(game: GameState):
        bots = {Player.black: RandomBot(), Player.white: RandomBot()}

        while (not game.is_over()):
            bot_move = bots[game.next_player].select_move(game)
            game = game.apply_move(bot_move)
        return game.winner()
Ejemplo n.º 3
0
def main():
    board_size = 9
    game = goboard.GameState.new_game(board_size)
    bots = {
        gotypes.Player.black: RandomBot(),
        gotypes.Player.white: RandomBot(),
    }
    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)
Ejemplo n.º 4
0
def main():
    board_size = 4
    results = {}
    start = time.time()

    for i in range(10):
        game = GameState.new_game(board_size)
        bots = {
            Player.black: RandomBot(),  # MinimaxBot(2, capture_diff),
            Player.white: MCBot(30),
        }
        while not game.is_over():
            # time.sleep(0.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)
        if capture_diff(game) > 0:
            results[game.next_player] = results.get(game.next_player, 0) + 1
        elif capture_diff(game) < 0:
            results[game.next_player.other] = results.get(
                game.next_player.other, 0) + 1
        # print(game.next_player, capture_diff(game))
    print(results, time.time() - start)

    results = {}
    start = time.time()

    for i in range(10):
        game = GameState.new_game(board_size)
        bots = {
            Player.black: RandomBot(),  # MinimaxBot(2, capture_diff),
            Player.white: MinimaxBot(3, capture_diff),
        }
        while not game.is_over():
            # time.sleep(0.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)
        if capture_diff(game) > 0:
            results[game.next_player] = results.get(game.next_player, 0) + 1
        elif capture_diff(game) < 0:
            results[game.next_player.other] = results.get(
                game.next_player.other, 0) + 1
        # print(game.next_player, capture_diff(game))
    print(results, time.time() - start)
Ejemplo n.º 5
0
def main():
    board_size = 9
    game = goboard.GameState.new_game(board_size)
    bot = 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().upper())
            move = goboard.Move.play(point)
        else:
            move = bot.select_move(game)
        print_move(game.next_player, move)
        game = game.apply_move(move)
Ejemplo n.º 6
0
def main():
    board_size = 5
    pygame.init()
    pygame.display.set_caption('Goban')

    game = GameState.new_game(board_size)
    bots = {
        gotypes.Player.black: RandomBot(),
        gotypes.Player.white: AlphaBetaAgent(2, capture_diff),
    }
    while not game.is_over():
        #time.sleep(0.3)

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

    print("winner is:", game.winner())
    print("score is is:", compute_game_result(game))
    input("Press Enter to continue...")
Ejemplo n.º 7
0
def simulate_random_game(game_state):
    bot = RandomBot()
    while not game_state.is_over():
        bot_move = bot.select_move(game_state)
        game_state = game_state.apply_move(bot_move)
    return game_state.winner()
Ejemplo n.º 8
0
from dlgo.agent.naive import RandomBot
from dlgo.agent import load_prediction_agent
from dlgo.httpfrontend.server import get_web_app
import h5py

bots = {}
random_agent = RandomBot()
# bot_agent = load_prediction_agent(h5py.File("agents/GHGHbot1_rl_policy.h5", "r"))
bot_agent = load_prediction_agent(h5py.File('agents/deep_bot_2.h5', "r"))
web_app = get_web_app({'random': random_agent, 'predict': bot_agent})
web_app.run(threaded=False)
Ejemplo n.º 9
0
#!/usr/local/bin/python2
from dlgo.gtp import GTPFrontend
from dlgo.agent.predict import load_prediction_agent
from dlgo.agent import termination
from dlgo.agent.naive import RandomBot
import h5py

# model_file = h5py.File("agents/betago.hdf5", "r")
model_file = h5py.File("agents/deep_bot_2.h5", "r")
agent = load_prediction_agent(model_file)
agent2 = RandomBot()
strategy = termination.get("opponent_passes")
termination_agent = termination.TerminationAgent(agent2, strategy)

frontend = GTPFrontend(termination_agent)
frontend.run()