function number_of_attacks = find_attacks_universal(A) % This functions finds the attacks on the board for arbitrary table size. % The function is called with the board matrix A N = size(A, 1); [a b]=find(A); number_of_attacks=0; for i=1:N-1 p1=a(i); q1=b(i); for j=i+1:N p2=a(j); q2=b(j); if ((p1==p2) || (q1==q2) || abs(p1-p2)==abs(q1-q2)) % number_of_attacks = 1; % delete this later % return; % delete this later, not part of the program number_of_attacks=number_of_attacks+1; end end end end