function number_of_attacks = find_attacks_YES_NO(A) % This functions finds the attacks on the board for arbitrary table size. % The function is called with the board matrix A % The return value is either 0 (no attacks) or 1 (at least 1 attack) % The function terminates when the first attck is found 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