In evolutionary computation and, in particular, in the context of genetic algorithms, there is the concept of a fitness function. The better a state, the greater the value of the fitness function for that state.
What would be a good fitness function for the 8-queens problem?