function [neighs] = find_neighs(tokens,i,j,p)
%
% create search array
vdsrch_nsew = [1 0; 0 1; -1 0; 0 -1];
% determine game grid dimension from tokens array
nmax = length(tokens);
% create empty output vector
neighs = [];
% search surrounding cells for player p squares (loop through directions)
% and return a vector of linear indices of all finds
% NOTE: only count N-S-E-W connection directions
for s = 1:length(vdsrch_nsew)
    loc_j = j + vdsrch_nsew(s,1);
    loc_i = i + vdsrch_nsew(s,2);
    % avoid searching beyond game edges!
    if ( (loc_i >= 1) && (loc_j >= 1) && (loc_i <= nmax) && (loc_j <= nmax) )
        if (tokens(loc_i,loc_j) == p)
            neighs = [neighs sub2ind([nmax nmax],loc_i,loc_j)];
        end
    end
end
end
