a hungry bird.
are attracted by FooD?, e.g. by an AppleTree that has grown some.
http://an.org/programming/bird.py (Hungry, Growing and Breeding birds)
hungryness part:
- class Bird(World):
- """A bird. Flies, and wants to eat often. Might be called HungryBird, until gets food (test returns true then - perhaps gets to Breeding).
(...)
Have been thinking of these as a swarm too, but can start as individuals too (there is no difference really, in a way, as we know ;)"""
SPEED = 0.01
- def begin_round(self):
- if self.target is None:
- if self.parent.food:
- self.target = random.choice(self.parent.food) print "Bird got to know there is food, goes to get some at", self.target, self
- else:
- if self.target in self.parent.food:
- t = self.target
- else:
- """oh no my food has disappeared!""" self.target = None
self.test()
- def get(self, food):
- self.food.append(self.parent.give(food))
- def test(self):
#assert self.want(Food) - no need to code really, that's what this is #if self.had_food is None: # self.had_food = self.food
- if self.target is None:
- if self.parent.food:
- print "the world has food but this bird no target, what's wrong?", self.parent.food
- elif not self.food:
- #print "Has no food yet - going towards", self.target, self pass
#else: #is this right - or should be 'if self.food'? if self.food:
print "Bird got food succesfully!", self #target might go to None if these were to be not greedy? return True #success!return False #not (yet
x.