def traverseTo(self, goal_location):
        goal_reached = False
        gx, gy = goal_location
        while not self.isStarving() and not goal_reached:
            lx, ly = world.locationOf(self)
            dx = gx - lx
            if dx!=0:
                dx = round(dx/abs(dx))
            dy = gy - ly
            if dy != 0:
                dy = round(dy/abs(dy))
            location = W.addlocs((lx,ly),(dx,dy))
#             location, resources = world.bestLocationAt(location)
            self.moveTo(location)
            self.forage()
            self.eat()
            if location==goal_location or not self.isHungry():
                goal_reached = True
Пример #2
0
 def traverseTo(self, goal_location):
     goal_reached = False
     gx, gy = goal_location
     while not self.isStarving() and not goal_reached:
         lx, ly = world.locationOf(self)
         dx = gx - lx
         if dx != 0:
             dx = round(dx / abs(dx))
         dy = gy - ly
         if dy != 0:
             dy = round(dy / abs(dy))
         location = W.addlocs((lx, ly), (dx, dy))
         #             location, resources = world.bestLocationAt(location)
         self.moveTo(location)
         self.forage()
         self.eat()
         if location == goal_location or not self.isHungry():
             goal_reached = True
 def moveRandomDelta(self):
     d_loc = (rnd.randrange(3)-1,rnd.randrange(3)-1)
     location = world.locationOf(self)
     self.moveTo(W.addlocs(location, d_loc))
Пример #4
0
 def moveRandomDelta(self):
     d_loc = (rnd.randrange(3) - 1, rnd.randrange(3) - 1)
     location = world.locationOf(self)
     self.moveTo(W.addlocs(location, d_loc))