def _rock_available(self): for rock in self.world.rocks: if rects_are_overlapping(self.get_bounds(), rock.get_bounds(), self.PICKUP_REACH): return rock return None
def _particle_available(self): for particle in self.world.particles: if rects_are_overlapping(self.get_bounds(), particle.get_bounds(), self.PICKUP_REACH): return particle return None
def _crumb_available(self): for crumb in self.world.crumbs: if rects_are_overlapping(self.get_bounds(), crumb.get_bounds(), self.PICKUP_REACH): return crumb return None
def _morona_range(self): for morona in self.world.moronas: if rects_are_overlapping(self.get_bounds(), morona.get_bounds(), self.SENSOR_RANGE): return morona return None
def _morona_available(self): for morona in self.world.moronas: if rects_are_overlapping(self.get_bounds(), morona.get_bounds(), self.PICKUP_REACH): return morona return None
def _can_move(self): new_self = Explorer(self.x + self.dx, self.y + self.dy, self.world) bounds = new_self.get_bounds() # Tengo una piedra y la puedo dejar en base if self.has_rock and self._drop_available(): return True if not rect_in_world(bounds, new_self.world): return False for other in new_self.world.entities: # Allow collisions with other explorers. if isinstance(other, Explorer): continue # Allow collisions with other moronas. if isinstance(other, Morona): continue if not self.has_rock and isinstance(other, Rock): return True if rects_are_overlapping(bounds, other.get_bounds(), 2): return False return True
def _sense_particle(self): for particle in self.world.particles: if rects_are_overlapping(self.get_bounds(), particle.get_bounds(), self.PARTICLE_SENSOR_RANGE): return particle return None
def _morona_available(self): for siblings in self.world.moronas: for morona in self.world.moronas[siblings]: if rects_are_overlapping(self.get_bounds(), morona.get_bounds()): return morona, siblings return None, 0
def _pickup_available(self): for explorer in self.world.explorers: if (rects_are_overlapping(self.get_bounds(), explorer.get_bounds(), self.PICKUP_REACH) and explorer.has_rock): return explorer return None
def _sense_rock(self): # Wait a bit so that the explorers spread out. if self.ticks < self.SENSE_DELAY: return None for rock in self.world.rocks: if rects_are_overlapping(self.get_bounds(), rock.get_bounds(), self.SENSOR_RANGE): return rock return None
def _sense_crumbs(self): # Wait a bit so that the explorers spread out. if self.ticks < self.SENSE_DELAY: return None for crumb in self.world.crumbs: if rects_are_overlapping(self.get_bounds(), crumb.get_bounds(), self.SENSOR_RANGE): return crumb return None
def has_room(self, obstacles, world): """Checks whether self has room in world, among other obstacles.""" bounds = self.get_bounds() if not rect_in_world(bounds, world): return False for other in obstacles + world.entities: if rects_are_overlapping(bounds, other.get_bounds()): return False return True
def _obstacle_range(self): if self.has_rock: obstacle_range = 10 else: obstacle_range = 1 for obstacle in self.world.obstacles: if rects_are_overlapping(self.get_bounds(), obstacle.get_bounds(), obstacle_range): return obstacle return None
def has_room(self, moronas, world): """Checks whether self has room in world, among other moronas.""" bounds = self.get_bounds() if not rect_in_world(bounds, world): return False for other in world.entities_but_explorer: if rects_are_overlapping(bounds, other.get_bounds()): return False return True
def _can_move(self): new_self = Explorer(self.x + self.dx, self.y + self.dy, self.world) bounds = new_self.get_bounds() if not rect_in_world(bounds, new_self.world): return False for other in new_self.world.entities: # Allow collisions with other explorers. if isinstance(other, Explorer): continue if rects_are_overlapping(bounds, other.get_bounds()): return False return True
def has_room(self, world): """Checks whether self has room in world.""" bounds = self.get_bounds() if not rect_in_world(bounds, world): return False for other in world.entities: # Rocks can be one on top of another, it doesn't matter. if isinstance(other, Crumb): continue if rects_are_overlapping(bounds, other.get_bounds()): return False return True
def has_room(self, world): """Checks whether self has room in world.""" bounds = self.get_bounds() if not rect_in_world(bounds, world): return False for other in world.entities: # Rocks can be one on top of another, it doesn't matter. if isinstance(other, Rock): continue if rects_are_overlapping(bounds, other.get_bounds()): return False return True
def _drop_available(self): if rects_are_overlapping(self.get_bounds(), self.world.mars_base.get_bounds(), self.PICKUP_REACH): return True return False