def load_text(self): self.txt = { 'name': tx.new_text(self.fonts, 'calibri_12', self.name, self.color['sblue']), 'val': tx.new_text(self.fonts, 'calibri_8', '-', self.color['sblue']) }
def update_text(self): self.txt['min'] = tx.new_text(self.fonts, 'calibri_8', int(self.val[-1] * 0.5), self.color['sblue']) self.txt['max'] = tx.new_text(self.fonts, 'calibri_8', int(self.val[-1] * 1.5), self.color['sblue']) self.txt['val'] = tx.new_text(self.fonts, 'calibri_8', self.val[-1], self.color['sblue']) self.txt['slc'] = tx.new_text( self.fonts, 'calibri_8', '[{}:{}]'.format(-self.zpoints + self.zslide, self.zslide), self.color['sblue'])
def __init__(self, database): Bar.idd = 0 Bar.offs = 0 self.name = "Tweakeables Variables" self.glist = [] self.blist = [] self.flist = [] self.btext = tx.new_text(Setting.fonts, 'calibri_15', "Bunny Rates", (127, 118, 200)) self.ftext = tx.new_text(Setting.fonts, 'calibri_15', "Fox Rates", (127, 118, 200)) self.ptext = tx.new_text(Setting.fonts, 'calibri_15', "Start Simulation", (127, 118, 200)) self.receive_db(database)
def ent_slot_draw_list(self, display): for n, ent in enumerate( self.ent_list[self.current_slot:self.current_slot + 6]): x, y = self.pos['ent_slots'][0] y = y + 85 * n for v in ent.needs.values(): a, s, d, f = v[3] pc = (v[0] / v[1]) pygame.draw.rect(display, v[2], (x + a, y + s, int(d * pc), f)) if HUD.bdraw: display.blit(self.spr['bx1'], (x, y)) display.blit(ent.astxt['id'], (x + 26, y + 3)) display.blit(ent.astxt['age'], (x + 60, y + 23)) display.blit(ent.astxt['name_10'], (x + 72, y + 3)) display.blit(ent.astxt[str(ent.status)], (x + 214, y + 3)) display.blit(en.Ent.min[int(ent.sprid / 2)], (x + 5, y - 40)) cord = tx.new_text(self.fonts, "calibri_10", ent.cord, self.sblue) display.blit(cord, (x + 265, y + 58)) if ent.death > 0: self.spr['ded'] = self.spr['ded'].convert() self.spr['ded'].set_alpha(int(ent.death * (0.5))) display.blit(self.spr['ded'], (x, y))
def get_followed(self, game): for x in game.ent_list: x.followed = False ex, ey = self.cord cx, cy = tuple(game.cam.cord) game.addcord(0, (ex - cx) * game.scale) game.addcord(1, (ey - cy) * game.scale) self.followed = True self.astxt['view'] = tx.new_text( self.fonts, 'calibri_15', 'Viewing {}, with ID: {}, Fitness: {:.2f}'.format( self.name, self.id, self.genome.fitness), (221, 221, 250))
def ent_slot_draw(self, display): string = "Entities Alive: {} Showing {} - {}".format( len(self.ent_list), self.current_slot + 1, self.current_slot + 6) qnt = tx.new_text(self.fonts, "calibri_10", string, self.sblue) display.blit(qnt, (100, 70)) # if self.pos['misc']['box_bunny'][0]: # pygame.draw.rect(display, self.white, self.pos['misc']['box_bunny'][1], width=0) # else: # pygame.draw.rect(display, self.white, self.pos['misc']['box_bunny'][1], 1) # if self.pos['misc']['box_fox'][0]: # pygame.draw.rect(display, self.orange, self.pos['misc']['box_fox'][1], 0) # else: # pygame.draw.rect(display, self.orange, self.pos['misc']['box_fox'][1], 1) self.ent_slot_draw_list(display)
def tick(self, game, n=True): self.up_queue(game) self.preg(game) self.ticks += 1 if self.lovedelay > 0: self.lovedelay -= 1 if self.ticks % 600 == 0: self.inf['age'] += 1 self.genome.fitness += Ent.add if self.inf['age'] >= 50: game.kill(self, 'Old') self.astxt['age'] = tx.new_text(self.fonts, 'calibri_10', ('Age: {}').format( self.inf['age']), self.sblue) if self.needs['hungry'][0] <= self.needs['hungry'][1]: self.needs['hungry'][0] += self.global_inc['hungry'] if self.needs['thirst'][0] <= self.needs["thirst"][1]: self.needs['thirst'][0] += self.global_inc['thirst'] if self.needs['love'][0] <= self.needs["love"][1]: if self.inf['age'] >= 12 and self.lovedelay < 5: self.needs['love'][0] += self.global_inc['love'] / 2 if self.needs['rest'][0] <= self.needs["rest"][1]: self.needs['rest'][0] += self.global_inc['rest'] for b, x in self.needs.items(): if x[0] >= x[1]: if b != "love": self.death += 0.5 self.motive = b n = False if n: self.death -= 1 if self.death < 0: self.death = 0 if self.death >= 300: self.score -= 100 game.kill(self, self.motive) HUD.deadt[self.specie].append( (self.motive, self.specie, self.id, self.cord, self.score))
def action(self, game): self.astxt['fitness'] = tx.new_text( self.fonts, 'calibri_10', ('Fit: {:.2f}').format(self.genome.fitness), self.sblue) if self.status == "idle" and len( self.queue) == 0 and self.current == ['empty']: dec = [5] #if self.specie=='bunny' and self.ident_run():return # dec = Ent.decision_log(self) in1, in2, in3, in4 = self.getin() output = self.nn.activate((in1, in2, in3, in4)) dec[0] = np.argmax(output) + 1 if dec[0] == 1: if self.specie.lower() == 'bunny': if not self.search_for('food'): if self.tries[0] < 3: self.rand_path(self, 4) self.tries[0] += 1 else: self.rand_path(self, 24, True, 'food') self.tries[0] == 0 else: if not self.search_for('hunt'): if self.tries[0] < 3: self.rand_path(self, 4) self.tries[0] += 1 else: self.rand_path(self, 24, True, 'food') self.tries[0] == 0 elif dec[0] == 2: if not self.search_for('water'): if self.tries[1] < 3: self.rand_path(self, 4) self.tries[1] += 1 else: self.rand_path(self, 24, True, 'water') self.tries[1] == 0 return elif dec[0] == 3 and self.tries[2] < 5: self.needs['love'][0] = 0 if not self.search_for('love'): if self.tries[2] < 2: self.rand_path(self, 4) self.tries[2] += 1 else: self.rand_path(self, 24, True, 'love') self.tries[2] == 0 return elif dec[0] == 4: self.queue.append(("cmd", "self.rest()", "rest")) self.read_queue() return elif dec[0] == 5: if self.needs['thirst'][0] / self.needs['thirst'][ 1] < 0.5 and self.needs['hungry'][0] / self.needs[ 'thirst'][1] < 0.5: self.rand_path(self, 24, True, 'love') return if self.needs['thirst'][0] > self.needs['hungry'][0]: self.rand_path(self, 24, True, 'water') else: if self.specie == 'fox': self.rand_path(self, 32, True, 'hunt') else: self.rand_path(self, 24, True, 'food') if self.status == 'idle' and len(self.queue) != 0: self.read_queue()
def load_varables(self, game, gene): #--- Sprites----# self.eat_counter = 0 self.drink_counter = 0 self.love_counter = 0 self.flp_f = self.load_sprites(game, False) self.flp_t = self.load_sprites(game, True) self.spr = self.flp_f self.buf_flpf = self.flp_f.copy() self.buf_flpt = self.flp_t.copy() self.lovedelay = 4000 sh = ha.SpriteSheet('data/colect1.png') self.icon_spr = {} self.icons = { 'resting': (137, 1, 31, 32, False), 'loving': (169, 1, 22, 22, False), 'eating': (192, 1, 18, 22, False), 'drinking': (211, 1, 18, 22, False), 'walking': (230, 1, 32, 22, False), 'waiting': (0, 0, 0, 0, False), 'idle': (0, 0, 0, 0, False) } for x, y in self.icons.items(): self.icon_spr[x] = game.setid(1, sh, y) #---------------# gender = ('male', 'female') if gene == False: self.inf = { 'age': 15, #numpy.random.randint(5,16), 'speed': numpy.random.randint(-10, 10) * 0.015625 + 1 + Ent.database[self.specie]['inf']['speed'], 'view': Ent.database[self.specie]['inf']['view'], 'gender': gender[numpy.random.randint(2)], 'type': "log" } self.inc = { 'hungry': numpy.random.randint(-20, 20) / 100 + 1, 'thirst': numpy.random.randint(-20, 20) / 100 + 1, 'love': numpy.random.randint(-20, 20) / 100 + 1, 'rest': numpy.random.randint(-20, 20) / 100 + 1 } self.base = { 'hungry': numpy.random.randint(-20, 20) / 100 + 1 * Ent.database[self.specie]['base']['hungry'], 'thirst': numpy.random.randint(-20, 20) / 100 + 1 * Ent.database[self.specie]['base']['thirst'], 'love': numpy.random.randint(-20, 20) / 100 + 1 * Ent.database[self.specie]['base']['love'], 'rest': numpy.random.randint(-20, 20) / 100 + 1 * Ent.database[self.specie]['base']['rest'] } if gene: self.inf = { 'age': 0, 'speed': numpy.random.randint(-10, 10) * 0.015625 + 1 * gene['inf']['speed'], 'view': Ent.database[self.specie]['inf']['view'], 'gender': gender[numpy.random.randint(2)], 'type': "log" } self.inc = { 'hungry': numpy.random.randint(-8, 8) / 100 + 1 * gene['inc']['hungry'], 'thirst': gene['inc']['thirst'], 'love': numpy.random.randint(-8, 8) / 100 + 1 * gene['inc']['love'], 'rest': gene['inc']['rest'] } self.base = { 'hungry': numpy.random.randint(-5, 5) / 100 + 1 * gene['base']['hungry'], 'thirst': numpy.random.randint(-5, 5) / 100 + 1 * gene['base']['thirst'], 'love': numpy.random.randint(-5, 5) / 100 + 1 * gene['base']['love'], 'rest': numpy.random.randint(-5, 5) / 100 + 1 * gene['base']['rest'] } self.inc = { 'hungry': self.inc['hungry'] * ((self.inf['speed'] / 2) + 0.5), 'thirst': self.inc['thirst'] * ((self.inf['speed'] / 2) + 0.5) / (self.inc['hungry']**2), 'love': self.inc['love'] * self.inf['speed']**2, 'rest': self.inc['rest'] * ((self.inf['speed'] / 2) + 0.5) / (self.inc['hungry'] / 2 + 0.5) } self.global_inc = { 'hungry': Ent.database[self.specie]['inc']['hungry'] * self.inc['hungry'] * ((self.inc['love'] / 2) + 0.5), 'thirst': Ent.database[self.specie]['inc']['thirst'] * self.inc['thirst'] * ((self.inc['love'] / 2) + 0.5), 'love': Ent.database[self.specie]['inc']['love'] * self.inc['love'], 'rest': Ent.database[self.specie]['inc']['rest'] * self.inc['rest'] } self.stp_scale = 2 * self.inf['speed'] * game.scale game.data["ent"][self.cord[0]][self.cord[1]].append(self.id) self.walkeable = [0, 3, 4] self.water = [2, 1] self.queue = list() self.upqueue = list() self.path = set_path self.rand_path = random_path self.validate = value_tile self.steps = 0 self.lovedelay = 0 self.score = 0 self.buf = 0 self.pos = [0, 0] self.followed = False self.death = 0 self.birth = False self.b_counter = -1 self.ticks = 0 self.tries = [0, 0, 0] self.astxt = { 'name_10': tx.new_text(self.fonts, 'calibri_10', ('{} {}').format(self.inf['gender'], self.name), self.sblue), 'id': tx.new_text(self.fonts, 'calibri_10', self.id, self.sblue), 'walking': tx.new_text(self.fonts, 'calibri_10', 'walking', self.sblue), 'idle': tx.new_text(self.fonts, 'calibri_10', 'idle', self.sblue), 'eating': tx.new_text(self.fonts, 'calibri_10', 'eating', self.sblue), 'drinking': tx.new_text(self.fonts, 'calibri_10', 'drinking', self.sblue), 'resting': tx.new_text(self.fonts, 'calibri_10', 'resting', self.sblue), 'waiting': tx.new_text(self.fonts, 'calibri_10', 'waiting', self.sblue), 'loving': tx.new_text(self.fonts, 'calibri_10', 'loving', self.sblue), 'view': tx.new_text( self.fonts, 'calibri_15', 'Viewing {}, with ID: {}, Fitness: {:.2f}'.format( self.name, self.id, self.genome.fitness), (171, 191, 200)), 'speed': tx.new_text(self.fonts, 'calibri_10', ('Speed: {:.2f}').format(self.inf['speed']), self.sblue), 'hungry': tx.new_text(self.fonts, 'calibri_10', ('Hungry: {:.2f}').format(self.inc['hungry']), self.sblue), 'thirst': tx.new_text(self.fonts, 'calibri_10', ('Thirst: {:.2f}').format(self.inc['thirst']), self.sblue), 'love': tx.new_text(self.fonts, 'calibri_10', ('Love: {:.2f}').format(self.inc['love']), self.sblue), 'rest': tx.new_text(self.fonts, 'calibri_10', ('Rest: {:.2f}').format(self.inc['rest']), self.sblue), 'fitness': tx.new_text(self.fonts, 'calibri_10', ('Fit: {:.2f}').format(self.genome.fitness), self.sblue), 'age': tx.new_text(self.fonts, 'calibri_10', ('Age: {}').format(self.inf['age']), self.sblue) }
def update_text(self): self.nametext = tx.new_text(Setting.fonts, 'calibri_10', self.name, (127, 118, 200)) self.valtext = tx.new_text(Setting.fonts, 'calibri_10', ('{:.2f}').format(self.val * self.mult), (127, 118, 200))