def next_step(self, things,t): try: if self.lider == None: self.lider = getPerrito(things) except: pass if self.life > self.vida : if self.next_move == 'move': action = self.next_move target = tuple(random.choice(emptyPlace(self,things))) self.next_move = 'heal' elif self.next_move == 'heal': action = self.next_move target = self self.vida = self.life self.next_move = 'move' else: self.next_move = 'move' else: target = sort_by_distance(self.lider.position,adyacent_positions(self))[0] if (things.get(target) is None): action = 'move' self.lidermove = target # self.status = 'Perrito' else: # self.status = 'Perrito' if not isinstance(things.get(target), Player): action = 'attack' target = things.get(target) self.vida = self.life if action: return action, target
def next_step(self, things, t): try: if self.lider == None: self.lider = getPerrito(things) except: pass if self.life > self.vida: if self.next_move == 'move': action = self.next_move target = tuple(random.choice(emptyPlace(self, things))) self.next_move = 'heal' elif self.next_move == 'heal': action = self.next_move target = self self.vida = self.life self.next_move = 'move' else: self.next_move = 'move' else: target = sort_by_distance(self.lider.position, adjacent_positions(self))[0] if (things.get(target) is None): action = 'move' self.lidermove = target # self.status = 'Perrito' else: # self.status = 'Perrito' if not isinstance(things.get(target), Player): action = 'attack' target = things.get(target) self.vida = self.life if action: return action, target
def next_step(self, things, t): """Zombies attack if in range, else move in direction of players.""" action = None # possible targets for movement and attack humans = [ thing for thing in things.values() if isinstance(thing, Player) ] positions = possible_moves(self.position, things) if humans: # targets available target = closest(self, humans) if distance(self.position, target.position) < self.weapon.max_range: # target in range, attack action = 'attack', target else: # target not in range, _try_ to move if positions: # move best_position = closest(target, positions) action = 'move', best_position else: # if blocked by obstacles, try to break them adjacent = sort_by_distance(target, adjacent_positions(self)) for position in adjacent: thing = things.get(position) if isinstance(thing, (Box, Wall)): return 'attack', thing else: # no targets, just wander around if positions: action = 'move', random.choice(positions) return action
def next_step(self, things, t): '''Zombies attack if in range, else move in direction of players.''' action = None # possible targets for movement and attack humans = [thing for thing in things.values() if isinstance(thing, Player)] positions = possible_moves(self.position, things) if humans: # targets available target = closest(self, humans) if distance(self.position, target.position) < self.weapon.max_range: # target in range, attack action = 'attack', target else: # target not in range, _try_ to move if positions: # move best_position = closest(target, positions) action = 'move', best_position else: # if blocked by obstacles, try to break them adyacents = sort_by_distance(target, adyacent_positions(self)) for position in adyacents: thing = things.get(position) if isinstance(thing, (Box, Wall)): return 'attack', thing else: # no targets, just wander around if positions: action = 'move', random.choice(positions) return action