Jump to content
Wikibooks The Free Textbook Project

Talk:Python Programming/Source Documentation and Comments

Page contents not supported in other languages.
Add topic
From Wikibooks, open books for an open world

i need help ,please explain this code



import numpy as np class Agent():

 Template for Agent class. Uncallable
 def __init__(self, start_loc, home_loc, start_face):
 self.bump = False
 self.dirty = False
 self.home = False
 self.loc = start_loc
 self.home_loc =home_loc
 self.bearing = self.__bearing__(start_face)
 self.percept_sequence = []
 self.action = 'powerup'
 def __bearing__(self, face):
 Converts an alphanumeric bearing into a coordinate
 return (np.array([-1,0]) if face=='N'
 else np.array([1,0]) if face=='S'
 else np.array([0,1]) if face=='E'
 else np.array([0,-1]))
 def get_percept(self, state):
 
 Sets conditions for when each of three onboard detectors should be set
 to 1
 
 self.bump = False
 self.dirty = False
 self.home = False
 if (min(self.loc + self.bearing) < 0
 or min(state.shape - self.loc - self.bearing) == 0
 or state[self.loc[0] + self.bearing[0],
 self.loc[1] + self.bearing[1]] == 2):
 self.bump = True
 if state[self.loc[0], self.loc[1]] == 1:
 self.dirty = True
 # determine if vacuum is in home loc
 if (self.loc-self.home_loc).sum() == 0:
 self.home = True
 print (self.bump, self.dirty, self.home)
 self.percept_sequence.append((self.bump, self.dirty, self.home))

Start a discussion about Python Programming/Source Documentation and Comments

Talk pages are where people discuss how to make content on Wikibooks the best that it can be. You can use this page to start a discussion with others about how to improve Python Programming/Source Documentation and Comments.

Start a discussion

AltStyle によって変換されたページ (->オリジナル) /