AI Problem Solving

Monkey & Banana Problem

Can you solve the classic AI planning puzzle? Help the monkey reach the bananas — or let search algorithms find the optimal path.

The Scenario

A monkey must plan actions to reach bananas hanging from the ceiling using a box as a tool.

šŸ’

Monkey (Agent)

Starts at A, height Low. Can walk, push the box, climb it, and grasp.

šŸŒ

Bananas (Goal)

Hanging at location B, height High. Cannot be moved — monkey must come to them.

šŸ“¦

Box (Tool)

At location C, height Low. Monkey can push it anywhere and climb on top.

šŸŽÆ

Goal State

Monkey on box at B, height High, banana grasped: (B,High,B,T)

State = (MonkeyLoc, Height, BoxLoc, HasBanana)
Initial:
(A, Low, C, false)
Goal:
(B, High, B, true)
State Space:
3 Ɨ 2 Ɨ 3 Ɨ 2 = 36

Play the Game

Solve manually, watch AI algorithms solve it, or compare all six algorithms side by side.

State(A,Lo,C,F)
Moves0
Time0:00
Use buttons or keys 1–8 to move the monkey!
A
B
C
šŸŒšŸŒšŸŒ
Box
šŸ’Monkey

šŸŽ‰ Goal Achieved!

Shortcuts: 1–3 Walk  4–6 Push  7 Climb  8 Grasp
🚶 Walk
šŸ“¦ Push Box
⚔ Special
šŸŽ‰ Puzzle Solved!
Switch to Compare tab to see how you rank against AI →
—
Your Moves
4
Optimal
—
Time
—
🐢 ⚔

Run all 6 algorithms simultaneously and compare nodes explored, optimality, and efficiency. Complete the manual puzzle first to include your own score!

Move History
No moves yet — start playing!

State Transitions

The 4-step optimal path found by A* and BFS.

StepActionMonkeyHeightBoxBanana?
0InitialALowCNo
1Walk(A→C)CLowCNo
2Push(C→B)BLowBNo
3ClimbBHighBNo
4GraspBHighBYes āœ“

Available Actions

Each action has preconditions and effects on the state.

Walk(X, Y)

Pre: at(X) Height=Low
Monkey moves from X to Y. Cannot walk while on the box.

Push(X, Y)

Pre: at(X) Box at X Height=Low
Monkey pushes box from X to Y. Both move together.

Climb

Pre: at(X) Box at X Height=Low
Monkey climbs onto the box. Height: Low → High.

Grasp

Pre: at(B) Height=High Banana at B
Monkey grabs the bananas. HasBanana → true. Goal!

State-Space Search Tree

Purple path = optimal solution. Dashed = pruned (already visited). Green = goal.

How the Solution is Found

Six search strategies compared — each with different tradeoffs in optimality, completeness, and efficiency.

A* Search
f(n) = g(n) + h(n)
Combines path cost g(n) with admissible heuristic h(n) counting remaining subgoals. Guarantees optimality while exploring fewer nodes than BFS.
Optimal āœ“Complete āœ“O(b^d)6 nodes
BFS
Breadth-First Search
Explores all nodes at depth d before d+1 using a FIFO queue. Finds shortest path but explores more nodes than A*.
Optimal āœ“Complete āœ“O(b^d)13 nodes
DFS
Depth-First Search
Dives deep into one branch via LIFO stack before backtracking. Memory-efficient O(bm) but may find suboptimal paths.
Optimal āœ—Complete āœ—*O(b^m)6 nodes
UCS
Uniform-Cost Search
Expands least-cost node via priority queue. A* with h=0 / Dijkstra's algorithm. Optimal for non-negative costs.
Optimal āœ“Complete āœ“O(b^d)17 nodes
Greedy BFS
Greedy Best-First Search
Expands node closest to goal using only h(n), ignoring path cost. Fast but not guaranteed optimal.
Optimal āœ—Complete āœ—O(b^m)6 nodes
IDDFS
Iterative Deepening DFS
Runs DFS with increasing depth limits (0,1,2…). Combines BFS optimality with DFS memory efficiency.
Optimal āœ“Complete āœ“O(b^d)68 nodes

Computational Models Compared

Four AI paradigms that can represent and solve this problem.

Primary
🧠

State-Space Search

Classical AI Planning

Represents the world as states (4-tuples) and operators as transitions. Graph search algorithms (BFS, A*) find a path from initial to goal state.

Representation(Loc, Height, Box, Banana)
State Space36 states (3Ɨ2Ɨ3Ɨ2)
Optimal Path4 actions
Best AlgorithmA* with subgoal h(n)
āš™ļø

Production System

IF-THEN Rule Engine (CLIPS / OPS5)

Uses IF-THEN rules (productions). A recognize-act cycle matches preconditions against working memory and fires the best rule.

Rules4 productions
Working MemoryCurrent state tuple
Conflict ResolutionGoal-directed priority
ArchitectureForward chaining
šŸ“

PDDL Planning

Planning Domain Definition Language

The standard for classical AI planning. Defines domain (predicates, operators with pre/effects) and problem (objects, init, goal).

Predicatesat(X), on(box), has(banana)
OperatorsWalk, Push, Climb, Grasp
PlannerForward state-space search
StandardPDDL 2.1
šŸ”—

Means-Ends Analysis

General Problem Solver — Newell & Simon (1959)

Identifies difference between current and goal state, selects operator to reduce that difference. Recursively sets subgoals.

ApproachDifference reduction
SubgoalsGet box → Move → Climb → Grasp
OriginNewell, Shaw, Simon (1959)
StrengthGoal-directed, no blind search

Algorithm Comparison

4
Optimal Path Length
6
A* Nodes Explored
13
BFS Nodes Explored
68
IDDFS Nodes Explored