forked from oreillyj-cse/Fall19PrologCode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblocks.pl
21 lines (17 loc) · 780 Bytes
/
blocks.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
% on(X,Y) means that block X is directly on top of block Y.
on(b1,b2). on(b3,b4). on(b4,b5). on(b5,b6).
% just left(X,Y) means that blocks X and Y are on the table
% and that X is immediately to the left of Y.
just_left(b2,b6). just_left(b6,b7).
% above(X,Y) means that block X is somewhere above block Y
% in the pile where Y occurs.
above(X,Y) :- on(X,Y).
above(X,Y) :- on(X,Z), above(Z,Y).
% left(X,Y) means that block X is somewhere to the left
% of block Y but perhaps higher or lower than Y.
left(X,Y) :- just_left(X,Y).
left(X,Y) :- just_left(X,Z), left(Z,Y).
left(X,Y) :- on(X,Z), left(Z,Y). % leftmost is on something.
left(X,Y) :- on(Y,Z), left(X,Z). % rightmost is on something.
% right(X,Y) is the opposite of left(X,Y).
right(Y,X) :- left(X,Y).