def __init__(self, pos): """ Initializes a critter creating his brain, setting his energy and age using the settings functions and assigning it the given position Parameter pos is a tuple with the coordinates of the critter in the world """ self.brain = Brain() self.energy = Critter_s.start_energy() self.age = Critter_s.start_age() self.pos = pos
def crossover(self, partner): """ Returns the critters' child and decreases energy to this critter and the partner Parameter partner is the critter's partner """ self.energy -= Critter_s.mate_cost partner.energy -= Critter_s.mate_cost2 child = Critter(Critter_s.randpos()) child.brain = self.brain.crossover(partner.brain) return child
def __init__(self): """ Initializes a simulation creating the world (which is a grid), creating a dictionary of critters, the keys are tuples representing the positions and the values are the critters, spawning food and then syncing everything with the world """ self.world = Grid(Environment_s.width, Environment_s.height) self.world_age = 0 self.population = {} for i in range(Simulation_s.n_crit): c = Critter(Critter_s.randpos()) self.population[c.pos] = c self.food = Food(Simulation_s.n_food) self.sync()