function number_of_attacks = find_attacks_gen(A) % finds thenumber of attacks for queens for the general case. % The board does not have to be square shape, and the number of % queens is arbitrary. If queens "P" and "Q" attacks each other, % it counts for 1 attack, not 2. [a b]=find(A); number_of_attacks=0; for i=1:numel(a)-1 % N-1 p1=a(i); q1=b(i); for j=i+1:numel(a) % N p2=a(j); q2=b(j); if ((p1==p2) || (q1==q2) || abs(p1-p2)==abs(q1-q2)) number_of_attacks=number_of_attacks+1; end end end end