function f = FitnessFunction8queens(x)

KATASTASH=zeros(8,8);
row=9-x;
for col=1:8
    KATASTASH(row(col),col) = 1;
end

Q=zeros(1,8);
for col=1:8
    d1 = sum(diag(KATASTASH,-row(col)+col))-1;          % diagonios \
    d2 = sum(diag(flip(KATASTASH),row(col)-(9-col)))-1; % diagonios /
    Q(col) = (sum(KATASTASH(:,col))-1)+(sum(KATASTASH(row(col),:))-1) + d1 + d2; % sthlh & grammh + diagwnioi
    KATASTASH(row(col),col)=0;
end

f = sum(Q);

end