%   TTTStartGamePBCB.m
%   Description:
%       This script will check the current state of the game to see if a
%   player has won. If the human has won, it gets the current number for
%   wins, adds 1, and displays the new number. This script does the same
%   thing for a loss and tie.
%
%   Variables:
%       StartNewGame, boolean, keeps track of whether or not a new game
%           must be started because a current game is running
%       GameOver, boolean, keeps track of whether the current game is over
%          or not
%       MainGame, 3x3 matrix, board with values for X's and O's in
%           appropriate positions
%       CurrentPlayer, string, keeps track of who's turn it is
%       Wins, integer, temporary variable to store the number of wins
%       Losses, integer, temporary variable to store the number of losses
%       Ties, integer, temporary variable to store the number of ties
%
%   Team DATT "All DATT and dim sum."
%   11/17/05

for x = 1:3
    if sum(MainGame(x,:))==3|sum(MainGame(:,x))==3|...
           (MainGame(1)+MainGame(5)+MainGame(9))==3|...
           (MainGame(7)+MainGame(5)+MainGame(3))==3
        if CurrentPlayer == 'Compu' %Means that last turn was Human's
            Wins = get(findobj('tag','WinNumST'),'string');
            Wins = str2num(Wins) + 1;
            set(findobj('tag','WinNumST'),'string',num2str(Wins))
        else
            Losses = get(findobj('tag','LossesNumST'),'string');
            Losses = str2num(Losses) + 1;
            set(findobj('tag','LossesNumST'),'string',num2str(Losses))
        end
        StartNewGame=false;
        GameOver=true;
        return
    end
    if sum(MainGame(x,:))==-3|sum(MainGame(:,x))==-3|...
           (MainGame(1)+MainGame(5)+MainGame(9))==-3|...
           (MainGame(7)+MainGame(5)+MainGame(3))==-3
        if CurrentPlayer == 'Compu' %Means that last turn was Human's
            Wins = get(findobj('tag','WinNumST'),'string');
            Wins = str2num(Wins) + 1;
            set(findobj('tag','WinNumST'),'string',num2str(Wins))
        else
            Losses = get(findobj('tag','LossesNumST'),'string');
            Losses = str2num(Losses) + 1;
            set(findobj('tag','LossesNumST'),'string',num2str(Losses))
        end
        StartNewGame=false;
        GameOver=true;
        return
    end
end

if GameOver == false
    for x = 1:9
        if MainGame(x) == 0
            return %MainGame is not full, therefore no chance for a tie
        end
    end
    Ties = get(findobj('tag','TiesNumST'),'string');
    Ties = str2num(Ties) + 1;
    set(findobj('tag','TiesNumST'),'string',num2str(Ties))
    GameOver = true;
    StartNewGame=false;
end