Knowledge base for Wumpus World in AI

Table of Content:

Content Highlight:

The knowledge base for the Wumpus World in AI uses propositional logic to represent the environment, with variables indicating pits, breezes, the Wumpus, stenches, visited rooms, gold, and safety. Rules define relationships like pits causing breezes and the Wumpus causing stenches. The knowledge base is used to make inferences, such as proving the presence of the Wumpus in a specific room.

Knowledge base for Wumpus world in Artificial intelligence:

In the previous topic, we learned about the Wumpus World and how a knowledge-based agent explores the environment. In this topic, we will create a knowledge base for the Wumpus World and derive some proofs using propositional logic.

The agent begins its exploration from the first square [1, 1], which we know to be safe. To construct a knowledge base for the Wumpus World, we will use rules and atomic propositions. We will use symbols [i, j] for each location in the Wumpus World, where i represents the row location and j represents the column location.

Knowledge Base for Wumpus World Intelligence (AI)

Atomic proposition variable for Wumpus world:

  • Pi,j: Represents the presence of a pit in room [i, j].
  • Bi,j: Indicates if the agent perceives a breeze in room [i, j].
  • Wi,j: Denotes the presence of the Wumpus in square [i, j].
  • Si,j: Indicates if the agent perceives a stench in square [i, j].
  • Vi,j: Represents whether square [i, j] has been visited by the agent.
  • Gi,j: Indicates the presence of gold (and glitter) in square [i, j].
  • OKi,j: Represents whether room [i, j] is safe for the agent to enter.

[Note: There will be 7*4*4= 122 propositional variables for a 4 * 4 square board.]

Some Propositional Rules for the wumpus world:

  1. Pit Presence Rule: If a room contains a pit, there will be a breeze in that room. Conversely, if there is a breeze in a room, it indicates the presence of a pit nearby. This rule captures the relationship between pits and breezes:
    • If P i,j (there is a pit in room [i, j]), then Bi,j (there is a breeze in room [i, j]).
    • If Bi,j (there is a breeze in room [i, j]), then there is a pit nearby: ∃(x,y) ∈ Adj(i,j) such that P i,j.
  2. Wumpus Presence Rule: Similarly, if a room contains the Wumpus, there will be a stench in that room. Conversely, if there is a stench in a room, it indicates the presence of the Wumpus nearby. This rule can be expressed as:
    • If Wi,j (the Wumpus is in room [i, j]), then Si,j (there is a stench in room [i, j]).
    • If Si,j (there is a stench in room [i, j]), then the Wumpus is nearby: ∃(x,y) ∈ Adj(i,j) such that Wx,y.
  3. Gold Glitter Rule: When there is gold in a room, the agent will perceive glitter in that room. This rule is straightforward:
    • If Gi,j (there is gold in room [i, j]), then Glitteri,j (there is glitter in room [i, j).
  4. Stench Perception Rule: The agent perceives a stench if it is in a room adjacent to the Wumpus. This rule captures the agent's perception of stenches:
    • If the agent is in room [i, j] and there is a stench in a room adjacent to [i, j], then the agent perceives a stench: Si,j if ∃(x,y) ∈ Adj(i,j) such that W x,y.
  5. Breeze Perception Rule: Similarly, the agent perceives a breeze if it is in a room adjacent to a pit. This rule describes the agent's perception of breezes:
    • If the agent is in room [i, j] and there is a breeze in a room adjacent to [i, j], then the agent perceives a breeze: Bi,j if ∃(x,y) ∈ Adj(i,j) such that P x,y.
  6. Safe Room Rule: A room is safe for the agent if there are no pits or the Wumpus in that room. This rule helps the agent determine safe moves:
    • A room [i, j] is safe for the agent to enter if there are no pits or the Wumpus in that room: OKi,j ¬Pi,j ∧ ¬Wi,j.

Representation of Knowledgebase for Wumpus world:

Following is the Simple KB for wumpus world when an agent moves from room [1, 1], to room [2,1]:

Knowledge Base for Wumpus World2 Intelligence (AI)

Here in the first row, we have mentioned propositional variables for room[1,1], which is showing that room does not have wumpus(¬ W11 ), no stench (¬S11), no Pit(¬P11), no breeze(¬B11), no gold (¬G11), visited (V11), and the room is Safe(OK11) .


In the second row, we have the propositional variables for room [1,2], indicating that there is no Wumpus, the stench and breeze are unknown as an agent has not visited room [1,2], there is no pit, the room is not yet visited, and the room is safe.


In the third row, we have the propositional variables for room [2,1], indicating that there is no Wumpus (¬W2,1), no stench (¬S2,1), no Pit (¬P2,1), Perceives breeze (B2,1), no glitter (¬G2,1), visited (V2,1), and room is safe (OK2,1).

Prove that Wumpus is in the room (1, 3):

We can prove that wumpus is in the room (1, 3) using propositional rules which we have derived for the wumpus world and using inference rule.

  • Apply Modus Ponens with ¬S11 and R1: At first we will apply MP rule with R1 which is ¬S11 → ¬W11 ∧ ¬W12 ∧ ¬W21, and ¬S11 which will give this output ¬ W11 ∧ W12 ∧ W12
    Apply Modus Ponens step 1
  • Apply And-Elimination Rule: After we apply And-elimination rule to ¬W11 ∧ ¬W12 ∧ ¬W21, we will see three statements:
    ¬W11, ¬W12, and ¬W21.
  • Apply Modus Ponens to ¬S21, and R2: We will now apply Modus Ponens to ¬S21 and R2 which is ¬S21 → ¬W21 ∧¬ W22 ∧ ¬W31, which will give the Output as ¬W21 ∧ ¬W22 ∧ ¬W31.
    Apply Modus Ponens step 2
  • Apply And -Elimination rule: Again we will now apply And-elimination rule to ¬W21 ∧ ¬W22 ∧ ¬W31, We will see three statements:
    ¬W21, ¬W22, and ¬W31.
  • Apply MP to S12 and R4: Apply Modus Ponens to S12 and R4 which is S12 →W13 ∨ W12 ∨ W22 ∨ W11, we will get the output as W13 ∨ W12 ∨ W22 ∨ W11.
    Apply Modus Ponens step 3
  • Apply Unit resolution on W13 ∨ W12 ∨ W22 ∨ W11 and ¬W11 : After applying Unit resolution formula on W13 ∨ W12 ∨ W22 ∨ W11 and ¬W11 we will see W13 ∨ W12 ∨ W22
    Apply Modus Ponens step 4
  • Apply Unit resolution on W13 ∨ W12 ∨ W22 and ¬W22 : After applying Unit resolution on W13 ∨ W12 ∨ W22, and ¬W22, we will get W13 ∨ W12 as output.
    Apply Modus Ponens step 5
  • Apply Unit Resolution on W13 ∨ W12 and ¬W12 : After Applying Unit resolution on W13 ∨ W12 and ¬W12, we will see W13 as an output, therefore, it is proved that the Wumpus is in the room [1, 3].
    Apply Modus Ponens proved