function tf = xwins(A)
%XWINS Does X have tic-tac-toe?
%   tf = xwins(A) returns true if X wins on the
%   tic-tic-toe board A. A is a square matrix.
%
%   X wins if any row, any column, or either main
%   diagonal of A is made up of all 1s.

[rows, cols] = size(A);
% check rows
tf = false;
for r = 1:rows
    if all(A(r, :) == 1)
        tf = true;
    end
end

% check columns
if ~tf
    for c = 1:cols
        if all(A(:, c) == 1)
            tf = true;
        end
    end
end

% check main diagonal
if ~tf
    tf = true;
    for r = 1:rows
        if A(r, r) ~= 1
            tf = false;
        end
    end
end

% check second diagonal
if ~tf
    tf = true;
    for r = 1:rows
        if A(r, cols - r + 1) ~= 1
            tf = false;
        end
    end
end
