3
\$\begingroup\$

The monkey-banana problem: There many variations to this problem, but the basic premise is that a monkey is in a room with a banana and a chair, and the monkey cannot reach the banana until he moves the chair close to the banana (so as to reach it), then climbs the chair and gets the banana.

(Note : Often times, the chair is replaced with a box or a similar object that the monkey can climb on. Also, a stick may be added to the mix, which the monkey needs to swing at the banana in order to make it drop to the floor.)

I came up with this program to solve a simple monkey-banana problem in AI (no stick). I think it's overly simple, but I would like to know what you think.

on(floor,monkey).
on(floor,chair).
in(room,monkey).
in(room,chair).
in(room,banana).
at(ceiling,banana).

strong(monkey).
grasp(monkey).
climb(monkey,chair).

push(monkey,chair):-
    strong(monkey).

under(banana,chair):-
    push(monkey,chair).


canreach(banana,monkey):-
    at(floor,banana);
    at(ceiling,banana),
    under(banana,chair),
    climb(monkey,chair).

canget(banana,monkey):-
    canreach(banana,monkey),grasp(monkey).

Should I add location attributes as well? I think that I have hard-coded a lot of things, or maybe having the stick included in the problem would make a better search tree?

\$\endgroup\$
  • \$\begingroup\$ What is the monkey-banana problem exactly? \$\endgroup\$ – Simon Forsberg Oct 31 '15 at 13:55
  • 1
    \$\begingroup\$ There many variations to that, but the basic premise is that a monkey is in a room with a banana and a chair, and the monkey cannot reach the banana until he moves the chair close to the banana (so as to reach it), then climbs the chair and gets the banana. \$\endgroup\$ – goelakash Oct 31 '15 at 13:57
  • \$\begingroup\$ @goelakash Good include this in the post as comments are often deleted \$\endgroup\$ – Caridorc Oct 31 '15 at 14:21
  • \$\begingroup\$ @SimonForsberg monkey-banana is a homework problem :D \$\endgroup\$ – Filip Bartuzi Oct 31 '15 at 15:51
  • \$\begingroup\$ Yeah, but I did code this up. Prof took 2 classes this sem and expects intermediate proficiency. \$\endgroup\$ – goelakash Oct 31 '15 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.