To solve Wumpus World Problem using Python demonstrating Inferences from Propositional Logic
The Wumpus world is a simple world example to illustrate the worth of a knowledge-based agent and to represent knowledge representation.
The figure below shows a Wumpus world containing one pit and one Wumpus. There is an agent in room [1,1]. The goal of the agent is to exit the Wumpus world alive. The agent can exit the Wumpus world by reaching room [4,4]. The wumpus world contains exactly one Wumpus and one pit. There will be a breeze in the rooms adjacent to the pit, and there will be a stench in the rooms adjacent to Wumpus.
Wumpus World RepresentationThis is a python program that uses propositional logic sentences to check which rooms are safe.
It is assumed that there will always be a safe path that the agent can take to exit the Wumpus world. The logical agent can take four actions: Up, Down, Left and Right. These actions help the agent move from one room to an adjacent room. The agent can perceive two things: Breeze and Stench.
#DEVELOPED BY : Naveen Kumar P
#REGISTER NUMBER: 212222230092
wumpus=[["Save","Breeze","PIT","Breeze"],
["Smell","Save","Breeze","Save"],
["WUMPUS","GOLD","PIT","Breeze"],
["Smell","Save","Breeze","PIT"]]
row=0
column=0
arrow=True
player=True
score=0
while(player):
choice=input("press u to move up\npress d to move down\npress l to move left\npress r to move right\n")
if choice == "u":
if row != 0:
row-=1
else:
print("move denied")
print("current location: ",wumpus[row][column],"\n")
elif choice == "d" :
if row!=3:
row+=1
else:
print("move denied")
print("current location: ",wumpus[row][column],"\n")
elif choice == "l" :
if column!=0:
column-=1
else:
print("move denied")
print("current location: ",wumpus[row][column],"\n")
elif choice == "r" :
if column!=3:
column+=1
else:
print("move denied")
print("current location: ",wumpus[row][column],"\n")
else:
print("move denied")
if wumpus[row][column]=="Smell" and arrow != False:
arrow_choice=input("do you want to throw an arrow-->\npress y to throw\npress n to save your arrow\n")
if arrow_choice == "y":
arrow_throw=input("press u to throw up\npress d to throw down\npress l to throw left\npress r to throw right\n")
if arrow_throw == "u":
if wumpus[row-1][column] == "WUMPUS":
print("wumpus killed!")
score+=1000
print("score: ",score)
wumpus[row-1][column] = "Save"
wumpus[1][0]="Save"
wumpus[3][0]="Save"
else:
print("arrow wasted...")
score-=10
print("score: ",score)
elif arrow_throw == "d":
if wumpus[row+1][column] == "WUMPUS":
print("wumpus killed!")
score+=1000
print("score: ",score)
wumpus[row+1][column] = "Save"
wumpus[1][0]="Save"
wumpus[3][0]="Save"
else:
print("arrow wasted...")
score-=10
print("score: ",score)
elif arrow_throw == "l":
if wumpus[row][column-1] == "WUMPUS":
print("wumpus killed!")
score+=1000
print("score: ",score)
wumpus[row][column-1] = "Save"
wumpus[1][0]="Save"
wumpus[3][0]="Save"
else:
print("arrow wasted...")
score-=10
print("score: ",score)
elif arrow_throw == "r":
if wumpus[row][column+1] == "WUMPUS":
print("wumpus killed!")
score+=1000
print("score: ",score)
wumpus[row][column+1] = "Save"
wumpus[1][0]="Save"
wumpus[3][0]="Save"
else:
print("arrow wasted...")
score-=10
print("score: ",score)
arrow=False
if wumpus[row][column] == "WUMPUS" :
score-=1000
print("\nWumpus here!!\n You Die\nAnd your score is: ",score
,"\n")
break
if(wumpus[row][column]=='GOLD'):
score+=1000
print("GOLD FOUND!You won....\nYour score is: ",score,"\n")
break
if(wumpus[row][column]=='PIT'):
score-=1000
print("Ahhhhh!!!!\nYou fell in pit.\nAnd your score is: ",score,"\n")
break
![](https://private-user-images.githubusercontent.com/87870499/277158772-8696111a-a4a7-47cb-ba4b-43a4ef88573f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjIwMTk0MTQsIm5iZiI6MTcyMjAxOTExNCwicGF0aCI6Ii84Nzg3MDQ5OS8yNzcxNTg3NzItODY5NjExMWEtYTRhNy00N2NiLWJhNGItNDNhNGVmODg1NzNmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MjYlMkZ1cy1lYXN0LT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