/*
 * nocheck(L, X/Y) takes a queen X/Y and a list
 * of queens. It succeeds if and only if the X/Y
 * queen holds none of the others in check.
 */

nocheck([], _).
nocheck([X1/Y1 | Rest], X/Y) :-
    % X =\= X1,
    Y =\= Y1,
    abs(Y1-Y) =\= abs(X1-X),
    nocheck(Rest, X/Y).

/*
 * legal(L) succeeds if L is a legal placement of
 * queens: all coordinates in range and no queen
 * in check.
 */
legal([]).
legal([X/Y | Rest]) :-
    legal(Rest),
    % member(X, [1,2,3,4,5,6,7,8]),
    member(Y, [1,2,3,4,5,6,7,8]),
    nocheck(Rest, X/Y).

/*
 * eightqueens(X) succeeds if X is a legal
 * placement of eight queens, listed in order
 * of their X coordinates.
 */

eightqueens(X) :-
    X = [1/_,2/_,3/_,4/_,5/_,6/_,7/_,8/_],
    legal(X).
