# Implementation of Monkey-Banana Problem in Prolog

domains
X=string

predicates
take(X,X)
move(X,X)
get_on(X,X)
hit(X,X,X)

go clauses
go:-
take("Monkey","Stick"),
move("Monkey","Chair"),
get_on("Monkey","Chair"),
hit("Monkey","Stick","Banana"),
write("The monkey has hit the banana").

go:-
write("The monkey couldn't reach the banana").

take(Animal,Object):-
write("Does the ",Animal," take the ",Object,"?(y/n)"),

move(Animal,Object):-
write("Does the ",Animal," move the ",Object,"?(y/n)"),

get_on(Animal,Object):-
write("Does the ",Animal," get on ",Object,"?(y/n)"),

hit(Animal,Object,Fruit):-
write("Does the ",Animal," hit the ",Fruit,"with the",Object,"?(y/n)"),

Output:
Goal:go
Does the Monkey take the Stick?(y/n)
y
Does the Monkey move the Chair?(y/n)
y
Does the Monkey get on Chair?(y/n)
y
Does the Monkey hit the Banana with the Stick?(y/n)
y
The monkey has hit the banana

Goal:go
Does the Monkey take the Stick?(y/n)
y
Does the Monkey move the Chair?(y/n)
n
The monkey couldn't reach the banana

## 3 thoughts on “Implementation of Monkey-Banana Problem in Prolog”

1. manoj shinde says:

error while running..

2. manoj shinde says:

?- [‘L:/MANOJ/8TH SEM/AI/PROLOG TRY/Monkey_B2.pl’].
ERROR: l:/manoj/8th sem/ai/prolog try/monkey_b2.pl:1:8: Syntax error: Operator expected
Warning: l:/manoj/8th sem/ai/prolog try/monkey_b2.pl:18:
Redefined static procedure go/0
Previously defined at l:/manoj/8th sem/ai/prolog try/diagnosis.pl:15
true.

error occurred

1. san says:

we are havin AI in 7th sem..

This site uses Akismet to reduce spam. Learn how your comment data is processed.