🏰 Wumpus World

Russell & Norvig β€” AI: A Modern Approach

Inspired by a warm conversation with Prof. R K Mishra & Prof. Devender Singh, IIT BHU

Score: 0 🏹 1 πŸ’° No 🦢 0 🧭 ➑
 
β–Ά Knowledge Base

Game Rules (Section 7.2)

Objective

Find the gold ✨, grab it, and climb out at [1,1] alive. Maximize your score.

The Cave

Percepts (what you sense)

PerceptMeans
🟒 StenchWumpus is in an adjacent cell (up/down/left/right)
πŸ’¨ BreezeA pit is in an adjacent cell
✨ GlitterGold is in this cell β€” use Grab!
BumpYou walked into a wall (no movement)
🎯 ScreamYour arrow killed the Wumpus

Scoring

EventPoints
Grab gold + climb out at [1,1]+1000
Death (pit or Wumpus)βˆ’1000
Each actionβˆ’1
Shooting the arrowβˆ’10

Arrow Rules

Controls

Movement (also changes facing)

InputAction
↑ button / Arrow Up / WMove up (face up)
↓ button / Arrow Down / SMove down (face down)
← button / Arrow Left / AMove left (face left)
β†’ button / Arrow Right / DMove right (face right)
Swipe on touchscreenMove in swipe direction

Turning (change facing without moving)

InputAction
↩ Q button / Q keyTurn left (counter-clockwise)
E β†ͺ button / E keyTurn right (clockwise)

Turning costs βˆ’1 point (it's an action). Use this to aim your arrow before shooting!

Actions

InputAction
βœ‹ Grab / G keyPick up gold (if in current cell)
🏹 Shoot / F keyFire arrow in facing direction (straight line)
πŸ§— Climb / C keyClimb out β€” only works at [1,1]
πŸ”„ NewStart a new game

Grid Symbols

SymbolMeaning
πŸ§‘β€πŸš€βž‘ πŸ§‘β€πŸš€β¬† πŸ§‘β€πŸš€β¬‡ πŸ§‘β€πŸš€β¬…You (explorer + arrow shows facing direction)
πŸ‘ΉWumpus (revealed on death/game end)
πŸ•³οΈPit (revealed on death/game end)
✨Gold
βœ…KB inferred: cell is safe
❓Unknown β€” cannot determine safety
☠️Dead Wumpus (killed by your arrow)

1. Environment Definition (Ch. 2)

Section 2.3 PEAS Description
PEASWumpus World
Performance+1000 gold & escape, βˆ’1000 death, βˆ’1/action, βˆ’10 arrow
Environment4Γ—4 (or NΓ—N) grid cave with pits, wumpus, gold
ActuatorsForward, TurnLeft, TurnRight, Grab, Shoot, Climb
SensorsStench, Breeze, Glitter, Bump, Scream
Section 2.3.2 Environment Properties
PropertyValue
ObservablePartially β€” only current cell percepts
DeterministicYes in Classic; No in Stochastic mode
Episodic / SequentialSequential β€” past actions affect future
Static / DynamicStatic β€” world doesn't change while agent thinks
Discrete / ContinuousDiscrete
Single / Multi-agentSingle agent (Wumpus is environment, not agent)

2. Knowledge-Based Agents (Ch. 7)

Section 7.1 Core Architecture
A knowledge-based agent maintains a Knowledge Base (KB) of sentences in a formal language. It reasons by:
1. TELL β€” add new percept to KB
2. ASK β€” query KB to decide action
3. Act β€” perform the chosen action
Section 7.2 Wumpus World Specification

Propositional Logic Inference

Section 7.3–7.5

Key idea: encode percepts as propositions and use inference rules.

Β¬B₁,₁ β†’ Β¬P₁,β‚‚ ∧ Β¬Pβ‚‚,₁

"No breeze at [1,1] implies no pit at [1,2] and [2,1]"

S₁,β‚‚ ∧ Β¬S₁,₁ β†’ W₁,₃ ∨ Wβ‚‚,β‚‚

"Stench at [1,2] but not [1,1] β†’ Wumpus is at [1,3] or [2,2]"

Methods to determine entailment (KB ⊨ α):

3. First-Order Logic (Ch. 8–9)

Section 8.3
Propositional logic needs a separate symbol for each cell: P₁,₁, P₁,β‚‚, ... Pβ‚„,β‚„ (16 symbols just for pits!).
FOL uses variables and quantifiers β€” one rule covers all cells:
βˆ€x,y Breeze(x,y) ⟺ βˆƒa,b (Adjacent(x,y,a,b) ∧ Pit(a,b))

"A cell has breeze iff some adjacent cell has a pit" β€” covers any grid size with one sentence.

βˆ€x,y Β¬Breeze(x,y) β†’ βˆ€a,b (Adjacent(x,y,a,b) β†’ Β¬Pit(a,b))

"No breeze means all neighbors are pit-free."

4. Uncertainty & Probability (Ch. 13)

Section 13.1
When the agent faces unknown cells with conflicting information, logical entailment can't decide. Instead, compute P(Pit | percepts) using Bayes' theorem:
P(Pit₃,₁ | known) = Ξ± Β· P(known | Pit₃,₁) Β· P(Pit₃,₁)

Where:

Section 13.2 Bayesian Network for Wumpus

The book builds a Bayesian network where:

5. Sensor Models & Filtering (Ch. 15)

Section 15.1–15.2
What if your sensors are unreliable? A breeze might be a false positive, or you might miss a real stench.
The sensor model defines: P(percept | true_state)
P(Stench_observed | Wumpus_adjacent) = 0.85
P(Stench_observed | Β¬Wumpus_adjacent) = 0.15

Now even "safe" inferences might be wrong. You need to maintain belief states β€” probability distributions over possible worlds, updated at each step.

This connects to:

6. Decision Theory (Ch. 16)

Section 16.1–16.3
With uncertain actions AND uncertain sensors, the agent needs a full decision-theoretic framework:
MEU β€” Maximum Expected Utility: choose the action that maximizes expected utility over all possible outcomes.
action* = argmax_a Ξ£_s P(s|evidence) Β· U(s, a)

Where U(s,a) accounts for:

7. Quick Reference β€” Symbols in Game

In GameFormalMeaning
πŸ’¨ BreezeBx,yAdjacent cell has a pit
🟒 StenchSx,yAdjacent cell has Wumpus
✨ GlitterGx,yGold is in this cell
βœ… SafeKB ⊨ Β¬P ∧ Β¬WInferred: no pit and no Wumpus
❓ UnknownKB ⊭ safeCannot determine safety
⚠️ SLIPPEDP(s'|s,a) β‰  1Non-deterministic transition
🚫 sensors unreliableP(obs|state) < 1Sensor model is noisy

8. Mode β†’ Chapter Mapping

Game ModeChaptersConcepts Practiced
πŸ“– ClassicCh. 2, 7PEAS, propositional logic, KB agents, entailment
🎲 StochasticCh. 13Probability, Bayes' theorem, uncertain actions*
πŸ“‘ NoisyCh. 15Sensor models, belief states, filtering*
πŸ—ΊοΈ LargeCh. 8–9FOL scalability, universal quantification*
πŸ’€ NightmareCh. 16Decision theory, MEU, decision networks*

* Stochastic, Noisy, Large, and Nightmare are extensions inspired by textbook concepts. Classic mode is the exact specification from Section 7.2.

Reference: Russell, S. & Norvig, P. β€” Artificial Intelligence: A Modern Approach (4th Edition)