I am writing a rule in Prolog to create a fact, pit(x,y). This rule below is called three times from my main function, and it is inserting three pits in which none of them is at (1,1) or (1,2) or (2,1) but the problem is that sometimes 2 pits have the same x and y where x and y can be from 1 to 4 only. (4x4 grid)
placePit(_) :- Px is random(4)+1,
Py is random(4)+1,
write(Px),
write(' '),
writeln(Py),
(Px =\= 1;
Py =\= 1),
(Px =\= 1;
Py =\= 2),
(Px =\= 2;
Py =\= 1)
->
pit(Px,Py);
placePit(4).
I don't want this to happen, so I write another rule to check whether 2 pits are the same first and will extend later to REMOVE EITHER ONE from the database. From what I have tested, it doesn't get fired at all even though 2 pits appear to be the same. What am I doing wrong? How to remove duplicate facts?
pit(A,B) :- pit(C,D),
A = C,
B = D,
write('Duplicate').
PS. I am very new at Prolog. Any suggestion is appreciated.