You are on page 1of 27

LINGAYA’ S VIDYAPEETH, FARIDABAD

(U/S 3 of UGC Act, 1956)

ARTIFICIAL INTELLIGENCE LAB


CA- 1354 A

LAB FILE
BCA 3rd Year

Nachauli, Old Faridabad-Jasana Road,

Faridabad 121002, Phone: (129) 2201008, 2201009;

WebSite: www.lingayasuniversity.edu.in

Name :………………………………………………………

Roll No :…………………….. Branch: ………………

Group :……………………….. Session: 20….. – 20……

SCHOOL OF COMPUTER SCIENCE

0
PROGRAM NO. - 1

OBJECTIVES: STUDY OF PROLOG

PROLOG-PROGRAMMING IN LOGIC

PROLOG stands for Programming In Logic – an idea that emerged in the early 1970 ’s to use
logic as programming language. The early developers of this idea included Robert Kowalski at
Edinburgh ( on the theoretical side ), Marrten van Emden at Edinburgh ( experimental
demonstration) and Alian Colmerauer at Marseilles (implementation ). David D.H. Warren’s
efficient implementation at Edinburgh in the mid -1970’s greatly contributed to the popularity of
PROLOG.

PROLOG is a programming language centered around a small set of basic mechanisms,


Including pattern matching, tree based data structuring and automatic backtracking. This Small
set constitutes a surprisingly powerful and flexible programming framework. PROLOG is
especially well suited for problems that involve objects- in particular, structured objects- and
relations between them.

SYMBOLIC LANGUAGE

PROLOG is a programming language for symbolic, non-numeric computation. It is Especially


well suited for solving problems that involve objects and relations between objects. For example,
it is an easy exercise in prolog to express spatial relationship between objects, such as the blue
sphere is behind the green one. It is also easy to state a more general rule: if object X is closer to
the observer than object Y, and object Y is closer than Z, then X must be closer than Z. PROLOG
can reason about the spatial relationships and their consistency with respect to the general rule.
Features like this make PROLOG a powerful language for Artificial Language(AI) and non-
numerical programming.

There are well-known examples of symbolic computation whose implementation in other


standard languages took tens of pages of indigestible code. When the same algorithms were
implemented in PROLOG, the result was a crystal-clear program easily fitting on one page.

FACTS, RULES AND QUERIES

Programming in PROLOG is accomplished by creating a database of facts and rules about


objects, their properties, and their relationships to other objects. Queries then can be posed about
the objects and valid conclusions will be determined and returned by the program. Responses to
user queries are determined through a form of inferencing control known as resolution.

1
FOR EXAMPLE:

a) FACTS:

b) Properties of objects, or relationships between objects;


c) "Dr Turing lectures in course 9020", is written in Prolog as:
d) lectures(turing, 9020).

b ) RULES:

To represent the general rule for grandfather, we write:

grandfather(X,Z)

parent(X,Y)

parent(Y,Z)

male(X)

c) QUERIES:

 Once we have a database of facts (and, soon, rules) we can ask questions about the stored
information.
 Suppose we want to know if Turing lectures in course 9020. We can ask:
 lecture(turnig,9020).

Applications of Prolog

Some applications of Prolog are:

 intelligent data base retrieval


 natural language understanding
 expert systems
 specification language
 machine learning
 robot planning
 automated reasoning

2
 problem solving

PROGRAM NO. – 2

AIM: TO FIND THE ROUTE DISTANCE BETWEEN TWO CITIES

road("Karimnagar","Warangal",100).
road("Karimnagar","Hyderabad",120).
road("Hyderabad","Warangal",120).
road("Warangal","Vijaywada",120).
road("Hyderabad","Vijaywada",120).
road("Hyderabad","Kazipet",170).
road("Kazipet","Vijaywada",220).
road("Warangal","Vishakapatnam",170).
road("Vijaywada","Vishakapatnam",120).

route(Town1,Town2,Distance):-
road(Town1,Town2,Distance).

route(Town1,Town2,Distance):-
road(Town1,X,Dist1),
route(X,Town2,Dist2),
Distance=Dist1+Dist2,
!.

route("Karimnagar", "Vishakapatnam", X),


write("Distance from Karimnagar to Vishakapatnam is ",X),nl.

Output:

Distance from Karimnagar to Vishakapatnam is 270


X=270
1 Solution

3
PROGRAM NO. – 3

AIM: TO IMPLEMENT TOWER OF HANOI

Tower(1,A,C,B):-
write("move from",A,"to",C),nl.
Tower(N,A,C,B):-
Z=N-1,
Tower(Z,A,B,C),
write("move from",A,"to",C),nl,
Tower(Z,B,C,A).

Output:

move from1to3
move from1to2
move from3to2
move from1to3
move from2to1
move from2to3
move from1to3
yes

4
PROGRAM NO. – 4

AIM: TO CALCULATE THE FACTORIAL OF A NUMBER

fact(integer,integer)
go

clauses
go:-
write("enter the no."),nl,
readint(A),
B=1,
fact(A,B).
fact(A,B):-
A<>1,
Y=A-1,
Z=A*B,
fact(Y,Z).
fact(1,B):-
write("factorial is",B).

Output:

enter the no.


6
factorial is720yes

5
PROGRAM NO. – 5

AIM: TO IMPLEMENT HARDWARE SIMULATION USING LOGICAL GATES

not_(D,D)
and_(D,D,D)
or_(D,D,D)
txor_(D,D,D)

CLAUSES
not_(1,0). not_(0,1).
and_(0,0,0). and_(0,1,0).
and_(1,0,0). and_(1,1,1).
or_(0,0,0). or_(0,1,1).
or_(1,0,1). or_(1,1,1).

% See the documentarion for the XOR circuit


txor_(Input1,Input2,Output):-
not_(Input1,N1),
not_(Input2,N2),
not_(Input3,N3),
not_(Input4,N4),

and_(Input1,N2,N6),
and_(Input2,N1,N5),
and_(Input3,N4,N8),
and_(Input4,N3,N7),

or_(N5,N6,N9),
or_(N7,N8,N10),
or_(N9,N10,Output).

txor_(Input1,Input2,Output), % Use GOAL mode to see results !!!


format(Msg," xor_(%,%,%)",Input1,Input2,Output),
write(Msg).

Output:

xor_(1,1,0)Input1=1, Input2=1, Output=0, Msg= xor_(1,1,0)


xor_(1,1,1)Input1=1, Input2=1, Output=1, Msg= xor_(1,1,1)
xor_(1,1,1)Input1=1, Input2=1, Output=1, Msg= xor_(1,1,1)
6
xor_(1,1,0)Input1=1, Input2=1, Output=0, Msg= xor_(1,1,0)
xor_(1,0,1)Input1=1, Input2=0, Output=1, Msg= xor_(1,0,1)
xor_(1,0,1)Input1=1, Input2=0, Output=1, Msg= xor_(1,0,1)
xor_(1,0,1)Input1=1, Input2=0, Output=1, Msg= xor_(1,0,1)
xor_(1,0,1)Input1=1, Input2=0, Output=1, Msg= xor_(1,0,1)
xor_(0,1,1)Input1=0, Input2=1, Output=1, Msg= xor_(0,1,1)
xor_(0,1,1)Input1=0, Input2=1, Output=1, Msg= xor_(0,1,1)
xor_(0,1,1)Input1=0, Input2=1, Output=1, Msg= xor_(0,1,1)
xor_(0,1,1)Input1=0, Input2=1, Output=1, Msg= xor_(0,1,1)
xor_(0,0,0)Input1=0, Input2=0, Output=0, Msg= xor_(0,0,0)
xor_(0,0,1)Input1=0, Input2=0, Output=1, Msg= xor_(0,0,1)
xor_(0,0,1)Input1=0, Input2=0, Output=1, Msg= xor_(0,0,1)
xor_(0,0,0)Input1=0, Input2=0, Output=0, Msg= xor_(0,0,0)
16 Solutions

PROGRAM NO. – 6
7
AIM: TO IMPLEMENT FAMILY RELATIONSHIPS

DATABASE - tmp
son(STRING,STRING)
sister(STRING,STRING)
brother(STRING,STRING)
married(STRING,STRING)

son("Deepak","Jack").
sister("Jiya","swati").
brother("Sonia", "Harsh").
married("Jack", "Jiya").
married("Lokesh", "Sonia").
married("Priya","Deepak").

father(STRING father,STRING child)


grandfather(STRING grandfather,STRING grandchild)
sister_in_law(STRING,STRING)
brother_in_law(STRING,STRING)
father_in_law(STRING,STRING)

father(A,B):-son(B,A).

grandfather(A,B):-father(A,C), father(C,B).

sister_in_law(A,B):-married(A,C), sister(C,B).
sister_in_law(A,B):-brother(A,C), married(C,B).

brother_in_law(A,B):-married(A,C), brother(C,B).
brother_in_law(A,B):-brother(A,C), married(C,B).

father_in_law(A,B):-married(A,C), son(C,B).

father_in_law("Priya",Z),
format(Msg,"father_in_law(\"Priya\",%)",Z),
write(Msg).
%GOAL father_in_law("Priya",Z).

Output:

father_in_law("Priya",Jack)Z=Jack, Msg=father_in_law("Priya",Jack)
PROGRAM NO. – 7

8
AIM: LOGON EXAMPLE WITH RECURSION AND NO REPEAT PREDICATE

logon :-
getinput(Name,Password),

user(Name,Password),
write("You are now logged on."),nl.
logon :-
write("Sorry, you are not permitted access."),
write("Please try again."),nl,
logon.

getinput(Name,Password) :-
write("Please Enter Your Name:"),
readln(Name),nl,
write("Please Enter Password:"),

readln(Password),nl.
user(bill,bigfoot).

user(john,superman).
user(sue,happy).

getinput(Name,Password).

Output:

Please Enter Your Name:bill

Please Enter Password:bigfoot

Name=bill, Password=bigfoot
1 Solution

PROGRAM NO. – 8

9
AIM: TO PRINT THE LIST OF CUSTOMERS HAVING DIFFERENT COLORED CARS
WITH PRICE AND MODEL AVAILABLE.

cust_names([jitander,preeti,veena,avinash,jyeshtha],green).
cust_names([arvind,poonam,abhijeet],white).
cust_names([daya,bhanu,anuradha,anju],red).
model(red,[hyundai_accent,ford_monedo,indgo]).
model(white,[maruti_esteem,maruti_baleno]).
model(green,[toyota_avalon,lotus_elise]).
model(green,[toyta_avalon,lotus_elise]).
price(red,450000).
price(white,350000).
price(green,430000).
cost(green):-
cust_names(A,green),nl,
write(A),nl,
price(green,X),nl,
write("the price of green color car is ",X),nl,
model(green,Y),nl,
write("the model available in green color ",Y),nl.
cost(white):-
cust_names(A,white),nl,
write(A),nl,
price (white,X),nl,
write("the price of white color car is ",X),nl,
model(blue,Y),nl,
write(" the models available in white color ",Y),nl.

goal:
write(" name list of customers who own green color car :-"),nl,
cost(green).
/*write("name list of customers who own red color car :-"),nl,
cost(red).
write("name list of customer who own white color car :-"),nl,
cost(white). */

Output:
name list of customers who own green color car :-

["jitender","preeti","veena","avinash","jyeshtha"]

the price of green color car is 430000

10
the model available in green color ["toyota_avalon","lotus_elise"]
yes

11
PROGRAM NO. – 9

AIM: TO IMPLEMENT WATER JUG PROBLEM

waterjug(X,Y):-
X=0,
Y=0,
write("4l jug empty & 3l jug empty"),nl,
Z=0,
A=3,
waterjug(Z,A).
waterjug(X,Y):-
X=0,
Y=3,
write("4l jug empty & 3ljug 3l water"),nl,
Z=3,
A=0,
waterjug(Z,A).
waterjug(X,Y):-
X=3,
Y=0,
write(" 4l jug 3l water & 3l jug empty"),nl,
Z=3,
A=3,
waterjug(Z,A).
waterjug(X,Y):-
Z=3,
A=3,
write("4l jug 3l water& 3l jug 3l water"),nl,
Z=4,
A=2,
waterjug(Z,A).
waterjug(X,Y):-
X=4,
Y=2,
write("4l jugh 4l water & 3l jug 2l water"),nl,
Z=0,
A=2,
waterjug(Z,A).
waterjug(X,A):-
X=0,
Y=2,
write("4l jug empty & 3l jug 2l water"),nl,
Z=2,
A=0,

12
waterjug(Z,A).
waterjug(X,Y):-
X=2,
Y=0,
write("Goal Achieved").

goal:waterjug(0,0).

Output:

4l jug empty & 3l jug empty


4l jug empty & 3ljug 3l water
4l jug 3l water & 3l jug empty
4l jug 3l water& 3l jug 3l water
4l jug 3l water& 3l jug 3l water
4l jug 3l water& 3l jug 3l water
4l jug empty & 3l jug 2l water
4l jug 3l water& 3l jug 3l water
4l jug empty & 3l jug 2l water
4l jug 3l water& 3l jug 3l water
Goal Achievedyes

PROGRAM NO. – 10

13
AIM: TO IMPLEMENT BREADTH FIRST SEARCH

pop([Head|Tail],S1,X):-
X=Head,
S1=Tail.
append([],LIST1,LIST1).
append([X|LIST1],LIST2,[X|LIST3]):-
append(LIST1,LIST2,LIST3).
checkbfs([]):-
write("STACK NULL").
checkbfs(STACK):-
write("checkbfs"),nl,
pop(STACK,STACK2,X),
test(X,STACK2,S3),
write(S3),nl,
checkbfs(S3).
test(A,STACK2,S3):-
A=5,nl,
write(A,"goal found"),
S3=[].
test(A,STACK2,S3):-
write(A),nl,
S3=STACK2.
go:-
A=[10],B=[7],C=[6],D=[5],E=[12],F=[11],G=[15],
H=[16],I=[17],J=[20],
append(I,J,R1),
append(G,H,R2),
append(E,F,R3),
append(R2,R1,R4),
append(R3,R4,R5),
append(C,D,R6),
append(B,R6,R7),
append(R7,R5,R8),
append(A,R8,R9),
ROOT=R9,
write("Starting Program\n"),nl,
checkbfs(ROOT).

Goal:go.

Output:

Starting Program
14
checkbfs
10
[7,6,5,12,11,15,16,17,20]
checkbfs
7
[6,5,12,11,15,16,17,20]
checkbfs
6
[5,12,11,15,16,17,20]
checkbfs

5goal found[]
STACK NULLyes

PROGRAM NO. – 11

AIM: TO IMPLEMENT DEPTH FIRST SEARCH


15
pop(W,W,Value)
append(W,W,W)
go
checkdfs(W)
test(Value,W,W)

pop([Head|Tail],S1,X):-
X=Head,
S1=Tail.
append([],LIST1,LIST1).
append([X|LIST1],LIST2,[X|LIST3]):-
append(LIST1,LIST2,LIST3).
checkdfs([]):-
write("STACK NULL").
checkdfs(STACK):-
write("checkdfs"),nl,
pop(STACK,STACK2,X),
test(X,STACK2,S3),
write(S3),nl,
checkdfs(S3).
test(A,STACK2,S3):-
A=5,nl,
write(A,"goal found"),
S3=[].
test(A,STACK2,S3):-
write(A),nl,
S3=STACK2.

go:-
D=[16],
E=[12],
F=[11],
G=[6],
H=[8],
I=[28],
J=[5],
A=[14],
append(D,E,A2),
append(A,A2,A1),
B=A1,
append(G,H,B2),
append(F,B2,B3),
append(B,B3,B1),
C1=[7],
append(F,J,C2),
16
append(C1,C2,C),
ROOT1=[10],
append(B,C,R2),
append(A1,R2,R3),
append(ROOT1,R3,ROOT),
write("starting program"),nl,
checkdfs(ROOT).

Goal:go.

Output:

starting program
checkdfs
10
[14,16,12,14,16,12,7,11,5]
checkdfs
14
[16,12,14,16,12,7,11,5]
checkdfs
16
[12,14,16,12,7,11,5]
checkdfs
12
[14,16,12,7,11,5]
checkdfs
14
[16,12,7,11,5]
checkdfs
16
[12,7,11,5]
checkdfs
12
[7,11,5]
checkdfs
7
[11,5]
checkdfs
11
[5]
checkdfs

5goal found[]
STACK NULLyes
17
PROGRAM NO. – 12

AIM: TO IMPLEMENT ZEBRA (FIVE HOUSES LOGIC PUZZLE) PROBLEM

nondeterm solve
18
nondeterm candidate(HLIST,HLIST,HLIST,HLIST,HLIST)
nondeterm perm(HLIST)
nondeterm constraints(HLIST,HLIST,HLIST,HLIST,HLIST)
nondeterm permutation(NOLIST,NOLIST)
nondeterm delete(NO,NOLIST,NOLIST)
member(HOUSE,HLIST)
nondeterm next(NO,NO)
nondeterm lleft(NO,NO)

GOAL solve.

solve() :-
constraints(Colours,Drinks,Nationalities,Cigarettes,Pets),
candidate(Colours,Drinks,Nationalities,Cigarettes,Pets),
member(h(water,WaterHouse), Drinks),member(h(WaterColour,WaterHouse), Colours),
member(h(zebra,ZebraHouse), Pets),member(h(ZebraColour,ZebraHouse), Colours),
write("They drink water in the ",WaterColour," house\n"),
write("The zebra live in the ",ZebraColour," house\n").

candidate(L1, L2, L3, L4, L5) :-


perm(L1),perm(L2),perm(L3),perm(L4),perm(L5).

perm([h(_,A),h(_,B),h(_,C),h(_,D),h(_,E)]) :-
permutation([A,B,C,D,E],[1,2,3,4,5]).

constraints(Colours, Drinks, Nationalities, Cigarettes, Pets) :-


% The Englishman lives in the red house
member(h(englishman,H1), Nationalities),
member(h(red,H1), Colours),
% The Spaniard owns the dog
member(h(spaniard,H2), Nationalities),
member(h(dog,H2), Pets),
% The Norwegian lives in the first house on the lleft
member(h(norwegian,1), Nationalities),
% Kools are smoked in the yellow house.
member(h(kools,H3), Cigarettes),
member(h(yellow,H3), Colours),
% The man who smokes Chesterfields lives in the house
% next to the man with the fox.
member(h(chesterfields,H4), Cigarettes),
next(H4, H5),
member(h(fox,H5), Pets),
% The Norwegian lives next to the blue house
member(h(norwegian,H6), Nationalities),
next(H6, H7),
19
member(h(blue,H7), Colours),
% The Winston smoker owns snails.
member(h(winston,H8), Cigarettes),
member(h(snails,H8), Pets),
% The lucky strike smoker drinks orange juice
member(h(lucky_strike,H9), Cigarettes),
member(h(orange_juice,H9), Drinks),
% The Ukrainian drinks tea
member(h(ukrainian,H10), Nationalities),
member(h(tea,H10), Drinks),
% The Japanese smokes parliaments
member(h(japanese,H11), Nationalities),
member(h(parliaments,H11), Cigarettes),
% Kools are smoked in the house next to the house where the horse is kept.
member(h(kools,H12), Cigarettes),
next(H12, H13),
member(h(horse,H13), Pets),
% Coffee is drunk in the green house
member(h(coffee,H14), Drinks),
member(h(green,H14), Colours),
% The green house is immediately to the right (your right) of the ivory house
member(h(green,H15), Colours),
lleft(H16, H15),
member(h(ivory,H16), Colours),
% Milk is drunk in the middle house.
member(h(milk,3), Drinks).

permutation([],[]).
permutation([A|X],Y) :- delete(A,Y,Y1), permutation(X,Y1).

delete(A,[A|X],X).
delete(A,[B|X],[B|Y]) :- delete(A,X,Y).

member(A,[A|_]) :- !.
member(A,[_|X]) :- member(A,X).

next(X,Y) :- lleft(X,Y).
next(X,Y) :- lleft(Y,X).

lleft(1,2).
lleft(2,3).
lleft(3,4).
lleft(4,5).

20
Output:

They drink water in the yellow house


The zebra live in the green house
yes

PROGRAM NO. – 13

AIM: TO ANALYZE GRAMMAR OF SENTENCE

GLOBAL DATABASE
det( STRING )
noun( STRING )
21
rel( STRING )
verb( STRING )

DETERM = none ; determ( STRING )


NOUNP = nounp( DETERM, STRING, RELCL)
RELCL = none ; relcl( STRING, VERBP )
SENTENCE = sent( NOUNP, VERBP )
VERBP = verb( STRING ) ; verbp( STRING, NOUNP )
TOKL = STRING*

% Recognition of words in different forms


is_det( STRING )
is_noun( STRING )
is_rel( STRING )
is_verb( STRING )

% Parser
nondeterm s_determ( TOKL, TOKL, DETERM )
nondeterm s_nounp( TOKL, TOKL, NOUNP )
nondeterm s_relcl( TOKL, TOKL, RELCL )
nondeterm s_sentence( TOKL, TOKL, SENTENCE )
nondeterm s_verbp( TOKL, TOKL, VERBP )

% scanner
check(STRING)
tokl( STRING, TOKL )

GOAL
consult("sen_an.dba"),
write("Try: every men loves women\n"),
write("Write a sentence: "),
readln(STR),
tokl(STR,TOKL),
s_sentence( TOKL, RESTTOKL, SENT ),
RESTTOKL = [],
write(SENT).

s_sentence(TOKL,TOKL2,sent(NOUNP,VERBP)):-
s_nounp(TOKL,TOKL1,NOUNP),
s_verbp(TOKL1,TOKL2,VERBP),
TOKL2 = [] ,!.
s_sentence(_,_,_):-
write(">> Sentence not recognized\n"),fail.
22
s_nounp(TOKL,TOKL2,nounp(DETERM,NOUN,RELCL)):-
s_determ(TOKL,[NOUN|TOKL1],DETERM),
is_noun(NOUN),
s_relcl(TOKL1,TOKL2,RELCL).

s_determ([DETERM|TOKL],TOKL,determ(DETERM)):-
is_det(DETERM).
s_determ(TOKL,TOKL,none).

s_relcl([REL|TOKL],TOKL1,relcl(REL,VERBP)):-
is_rel(REL),
s_verbp(TOKL,TOKL1,VERBP).
s_relcl(TOKL,TOKL,none).

s_verbp([VERB|TOKL],TOKL1,verbp(VERB,NOUNP)):-
is_verb(VERB),
s_nounp(TOKL,TOKL1,NOUNP).
s_verbp([VERB|TOKL],TOKL,verb(VERB)):-
is_verb(VERB).

is_noun(X):-noun(X),!.
is_noun(X):-noun(Y),concat(Y,"s",X),!.

is_det(X):-det(X),!.

is_rel(X):-rel(X),!.

is_verb(X):-verb(X),!.
is_verb(X):-verb(Y),concat(Y,"s",X),!.
is_verb(X):-verb(Y),concat(Y,"ed",X),!.
is_verb(X):-verb(Y),concat(Y,"es",X),!.
is_verb(X):-verb(Y),concat(Y,"ing",X),!.

tokl(STR,[TOK|TOKL]) :-
fronttoken(STR,TOK,STR1),
check(TOK),!,
tokl(STR1,TOKL).
tokl(_,[]).

check(WORD):-is_noun(WORD),!.
check(WORD):-is_det(WORD),!.
check(WORD):-is_rel(WORD),!.
check(WORD):-is_verb(WORD),!.
check(WORD):- write(">> Unknown word: ",WORD),nl.

23
PROGRAM NO. – 14

AIM: PROGRAM TO SOLVE EIGHT QUEENS PROBLEM

H,F,I,Y,Y1,Xdist,Dist1,Queen=integer
T,L,L1,PL,PT,Queen,Others=integer*

24
safe(L)
solution(L)
permutation(L,L)
del(I,L,L)
noattack(I,L,L)

solution(Queens):-
permutation([1,2,3,4,5,6,7,8],Queens),
safe(Queens).
permutation([],[]).
permutation([H|T],PL):-
permutation(T,PT),
del(H,PT,PI).
del(I,L,L1).
.safe([]).
safe([Queen|Others]):-
safe(Others),
noattack(Queen,Others,1).
noattack(_,[],_).
noattack(Y,[Y1|Ylist],Xdist):-
Y1-Y<>Xdist,
Y-Y1<>Xdist,
Dist1=Xdist+1,
Noattack(Y,Ylist,Dist1).

OUTPUT:
Goal:
Solutions(s)

PROGRAM NO. – 15

AIM: PROGRAM TO SOLVE MONKEY BANANA

State1,State2,MH,MV,BP,HB,P1,P2=symbol
Move=symbol*

move(State1,Move,State2).
state(MH,MV,BP,HB).
push(P1,P2).
25
walk(P1,P2).
grasp.
climb.

move(State(middle,onbox,middle,hasnot),grasp,state(middle,onbox,middle,has)).

move(State(P,onfloor,P,H),climb,state(P,onbox,P,H)).

move(State(P1,onfloor,P1,H),push(P1,P2),state(P2,onfloor,P2,H)).

move state(P1,onfloor,B,H),
walk(P1,P2), % Walk from P1 to P2.
state(P2,onfloor,B,H)).
% change state (State): monkey can get banana in State.

Change state(state(_,_,_,has)). % can 1: Monkey already has it.

Change state (State1):- % can2: Do some work to get it.


move (State1,Move,State2), % Do something
Change state (State2). % Get it

26

You might also like