Exemplo n.º 1
0
 def prepareToMove(self):
     self._life = self._life - 1
     if self._life <= 0:
         self.state = Dead(self)
     elif self.target is None:
         self.state = Exploration(self)
     elif self.target.x == self.x and self.target.y == self.y:
         self.state = FoundTarget(self, self.grid, self.x, self.y, self._antPromotion)
     else:
         foundX, foundY, foundScent = self.findScent(TARGET_PHEROMONE_KIND)
         if foundScent == 0:
             self.state = Exploration(self)
         else:
             self.state = FollowingScent(self, foundX, foundY, TARGET_PHEROMONE_KIND)
Exemplo n.º 2
0
class AntFemale(AbstractAnt):
    def __init__(self, grid, sprite, antPromotion, life=100, randomizer=None):
        AbstractAnt.__init__(self, grid, sprite, life=life, randomizer=randomizer)
        self.pheromones = []
        self.state = None
        self.target = None
        self._antPromotion = antPromotion

    def goToTarget(self, target):
        self.target = target

    def canFly(self):
        return True

    @ensure(valid_state="self.state is not None")
    def prepareToMove(self):
        self._life = self._life - 1
        if self._life <= 0:
            self.state = Dead(self)
        elif self.target is None:
            self.state = Exploration(self)
        elif self.target.x == self.x and self.target.y == self.y:
            self.state = FoundTarget(self, self.grid, self.x, self.y, self._antPromotion)
        else:
            foundX, foundY, foundScent = self.findScent(TARGET_PHEROMONE_KIND)
            if foundScent == 0:
                self.state = Exploration(self)
            else:
                self.state = FollowingScent(self, foundX, foundY, TARGET_PHEROMONE_KIND)

    def move(self):
        return self.state.move()

    def isDead(self):
        return self.state.dead