/** on(Square1,S1Z1,S1Z2,Square2,S2Z1,S2Z2) checks whether Cube 1 with top and bottom faces Square1, bottom S1Z1 and top S1Z2 is on Cube 2 with top and bottom faces Square2, bottom S2Z1 and top S2Z2. same(+Square1,+Square2,-EmptyList) checks whether Square1 and Square2 are the same ?- on([[0,0],[1,0],[0,1],[1,1]],1,2,[[0,0],[1,0],[0,1],[1,1]],0,1). Yes **/ on(Square1,S1Z1,_,Square2,_,S2Z2) :- S1Z1=S2Z2, same(Square1,Square2,_). same([],_,[]). same([Point1|Points1],Square2,Square4) :- delete(Square2,Point1,Square3), same(Points1,Square3,Square4).