0% found this document useful (0 votes)
8 views9 pages

AIA_Exp 1_ VU22EECE0100102

The document details an experiment where an agent navigates a 4x4 grid in the Wumpus World using Python. The agent's objective is to explore, avoid dangers, collect gold, and return to the starting position, with various functions implemented for movement and decision-making. The experiment concludes with the agent successfully collecting gold and returning to its initial position.

Uploaded by

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

AIA_Exp 1_ VU22EECE0100102

The document details an experiment where an agent navigates a 4x4 grid in the Wumpus World using Python. The agent's objective is to explore, avoid dangers, collect gold, and return to the starting position, with various functions implemented for movement and decision-making. The experiment concludes with the agent successfully collecting gold and returning to its initial position.

Uploaded by

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

Ram Prasad

VU22EECE0100102

Wumpus World

Aim: To Implement WUMPUS World using Python.


Apparatus: pc, Google COLAB
Introduction:
This document records an experiment where an agent navigates through a virtual world
represented by a 4x4 grid. The agent's goal is to explore the environment, avoid dangers, find
gold, and return to the starting position.

Python Code :

def learnagent(world,i,j):
'''Function for an agent to know what position contains which
environment objects'''
if (world[i][j]==9):
agi,agj=i,j
print("\nNow the agent is at "+str(agi)+","+str(agj))
print("You came across a stench")
return agi,agj

elif (world[i][j]==7):
agi,agj=i,j
print("\nNow the agent is at "+str(agi)+","+str(agj))
print("You came across a pit")
return -5,-5

elif (world[i][j]==6):
agi,agj=i,j
print("\nNow the agent is at "+str(agi)+","+str(agj))
print("You found gold")
return -4,-4

elif (world[i][j]==5):
agi,agj=i,j
print("\nNow the agent is at "+str(agi)+","+str(agj))
print("You feel breeze")
return agi,agj

elif (world[i][j]==-1):
agi,agj=i,j
print("\nNow the agent is at "+str(agi)+","+str(agj))
print("You met wumpus")
return -5,-5
else: #if world environment was empty
agi,agj=i,j
print("\nNow the agent is at "+str(agi)+","+str(agj))
return agi,agj

def checkinp(agi,agj):
'''Function for checking input going in forward direction to get gold'''
if(agi==0 and agj==0):
print("\nyou can go at "+str(agi+1)+" "+str(agj)) #can move
upward
print("you can go at "+str(agi)+" "+str(agj+1)) #can move right
agvi=int(input("\nEnter input for row => "))
agvj=int(input("Enter input for column => "))
if(agvi==agi+1 and agvj==agj or agvi==agi and agvj==agj+1):
return agvi,agvj
else:
return -5
elif(agi==3 and agj==0):
print("\nyou can go at "+str(agi-1)+" "+str(agj)) #can go left
print("you can go at "+str(agi)+" "+str(agj+1)) #can go right
agvi=int(input("\nEnter input for row => "))
agvj=int(input("Enter input for column => "))
if(agvi==agi-1 and agvj==agj or agvi==agi and agvj==agj+1):
return agvi,agvj
else:
return -5
elif(agi==3 and agj==3):
print("\nyou can go at "+str(agi-1)+" "+str(agj)) #can go down
print("you can go at "+str(agi)+" "+str(agj-1)) #can go left
agvi=int(input("\nEnter input for row => "))
agvj=int(input("Enter input for column => "))
if(agvi==agi-1 and agvj==agj or agvi==agi and agvj==agj-1):
return agvi,agvj
else:
return -5
elif(agi==0 and agj==3):
print("\nyou can go at "+str(agi+1)+" "+str(agj)) #can go upward
print("you can go at "+str(agi)+" "+str(agj-1)) #can go left
agvi=int(input("\nEnter input for row => "))
agvj=int(input("Enter input for column => "))
if(agvi==agi+1 and agvj==agj or agvi==agi and agvj==agj-1):
return agvi,agvj
else:
return -5,-5
elif(agi==1 and agj==0 or agi==2 and agj==0 or agi==3 and agj==0):
print("\nyou can go at "+str(agi+1)+" "+str(agj)) #can go upward
print("you can go at "+str(agi)+" "+str(agj+1)) #can move right
agvi=int(input("\nEnter input for row => "))
agvj=int(input("Enter input for column => "))
if(agvi==agi+1 and agvj==agj or agvi==agi and agvj==agj+1):
return agvi,agvj
else:
return -5,-5
elif(agi==0 and agj==3 or agi==1 and agj==3 or agi==2 and agj==3 or
agi==3 and agj==3):
print("you can go at "+str(agi+1)+" "+str(agj)) #can go upward
print("you can go at "+str(agi)+" "+str(agj-1)) #can go left
agvi=int(input("Enter input for row => "))
agvj=int(input("Enter input for column => "))
if(agvi==agi+1 and agvj==agj or agvi==agi and agvj==agj-1):
return agvi,agvj
else:
return -5,-5
elif(agi==3 and agj==1 or agi==3 and agj==2 or agi==3 and agj==3):
print("\nyou can go at "+str(agi)+" "+str(agj+1)) #can go right
print("you can go at "+str(agi)+" "+str(agj-1)) #can go left
print("you can go at "+str(agi-1)+" "+str(agj)) #can move downward
agvi=int(input("\nEnter input for row => "))
agvj=int(input("Enter input for column => "))
if(agvi==agi and agvj==agj+1 or agvi==agi and agvj==agj-1 or
agvi==agi-1 and agvj==agj):
return agvi,agvj
else:
return -5,-5
else:
print("\nyou can go at "+str(agi)+" "+str(agj+1)) #can go right
print("you can go at "+str(agi)+" "+str(agj-1)) #can go left
print("you can go at "+str(agi+1)+" "+str(agj)) #can move upward
agvi=int(input("\nEnter input for row => "))
agvj=int(input("Enter input for column => "))
if(agvi==agi and agvj==agj+1 or agvi==agi and agvj==agj-1 or
agvi==agi+1 and agvj==agj):
return agvi,agvj
else:
return -5,-5

def checkinpreverse(agi,agj):
'''Function for checking input going in reverse direction to get back to
original position'''
if(agi==0 and agj==3):
print("you can go at "+str(agi)+" "+str(agj-1)) #can go left
agvi=int(input("\nEnter input for row => "))
agvj=int(input("Enter input for column => "))
if(agvi==agi and agvj==agj-1):
return agvi,agvj
else:
return -5,-5
elif(agi==0 and agj==2 or agi==0 and agj==1):
print("you can go at "+str(agi)+" "+str(agj+1)) #can go right
print("you can go at "+str(agi)+" "+str(agj-1)) #can go left
agvi=int(input("\nEnter input for row => "))
agvj=int(input("Enter input for column => "))
if(agvi==agi and agvj==agj-1 or agvi==agi and agvj==agj+1 ):
return agvi,agvj
else:
return -5,-5
elif(agi==1 and agj==0 or agi==2 and agj==0):
print("\nyou can go at "+str(agi-1)+" "+str(agj)) #can go downward
print("you can go at "+str(agi)+" "+str(agj+1)) #can move right
agvi=int(input("\nEnter input for row => "))
agvj=int(input("Enter input for column => "))
if(agvi==agi-1 and agvj==agj or agvi==agi and agvj==agj+1):
return agvi,agvj
else:
return -5,-5
elif(agi==1 and agj==3 or agi==2 and agj==3):
print("you can go at "+str(agi-1)+" "+str(agj)) #can go downward
print("you can go at "+str(agi)+" "+str(agj-1)) #can go left
agvi=int(input("Enter input for row => "))
agvj=int(input("Enter input for column => "))
if(agvi==agi-1 and agvj==agj or agvi==agi and agvj==agj-1):
return agvi,agvj
else:
return -5,-5
else:
print("\nyou can go at "+str(agi-1)+" "+str(agj)) #can go downward
print("you can go at "+str(agi)+" "+str(agj-1)) #can go left
print("you can go at "+str(agi)+" "+str(agj+1)) #can go right
agvi=int(input("\nEnter input for row => "))
agvj=int(input("Enter input for column => "))
if(agvi==agi-1 and agvj==agj or agvi==agi and agvj==agj-1 or agvi==agi
and agvj==agj+1):
return agvi,agvj
else:
return -5,-5

world=[ [0,5,7,5],
[9,0,5,0],
[-1,6,7,5],
[9,0,5,7] ] #declaration of a world

agi,agj=0,0 #initial agent position


print("\n\n\ninitially agent is at "+str(agi)+","+str(agj))
print("\nyou can go at "+str(agi+1)+" "+str(agj))
print("you can go at "+str(agi)+" "+str(agj+1))

agvi=int(input("Enter input for row => "))


agvj=int(input("Enter input for column => ")) #taking row and column
values
if(agvi==1 and agvj==0 or agvi==0 and agvj==1):
agi,agj=learnagent(world,agvi,agvj) #if input valid calling learn
agent function
else:
print("Not valid")

while(agi>=0):
agvi,agvj=checkinp(agi,agj)
if(agvi!=-5 and agvj!=-5):
agi,agj=learnagent(world,agvi,agvj)
else:
print("\nNot valid")

if(agi==-5):
print("\nGame over Sorry try next time!!!")
else:
print("\nYou have unlocked next level move back to your initial
position") #acquired gold

agi,agj=2,1 #implementation of reverse logic

while(agi>=0):
agvi,agvj=checkinpreverse(agi,agj)
if(agvi==0 and agvj==0):
agi,agj=-4,-4
elif(agvi!=-5 and agvj!=-5):
agi,agj=learnagent(world,agvi,agvj)
else:
print("\nNot valid")

if(agi==-5):
print("\nYou were really close but unfortunately you failed!!! Try
next time")
else:
print("\nHurray You won!!!!! Three cheers.")
Environment:
● A 4*4 grid of rooms.
● The agent initially in room square [0, 0], facing toward the right.
● Location of Wumpus and gold are chosen randomly except the first square [0,0].
● Each square of the cave can be a pit with probability 0.2 except the first square.
● Agent can Move:
1. Left turn,
2. Right turn
3. Move forward
4. Grab

Note: Diagonal movement is not allowed.


Observations:

initially agent is at 0,0

you can go at 1 0
you can go at 0 1
Enter input for row => 1
Enter input for column => 0

Now the agent is at 1,0


You came across a stench

you can go at 2 0
you can go at 1 1

Enter input for row => 1


Enter input for column => 1

Now the agent is at 1,1

you can go at 1 2
you can go at 1 0
you can go at 2 1

Enter input for row => 2


Enter input for column => 1

Now the agent is at 2,1


You found gold

You have unlocked next level move back to your initial position

you can go at 1 1
you can go at 2 0
you can go at 2 2

Enter input for row => 1


Enter input for column => 1

Now the agent is at 1,1

you can go at 0 1
you can go at 1 0
you can go at 1 2

Enter input for row => 1


Enter input for column => 0

Now the agent is at 1,0


You came across a stench

you can go at 0 0
you can go at 1 1

Enter input for row => 1


Enter input for column => 1

Now the agent is at 1,1

you can go at 0 1
you can go at 1 0
you can go at 1 2

Enter input for row => 1


Enter input for column => 0

Now the agent is at 1,0


You came across a stench

you can go at 0 0
you can go at 1 1

Enter input for row => 0


Enter input for column => 0

Hurray You won!!!!! Three cheers.


Explanation:

Phase 1: Moving Forward

● Initial Movement Options:


○ The agent can move right or down from (0, 0).
● Agent's Movement:
○ User inputs to move to (1, 0).
● Encounter:
○ The agent encounters a stench at (1, 0).
● Learning and Decision:
○ Agent's new position is recorded, and it identifies the stench.
● Continued Exploration:
○ Agent continues exploring based on available movements and encounters.

Phase 2: Collecting Gold and Reversing

1. Gold Collection:
○ Agent collects gold at (1, 2).
2. Return Journey:
○ Agent needs to return to (0, 0).
3. Completion:
○ Agent successfully returns to (0, 0).

Result: The experiment demonstrated the agent's ability to navigate a complex


environment, avoid dangers, achieve goals, and return to the starting position. This exercise
highlighted the effectiveness of the agent's decision-making process and pathfinding
capabilities.

You might also like