Beispiel #1
0
def def_heuristic(board, player, opponent, last_move_index, boardsize, mode=0):
    
    # if looking for open four threats
    if mode == 4:
        # get open four blocking moves
        def_moves = check_blockwin(board, player, opponent, last_move_index, boardsize, 4)
    
    # if looking for win threats
    else:
        # get win blocking moves
        def_moves = check_blockwin(board, player, opponent, last_move_index, boardsize)
    
    # if any open four/win blocking moves
    if def_moves:
        count = 0
        # for each blocking move
        while count < len(def_moves):
            # convert move to board location
            move = int(def_moves[count])
            move = u.point_to_boardloc(move, boardsize)
            def_moves[count] = move
            count += 1    
        return def_moves
    
    # if no blocking moves available
    else:
        return []
Beispiel #2
0
def win_heuristic(player_move_history, board, player, opponent, boardsize, mode=0):
    
    # if looking for open four moves
    if mode == 4:
        # get open four moves
        win_moves = get_win_moves(player_move_history, board, player, opponent, boardsize, 4)
    
    # if looking for winning moves
    else:
        # get winning moves
        win_moves = get_win_moves(player_move_history, board, player, opponent, boardsize)
    
    # if open four/winning moves available
    if win_moves:
        count = 0
        # for each move
        while count < len(win_moves):
            # convert move to board location
            move = int(win_moves[count])
            move = u.point_to_boardloc(move, boardsize)
            win_moves[count] = move
            count += 1
        return win_moves
    
    # if no moves available
    else:
        return []
Beispiel #3
0
def get_win_moves(previous_moves, board, player, opponent, boardsize, mode=0):
    moves_analyzed = []
    moves = []
    
    # for each move in the move history, starting at the most recent move
    for m in reversed(previous_moves):
        # get board index of move
        tempmove_index = u.boardloc_to_point(m, boardsize)
        templist = []
        emptycount = 8
        
        # if space in row above point is empty and space not yet analyzed
        if board[tempmove_index + (boardsize + 1)] == 0 and tempmove_index + (boardsize + 1) not in moves_analyzed:
            # add space to list
            templist.append(tempmove_index + (boardsize + 1))
        
        # if space in row above point is not empty
        elif board[tempmove_index + (boardsize + 1)] != 0:
            emptycount -= 1
            
        # if space in row below point is empty and space not yet analyzed
        if board[tempmove_index - (boardsize + 1)] == 0 and tempmove_index - (boardsize + 1) not in moves_analyzed:
            # add space to list
            templist.append(tempmove_index - (boardsize + 1))
            
        # # if space in row below point is not empty
        elif board[tempmove_index - (boardsize + 1)] != 0:
            emptycount -= 1
        
        # if space in column to the right of the point is not empty and space not yet analyzed
        if board[tempmove_index + 1] == 0 and tempmove_index + 1 not in moves_analyzed:
            templist.append(tempmove_index + 1)
        
        # if space in column to the right of the point is empty
        elif board[tempmove_index + 1] != 0:
            emptycount -= 1
        
        # if space in column to the left of the point is not empty and space not yet analyzed
        if board[tempmove_index - 1] == 0 and tempmove_index - 1 not in moves_analyzed:
            templist.append(tempmove_index - 1)
        
        # if space in column to the left of the point is empty
        elif board[tempmove_index - 1] != 0:
            emptycount -= 1
        
        # if space up and left of point is not empty and space not yet analyzed
        if board[tempmove_index + (boardsize + 1) + 1] == 0 and tempmove_index + (boardsize + 1) + 1 not in moves_analyzed:
            templist.append(tempmove_index + (boardsize + 1) + 1)
            
        # if space up and left of point is empty
        elif board[tempmove_index + (boardsize + 1) + 1] != 0:
            emptycount -= 1
            
        # if space down and right of point is not empty and space not yet analyzed
        if board[tempmove_index - (boardsize + 1) - 1] == 0 and tempmove_index - (boardsize + 1) - 1 not in moves_analyzed:
            templist.append(tempmove_index - (boardsize + 1) - 1)
            
        # if space down and right of point is empty
        elif board[tempmove_index - (boardsize + 1) - 1] != 0:
            emptycount -= 1
            
        # if space up and right of point is not empty and space not yet analyzed
        if board[tempmove_index + (boardsize + 1) - 1] == 0 and tempmove_index + (boardsize + 1) - 1 not in moves_analyzed:
            templist.append(tempmove_index + (boardsize + 1) - 1)
            
        # if space up and right of point is empty
        elif board[tempmove_index + (boardsize + 1) - 1] != 0:
            emptycount -= 1
            
        # if space down and left of point is not empty and space not yet analyzed
        if board[tempmove_index - (boardsize + 1) + 1] == 0 and tempmove_index - (boardsize + 1) + 1 not in moves_analyzed:
            templist.append(tempmove_index - (boardsize + 1) + 1)
            
        # if space down and left of point is empty
        elif board[tempmove_index - (boardsize + 1) + 1] != 0:
            emptycount -= 1
        
        # if all spaces around point are filled
        if emptycount == 0:
            # not sure if anything needs to be done here
            # leaving in just in case
            pass
        
        # if at least one empty space around point
        else:
            
            # for each empty space around point
            for pos in templist:
                # make a copy of the board
                tempboard = board.copy()
                # get board location of point
                move = u.point_to_boardloc(pos, boardsize)
                # play move on copy of board
                move_status = u.play_move(move, tempboard, boardsize, player, opponent, 1)
                
                # if checking to see if move caused win
                if mode == 0:
                    # vertical win check
                    moves1 = get_line(tempboard, player, opponent, pos, (boardsize + 1))
                    if moves1:
                        # if move caused a win
                        if moves1[0] == 10000:
                            # if move not in movelist
                            if pos not in moves:
                                # add move to list
                                moves.append(pos)
                    # horiztonal win check
                    moves1 = get_line(tempboard, player, opponent, pos, 1)
                    if moves1:
                        if moves1[0] == 10000:
                            if pos not in moves:
                                moves.append(pos)
                    # diagonal up/left down/right win check
                    moves1 = get_line(tempboard, player, opponent, pos, (boardsize + 1), True)
                    if moves1:
                        if moves1[0] == 10000:
                            if pos not in moves:
                                moves.append(pos)
                    # diagonal up/right down/left win check
                    moves1 = get_line(tempboard, player, opponent, pos, -(boardsize + 1), True)
                    if moves1:
                        if moves1[0] == 10000:
                            if pos not in moves:
                                moves.append(pos)
                
                # if checking to see if move caused open four
                elif mode == 4:
                    # vertical open four check
                    moves1 = get_line(tempboard, player, opponent, pos, (boardsize + 1), False, 4)
                    if moves1:
                        # move caused an open four
                        if moves1[0] == 4:
                            # if move not in movelist
                            if pos not in moves:
                                # add move to list
                                moves.append(pos)
                    # horiztonal open four check
                    moves1 = get_line(tempboard, player, opponent, pos, 1, False, 4)
                    if moves1:
                        if moves1[0] == 4:
                            if pos not in moves:
                                moves.append(pos)
                    # diagonal up/right down/left open four check
                    moves1 = get_line(tempboard, player, opponent, pos, (boardsize + 1), True, 4)
                    if moves1:
                        if moves1[0] == 4:
                            if pos not in moves:
                                moves.append(pos)
                    # diagonal up/left down/right open four check
                    moves1 = get_line(tempboard, player, opponent, pos, -(boardsize + 1), True, 4)
                    if moves1:
                        if moves1[0] == 4:
                            if pos not in moves:
                                moves.append(pos)
                # add move to analyzed list
                # prevents looking at same move twice
                moves_analyzed.append(pos)
                
    return moves
Beispiel #4
0
def current_position_evaluation(player,
                                opponent,
                                board,
                                boardsize,
                                move_history,
                                ruleset,
                                mode=0):

    # if current player is black
    if player == 1:
        playercolour = 'black'

    # if current player is white
    elif player == 2:
        playercolour = 'white'

    # if no moves have been made
    if len(move_history) == 0:
        # get center point
        pos = (len(board) - 1) // 2
        move = u.point_to_boardloc(pos, boardsize)

        # if display mode
        if mode == 0:
            print("\nblack must play", move, "to start the game")

        # if return mode
        else:
            return move

    # if tournament rules are in use and it is black's second move
    elif player == 1 and ruleset == 1 and len(move_history) == 2:
        # get list of empty spaces on current board
        available_moves = u.get_empty_spaces(board, boardsize)
        # get center point
        center = (len(board) - 1) // 2
        center = u.point_to_boardloc(center, boardsize)
        center_ord = ord(center[0])
        legal_moves = []
        # for every empty space
        for move in available_moves:
            move_ord = ord(move[0])
            ord_diff = abs(center_ord - move_ord)

            # if current column is less than 3 spaces away from center
            if ord_diff < 3:
                center_coord = int(center[1])
                move_coord = int(move[1])
                coord_diff = abs(center_coord - move_coord)

                # if current row is 3+ spaces away from center
                if coord_diff >= 3:
                    # add to legal move list
                    legal_moves.append(move)
            else:
                # add to legal move list
                legal_moves.append(move)

        # if display lower
        if mode == 0:
            count = 1
            print(
                '\nblack must play in one of the following spaces as per tournament rules:'
            )
            # display legal moves
            for i in legal_moves:
                print(i, end=' ')
                # max row of 10 for readability
                if count == 10:
                    print('')
                    count = 1
                else:
                    count += 1
            print('')

        # if return mode
        else:
            # return random legal move
            random.shuffle(legal_moves)
            move = legal_moves[0]
            return move

    else:
        # get board location of most recent move
        last_move = move_history[-1]
        last_move_index = u.boardloc_to_point(last_move[1], boardsize)
        # get player's move history
        player_move_history = heur.parse_move_history(player, move_history)
        # check for winning moves
        win_moves = heur.win_heuristic(player_move_history, board, player,
                                       opponent, boardsize)

        # if any winning moves exist
        if win_moves:

            # if display mode
            if mode == 0:
                # display winning moves
                print("\nwinning moves for", playercolour, "are: ", end='')
                for move in win_moves:
                    move = move + ' '
                    print(move, end='')
                print('')

            else:
                # randomly pick winning move to play
                random.shuffle(win_moves)
                move = win_moves[0]
                return move

        # if no winning moves exist
        else:
            # check for opponent winning moves to block
            def_moves = heur.def_heuristic(board, player, opponent,
                                           last_move_index, boardsize)

            # if blocking moves exist
            if def_moves:

                # if display mode
                if mode == 0:

                    # display blocking moves

                    # if more than one blocking move exists
                    if len(def_moves) > 1:
                        print(
                            "\na",
                            playercolour,
                            "with proper play, loss is inevitable. blocking moves would be: ",
                            end='')
                    else:
                        print("\nmove that will prevent a",
                              playercolour,
                              "loss is: ",
                              end='')
                    for move in def_moves:
                        move = move + ' '
                        print(move, end='')
                    print('')

                else:
                    # randomly pick blocking move to play
                    random.shuffle(def_moves)
                    move = def_moves[0]
                    return move

            # if no blocking moves exist
            else:
                # check for moves that create open fours
                four_moves = heur.win_heuristic(player_move_history, board,
                                                player, opponent, boardsize, 4)

                # if open four moves exist
                if four_moves:

                    # if display mode
                    if mode == 0:
                        # display open four moves
                        print('')
                        print(playercolour,
                              "can make an open four with: ",
                              end='')
                        for move in four_moves:
                            move = move + ' '
                            print(move, end='')
                        print('')

                    else:
                        # randomly pick open four move to play
                        random.shuffle(four_moves)
                        move = four_moves[0]
                        return move

                # if no open four moves exist
                else:
                    # check for moves that block opponent open fours
                    def_moves = heur.def_heuristic(board, player, opponent,
                                                   last_move_index, boardsize,
                                                   4)

                    # if moves that block opponent open fours exist
                    if def_moves:

                        # if display mode
                        if mode == 0:
                            # display blocking moves
                            print('')
                            print(playercolour,
                                  "can block an open four with: ",
                                  end='')
                            for move in def_moves:
                                move = move + ' '
                                print(move, end='')
                            print('')

                        else:
                            # randomly pick blocking move to play
                            random.shuffle(def_moves)
                            move = def_moves[0]
                            return move

                    # if no heuristic-determined moves exist
                    else:

                        # if display mode
                        if mode == 0:
                            print(
                                "\nthere are no specific moves to play at this time"
                            )

                        else:
                            # randomly pick legal move to play
                            legal_moves = u.get_empty_spaces(board, boardsize)
                            random.shuffle(legal_moves)
                            move = legal_moves[0]
                            return move
Beispiel #5
0
def startgame_cmd(boardsize, ruleset):
    # reset game information
    player, opponent = u.reset_players()
    black_capture_count, white_capture_count = u.reset_cap_counts()
    black_win, white_win, draw = u.reset_win_status()
    # build new board
    board, move_history = u.build_board(boardsize)
    u.show_board(board, boardsize)
    # user chooses colour to play
    arg = input(
        "\nChoose your colour (b for black, w for white, c to cancel): ")
    argcheck = False

    # while input not validated
    while not argcheck:
        arg = arg.lower()

        # if invalid input
        if arg != "b" and arg != "w" and arg != "c":
            print(
                "\nError: Incorrect input for command. Consult README for more info"
            )
            arg = input(
                "\nChoose your colour (b for black, w for white, c to cancel): "
            )

        else:
            # input validated
            argcheck = True

    # if user cancels game
    if arg == "c":
        print("\nGame has been cancelled")
        u.show_board(board, boardsize)

    # if user wants to play black
    elif arg == "b":
        player = 1

    # if user wants to play white
    elif arg == "w":
        opponent = 1

    # user choice of player for cpu to use
    arg2 = input(
        "\nChoose the player for your opponent. 1 for Random, 2 for Heuristic: "
    )
    argcheck2 = False

    # while input not validated
    while not argcheck2:

        # if invalid input
        if arg2 != "1" and arg2 != "2":
            print(
                "\nError: Incorrect input for command. Consult README for more info"
            )
            arg2 = input(
                "\nChose the player for your opponent. 1 for Random, 2 for Heuristic: "
            )

        else:
            # input validated
            argcheck2 = True

    # if user playing white
    if opponent == 1:

        # while game is ongoing
        while not black_win and not white_win and not draw:

            # if black using random player
            if arg2 == "1":
                # generate and play random move
                board, player, opponent, black_capture_count, white_capture_count,\
                    black_win, white_win, draw \
                    = genmove_cmd(board, boardsize, 1, 2, black_capture_count,
                                  white_capture_count, black_win, white_win, draw, move_history, ruleset)

            # if black using heuristic player
            elif arg2 == "2":
                # obtain black's heuristic-determined move
                black_move = current_position_evaluation(
                    player, opponent, board, boardsize, move_history, ruleset,
                    1)
                # play specified move
                board, player, opponent, black_capture_count, white_capture_count,\
                    black_win, white_win, draw \
                    = play_cmd(board, boardsize, player, opponent, black_capture_count,
                               white_capture_count, black_win, white_win, draw, black_move, move_history)

            # if black's move ended the game
            if black_win or white_win or draw:
                # exit game
                break

            else:
                # user enters move they want to play
                move_arg = input(
                    "\nPlease enter your move, enter 'poseval' to evaluate the position, or enter 'quit' to exit: "
                )
                move_arg = move_arg.lower()

                # if user wants to exit
                if move_arg == "quit":
                    print("\nGame cancelled")
                    # exit game
                    break
                else:
                    moveargcheck = False
                    while not moveargcheck:

                        if move_arg == "poseval":
                            # evaluate current position
                            current_position_evaluation(
                                player, opponent, board, boardsize,
                                move_history, ruleset)
                            move_arg = input(
                                "\nPlease enter your move, enter 'poseval' to evaluate the position, or enter 'quit' to exit: "
                            )
                            move_arg = move_arg.lower()

                        elif move_arg == "quit":
                            print("\nGame cancelled")
                            # exit game
                            moveargcheck = 69

                        else:
                            # else
                            # play specified move
                            moveargcheck = True
                            board, player, opponent, black_capture_count, white_capture_count,\
                                black_win, white_win, draw \
                                = play_cmd(board, boardsize, 2, 1, black_capture_count,
                                           white_capture_count, black_win, white_win, draw, move_arg, move_history)

                    if moveargcheck == 69:
                        # exit game
                        break

    # if user playing black
    elif player == 1:

        # while game is ongoing
        while not black_win and not white_win and not draw:
            # user enters move they want to play
            move_arg = input(
                "\nPlease enter your move, or enter 'quit' to exit: ")
            move_arg = move_arg.lower()

            # if user wants to exit
            if move_arg == "quit":
                print("\nGame cancelled")
                # exit game
                break

            movecheck = False

            # while input not validated
            while not movecheck:

                if move_arg == "poseval":
                    # evaluate current position
                    current_position_evaluation(player, opponent, board,
                                                boardsize, move_history,
                                                ruleset)
                    move_arg = input(
                        "\nPlease enter your move, enter 'poseval' to evaluate the position, or enter 'quit' to exit: "
                    )
                    move_arg = move_arg.lower()

                elif move_arg == "quit":
                    print("\nGame cancelled")
                    # exit game
                    movecheck = 69

                # if no moves have been made
                elif len(move_history) == 0:
                    # get center point
                    pos = (len(board) - 1) // 2
                    center = u.point_to_boardloc(pos, boardsize)

                    # if move specified is not center point
                    if move_arg != center:
                        print(
                            "\nError: Black's first move must be the center point"
                        )
                        # display current board
                        u.show_board(board, boardsize)
                        # user enters move they want to make
                        move_arg = input(
                            "\nPlease enter your move, or enter 'quit' to exit: "
                        )
                        move_arg = move_arg.lower()

                        # if user wants to exit
                        if move_arg == "quit":
                            print("\nGame cancelled")
                            # exit game
                            movecheck = 69

                    else:
                        # input validated
                        movecheck = True
                        # play specified move
                        board, player, opponent, black_capture_count, white_capture_count,\
                            black_win, white_win, draw \
                            = play_cmd(board, boardsize, 1, 2, black_capture_count,
                                       white_capture_count, black_win, white_win, draw, move_arg, move_history)

                # if previous check passes and tournament rules are in use
                elif ruleset == 1:
                    # check if move entered is legal according to tournament rules
                    check = u.tournament_rule_check(board, boardsize, player,
                                                    move_history, move_arg)

                    # if move is legal
                    if check:
                        # input validated
                        movecheck = True
                        # play specified move
                        board, player, opponent, black_capture_count, white_capture_count,\
                            black_win, white_win, draw \
                            = play_cmd(board, boardsize, 1, 2, black_capture_count,
                                       white_capture_count, black_win, white_win, draw, move_arg, move_history)

                    else:
                        # display current board
                        u.show_board(board, boardsize)
                        # user enters move they want to make
                        move_arg = input(
                            "\nPlease enter your move, or enter 'quit' to exit: "
                        )
                        move_arg = move_arg.lower()

                        # if user wants to exit
                        if move_arg == "quit":
                            print("\nGame cancelled")
                            # exit game
                            movecheck = 69

                else:
                    # input validated
                    movecheck = True
                    # play specified move
                    board, player, opponent, black_capture_count, white_capture_count,\
                        black_win, white_win, draw \
                        = play_cmd(board, boardsize, 1, 2, black_capture_count,
                                   white_capture_count, black_win, white_win, draw, move_arg, move_history)

            if movecheck == 69:
                # exit game
                break

            # if black's move ended the game
            if black_win or white_win or draw:
                # exit game
                break

            else:

                # if white is using random player
                if arg2 == "1":
                    # generate and play random move
                    board, player, opponent, black_capture_count, white_capture_count,\
                        black_win, white_win, draw \
                        = genmove_cmd(board, boardsize, 2, 1, black_capture_count,
                                      white_capture_count, black_win, white_win, draw, move_history, ruleset)

                # if white is using heuristic player
                elif arg2 == "2":
                    # obtain white's heurisitc-determined move
                    white_move = current_position_evaluation(
                        player, opponent, board, boardsize, move_history,
                        ruleset, 1)
                    # play specified move
                    board, player, opponent, black_capture_count, white_capture_count,\
                        black_win, white_win, draw \
                        = play_cmd(board, boardsize, player, opponent, black_capture_count,
                                   white_capture_count, black_win, white_win, draw, white_move, move_history)
Beispiel #6
0
def main():

    commandlist = [
        "boardsize", "reset", "quit", "genmove", "play", "commands",
        "emptyspaces", "ptm", "winner", "showboard", "capturecounts",
        "playcpugame", "changeptm", "movehistory", "rules", "changerules",
        "startgame", "poseval"
    ]

    boardsize = 7

    # build board
    board, move_history = u.build_board(boardsize)

    # show board
    print("Pente random player, by Adam Pumphrey")
    print("\nBlack = 1")
    print("White = 2")
    print("Empty space = 0")
    u.show_board(board, boardsize)

    # initialize game information
    player = 1
    opponent = 2
    ruleset = 1
    black_capture_count = 0
    white_capture_count = 0
    black_win = False
    white_win = False
    draw = False

    # prompt for command
    user_inp = input("\nPlease enter a command: ")

    while user_inp:
        command = user_inp.split(" ")
        # checks validity of command entered
        check_result = u.check_inp_command(command, commandlist)

        # if command entered is invalid
        if not check_result:
            print(
                "\nError: Command does not exist. Use 'commands' to list existing commands"
            )

        # if command entered is valid
        elif check_result:
            '''execute command'''

            # boardsize command
            if command[0] == "boardsize":
                # try changing boardsize
                board, boardsize, move_history, success = com.boardsize_cmd(
                    command, board, boardsize, move_history)

                # if boardsize change successful
                if success:
                    # reset game information
                    player, opponent = u.reset_players()
                    black_capture_count, white_capture_count = u.reset_cap_counts(
                    )
                    black_win, white_win, draw = u.reset_win_status()

            # reset command
            elif command[0] == "reset":
                # if too many arguments
                if len(command) > 1:
                    print(
                        "\nError: Command does not require additional input. Consult README for more info"
                    )

                else:
                    # reset game information
                    player, opponent = u.reset_players()
                    black_capture_count, white_capture_count = u.reset_cap_counts(
                    )
                    black_win, white_win, draw = u.reset_win_status()
                    # build new board
                    board, move_history = u.build_board(boardsize)
                    # display board
                    u.show_board(board, boardsize)

            # quit command
            elif command[0] == "quit":

                # if too many arguments
                if len(command) > 1:
                    print(
                        "\nError: Command does not require additional input. Consult README for more info"
                    )

                else:
                    # kill program
                    u.quit()

            # genmove command
            elif command[0] == "genmove":

                # if too many arguments
                if len(command) > 1:
                    print(
                        "\nError: Command does not require additional input. Consult README for more info"
                    )

                # if game has ended and board + info not reset
                elif u.check_game_status(black_win, white_win, draw):
                    print(
                        "\nGame is over. To start a new game, please use the 'reset' command"
                    )

                else:
                    # generate and play random move
                    board, player, opponent, black_capture_count, white_capture_count,\
                    black_win, white_win, draw \
                    = com.genmove_cmd(board, boardsize, player, opponent, black_capture_count,
                                  white_capture_count, black_win, white_win, draw, move_history, ruleset)

            # play command
            elif command[0] == "play":

                # if not enough arguments
                if len(command) < 2:
                    print(
                        "\nError: Command requires additional input. Consult README for more info"
                    )

                # if too many arguments
                elif len(command) > 2:
                    print(
                        "\nError: Incorrect amount of input for command. Consult README for more info"
                    )

                # if game has ended and board + info not reset
                elif u.check_game_status(black_win, white_win, draw):
                    print(
                        "\nGame is over. To start a new game, please use the 'reset' command"
                    )

                else:

                    # if black to move and it is the first move of the game
                    if player == 1 and len(move_history) == 0:
                        # get center point
                        pos = (len(board) - 1) // 2
                        center = u.point_to_boardloc(pos, boardsize)

                        # if move entered is not the center point
                        if command[1] != center:
                            print(
                                "\nError: Black's first move must be the center point"
                            )
                            u.show_board(board, boardsize)

                        else:
                            # play specified move
                            board, player, opponent, black_capture_count, white_capture_count,\
                                black_win, white_win, draw \
                                = com.play_cmd(board, boardsize, player, opponent, black_capture_count,
                                           white_capture_count, black_win, white_win, draw, command[1], move_history)

                    # if previous check passes and tournament rules are in use
                    elif ruleset == 1:
                        # check if move entered is legal according to tournament rules
                        check = u.tournament_rule_check(
                            board, boardsize, player, move_history, command[1])

                        # if move is legal
                        if check:
                            # play specified move
                            board, player, opponent, black_capture_count, white_capture_count,\
                                black_win, white_win, draw \
                                = com.play_cmd(board, boardsize, player, opponent, black_capture_count,
                                           white_capture_count, black_win, white_win, draw, command[1], move_history)

                        # if move is illegal
                        else:
                            # show current board
                            u.show_board(board, boardsize)

                    else:
                        # play specified move
                        board, player, opponent, black_capture_count, white_capture_count,\
                            black_win, white_win, draw \
                            = com.play_cmd(board, boardsize, player, opponent, black_capture_count,
                                       white_capture_count, black_win, white_win, draw, command[1], move_history)

            # commands command (lol)
            elif command[0] == "commands":

                # if too many arguments
                if len(command) > 1:
                    print(
                        "\nError: Command does not require additional input. Consult README for more info"
                    )

                else:
                    print("\nCommands:")
                    # display commands
                    for i in commandlist:
                        print(" ", i)

            # emptyspaces command
            elif command[0] == "emptyspaces":

                # if too many arguments
                if len(command) > 1:
                    print(
                        "\nError: Command does not require additional input. Consult README for more info"
                    )

                else:
                    # display remaining empty board spaces
                    com.emptyspaces_cmd(board, boardsize)

            # ptm command
            elif command[0] == "ptm":

                # if too many arguments
                if len(command) > 1:
                    print(
                        "\nError: Command does not require additional input. Consult README for more info"
                    )

                else:
                    # if game has ended and board + info not reset
                    if u.check_game_status(black_win, white_win, draw):
                        print(
                            "\nThe game has ended. To start a new game, please use the 'reset' command"
                        )

                    else:
                        # display player-to-move
                        com.ptm_cmd(player)

            # changeptm command
            elif command[0] == "changeptm":

                # if not enough arguments
                if len(command) < 2:
                    print(
                        "\nError: Command requires additional input. Consult README for more info"
                    )

                # if too many arguments
                elif len(command) > 2:
                    print(
                        "\nError: Incorrect amount of input for command. Consult README for more info"
                    )

                # if game has ended and board + info not reset
                elif u.check_game_status(black_win, white_win, draw):
                    print(
                        "\nThe game has ended. To start a new game, please use the 'reset' command"
                    )

                else:
                    inp = command[1]

                    # if invalid input
                    if not inp.isalpha():
                        print(
                            "\nError: Incorrect input for command. Consult README for more info"
                        )

                    else:
                        # change player-to-move
                        player, opponent = com.changeptm_cmd(
                            inp, player, opponent)

            # winner command
            elif command[0] == "winner":

                # if too many arguments
                if len(command) > 1:
                    print(
                        "\nError: Command does not require additional input. Consult README for more info"
                    )

                else:
                    # display current game status
                    com.winner_cmd(black_win, white_win, draw)

            # showboard command
            elif command[0] == "showboard":

                # if too many arguments
                if len(command) > 1:
                    print(
                        "\nError: Command does not require additional input. Consult README for more info"
                    )

                else:
                    # display current board
                    u.show_board(board, boardsize)

            # capturecounts command
            elif command[0] == "capturecounts":

                # if too many arguments
                if len(command) > 1:
                    print(
                        "\nError: Command does not require additional input. Consult README for more info"
                    )

                else:
                    # display capture counts for each player
                    com.capturecounts_cmd(black_capture_count,
                                          white_capture_count)

            # playcpugame command
            elif command[0] == "playcpugame":

                # if too many arguments
                if len(command) > 1:
                    print(
                        "\nError: Command does not require additional input. Consult README for more info"
                    )

                else:
                    # reset game information
                    player, opponent = u.reset_players()
                    black_capture_count, white_capture_count = u.reset_cap_counts(
                    )
                    black_win, white_win, draw = u.reset_win_status()
                    # build new board
                    board, move_history = u.build_board(boardsize)
                    u.show_board(board, boardsize)
                    # user choice of player for black
                    inp1 = input(
                        "Choose the player for black. 1 for Random, 2 for Heuristic: "
                    )
                    inp1check = False

                    # while input not validated
                    while not inp1check:

                        # if input invalid
                        if inp1 != "1" and inp1 != "2":
                            print(
                                "\nError: Incorrect input for command. Consult README for more info"
                            )
                            inp1 = input(
                                "Choose the player for black. 1 for Random, 2 for Heuristic: "
                            )

                        else:
                            # input validated
                            inp1check = True

                    # user choice of player for white
                    inp2 = input(
                        "Choose the player for white. 1 for Random, 2 for Heuristic: "
                    )
                    inp2check = False

                    # while input not validated
                    while not inp2check:

                        # if input invalid
                        if inp2 != "1" and inp2 != "2":
                            print(
                                "\nError: Incorrect input for command. Consult README for more info"
                            )
                            inp2 = input(
                                "Choose the player for white. 1 for Random, 2 for Heuristic: "
                            )

                        else:
                            # input validated
                            inp2check = True

                    # if both black and white are using random player
                    if inp1 == "1" and inp2 == "1":

                        # while game is ongoing
                        while not black_win and not white_win and not draw:

                            # generate and play random moves
                            board, player, opponent, black_capture_count, white_capture_count,\
                                black_win, white_win, draw \
                                = com.genmove_cmd(board, boardsize, player, opponent, black_capture_count,
                                      white_capture_count, black_win, white_win, draw, move_history, ruleset)

                    # if black using heuristic, white using random
                    elif inp1 == "2" and inp2 == "1":

                        # while game is ongoing
                        while not black_win and not white_win and not draw:

                            # obtain black's heuristic-determined move
                            black_move = com.current_position_evaluation(
                                player, opponent, board, boardsize,
                                move_history, ruleset, 1)
                            # play specified move
                            board, player, opponent, black_capture_count, white_capture_count,\
                                black_win, white_win, draw \
                                = com.play_cmd(board, boardsize, player, opponent, black_capture_count,
                                           white_capture_count, black_win, white_win, draw, black_move, move_history)

                            # if black's move did not end the game
                            if not black_win and not white_win and not draw:
                                # generate and play random move for white
                                board, player, opponent, black_capture_count, white_capture_count,\
                                    black_win, white_win, draw \
                                    = com.genmove_cmd(board, boardsize, player, opponent, black_capture_count,
                                          white_capture_count, black_win, white_win, draw, move_history, ruleset)

                    # if black using random, white using heuristic
                    elif inp1 == "1" and inp2 == "2":

                        # while game is ongoing
                        while not black_win and not white_win and not draw:

                            # generate and play random move for black
                            board, player, opponent, black_capture_count, white_capture_count,\
                                black_win, white_win, draw \
                                = com.genmove_cmd(board, boardsize, player, opponent, black_capture_count,
                                      white_capture_count, black_win, white_win, draw, move_history, ruleset)

                            # if black's move did not end the game
                            if not black_win and not white_win and not draw:
                                # obtain white's heuristic-determined move
                                white_move = com.current_position_evaluation(
                                    player, opponent, board, boardsize,
                                    move_history, ruleset, 1)
                                # play specified move
                                board, player, opponent, black_capture_count, white_capture_count,\
                                    black_win, white_win, draw \
                                    = com.play_cmd(board, boardsize, player, opponent, black_capture_count,
                                               white_capture_count, black_win, white_win, draw, white_move, move_history)

                    # if both black and white using heuristic player
                    elif inp1 == "2" and inp2 == "2":

                        # while game is ongoing
                        while not black_win and not white_win and not draw:
                            # obtain black's heuristic-determined move
                            black_move = com.current_position_evaluation(
                                player, opponent, board, boardsize,
                                move_history, ruleset, 1)
                            # play specified moved
                            board, player, opponent, black_capture_count, white_capture_count,\
                                black_win, white_win, draw \
                                = com.play_cmd(board, boardsize, player, opponent, black_capture_count,
                                           white_capture_count, black_win, white_win, draw, black_move, move_history)

                            # if black's move did not end the game
                            if not black_win and not white_win and not draw:
                                # obtain white's heuristic-determined move
                                white_move = com.current_position_evaluation(
                                    player, opponent, board, boardsize,
                                    move_history, ruleset, 1)
                                # play specified move
                                board, player, opponent, black_capture_count, white_capture_count,\
                                    black_win, white_win, draw \
                                    = com.play_cmd(board, boardsize, player, opponent, black_capture_count,
                                               white_capture_count, black_win, white_win, draw, white_move, move_history)

            # movehistory command
            elif command[0] == "movehistory":
                # display move history for current game
                com.movehistory_cmd(command, move_history)

            # changerules command
            elif command[0] == "changerules":
                # user choice for ruleset change or cancel
                arg = input(
                    "\nEnter 1 for Tournament Rules, enter 2 for Casual Rules, enter c to cancel: "
                )
                argcheck = False

                # while input not validated
                while not argcheck:

                    # if input invalid
                    if arg != "1" and arg != "2" and arg != "c":
                        print(
                            "\nError: Incorrect input for command. Consult README for more info"
                        )
                        # display current ruleset
                        u.check_ruleset(ruleset)
                        arg = input(
                            "\nEnter 1 for Tournament Rules, enter 2 for Casual Rules, enter c to cancel: "
                        )

                    else:
                        # input validated
                        argcheck = True

                # if user wants to cancel rule change
                if arg == "c":
                    # display current ruleset
                    u.check_ruleset(ruleset)
                    # display current board
                    u.show_board(board, boardsize)

                else:
                    # change ruleset
                    ruleset = int(arg)
                    # display current ruleset
                    u.check_ruleset(ruleset)
                    # reset game information
                    player, opponent = u.reset_players()
                    black_capture_count, white_capture_count = u.reset_cap_counts(
                    )
                    black_win, white_win, draw = u.reset_win_status()
                    # build new board
                    board, move_history = u.build_board(boardsize)
                    u.show_board(board, boardsize)

            # rules command
            elif command[0] == "rules":
                # display current ruleset
                u.check_ruleset(ruleset)

            # startgame command
            elif command[0] == "startgame":
                # initialize a player vs. cpu game
                com.startgame_cmd(boardsize, ruleset)

            # poseval command
            elif command[0] == "poseval":

                # if too many argument
                if len(command) > 1:
                    print(
                        "\nError: Command does not require additional input. Consult README for more info"
                    )

                else:

                    # if game has ended and board + info not reset
                    if u.check_game_status(black_win, white_win, draw):
                        print(
                            "\nThe game has ended. To start a new game, please use the 'reset' command"
                        )

                    else:
                        # display evaluation for player-to-move's current position
                        com.current_position_evaluation(
                            player, opponent, board, boardsize, move_history,
                            ruleset)

        user_inp = input("\nPlease enter a command: ")