Esempio n. 1
0
def print_board(game: othello_console.Othello) -> None:
    """ Prints a board in the form of 2D list """
    print("B: {}  W: {}".format(add_pieces(game, "B"), add_pieces(game, "W")))
    for row in range(game.get_rows()):
        for col in range(game.get_cols()):
            print(game.get_board()[row][col], end=" ")
        print()
Esempio n. 2
0
def add_pieces(game: othello_console.Othello, piece: str) -> int:
    """ Totals the number of pieces of B/W given the piece type as a str """
    sum = 0
    for row in range(game.get_rows()):
        for col in range(game.get_cols()):
            board_piece = game.get_board()[row][col]
            if board_piece == piece:
                sum += 1
    return sum
Esempio n. 3
0
def read_move(game: othello_console.Othello) -> (int, int):
    """ Reads input and returns if move is valid """
    if not game.any_possible_moves():
        game.flip_current_turn()
        if not game.any_possible_moves():
            raise othello_console.GameOverError
        else:
            game.flip_current_turn()
            raise othello_console.PlayerCantMoveError

    while True:
        try:
            move = str(input().strip()).split(" ")
            row = int(move[0])-1
            col = int(move[1])-1
            if row < game.get_rows() and col < game.get_cols() and game.check_valid_move(row, col):
                print("VALID")
                return row, col
            else:
                raise othello_console.InvalidMoveError
        except:
            raise othello_console.InvalidInputError