%   TTTClickSquarePBCB.m
%   Description:
%   Inputs:
%   Outputs:
%   Team DATT "All DATT and dim sum."

if CurrentPlayer == 'Human'
    if get(gcbo,'string') == ' '
        SquarePosition = get(gcbo,'tag');
        SquarePosition = str2num(SquarePosition(4)); %Assigns number in tag
        
        if CurrentTurn == 'X'
            set(gcbo,'string','X')
            MainGame(SquarePosition) = -1; 
            CurrentTurn = 'O';
        else
            set(gcbo,'string','O')
            MainGame(SquarePosition) = 1;
            CurrentTurn = 'X';
        end
        CurrentPlayer = 'Compu'
    else
        break %Space is taken, not a valid move.
    end
    TTTWhoWon

    
    CompMoveValid = 0
    while CompMoveValid == 0
        CompMove = 10; %CompMove has not been generated.
        while (CompMove == 10)|(CompMove == 0)
            CompMove = floor(9*rand(1,1)+1) %randint(1,1,[1,9]) %Random move generated for Easy Computer
        end
        if get(findobj('tag',strcat('Pos',num2str(CompMove))),'string') == ' '
            if CurrentTurn == 'X'
                set(findobj('tag',strcat('Pos',num2str(CompMove))),'string','X')
                MainGame(CompMove) = -1;
                CurrentTurn = 'O';
            else
                set(findobj('tag',strcat('Pos',num2str(CompMove))),'string','O')
                MainGame(CompMove) = 1;
                CurrentTurn = 'X';
            end
            CurrentPlayer = 'Human';
            CompMoveValid = 1;
        else
            CompMoveValid = 0; %No need for this code but... says the comp's choice isn't good.
        end
    end
    TTTWhoWon
else
    CompMove = 10; %CompMove has not been generated yet.
    while (CompMove == 10)|(CompMove == 0)
        CompMove = floor(9*rand(1,1)+1) %randint(1,1,[1,9]) %Random move generated for Easy Computer
    end
    if get(findobj('tag',strcat('Pos',num2str(CompMove))),'string') == ' '
        if CurrentTurn == 'X'
            set(findobj('tag',strcat('Pos',num2str(CompMove))),'string','X')
            MainGame(CompMove) = -1;
            CurrentTurn = 'O';
        else
            set(findobj('tag',strcat('Pos',num2str(CompMove))),'string','O')
            MainGame(CompMove) = 1;
            CurrentTurn = 'X';
        end
        CurrentPlayer = 'Human';
    end
    TTTWhoWon
end