The Wumpus World is a small cave game used to show how a knowledge-based agent reasons under uncertainty.
The Rules
The Wumpus World is a 4 × 4 grid of rooms. The agent starts at [1,1] facing east. One room contains the wumpus, a monster that eats the agent; some rooms contain pits (about 20 percent probability each) that trap the agent; one room contains the gold. The goal is to find the gold and climb out alive. Actions: Forward, TurnLeft, TurnRight, Grab the gold, Shoot the single arrow in the facing direction, and Climb (only at [1,1]). The agent dies if it enters a pit or a room with a live wumpus.
The PEAS Description
Performance measure: +1000 for climbing out with the gold, −1000 for dying, −1 for each action, −10 for using the arrow. Environment: 4 × 4 grid, the start at [1,1], random placement of gold, wumpus and pits. Actuators: Forward, TurnLeft, TurnRight, Grab, Shoot, Climb. Sensors: five percepts: Stench in the room with the wumpus and in the directly adjacent rooms (not diagonal); Breeze in rooms adjacent to a pit; Glitter in the room with the gold; Bump when walking into a wall; Scream anywhere when the wumpus is killed. The environment is discrete, static, single-agent, sequential, deterministic in dynamics but partially observable: the agent cannot see where the pits and wumpus are.
Definition: Wumpus World. A 4 × 4 cave grid with a wumpus, pits and gold, in which a partially observing agent uses percepts (stench, breeze, glitter, bump, scream) and logical reasoning to find the gold safely.
Reasoning in the Cave
At [1,1] the agent perceives nothing, so by the rules neither [1,2] nor [2,1] contains a pit or wumpus: they are safe. Suppose it moves to [2,1] and perceives a breeze: a pit must lie in a neighbouring room, [3,1] or [2,2] (or [1,1], which is known safe). It cannot yet tell which, so it returns to [1,1] and goes to [1,2]. If it perceives no breeze at [1,2], then [2,2] and [1,3] contain no pit; since [2,1] had a breeze and [2,2] is pit-free, the pit must be at [3,1]. This is a logical inference that no single percept gives: it combines percepts from different times, which is why the agent needs a knowledge base. If at [1,2] it perceives a stench and no breeze, the wumpus is at [1,3] or [2,2]; since [2,1] had no stench, [2,2] cannot hold the wumpus, so the wumpus is at [1,3].
Lessons of the Example
The Wumpus World shows that logical reasoning gives guaranteed conclusions when the available information is enough, that the agent must sometimes gamble (when no safe move exists) which leads to probabilistic reasoning (Unit III), and that representing the KB with propositional logic (symbols such as Pᵢⱼ for "pit at [i,j]" and Bᵢⱼ for "breeze at [i,j]", with rules Bᵢⱼ ⇔ (P of any neighbour)) lets the agent infer safe squares automatically.
Table 1.6: Wumpus world percepts
| Percept | Meaning | Where perceived |
|---|---|---|
| Stench | Wumpus is adjacent or here | Rooms next to the wumpus |
| Breeze | A pit is adjacent | Rooms next to a pit |
| Glitter | Gold is here | The gold room |
| Bump | Wall ahead | When moving into a wall |
| Scream | The wumpus has died | Anywhere in the cave |
Example 1.6: Locating a pit
Problem: Percepts: [1,1] none; [2,1] breeze; [1,2] none. Which squares among [2,2], [3,1] and [1,3] have pits?
Solution:
- [1,2] has no breeze, so none of its neighbours [1,1], [2,2], [1,3] has a pit: [2,2] and [1,3] are safe.
- [2,1] has a breeze: a pit is in one of its neighbours [1,1], [3,1], [2,2]; [1,1] is visited (safe) and [2,2] is safe.
- Therefore the pit is at [3,1].
- Check all 8 models of {[2,2], [3,1], [1,3]}: only "pit at [3,1] only" is consistent.
Result: Pit at [3,1]; [2,2] and [1,3] are safe.
from itertools import product
cells = [(2, 2), (3, 1), (1, 3)]
def nb(x, y):
return [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]
ok = []
for vals in product([False, True], repeat=3):
pit = dict(zip(cells, vals))
has = lambda c: pit.get(c, False)
b11 = any(has(c) for c in nb(1, 1))
b21 = any(has(c) for c in nb(2, 1))
b12 = any(has(c) for c in nb(1, 2))
if (not b11) and b21 and (not b12):
ok.append([c for c in cells if pit[c]])
print("consistent models:", ok)
Output
consistent models: [[(3, 1)]]
Common mistakes
- Assuming stench or breeze appears diagonally; it appears only in directly adjacent rooms.
- Treating "no breeze here" as no information; it proves neighbours are safe.
- Forgetting that the agent can shoot only one arrow.
- Entering an unvisited room that is not proved safe.
Key takeaways
- 4 × 4 cave; agent starts at [1,1]; wumpus, pits and gold are hidden.
- Percepts: stench, breeze, glitter, bump, scream.
- Score: +1000 for gold and exit, −1000 for death, −1 per action, −10 for the arrow.
- Combining percepts from several squares lets the agent logically infer pits and the wumpus.
Practice questions
- Name the five percepts of the Wumpus World.
- If a visited room has no breeze, what follows?
- Why is the Wumpus World partially observable?
Answers to the practice questions
- Stench, breeze, glitter, bump and scream.
- None of its adjacent rooms contains a pit.
- The agent cannot see the pits, wumpus or gold locations except through percepts.
Sources
- Official BCA syllabus Artificial Intelligence, course code 26BCA404DS04, Unit I
