예제 #1
0
    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
예제 #2
0
    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
예제 #3
0
    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
예제 #4
0
 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
예제 #5
0
 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
예제 #6
0
    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
예제 #7
0
    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
예제 #8
0
    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
예제 #9
0
    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
예제 #10
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
예제 #11
0
    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
예제 #12
0
    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
예제 #13
0
    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
예제 #14
0
    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
예제 #15
0
    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
예제 #16
0
    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
예제 #17
0
    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
예제 #18
0
    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
예제 #19
0
    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
예제 #20
0
    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
예제 #21
0
    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
예제 #22
0
 def _drop_available(self):
     if rects_are_overlapping(self.get_bounds(),
                              self.world.mars_base.get_bounds(),
                              self.PICKUP_REACH):
         return True
     return False
예제 #23
0
 def _drop_available(self):
     if rects_are_overlapping(self.get_bounds(),
                              self.world.mars_base.get_bounds(),
                              self.PICKUP_REACH):
         return True
     return False