Class Agent
Class Agent
def __init__(self):
self._wumpusWorld = [
self._curLoc = [1,1]
self._isAlive = True
self._hasExited = False
def _FindIndicesForLocation(self,loc):
x,y = loc
return i,j
def _CheckForPitWumpus(self):
ww = self._wumpusWorld
i,j = self._FindIndicesForLocation(self._curLoc)
print(ww[i][j])
self._isAlive = False
print('Agent is DEAD.')
return self._isAlive
def TakeAction(self,action): # The function takes an action and returns whether the Agent is alive
validActions = ['Up','Down','Left','Right']
return False
if self._hasExited == True:
return False
index = validActions.index(action)
validMoves = [[0,1],[0,-1],[-1,0],[1,0]]
move = validMoves[index]
newLoc = []
newLoc.append(z)
self._curLoc = newLoc
self._hasExited=True
return self._CheckForPitWumpus()
def _FindAdjacentRooms(self):
cLoc = self._curLoc
validMoves = [[0,1],[0,-1],[-1,0],[1,0]]
adjRooms = []
for vM in validMoves:
room = []
valid = True
z = v + inc
if z<1 or z>4:
valid = False
break
else:
room.append(z)
if valid==True:
adjRooms.append(room)
return adjRooms
ww = self._wumpusWorld
if self._isAlive == False:
return [None,None]
if self._hasExited == True:
return [None,None]
adjRooms = self._FindAdjacentRooms()
i,j = self._FindIndicesForLocation(room)
if 'P' in ww[i][j]:
breeze = True
if 'W' in ww[i][j]:
stench = True
return [breeze,stench]
def FindCurrentLocation(self):
return self._curLoc
def main():
ag = Agent()
print('curLoc',ag.FindCurrentLocation())
ag.TakeAction('Right')
print('Percept',ag.PerceiveCurrentLocation())
ag.TakeAction('Right')
print('Percept',ag.PerceiveCurrentLocation())
ag.TakeAction('Right')
print('Percept',ag.PerceiveCurrentLocation())
ag.TakeAction('Up')
print('Percept',ag.PerceiveCurrentLocation())
ag.TakeAction('Up')
print('Percept',ag.PerceiveCurrentLocation())
ag.TakeAction('Up')
print('Percept',ag.PerceiveCurrentLocation())
if __name__=='__main__':
main()