function moves = findmoves(hand, table)
%  FINDMOVES  Determines all moves that can be made from the given hand.
%  FINDMOVES(HAND, TABLE), where HAND is the player's hand, and TABLE
%  represents the current table configuration of Seven, returns a list
%  containing all moves that can made from the given hand.
%  THIS FUNCTION UPDATES GLOBAL VARIABLES.


%
%  Assume there are no moves.
%
moves = [];

%
%  For each suit, check both the low and high side and see if the player's
%  hand contains the next card in the run.  If so, add the card to the moves
%  list.
%
if ~isempty(hand)
    for suit = 1:4

        lo = table(suit, 1) - 1;
        if ((lo >= 1) & (lo <= 7))

            card = lo + (suit - 1) * 13;
            index = find(hand == card);
	    if (index > 0)
                moves = [moves card];
            end
        end

        hi = table(suit, 2) + 1;
        if ((hi <= 13) & (hi > 7))

            card = hi + (suit - 1) * 13;
            index = find(hand == card);
	    if (index > 0)
                moves = [moves card];
            end
        end
    end
end
