clear clc A=zeros(8); % r=randperm(8); for j=1:8 % place queens r=randperm(8); r=r(1); A(r,j)=1; end clear r j show_the_solution(A) % show pause(0.2) number_of_attacks = find_attacks(A) qq=number_of_attacks; if number_of_attacks == 0 show_the_solution(A) return end counter=0; while number_of_attacks ~= 0 current_table = fill_table(A); counter=counter+1; [x y z]=find_minimums(current_table); if z >= number_of_attacks % if ">" the algorithm allows side moves % if ">=" no side moves disp('No solution this time.') xlabel('No solution this time.','FontSize',16) break end A=move_one_queen(current_table,A,x,y,z); [u v]=find(A); number_of_attacks=find_attacks(A); qq(end+1)=number_of_attacks; show_the_solution(A) text(-1.5,3.5,'counter','FontSize',16) ylabel(counter,'rotation',0,'FontSize',16) pause(0.2) end if number_of_attacks ==0 xlabel('Solution!','FontSize',16) end qq