0% found this document useful (0 votes)
19 views2 pages

Assignment

Assignment

Uploaded by

rishin029
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views2 pages

Assignment

Assignment

Uploaded by

rishin029
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Academic Year 2021-22 SAP ID: 60003190064

DEPARTMENT OF INFORMATION TECHNOLOGY


COURSE CODE: DJ19ITL504 DATE: 08-12-2021
COURSE NAME: Artificial Intelligence Laboratory CLASS: TY
EXPERIMENT NO. 8
CO/LO: Represent various real life problems using logic-based methods and use inference or
planning techniques to deduce the solution.
AIM: To solve Monkey and Banana Problem using PROLOG
DESCRIPTION:
Monkey and Banana Problem [1]
 A hungry monkey is in a room, and he is near the door.
 The monkey is on the floor.
 Bananas have been hung from the center of the ceiling of the room.
 There is a block (or chair) present in the room near the window.
 The monkey wants the banana, but cannot reach it.
How can the Monkey get the Banana?
 If the monkey is clever enough, he can come to the block, drag the block to the center,
climb on it, and get the banana. Below are few observations in this case −
 Monkey can reach the block, if both of them are at the same level. From the above image,
we can see that both the monkey and the block are on the floor.
 If the block position is not at the center, then monkey can drag it to the center.
 If monkey and the block both are on the floor, and block is at the center, then the monkey
can climb up on the block. So the vertical position of the monkey will be changed.
 When the monkey is on the block, and block is at the center, then the monkey can get the
bananas.
TECHNOLOGY STACK USED: SWI PROLOG
ALGORITHM:
 When the block is at the middle, and monkey is on top of the block, and monkey does not
have the banana (i.e. has not state), then using the grasp action, it will change from has
not state to have state.
 From the floor, it can move to the top of the block (i.e. on top state), by performing the
action climb.
 The push or drag operation moves the block from one place to another.
 Monkey can move from one place to another using walk or move clauses.
Academic Year 2021-22 SAP ID: 60003190064

SOURCE CODE:
a. M_and_B.pl
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),
drag(P1,P2),
state(P2,onfloor,P2,H)).
move(state(P1,onfloor,B,H),
walk(P1,P2),
state(P2,onfloor,B,H)).
canget(state(_,_,_,has)).
canget(State1) :-
move(State1,_,State2),
canget(State2).

b. Output Window

CONCLUSION:
Thus, we have implemented and solved the Monkeys and Bananas Problem in PROLOG.
REFERENCES:
[1] Ivan Bratko. 1990. PROLOG Programming for Artificial Intelligence (2nd. ed.). Addison-
Wesley Longman Publishing Co., Inc., USA.

You might also like