Prolog finding variables -
% check if 2 squares colide sides col( x, y, s, x2, y2, s2):- endx x + s, endy y + s, endx2 x2 + s2, endy2 y2 + s2, ( ( endx =:= x2, ( (y >= y2, y =< endy2);(endy >= y2, endy =< endy2))); % left-l side ( x =:= x2, ( (y >= y2, y =< endy2);(endy >= y2, endy =< endy2))); % left-r side ( endx =:= endx2, ( (y >= y2, y =< endy2);(endy >= y2, endy =< endy2))); % right-l side ( x =:= endx2, ( (y >= y2, y =< endy2);(endy >= y2, endy =< endy2))); % right-r side ( endy =:= y2, ( (x >= x2, x =< endx2);(endx >= x2, endx =< endx2))); % top-t side ( y =:= y2, ( (x >= x2, x =< endx2);(endx >= x2, endx =< endx2))); % top-b side ( endy =:= endy2, ( (x >= x2, x =< endx2);(endx >= x2, endx =< endx2))); % bottom-t side ( y =:= endy2, ( (x >= x2, x =< endx2);(endx >= x2, endx =< endx2))) % bottom-b side ).
it's working when set variables, wanted ask how change use: col( 0,0,3,1,2,s).
or col( 0, 0, 3, x,y, s).
possible?
i think try library(clpqr):
:- [library(clpr)]. col( x, y, s, x2, y2, s2):- { endx = x + s, endy = y + s, endx2 = x2 + s2, endy2 = y2 + s2, ( ( endx = x2, ( (y >= y2, y =< endy2);(endy >= y2, endy =< endy2))); % left-l side ( x = x2, ( (y >= y2, y =< endy2);(endy >= y2, endy =< endy2))); % left-r side ( endx = endx2, ( (y >= y2, y =< endy2);(endy >= y2, endy =< endy2))); % right-l side ( x = endx2, ( (y >= y2, y =< endy2);(endy >= y2, endy =< endy2))); % right-r side ( endy = y2, ( (x >= x2, x =< endx2);(endx >= x2, endx =< endx2))); % top-t side ( y = y2, ( (x >= x2, x =< endx2);(endx >= x2, endx =< endx2))); % top-b side ( endy = endy2, ( (x >= x2, x =< endx2);(endx >= x2, endx =< endx2))); % bottom-t side ( y = endy2, ( (x >= x2, x =< endx2);(endx >= x2, endx =< endx2))) % bottom-b side ) }.
test:
?- col( 0,0,3,1,2,s). s = 2.0 ; false.
with more variables you're left ranges handle:
?- col( 0, 0, 3, x,y, s). x = 3.0, {y=< -0.0, _g6533>=0.0, s= -y+_g6533, _g6550=3.0-y+_g6533} ; x = 3.0, {y=<3.0, _g8171>=3.0, s= -y+_g8171, _g8188=3.0-y+_g8171} ; x = 0.0, {y=< -0.0, _g10154>=0.0, s= -y+_g10154, _g10171= -y+_g10154} . ...