function [B] = attackedPositions(A, N) B = zeros(N); [p q] = find(A); positions = [p q]; for i = 1 : size(positions,1) temp1 = positions(i, 1); temp2 = positions(i, 2); % B(positions(i, 1), positions(i, 2)) = 1; % B(positions(i, 1), :) = 1; % row % B(:, positions(i, 2)) = 1; % column B(temp1, temp2) = 1; B(temp1, :) = 1; B(:, temp2) =1; while (temp1 > 0 && temp2 > 0) B(temp1, temp2) = 1; % left up temp1 = temp1 - 1; temp2 = temp2 - 1; end temp1 = positions(i, 1); temp2 = positions(i, 2); while (temp1 < N+1 && temp2 < N+1) B(temp1, temp2) = 1; % right down temp1 = temp1 + 1; temp2 = temp2 + 1; end temp1 = positions(i, 1); temp2 = positions(i, 2); while (temp1 > 1 && temp1 < N && temp2 > 1 && temp2 < N) B(temp1, temp2) = 1; % right up temp1 = temp1 - 1; temp2 = temp2 + 1; end temp1 = positions(i, 1); temp2 = positions(i, 2); while (temp1 > 1 && temp1 < N && temp2 > 1 && temp2 < N) B(temp1, temp2) = 1; % left down temp1 = temp1 + 1; temp2 = temp2 - 1; end end end