The Wumpus World is a classic example of a knowledge-based agent in AI. It is a 4x4 grid consisting of 16 rooms. Agent starts at Room[1,1] facing right and its goal is to retrieve treasure while avoiding hazards such as pits and the Wumpus. Agent navigate through the grid using its limited sensory input to make decisions that will keep it safe, collect treasure and exit the cave.
Pits: If the agent steps into a pit it falls and dies. A breeze in adjacent rooms suggests nearby pits.
Wumpus: A creature that kills agent if it enters its room. Rooms next to the Wumpus have a stench. Agent can use an arrow to kill the Wumpus.
Treasure: Agent’s main objective is to collect the treasure (gold) which is located in one room.
Breeze: Indicates a pit is nearby.
Stench: Indicates the Wumpus is nearby.
Agent must navigate carefully avoiding dangers to collect treasure and exit safely.
PEAS Description
PEAS stands for Performance Measures, Environment, Actuators and Sensors which describe agent’s capabilities and environment.
1. Performance measures: Rewards or Punishments
Agent gets gold and return back safe = +1000 points
Agent dies (pit or Wumpus)= -1000 points
Each move of the agent = -1 point
Agent uses the arrow = -10 points
2. Environment: A setting where everything will take place.
A cave with 16(4x4) rooms.
Rooms adjacent (not diagonally) to the Wumpus are stinking.
Rooms adjacent (not diagonally) to the pit are breezy.
Room with gold glitters.
Agent's initial position - Room[1, 1] and facing right side.
Location of Wumpus, gold and 3pits can be anywhere except in Room[1, 1].
3. Actuators: Devices that allow agent to perform following actions in the environment.
Move forward: Move to next room.
Turn right/left: Rotate agent 90 degrees.
Shoot: Kill Wumpus with arrow.
Grab: Take treasure.
Release: Drop treasure
4. Sensors: Devices help the agent in sensing following from the environment.
Breeze: Detected near a pit.
Stench: Detected near the Wumpus.
Glitter: Detected when treasure is in the room.
Scream: Triggered when Wumpus is killed.
Bump: Occurs when hitting a wall.
How the Agent Operates with PEAS
Perception: Agent uses sensory inputs (breeze, stench, glitter) to detect its surroundings and understand the environment.
Inference: Agent applies logical reasoning to find location of hazards. For example if it detects a breeze, it warns that a pit is nearby or if there’s a stench it suspects the Wumpus is in an adjacent room.
Planning: Based on its deductions agent plans its next move avoiding risky areas like rooms with suspected pits or the Wumpus.
Action: Agent performs planned action such as moving to a new room, shooting arrow at the Wumpus or taking the treasure.
This process repeats till the agent finds the cave using its sensory inputs, reasoning and planning to achieve its goal safely.
By using PEAS framework agent’s interactions with its environment are clearly defined, providing a structured approach to modeling intelligent behavior.
Implementation
Here we implements a Wumpus World AI agent:
Step 1: Initialize Explorer Agent and Environment
Imports copy for safe state copying and deque efficient traversal using queues .
Defines the Explorer class, which models an intelligent agent for the Wumpus World problem.
Initializes a 4×4 world grid containing hazards (Wumpus, Pit) and a goal (Gold).
Sets the agent’s starting position and tracks its survival and exit status.
Step 2: Coordinate Conversion and Hazard Checking
Converts 1-based coordinates to 0-based indices for accessing the grid.
Checks if the current cell contains a hazard (Wumpus or Pit) and updates _alive.
Detects if the agent has found the treasure and updates _exited.
Returns the agent’s alive status to guide further actions.
Step 3: Movement and Adjacent Cells
Moves the agent in the specified direction within grid bounds.
Prevents movement if the agent is dead or has exited.
Checks for hazards or treasure after moving.
_adjacent_cells returns all valid neighboring cells.
Step 4: Perception and Current Location
perceive detects hazards in adjacent cells, returning breeze for pits and stench for the Wumpus.
Prevents perception if the agent is dead or has exited.
Uses _adjacent_cells and _coords_to_index to check neighboring cells.
current_location simply returns the agent’s current position.
Step 5: Knowledge Base and Utility Functions
Initializes knowledge_base and actions_taken to track agent reasoning and moves.
current_status keeps a 4×4 grid of visited or safe cells.
neighbors returns valid adjacent cells for a given location.
is_valid checks if given row and column indices are within grid bounds.
Step 6: BFS Pathfinding and Literal Extraction
bfs_path finds a path from start to goal using Breadth-First Search on safe cells (current_status).
Tracks visited cells and parent pointers to reconstruct the sequence of moves.
Returns a list of directions to reach the goal or an empty list if unreachable.
literal_of extracts the first literal from a logical expression, useful for knowledge base reasoning
Step 7: Pure Literals and Unit Clauses
pure_literals identifies literals that appear with only one polarity in the expression, useful for simplifying the knowledge base.
Tracks symbols and ensures consistency across clauses to detect pure literals.
unit_clauses finds clauses with only one literal and checks for consistency.
Returns the list of unit clauses and a boolean indicating whether the knowledge base is consistent.
Step 8: DPLL SAT Solver
Implements the Davis-Putnam-Logemann-Loveland (DPLL) algorithm to check if a propositional logic expression is satisfiable.
Simplifies the expression using pure literals and unit clauses, reducing search space.
Recursively branches on a literal, trying both True and False assignments.
Returns True if the expression is satisfiable, False if inconsistent, and tracks recursive calls with total_calls.
Step 9: Simulation of Explorer Agent
Uses a stack-based DFS approach to explore the Wumpus World from start (1,1) to goal (3,3) while tracking visited cells.
Updates the knowledge_base with percepts (breeze, stench) and checks hazards using the DPLL solver.
Marks safe (1) and unsafe (2) cells in current_status and plans moves using bfs_path.
Records all moves in actions_taken and prints the final path and total DPLL calls after simulation.