%   TTTClickSquarePBCB.m
%   Description: 
%       This callback is called whenever a Position Square Button (ex. 
%   'Pos1') on the 'TicTacToe.fig' is pressed.
%       If the game is not over (GameOver==false) and the current player 
%   is Human (CurrentPlayer=='Human'), this script checks to see if the 
%   position clicked (gcbo) is taken. If the position is taken, the script
%   does nothing.If the position is available, it updates the display, 
%   updates the virtual main board (MainGame), and calls the script 
%   TTTWhoWon to check for any wins. If the game is still not over after 
%   the human's move, the script calls TTTCompMove to make a computer move.
%       If this script is called while it is the computer's turn, it calls
%   TTTCompMove.
%       If this script is called after the game is over (GameOver==true),
%   it does nothing.
%
%   Variables:
%       GameOver, boolean, keeps track of whether the current game is over
%          or not
%       CurrentPlayer, string, keeps track of who's turn it is
%       StartNewGame, boolean, keeps track of whether or not a new game
%           must be started because a current game is running
%       SquarePosition, string, temporary variable to store tag of clicked
%           square
%       MainGame, 3x3 matrix, board with values for X's and O's in
%             appropriate positions
%       CurrentTurn, char, keeps track of which mark is current (X or O)
%
%   Output:
%       Updates figure with appropriate move (X or O)
%
%   Team DATT "All DATT and dim sum."
%   12-05-05

if GameOver == false    
    if CurrentPlayer == 'Human'
        StartNewGame = true; %Confirmation for TTTNewGamePBCB that a new 
                           %game must start because this one is in progress
        if get(gcbo,'string') == ' '
            SquarePosition = get(gcbo,'tag');
            SquarePosition = str2num(SquarePosition(4)); %Assigns Square #
                                                         %(4th char in tag)
            if CurrentTurn == 'X'
                set(gcbo,'string','X')
                MainGame(SquarePosition) = -1; %-1 represents X's
                CurrentTurn = 'O';
            else
                set(gcbo,'string','O')
                MainGame(SquarePosition) = 1; %-1 represents O's
                CurrentTurn = 'X';
            end
            CurrentPlayer = 'Compu';
        else
            break %Space is taken, not a valid move.
        end
        TTTWhoWon
        
        if GameOver == false
            TTTCompMove
        end
    else
        TTTCompMove
    end
end