I have 3 recursive rules but one of them never unifies with my query.
checkCollisionDiagonal(QueenTarget,[],Qdist,0).
checkCollisionDiagonal(QueenTarget, [Q|QueenList], Qdist, X):-
abs(QueenTarget - Q) =\= Qdist,
NextQdist is Qdist + 1,
checkCollisionDiagonal(QueenTarget, QueenList, NextQdist, X).
checkCollisionDiagonal(QueenTarget, [Q|QueenList], Qdist, X):-
abs(QueenTarget - Q) = Qdist,
NextQdist is Qdist + 1,
checkCollisionDiagonal(QueenTarget, QueenList, NextQdist, X1),
X is X1+1.
The statement where the absolute value is different from Qdist works fine, if it doesn't unify my program should check the next statement (the one with absolute value equal to Qdist), but using trace I noticed that the second statement (abs = Qdist) is never evaluated. Why does it happens?
My query is checkCollisionDiagonal(1, [2,1,4,1], 1, X).
and the expected result should be 2 but it always returns false