Saturday, September 28, 2019

Program 4 Write a program to solve the Monkey Banana problem.


Explanation- Assume that a room containing a Monkey, a Table and a Banana. The Banana is hanging from the ceiling of the room. Table is not below the banana. Monkey is anywhere in the room. In this program/problem we will prove that monkey can grasp the banana. If the monkey is clever he can grasp the banana by placing the table below the banana. Monkey only can reach the banana if he jumps from the table, otherwise he cannot reach to banana by jumping from floor or anywhere in room (except table). Monkey (strong monkey) can push the table.

Program-
on(floor,monkey).
on(fllor,box).
in(room,monkey).
in(room,box).
in(room,banana).
at(ceiling,banana).
strong(monkey).
grasp(monkey).
climb(monkey,box).
push(monkey,box):-strong(monkey).
under(banana,box):-push(monkey,box).
canreach(banana,monkey):-at(floor,banana); at(ceiling,banana),under(banana,box),climb(monkey,box).
canget(banana,monkey):-canreach(banana,monkey),grasp(monkey).

Goal Monkey can grasp (reach) the banana
Output-