Wumpus World
Wumpus World
SUBMITTED BY
DHANUSH V 311521243012
BACHELOR OF TECHNOLOGY
In
ARTIFICIAL INTELLIGENCE AND DATA SCIENCE
DECEMBER 2022
TABLE OF CONTENTS
1 BRIEF 1
4 WORLD EXPLORATION 8 - 14
5 CODE 14 - 15
6 OUTPUT 15 - 17
7 CONCLUSION 18
BRIEF:
The Wumpus world is a simple world example to illustrate the worth of a knowledge-based agent and to
represent knowledge representation.
It was inspired by a video game Hunt the Wumpus by Gregory Yob in 1973.
The Wumpus World’s agent is an example of a knowledge-based agent that represents Knowledge
representation, reasoning and planning.
The Wumpus world is a cave with 4/4 rooms and pathways connecting them. As a result, there are a total of
16 rooms that are interconnected.
We now have a knowledge-based AI capable of progressing in this world.
There is an area in the cave with a beast named Wumpus who eats everybody who enters. The agent can
shoot the Wumpus, but he only has a single arrow.
There are some Pits chambers in the Wumpus world that are bottomless, and if an agent falls into one, he
will be stuck there indefinitely.
The intriguing thing about this cave is that there is a chance of finding a gold heap in one of the rooms.
So the agent's mission is to find the gold and get out of the cave without getting eaten by Wumpus or falling
into Pits. the agent returns with gold, he will be rewarded, but if he is devoured by Wumpus or falls into the
pit, he will be penalized.
a. Forward chaining
b. Backward chaining
FORWARD CHAINING:
Forward chaining is also known as a forward deduction or forward reasoning method when using an
inference engine. Forward chaining is a form of reasoning which start with atomic sentences in the
knowledge base and applies inference rules (Modus Ponens) in the forward direction to extract more data
until a goal is reached.
BACKWARD CHAINING:
Inference System is used when we want to update some information (sentences) in Knowledge-Based
System and to know the already present information.
This mechanism is done by TELL and ASK operations. They include inference i.e. producing new
sentences from old.
Inference must accept needs when one asks a question to KB and answer should follow from what has
been Told to KB.
Agent also has a KB, which initially has some background Knowledge. Whenever, agent program is
called, it performs some actions.
1. It TELLS what it recognized from the environment and what it needs to know to the knowledge base.
2. It ASKS what actions to do? and gets answers from the knowledge base.
3. It TELLS which action is selected, then agent will execute that action.
General algorithm
The above figure refers to the internal architecture of the knowledge based agents.
Here the learning element also plays a vital role in updating the knowledge base.
Performance measure:
o +1000 reward points if the agent comes out of the cave with the gold.
o -1000 points penalty for being eaten by the Wumpus or falling into the pit.
o -1 for each action, and -10 for using an arrow.
o The game ends if either agent dies or came out of the cave.
Environment:
Actuators:
o Left turn,
o Right turn
o Move forward
o Grab
o Release
o Shoot.
Sensors:
o The agent will perceive the stench if he is in the room adjacent to the Wumpus. (Not diagonally).
o The agent will perceive breeze if he is in the room directly adjacent to the Pit.
o The agent will perceive the glitter in the room where the gold is present.
o The agent will perceive the bump if he walks into a wall.
o When the Wumpus is shot, it emits a horrible scream which can be perceived anywhere in the cave.
o These percepts can be represented as five element list, in which we will have different indicators for
each sensor.
o Example if agent perceives stench, breeze, but no glitter, no bump, and no scream then it can be
represented as : [Stench, Breeze, None, None, None].
o Partially observable: The Wumpus world is partially observable because the agent can only
perceive the close environment such as an adjacent room.
o Deterministic: It is deterministic, as the result and outcome of the world are already known.
o Sequential: The order is important, so it is sequential.
o Static: It is static as Wumpus and Pits are not moving.
o Discrete: The environment is discrete.
o One agent: The environment is a single agent as we have one agent only and Wumpus is not
considered as an agent.
Now we will explore the Wumpus world and will determine how the agent will find its goal by applying
logical reasoning.
Initially, the agent is in the first room or on the square [1,1], and we already know that this room is safe for
the agent, so to represent on the below diagram (a) that room is safe we will add symbol OK. Symbol A is
used to represent agent, symbol B for the breeze, G for Glitter or gold, V for the visited room, P for pits, W
for Wumpus.
At Room [1,1] agent does not feel any breeze or any Stench which means the adjacent squares are also OK.
It is also important to note that the first move is randomized and doesn’t necessarily depend on the world
Agent's second Step:
Now agent needs to move forward, so it will either move to [1, 2], or [2,1]. Let's suppose agent moves to the
room [2, 1], at this room agent perceives some breeze which means Pit is around this room. The pit can be in
[3, 1], or [2,2], so we will add symbol P? to say that, is this Pit room?
Now agent will stop and think and will not make any harmful move. The agent will go back to the [1, 1]
room. The room [1,1], and [2,1] are visited by the agent, so we will use symbol V to represent the visited
squares.
In the room [1,2] agent perceives a stench which means there must be a Wumpus nearby. But Wumpus
cannot be in the room [1,1] as by rules of the game, and also not in [2,2] (Agent had not detected any stench
when he was at [2,1]).
Therefore agent infers that Wumpus is in the room [1,3], and in current state, there is no breeze which means
in [2,2] there is no Pit and no Wumpus. So it is safe, and we will mark it OK, and the agent moves to [2,2].
At room [2,2], here no stench and no breezes present so let's suppose agent decides to move to [2,3]. At
room [2,3] agent perceives glitter, so it should grab the gold and climb out of the cave.
CODE:
INITIAL:
class Character:
def __init__(self):
self.loc = (0,0)
self.alive = True
self.hasGold = False
if direction == 'a':
if direction == 'd':
if direction == 's':
class Room:
def __init__(self):
self.player = False
self.breeze = False
self.pit = False
self.stench = False
self.wumpus = False
self.gold= False
def __str__(self):
result = ""
result += "["
if(self.player == True):
result += "P"
else:
if(self.breeze == True):
result += "B"
else:
if(self.stench == True):
result += "S"
else:
if debug == True:
if(self.pit==True):
result +="H"
else:
if(self.wumpus==True):
result +="W"
else:
if(self.gold==True):
result += "G"
else:
result += "]"
return result
class Board:
self.rows = rows
self.columns = columns
self.map = {}
for r in range(rows):
for c in range(columns):
self.map[(r,c)] = Room()
self.player = Character()
self.placeItems()
self.checkSurrounding()
def placeItems(self):
self.map[(0,0)].player = True
noWumpus = True
while noWumpus == True:
noWumpus=False
pitCount = 5
pitCount -= 1
noGold = True
noGold= False
MOVEMENT:
return True
return True
return True
else:
return False
def checkLeft(self):
row = self.player.loc[0]
column = self.player.loc[1]
if column > 0:
def checkRight(self):
row = self.player.loc[0]
column = self.player.loc[1]
def checkUp(self):
row = self.player.loc[0]
column = self.player.loc[1]
if row > 0:
def checkDown(self):
row = self.player.loc[0]
column = self.player.loc[1]
def checkSurrounding(self):
self.checkLeft()
self.checkRight()
self.checkUp()
self.checkDown()
if self.canMove(direction)== True:
self.map[self.player.loc].player = False
self.player.move(direction)
self.map[self.player.loc].player = True
if self.map[self.player.loc].wumpus == True:
self.player.alive = False
self.player.alive = False
self.player.hasGold = True
else:
self.checkSurrounding()
def __repr__(self):
result = ""
for r in range(self.rows):
for c in range(self.columns):
result += '\n'
return result
INTERFACE:
class Game:
def __init__(self):
self.createBoard()
def askInput(self):
self.board.movePlayer(decision)
MAIN:
def createBoard(self):
self.board = Board(7,7)
def mainLoop(self):
print(self.board)
self.askInput()
print(self.board)
if self.board.player.hasGold == True:
else:
debug=False
game = Game()
game.mainLoop()
OUTPUT:
INITIAL STATE:
GAMEPLAY STATE:
END STATE:
CONCLUSION:
Thus the topics Brief, Knowledge Based agents, PEAS measure of Wumpus World Exploration,
has been successfully reported along with the code for the working game and sample output
TOOLS USED:
1) Python
2) Replit
3) Jupyter notebook
REFERNCES:
1) https://www.geeksforgeeks.org/ai-the-wumpus-world-description/
2) https://www.educative.io/answers/what-is-the-wumpus-world-in-artificial-intelligence
3) https://github.com/erikphillips/wumpus_world
4) https://replit.com/@KimMizhquiri1/Hunt-the-Wumpus?v=1