0% found this document useful (0 votes)
64 views

Wumpus World

The document describes a knowledge-based agent exploring the Wumpus World. It provides background on the Wumpus World and knowledge-based agents. It then details the agent's reasoning and actions as it explores the world, perceiving clues about pits and the Wumpus to safely locate the gold.

Uploaded by

zachinpubg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

Wumpus World

The document describes a knowledge-based agent exploring the Wumpus World. It provides background on the Wumpus World and knowledge-based agents. It then details the agent's reasoning and actions as it explores the world, perceiving clues about pits and the Wumpus to safely locate the gold.

Uploaded by

zachinpubg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

WUMPUS WORLD

A MINI PROJECT REPORT

SUBMITTED BY

DHANUSH V 311521243012

FRANCIS SHARON J 311521243014

SOORYA NARAYANAN V 311521243052

In partial fulfilment for the award


of the degree of

BACHELOR OF TECHNOLOGY
In
ARTIFICIAL INTELLIGENCE AND DATA SCIENCE

MEENAKSHI SUNDARARAJAN ENGINEERING COLLEGE

KODAMBAKKAM, CHENNAI – 600024.

ANNA UNIVERSITY: CHENNAI 600 025

DECEMBER 2022
TABLE OF CONTENTS

SNO TITLE PAGE NO

1 BRIEF 1

2 KNOWLEDGE BASED AGENTS 3-7

3 PEAS MEASURE FOR WUMPUS 7-8

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.

KNOWLEDGE BASED AGENTS:


Humans claim that how intelligence is achieved-not by purely reflect mechanisms but by process of
reasoning that operate on internal representation of knowledge. In AI these techniques for intelligence are
present in Knowledge Based Agents.
Knowledge-based agents also known as KBA have explicit representation of knowledge that can be
reasoned. They maintain internal state of knowledge, reason over it, update it and perform actions
accordingly. These agents act intelligently according to requirements.
Knowledge based agents give the current situation in the form of sentences. They have complete
knowledge of current situation of mini-world and its surroundings. These agents manipulate knowledge to
infer new things at “Knowledge level”.
The knowledge based agents are made up of,
 Knowledge base (KB)
 Inference engine (IE)
 Sensors/Actuators
KNOWLEDGE BASE (KB):
It is the key component of a knowledge-based agent. These deal with real facts of world. It is a mixture
of sentences which are explained in knowledge representation language.
INFERENCE ENGINE (IE):
It is knowledge-based system engine used to infer new knowledge in the system.The inference engine is
the component of the intelligent system in artificial intelligence, which applies logical rules to the
knowledge base to infer new information from known facts. The first inference engine was part of the expert
system.
Inference engine commonly proceeds in two modes, which are:

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:

Backward-chaining is also known as a backward deduction or backward reasoning method when


using an inference engine. A backward chaining algorithm is a form of reasoning, which starts with
the goal and works backward, chaining through rules to find known facts that support the goal.

ACTIONS PERFORMED BY AN AGENT:

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.

Actions done by KB Agent:

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

function KB_AGENT (percept) returns an action


KB : knowledge base
t : time ( counter initially 0)
TELL(KB, MAKE_PERCEPT_SENTENCE (percept,t) )
action = ASK(KB, MAKE_ACTION_QUERY (t) )
TELL(KB, MAKE_ACTION_SENTENCE (action,t) )
t=t+1
return action

 If a percept is given, agent adds it to KB,


 It will then ask KB for the best action
 It then tells KB that it has in fact taken that action.
STRUCTURE:

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.

PEAS MEASURE OF THE WUMPUS GAME:

To explain the Wumpus world we have given PEAS description as below:

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:

o A 4*4 grid of rooms.


o The agent initially in room square [1, 1], facing toward the right.
o Location of Wumpus and gold are chosen randomly except the first square [1,1].
o Each square of the cave can be a pit with probability 0.2 except the first square.

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].

The Wumpus world Properties:

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.

EXPLORING THE WUMPUS WORLD :

Now we will explore the Wumpus world and will determine how the agent will find its goal by applying
logical reasoning.

Agent's First step:

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.

Agent's third Step:

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].

Agent's fourth step:

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:

from random import *

class Character:

def __init__(self):

self.name = "agent x"

self.loc = (0,0)

self.alive = True

self.hasGold = False

def move(self, direction):

if direction == 'a':

self.loc = (self.loc[0], self.loc[1]-1)

if direction == 'd':

self.loc = (self.loc[0], self.loc[1]+1)


if direction == 'w':

self.loc = (self.loc[0]-1, self.loc[1])

if direction == 's':

self.loc = (self.loc[0]+1, self.loc[1])

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:

result += " "

if(self.breeze == True):

result += "B"

else:

result += " "

if(self.stench == True):

result += "S"

else:

result += " "

if debug == True:
if(self.pit==True):

result +="H"

else:

result += " "

if(self.wumpus==True):

result +="W"

else:

result += " "

if(self.gold==True):

result += "G"

else:

result += " "

result += "]"

return result

class Board:

def __init__(self, rows, columns):

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:

row = randint(0, self.rows-1)

column = randint(0, self.columns-1 )

if (row, column) != (0,0):

self.map[(row, column)].wumpus = True

noWumpus=False

pitCount = 5

while pitCount > 0:

row = randint(0, self.rows-1)

column = randint(0, self.columns-1 )

if (row, column)!=(0,0) and self.map[(row,column)].wumpus==False and


self.map[(row,column)].pit==False:

self.map[(row, column)].pit = True

pitCount -= 1

noGold = True

while noGold == True:

row = randint(0, self.rows-1)

column = randint(0, self.columns-1 )

if (row, column) != (0,0) and self.map[(row, column)].pit == False and self.map[(row,


column)].wumpus == False:

self.map[(row, column)].gold = True

noGold= False

MOVEMENT:

def canMove(self, direction):

if direction == 'a' and self.player.loc[1] > 0:

return True

elif direction == "d" and self.player.loc[1] < self.columns-1:

return True

elif direction == "w" and self.player.loc[0] >0:


return True

elif direction == 's' and self.player.loc[0] < self.rows-1:

return True

else:

return False

def checkLeft(self):

row = self.player.loc[0]

column = self.player.loc[1]

if column > 0:

if self.map[(row, column-1)].wumpus == True:

self.map[(row, column)].stench = True

if self.map[(row, column-1)].pit == True:

self.map[(row, column)].breeze = True

def checkRight(self):

row = self.player.loc[0]

column = self.player.loc[1]

if column < self.columns-1:

if self.map[(row, column+1)].wumpus == True:

self.map[(row, column)].stench = True

if self.map[(row, column+1)].pit == True:

self.map[(row, column)].breeze = True

def checkUp(self):

row = self.player.loc[0]

column = self.player.loc[1]

if row > 0:

if self.map[(row-1, column)].wumpus == True:

self.map[(row, column)].stench = True

if self.map[(row-1, column)].pit == True:


self.map[(row, column)].breeze = True

def checkDown(self):

row = self.player.loc[0]

column = self.player.loc[1]

if row < self.rows-1:

if self.map[(row+1, column)].wumpus == True:

self.map[(row, column)].stench = True

if self.map[(row+1, column)].pit == True:

self.map[(row, column)].breeze = True

def checkSurrounding(self):

self.checkLeft()

self.checkRight()

self.checkUp()

self.checkDown()

def movePlayer(self, direction):

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

elif self.map[self.player.loc].pit == True:

self.player.alive = False

elif self.map[self.player.loc].gold == True:

self.player.hasGold = True

else:

self.checkSurrounding()

def __repr__(self):
result = ""

for r in range(self.rows):

for c in range(self.columns):

result = result + str(self.map[(r,c)])

result += " "

result += '\n'

return result

INTERFACE:

class Game:

def __init__(self):

self.createBoard()

def askInput(self):

decision = input("Choose: Left:(a), Right:(d), Up:(w), Down:(s) ")

self.board.movePlayer(decision)

MAIN:

def createBoard(self):

self.board = Board(7,7)

def mainLoop(self):

print(self.board)

while self.board.player.alive == True and self.board.player.hasGold == False:

self.askInput()

print(self.board)

if self.board.player.hasGold == True:

print("You have found the gold!! You win!!!")

else:

print("Game over :(")

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

You might also like