Ejemplo n.º 1
0
def main():
    board_size = 9
    game = goboard.GameState.new_game(board_size)
    bots = {
        gotypes.Player.black: naive.RandomBot(),
        gotypes.Player.white: 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,numberOfCaptures = game.apply_move(bot_move)

        if len(numberOfCaptures) > 0:
            if game.next_player == gotypes.Player.black:
                captures[gotypes.Player.black] += numberOfCaptures[0]
            else:
                captures[gotypes.Player.white] += numberOfCaptures[0]

    winner,score = game.winner(captures)

    if winner == gotypes.Player.black:
        # print("Black is the WINNER!!!!")
    else:
Ejemplo n.º 2
0
async def main():
    board_size = 9
    game = goboard_slow.GameState.new_game(board_size)
    bots = {
        gotypes.Player.black: naive.RandomBot(),
        gotypes.Player.white: naive.RandomBot(),
    }
    while not game.is_over():
        print(chr(27) + "[2j")
        bot_move = bots[game.next_player].select_move(game)
        print_move(game.next_player, bot_move)
        game = game.apply_move(bot_move)
        print_board(game.board)

        board_json = {
            "board": {
                "rows": board_to_json(game.board)
            },
            "message": move_to_text(game.next_player, bot_move)
        }

        async with websockets.connect(uri) as websocket:
            await websocket.send(json.dumps(board_json))

        time.sleep(0.5)
Ejemplo n.º 3
0
def main():
    board_size = 9
    game = goboard.GameState.new_game(board_size)
    bots = {
        gotypes.Player.black: naive.RandomBot(),
        gotypes.Player.white: naive.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 = 9
    game = goboard.GameState.new_game(board_size)
    bot = naive.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)
    black_score = scoring.evaluate_territory(game.board).num_black_stones
    black_score = black_score + scoring.evaluate_territory(
        game.board).num_black_territory
    white_score = scoring.evaluate_territory(game.board).num_white_stones
    white_score = white_score + scoring.evaluate_territory(
        game.board).num_white_territory
    if black_score > white_score:
        print("\nPlayer Black Wins: ")
        print(black_score)
    elif white_score > black_score:
        print("\nPlayer White Wins: ")
        print(white_score)
Ejemplo n.º 5
0
def main():
    board_size = 19
    game = goboard.GameState.new_game(board_size)
    bot = naive.RandomBot()

    while not game.is_over():
        # print(chr(27) + "[2J")
        print_board(game.board)
        
        if game.next_player == gotypes.Player.black:
            human_move = input('Your turn: ')
            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,numberOfCaptures = game.apply_move(move)

        if len(numberOfCaptures) > 0:
            if game.next_player == gotypes.Player.black:
                captures[gotypes.Player.black] += numberOfCaptures
            else:
                captures[gotypes.Player.white] += numberOfCaptures

        # time.sleep(1)

    winner,score = game.winner(captures)

    if winner == gotypes.Player.black:
        # print("Black is the WINNER!!!!")
    else:
Ejemplo n.º 6
0
def main():
    board_size = 9
    game = goboard_slow.GameState.new_game(board_size)
    bots = {
        gotypes.Player.black: naive.RandomBot(),
        gotypes.Player.white: naive.RandomBot()
    }
    while not game.is_over():
        time.sleep(0.3)  # Sleep timer so we can observe bot moves

        print(
            chr(27) + "[2J"
        )  #Before each move, clear the screen, so the board is always printed to the same position on command line
        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.º 7
0
def main():
    board_size = 9
    komi = 3.5
    game = goboard_slow.GameState.new_game(board_size)
    bots = {
        gotypes.Player.black: naive.RandomBot(),
        gotypes.Player.white: naive.RandomBot(),
    }
    while not game.is_over():
        time.sleep(.3)

        clear()
        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)

    results = compute_game_result(game, komi)
    print("With a komi of %.1f" % komi)
    print("White Final Score: %d" % results.w)
    print("Black Final Score: %.1f" % (results.b - results.komi))
    print(results.winner, "wins by %.1f points" % results.winning_margin)
Ejemplo n.º 8
0
def main():
    while True:
        print("The board size(5-19)")
        board_size = int(input())
        if 19 >= board_size >= 5:
            break
        else:
            print("Wrong size,please input 5-19")
    game = goboard.GameState.new_game(board_size)
    bots = {
        gotypes.Player.black: naive.RandomBot(),
        gotypes.Player.white: naive.RandomBot(),
    }
    start = timeit.default_timer()
    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)
    stop = timeit.default_timer()
    print(scoring.compute_game_result(game))
    print('Runtime:', stop - start, 'seconds')
Ejemplo n.º 9
0
def main():
    board_size = 9
    game = goboard.GameState.new_game(board_size)
    bot = naive.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)
Ejemplo n.º 10
0
def main():
    board_size = 9
    game = goboard.GameState.new_game(board_size)
    bot = naive.RandomBot()
    print_board(game.board)

    while not game.is_over():
        # Since making a play is necessary for changing board state but also changes
        # next player we must save the current player
        player_before = game.next_player
        move = None
        if game.next_player == gotypes.Player.black:
            valid_move = False
            while not valid_move:
                try:
                    human_move = input('-- ').upper()
                    if match("PA(S)*", human_move):
                        move = goboard.Move.pass_turn()
                    elif match("RE(SIGN)*", human_move):
                        move = goboard.Move.resign()
                    else:
                        point = point_from_coords(human_move.strip())
                        move = goboard.Move.play(point)

                    valid_move = game.is_valid_move(move)
                    if not valid_move:
                        print("Invalid move")

                except AssertionError:
                    print("Invalid move")
                except ValueError:
                    print("Invalid move")
                except IndexError:
                    print("Invalid move")
            # end of human input loop
        else:
            move = bot.select_move(game)
        clear()
        game = game.apply_move(move)
        print_board(game.board)
        print_move(player_before, move)
Ejemplo n.º 11
0
def main():
    while True:
        print("The board size(5-19)")
        board_size = int(input())
        if 19 >= board_size >= 5:
            break
        else:
            print("Wrong size,please input 5-19")
    game = goboard.GameState.new_game(board_size)
    bot = naive.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(scoring.compute_game_result(game))
Ejemplo n.º 12
0
def main():
    options = get_options(argv[1:])
    size = abs(options.size)
    human = options.human
    komi = abs(options.komi)

    if size < 5 or size > 19:
        print("Board size must be between 5 and 19")
        exit(-1)

    if komi < 0 or komi > 10:
        print("Komi must be between 0 and 10")
        exit(-1)

    game = goboard.GameState.new_game(size)
    players = {}
    if human is None:
        players = {
            gotypes.Player.black: naive.RandomBot(),
            gotypes.Player.white: naive.RandomBot()
        }
    elif human == 'b':

        players = {
            gotypes.Player.black: human,
            gotypes.Player.white: naive.RandomBot()
        }
    elif human == 'w':
        players = {
            gotypes.Player.black: naive.RandomBot(),
            gotypes.Player.white: human
        }
    else:
        print(options)
        print("Invalid options error")
        exit(0)

    print_board(game.board)

    while not game.is_over():
        # Since making a play is necessary for changing board state but also changes
        # next player we must save the current player
        player_before = game.next_player
        move = None
        if players[game.next_player] == human:
            valid_move = False
            while not valid_move:
                try:
                    human_move = input('-- ').upper()
                    if match("P(ASS)*$", human_move):
                        move = goboard.Move.pass_turn()
                    elif match("R(ESIGN)*$", human_move):
                        move = goboard.Move.resign()
                    else:
                        point = point_from_coords(human_move.strip())
                        move = goboard.Move.play(point)

                    valid_move = game.is_valid_move(move)
                    if not valid_move:
                        print("Invalid move")

                except AssertionError:
                    print("Invalid move")
                except ValueError:
                    print("Invalid move")
                except IndexError:
                    print("Invalid move")
            # end of human input loop
        else:
            move = players[game.next_player].select_move(game)
        clear()
        game = game.apply_move(move)
        print_board(game.board)
        time.sleep(.1)
        print_move(player_before, move)
    # end of main game loop

    game.print_game_results(komi)