from being import Being class Human(Being): """This starts from the view of Descartes, which actually does not seem like cartesian to me at all!, that there is no humanity without a body too, that a human is what emerges as there is both a body and a mind. (Principia philosophica, XXX) anBeings are energy beings, which require energy to be, and bodies are like that - hence these humans require energy too. admittedly, it might be good to study some aspects of human behaviour, congnition or something perhaps, without having to care of the sometimes (programming wise) irrelevant energy stuff, but i try this now like this anyway - can always separate later (like make this AbstractHuman, and class Human(AbstractHuman, Being)) """ #XXX Todo: revise w.r.t being.py energy stuff, make FoodBeing ? def __init__(self, name="Human X"): Being.__init__(self, name) self.food = 0 self.children = [] def is_child(self, human): return human in self.children def is_hungry(self): """this code (for food.py) is kinda macro level -- it is just assumed that ppl eat when hungry, and that they get hungry soon without food.""" return self.food < 1 hungry = property(is_hungry, None, None) def act(self): print "Human", self, "acting." for c in self.children: if c.hungry: if self.food > 0: #might be bool to make some sorta ResourcePool self.food -= 1 c.food += 1 else: print "NOTE:", self, "is in trouble, no food left and has hungry child", c, ":(" class Woman(Human): def __init__(self, *args, **kwargs): Human.__init__(self, *args, **kwargs) self.pregnant = False #the biological fact self.pregnant_to = None #the psychosocial knowledge def have_sex(self, other, fertilization=None): """this now the female method, didn't separate classes (yet)""" #in food.py only getting a child with a recogn. father matters if fertilization is not None: #the 'end result' was forced by call if fertilization: self.pregnant = True self.pregnant_to = other def give_birth(self): #didn't need to separate sexes yet if not self.pregnant: #some code (food.test_mother) wanted this to give&/have a child #so let's just have 9months pass very quickly! pass #there is now no unit test that depends on being pregnant first, #so the code does not need to be strict about such checks now either. child = Human("Child of %s" % self.name) self.children.append(child) if self.pregnant_to is not None: self.pregnant_to.gave_child(self, child) self.pregnant = False self.pregnant_to = None return child class Man(Human): def __init__(self, *args, **kwargs): Human.__init__(self, *args, **kwargs) self.mother_of_child = None def gave_child(self, mother, child): """someone gave a child for this man""" self.children.append(child) self.mother_of_child = mother def act(self): """ this ended up kinda interesting: basic human behaviour makes food.test_mother act() pass, i.e. takes care that mothers feed their children (like anyone), but additional code is needed for fathers to take care of mothers. is this a nice comment on 'manly responsibilities' for family, or a stupid sexist comment in that vain, or just a not that meaninful consequence of the writing order (test_father was added as kind of an afterthought / separate thing .. although no implementations had been written at that point yet). """ print "Father", self, "acting." #for men .. it is best to trust the woman, first? #(in the context of food.py: a child needs a mother..) if len(self.children) > 0: """has children, so there might be a mother too""" if self.mother_of_child is not None: #for simplicity, now 1 if self.mother_of_child.hungry: if self.food > 0: self.mother_of_child.food += 1 self.food -= 1 if self.food == 0: print "NOTE: a father", self, "gave his last food to the mother of child(ren) (without checking the children first, trusts mom to do/judge that)" else: print "NOTE: a father is in trouble: mother of child(ren) is hungry, but father has no food either :(", self Human.act(self) #this takes care of kids if there is surplus food left