Implementation of Monkey-Banana Problem in Prolog
In this post, we implement the Monkey-Banana Problem in Prolog — a classic AI planning problem used to demonstrate goal-directed reasoning. The scenario: a monkey is in a room with a banana hanging from the ceiling. There is also a stick and a chair in the room. To reach the banana, the monkey must pick up the stick, move the chair under the banana, climb on the chair, and then hit the banana with the stick. The Prolog program models each required action as an interactive predicate and chains them together to achieve the final goal. How Does the Prolog Solution Work? Each step in the plan is modelled as a Prolog predicate (take, move, get_on, hit). Each predicate asks the user a yes/no question. The main goal go chains all four predicates together using Prolog's conjunction operator (,). If every step is confirmed by the user, the goal succeeds and the monkey reaches the banana. If any step fails, Prolog backtracks to the second go clause and reports failure.