Update evo.py

This commit is contained in:
Brad Stein 2022-07-24 13:39:56 -05:00 committed by GitHub
parent 41a0306066
commit 5fa10eba96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

408
evo.py
View File

@ -1,15 +1,31 @@
# To Do
# birth near moms
# non-random movements
# move away from theieves
# group by charming lifeforms
# group by kin
# bonus for kin in requests
# bonus for children in requests
# world full apocalypse
# graphical output
# csv outputs
# rewrite stats method :(
import random import random
import math
import names import names
genesis_count = 1000 # how many lifeforms to start with genesis_count = 100 # how many lifeforms to start with
apocalypse = 1000 # how many yaers until the world takes no more turns world_size = 75 # how big is the flat earth
world_size = 42 # how big is the flat earth apocalypse_years = 99 # how many yaers until no more months can pass
months_in_a_year = 12 # how many months in a year
roll_max = 100 # the upper bound for rolls roll_max = 100 # the upper bound for rolls
min_health = 800 min_health = 800
max_health = 1000 max_health = 1000
lifetime_min_start = 20 lifetime_min_start = 20
lifetime_max_start = 50 lifetime_max_start = 50
maturity_upper_bound_age = 13 maturity_min_start = 12
maturity_max_start = 19
luck_min_start = 1 luck_min_start = 1
luck_max_start = 8 luck_max_start = 8
resilence_min_start = 1 resilence_min_start = 1
@ -20,8 +36,8 @@ speed_min_start = 1
speed_max_start = 5 speed_max_start = 5
restless_min_start = 0 restless_min_start = 0
restless_max_start = 4 restless_max_start = 4
gestation_min_start = 5 gestation_min_start = 7
gestation_max_start = 8 gestation_max_start = 10
hunger_start = 0 hunger_start = 0
eat_rate_min_start = 2 eat_rate_min_start = 2
eat_rate_max_start = 7 eat_rate_max_start = 7
@ -41,51 +57,59 @@ reach_min_start = 1
reach_max_start = 4 reach_max_start = 4
skill_min_start = 8 skill_min_start = 8
skill_max_start = 24 skill_max_start = 24
kinship_min_start = 7
kinship_max_start = 14
begs = 0 begs = 0
gifts = 0 gifts = 0
thefts = 0 thefts = 0
finds = 0 finds = 0
last_id = 0 last_id = 0
month_avgs = []
month_lows = []
month_highs = []
apocalypse = apocalypse_years*months_in_a_year
world = [[None for i in range(world_size)] for j in range(world_size)] world = [[None for i in range(world_size)] for j in range(world_size)]
alive_list = [] alive_list = []
class LifeForm: class LifeForm:
def __init__(self): def __init__(self):
# broad properties # broad properties
self.luck = 0 # catch all positive/negative value self.luck = 0 # catch all positive/negative value
self.resilence = 0 # how many failures a lifeform can tollerate in a turn self.resilence = 0 # how many failures a lifeform can tollerate in a turn
self.skill = 0 # value of individual performance capability self.skill = 0 # value of individual performance capability
self.intelligence = 0 # how many turns ahead a lifeform can try to optimize strategies for dependent props self.intelligence = 0 # how many turns ahead a lifeform can try to optimize strategies for dependent props
# death properties # death properties
self.health = 0 # how far from death the lifeform is self.health = 0 # how far from death the lifeform is
self.lifetime = 0 # how many turns a lifeform has been alive self.lifetime = 0 # how many turns a lifeform has been alive
# movement properties # movement properties
self.speed = 0 # movements per round self.speed = 0 # movements per round
self.restless = 0 # likihood of trying to move per round self.restless = 0 # likihood of trying to move per round
# reproduction properties # reproduction properties
self.mature = False # whether or not entity can reproduce self.mature = False # whether or not entity can reproduce
self.male = False # whether the lifeform is male or female self.mature_age = 0 # age when mature
self.pregnant = False # whether or not for the current turn the lifeform is pregnant self.male = False # whether the lifeform is male or female
self.gestation = 0 # how many turns it takes for a new lifeform to birth self.pregnant = False # whether or not for the current turn the lifeform is pregnant
self.gestation = 0 # how many turns it takes for a new lifeform to birth
self.birth_month = 0 # what month the lifeform was born
# energy properties # energy properties
self.hunger = 0 # numerical value representing current hunger, affects health self.hunger = 0 # numerical value representing current hunger, affects health
self.eat_rate = 0 # how much food a lifeform tries to eat a turn self.eat_rate = 0 # how much food a lifeform tries to eat a turn
self.food = 0 # how much food a lifeform owns self.food = 0 # how much food a lifeform owns
self.greed = 0 # factor of actual need greater that lifeform requires self.greed = 0 # factor of actual need greater that lifeform requires
# social properties # social properties
self.happiness = 0 # how happy the lifeform is self.happiness = 0 # how happy the lifeform is
self.stingy = 0 # how willing a lifeform is to assist others against happiness self.stingy = 0 # how willing a lifeform is to assist others against happiness
self.charm = 0 # how much this lifeform affects other lifeforms nearby self.charm = 0 # how much this lifeform affects other lifeforms nearby
self.beauty = 0 # how preferable a lifeform is for mating self.beauty = 0 # how preferable a lifeform is for mating
self.reach = 0 # how far from the lifeform does it care about other lifeform's charm & attractiveness self.reach = 0 # how far from the lifeform does it care about other lifeform's charm & attractiveness
self.kinship = 0 # how much a lifeform cares about its kin self.kinship = 0 # how much a lifeform cares about its kin
self.family = "" self.family = ""
self.name = "" self.name = ""
@ -103,47 +127,49 @@ class LifeForm:
self.mated_recently = False self.mated_recently = False
# methods # methods
def take_turn(self): def take_turn(self, month):
self.move() self.move()
self.forage() self.forage()
self.mingle() self.mingle()
self.pregnancy() self.pregnancy(month)
self.eat() self.eat()
self.age() self.age(month)
def spawn(self, x, y, id, male, luck=0, resilence=0, intelligence=0, skill=0, health=0, lifetime=0, speed=0, def spawn(self, x, y, id, male, birth_month, luck=0, resilence=0, intelligence=0, skill=0, health=0, lifetime=0,
restless=0, mature=False, gestation=0, hunger=0, eat_rate=0, food=0, greed=0, happiness=0, stingy=0, speed=0,restless=0, mature=False, gestation=0, hunger=0, eat_rate=0, food=0, greed=0, happiness=0,
charm=0, beauty=0, reach=0, kinship=0, name="", family=""): stingy=0, charm=0, beauty=0, reach=0, kinship=0, name="", family="", mature_age=0):
self.luck = luck self.luck=luck
self.resilence = resilence self.resilence=resilence
self.intelligence = intelligence self.intelligence=intelligence
self.skill = skill self.skill=skill
self.health = health self.health=health
self.lifetime = lifetime self.lifetime=lifetime
self.speed = speed self.speed=speed
self.restless = restless self.restless=restless
self.resilence = resilence self.resilence=resilence
self.mature = mature self.mature=mature
self.male = male self.mature_age=mature_age
self.pregnant = False self.male=male
self.gestation = gestation self.pregnant=False
self.hunger = hunger self.gestation=gestation
self.eat_rate = eat_rate self.hunger=hunger
self.food = food self.eat_rate=eat_rate
self.greed = greed self.food=food
self.happiness = happiness self.greed=greed
self.stingy = stingy self.happiness=happiness
self.charm = charm self.stingy=stingy
self.beauty = beauty self.charm=charm
self.reach = reach self.beauty=beauty
self.kinship = kinship self.reach=reach
self.kinship=kinship
self.name=name self.name=name
self.family=family self.family=family
self.x = x self.birth_month=birth_month
self.y = y self.x=x
self.id = id self.y=y
self.id=id
def birth(self, x, y, id, male, food, mother_genes, father_genes, name, family): def birth(self, x, y, id, male, food, mother_genes, father_genes, name, family, birth_month):
self.male = male self.male = male
self.food = food self.food = food
self.lifetime = 0 self.lifetime = 0
@ -154,6 +180,7 @@ class LifeForm:
self.id = id self.id = id
self.name = name self.name = name
self.family = family self.family = family
self.birth_month = birth_month
for key in mother_genes.keys(): for key in mother_genes.keys():
mod = [mother_genes[key], father_genes[key]] mod = [mother_genes[key], father_genes[key]]
@ -182,6 +209,10 @@ class LifeForm:
if charm_improve_roll <= self.luck + self.charm: if charm_improve_roll <= self.luck + self.charm:
self.charm = self.charm + 1 self.charm = self.charm + 1
kinship_improve_roll = random.randrange(0, roll_max)
if kinship_improve_roll <= self.luck + self.kinship:
self.kinship = self.kinship + 1
greed_improve_roll = random.randrange(0, roll_max) greed_improve_roll = random.randrange(0, roll_max)
if greed_improve_roll <= self.luck + self.greed: if greed_improve_roll <= self.luck + self.greed:
self.greed = self.greed - 1 self.greed = self.greed - 1
@ -226,7 +257,9 @@ class LifeForm:
and self.happiness + target.luck + target.charm > self.stingy: and self.happiness + target.luck + target.charm > self.stingy:
self.food = self.food - ammount self.food = self.food - ammount
target.food = target.food + ammount target.food = target.food + ammount
# print(f"happiness pre-bump give {self.happiness}")
self.happiness = self.happiness + self.luck + self.stingy + target.charm self.happiness = self.happiness + self.luck + self.stingy + target.charm
# print(f"happiness post-bump give {self.happiness}")
stingy_roll = random.randrange(0, roll_max) stingy_roll = random.randrange(0, roll_max)
if stingy_roll < target.stingy: if stingy_roll < target.stingy:
target.stingy = target.stingy - 1 target.stingy = target.stingy - 1
@ -243,7 +276,9 @@ class LifeForm:
self.health = self.health - round(health_delta/2) self.health = self.health - round(health_delta/2)
if target.happiness > ammount - target.luck: if target.happiness > ammount - target.luck:
# print(f"happiness pre-bump take target {target.happiness}")
target.happiness = target.happiness - ammount + target.luck target.happiness = target.happiness - ammount + target.luck
# print(f"happiness post-bump take target {target.happiness}")
else: else:
target.happiness = 0 target.happiness = 0
@ -259,7 +294,9 @@ class LifeForm:
self.health = self.health - health_delta self.health = self.health - health_delta
if self.happiness > ammount - self.luck: if self.happiness > ammount - self.luck:
# print(f"happiness pre-bump take self {self.happiness}")
self.happiness = self.happiness - ammount + self.luck self.happiness = self.happiness - ammount + self.luck
# print(f"happiness post-bump take self {self.happiness}")
else: else:
self.happiness = 0 self.happiness = 0
@ -282,15 +319,18 @@ class LifeForm:
found_ammount_found = luck_imapct*(self.skill*self.intelligence - attempts - 1) found_ammount_found = luck_imapct*(self.skill*self.intelligence - attempts - 1)
self.food = self.food + found_ammount_found self.food = self.food + found_ammount_found
global finds; finds = finds + 1 global finds; finds = finds + 1
else:
self.happiness = self.happiness + self.hunger
def age(self): def age(self, month):
self.lifetime = self.lifetime + 1 if month > 0 and month % months_in_a_year == self.birth_month:
self.lifetime = self.lifetime + 1
self.mated_recently = False self.mated_recently = False
age_roll = random.randrange(0, roll_max) age_roll = random.randrange(0, round(self.lifetime/months_in_a_year) + 1)
if age_roll > self.luck: if age_roll > self.luck:
self.health = self.health - self.lifetime self.health = self.health - self.lifetime
maturity_offset = random.randrange(0, self.luck) maturity_offset = random.randrange(0, self.luck)
if not self.mature and maturity_upper_bound_age <= self.lifetime + maturity_offset: if not self.mature and self.mature_age <= self.lifetime + maturity_offset:
self.mature = True self.mature = True
if self.health < 0: if self.health < 0:
self.die() self.die()
@ -329,8 +369,11 @@ class LifeForm:
# attack/ignore # attack/ignore
def mate(self, target): def mate(self, target):
if self.health + self.beauty*self.luck*self.charm > target.beauty + target.health: if self.health + self.beauty > target.beauty + target.health:
self.happiness = self.happiness + self.health + self.beauty*self.luck*self.charm - target.beauty # print(f"happiness pre-bump mate success {self.happiness} {self.beauty} {target.beauty}")
self.happiness = self.happiness + abs(self.beauty - target.beauty) + self.luck
target.happiness = target.happiness + abs(target.beauty - self.beauty) + target.luck
# print(f"happiness post-bump mate success {self.happiness}")
if self.male and not target.male and not target.pregnant: if self.male and not target.male and not target.pregnant:
target.pregnant = True target.pregnant = True
target.rounds_pregnant = 0 target.rounds_pregnant = 0
@ -349,6 +392,7 @@ class LifeForm:
"stingy": self.stingy, "stingy": self.stingy,
"charm": self.charm, "charm": self.charm,
"beauty": self.beauty, "beauty": self.beauty,
"mature_age": self.mature_age,
"reach": self.reach, "reach": self.reach,
"kinship": self.kinship, "kinship": self.kinship,
"food": round(self.food/2) # This is not a property on the maternal list, daddy pays up front "food": round(self.food/2) # This is not a property on the maternal list, daddy pays up front
@ -373,6 +417,7 @@ class LifeForm:
"stingy": target.stingy, "stingy": target.stingy,
"charm": target.charm, "charm": target.charm,
"beauty": target.beauty, "beauty": target.beauty,
"mature_age": target.mature_age,
"reach": target.reach, "reach": target.reach,
"kinship": target.kinship, "kinship": target.kinship,
"food": round(target.food/2) # This is not a property on the maternal list, daddy pays up front "food": round(target.food/2) # This is not a property on the maternal list, daddy pays up front
@ -382,12 +427,14 @@ class LifeForm:
self.mated_recently = self.luck*self.greed > random.randrange(0, roll_max) self.mated_recently = self.luck*self.greed > random.randrange(0, roll_max)
else: else:
# if rejected, happiness transfer # if rejected, happiness transfer
self.happiness = self.happiness + self.beauty*self.luck*self.charm + self.health - target.beauty \ # print(f"happiness pre-bump mate reject self {self.happiness}")
- target.health self.happiness = self.happiness + self.beauty - target.beauty
target.happiness = target.happiness + target.beauty*target.luck*target.charm + target.health \ # print(f"happiness post-bump mate reject self {self.happiness}")
- self.beauty - self.health # print(f"happiness pre-bump mate reject target {target.happiness}")
target.happiness = target.happiness + target.beauty - self.beauty
# print(f"happiness post-bump mate reject target {target.happiness}")
def pregnancy(self): def pregnancy(self, month):
if not self.male and self.pregnant: if not self.male and self.pregnant:
if self.rounds_pregnant < self.gestation: if self.rounds_pregnant < self.gestation:
self.rounds_pregnant = self.rounds_pregnant + 1 self.rounds_pregnant = self.rounds_pregnant + 1
@ -408,6 +455,7 @@ class LifeForm:
"stingy": self.stingy, "stingy": self.stingy,
"charm": self.charm, "charm": self.charm,
"beauty": self.beauty, "beauty": self.beauty,
"mature_age": self.mature_age,
"reach": self.reach, "reach": self.reach,
"kinship": self.kinship "kinship": self.kinship
} }
@ -430,7 +478,8 @@ class LifeForm:
mother_genes=maternal_genes, mother_genes=maternal_genes,
father_genes=self.paternal_genes, father_genes=self.paternal_genes,
name=names.get_first_name(gender=gender_text), name=names.get_first_name(gender=gender_text),
family=family_name family=family_name,
birth_month=month%months_in_a_year
) )
child.parents.append(self) child.parents.append(self)
child.parents.append(self.baby_daddy) child.parents.append(self.baby_daddy)
@ -465,14 +514,179 @@ class LifeForm:
self.health = self.health + self.hunger self.health = self.health + self.hunger
happiness_mods = [self.hunger, self.luck] happiness_mods = [self.hunger, self.luck]
happiness_mods.sort() happiness_mods.sort()
# print(f"happiness pre-bump eat hungry {self.happiness}")
self.happiness = self.happiness + random.randrange(happiness_mods[0], happiness_mods[1] + 1) self.happiness = self.happiness + random.randrange(happiness_mods[0], happiness_mods[1] + 1)
# print(f"happiness post-bump eat hungry {self.happiness}")
elif self.luck > 0: elif self.luck > 0:
# print(f"happiness pre-bump eat hungerless {self.happiness}")
self.happiness = self.happiness + random.randrange(0, self.luck) self.happiness = self.happiness + random.randrange(0, self.luck)
# print(f"happiness post-bump eat hungerless {self.happiness}")
def print_world(): def print_world():
pass pass
def lifeform_stats(month):
# To any future critic... I felt lazy... sue me
precision = 2
new_average = {
"luck": 0,
"resilence": 0,
"skill": 0,
"intelligence": 0,
"health": 0,
"lifetime": 0,
"speed": 0,
"restless": 0,
"mature": 0,
"male": 0,
"pregnant": 0,
"gestation": 0,
"hunger": 0,
"eat_rate": 0,
"food": 0,
"greed": 0,
"happiness": 0,
"stingy": 0,
"charm": 0,
"beauty": 0,
"reach": 0,
"kinship": 0,
"alive": len(alive_list)
}
new_high = {
"luck": 0,
"resilence": 0,
"skill": 0,
"intelligence": 0,
"health": 0,
"lifetime": 0,
"speed": 0,
"restless": 0,
"gestation": 0,
"hunger": 0,
"eat_rate": 0,
"food": 0,
"greed": 0,
"happiness": 0,
"stingy": 0,
"charm": 0,
"beauty": 0,
"reach": 0,
"kinship": 0
}
new_low = {
"luck": luck_max_start*apocalypse,
"resilence": resilence_max_start*apocalypse,
"skill": skill_max_start*apocalypse,
"intelligence": intelligence_max_start*apocalypse,
"health": max_health*apocalypse,
"lifetime": lifetime_max_start*apocalypse,
"speed": speed_max_start*apocalypse,
"restless": restless_max_start*apocalypse,
"gestation": gestation_max_start*apocalypse,
"hunger": apocalypse*apocalypse,
"eat_rate": eat_rate_max_start*apocalypse,
"food": food_max_start*apocalypse,
"greed": greed_max_start*apocalypse,
"happiness": happiness_max_start*apocalypse,
"stingy": stingy_max_start*apocalypse,
"charm": charm_max_start*apocalypse,
"beauty": beauty_max_start*apocalypse,
"reach": reach_max_start*apocalypse,
"kinship": kinship_max_start*apocalypse
}
for lifeform in alive_list:
new_average["luck"] = new_average["luck"] + lifeform.luck
new_average["resilence"] = new_average["resilence"] + lifeform.resilence
new_average["skill"] = new_average["skill"] + lifeform.skill
new_average["intelligence"] = new_average["intelligence"] + lifeform.intelligence
new_average["health"] = new_average["health"] + lifeform.health if lifeform.health > 0 else 0
new_average["lifetime"] = new_average["lifetime"] + lifeform.lifetime
new_average["speed"] = new_average["speed"] + lifeform.speed
new_average["restless"] = new_average["restless"] + lifeform.restless
new_average["mature"] = new_average["mature"] + 1 if lifeform.mature else 0
new_average["male"] = new_average["male"] + 1 if lifeform.male else -1
new_average["pregnant"] = new_average["pregnant"] + 1 if not lifeform.male and lifeform.pregnant else 0
new_average["gestation"] = new_average["gestation"] + lifeform.gestation if not lifeform.male else new_average["gestation"]
new_average["hunger"] = new_average["hunger"] + lifeform.hunger
new_average["eat_rate"] = new_average["eat_rate"] + lifeform.eat_rate
new_average["food"] = new_average["food"] + lifeform.food
new_average["greed"] = new_average["greed"] + lifeform.greed
new_average["happiness"] = new_average["happiness"] + lifeform.happiness
new_average["stingy"] = new_average["stingy"] + lifeform.stingy
new_average["charm"] = new_average["charm"] + lifeform.charm
new_average["beauty"] = new_average["beauty"] + lifeform.beauty
new_average["reach"] = new_average["reach"] + lifeform.reach
new_average["kinship"] = new_average["kinship"] + lifeform.kinship
new_high["luck"] = lifeform.luck if new_high["luck"] < lifeform.luck else new_high["luck"]
new_high["resilence"] = lifeform.resilence if new_high["resilence"] < lifeform.resilence else new_high["resilence"]
new_high["skill"] = lifeform.skill if new_high["skill"] < lifeform.skill else new_high["skill"]
new_high["intelligence"] = lifeform.intelligence if new_high["intelligence"] < lifeform.intelligence else new_high["intelligence"]
new_high["health"] = lifeform.health if new_high["health"] < lifeform.health else new_high["health"]
new_high["lifetime"] = lifeform.lifetime if new_high["lifetime"] < lifeform.lifetime else new_high["lifetime"]
new_high["speed"] = lifeform.speed if new_high["speed"] < lifeform.speed else new_high["speed"]
new_high["restless"] = lifeform.restless if new_high["restless"] < lifeform.restless else new_high["restless"]
new_high["gestation"] = lifeform.gestation if new_high["gestation"] < lifeform.gestation and not lifeform.male else new_high["gestation"]
new_high["hunger"] = lifeform.hunger if new_high["hunger"] < lifeform.hunger else new_high["hunger"]
new_high["eat_rate"] = lifeform.eat_rate if new_high["eat_rate"] < lifeform.eat_rate else new_high["eat_rate"]
new_high["food"] = lifeform.food if new_high["food"] < lifeform.food else new_high["food"]
new_high["greed"] = lifeform.greed if new_high["greed"] < lifeform.greed else new_high["greed"]
new_high["happiness"] = lifeform.happiness if new_high["happiness"] < lifeform.luck else new_high["happiness"]
new_high["stingy"] = lifeform.stingy if new_high["stingy"] < lifeform.stingy else new_high["stingy"]
new_high["charm"] = lifeform.charm if new_high["charm"] < lifeform.charm else new_high["charm"]
new_high["beauty"] = lifeform.beauty if new_high["beauty"] < lifeform.beauty else new_high["beauty"]
new_high["reach"] = lifeform.reach if new_high["reach"] < lifeform.reach else new_high["reach"]
new_high["kinship"] = lifeform.kinship if new_high["kinship"] < lifeform.kinship else new_high["kinship"]
new_low["luck"] = lifeform.luck if new_low["luck"] >= lifeform.luck else new_low["luck"]
new_low["resilence"] = lifeform.resilence if new_low["resilence"] >= lifeform.resilence else new_low["resilence"]
new_low["skill"] = lifeform.skill if new_low["skill"] >= lifeform.skill else new_low["skill"]
new_low["intelligence"] = lifeform.intelligence if new_low["intelligence"] >= lifeform.intelligence else new_low["intelligence"]
new_low["health"] = lifeform.health if new_low["health"] >= lifeform.health else new_low["health"]
new_low["lifetime"] = lifeform.lifetime if new_low["lifetime"] >= lifeform.lifetime else new_low["lifetime"]
new_low["speed"] = lifeform.speed if new_low["speed"] >= lifeform.speed else new_low["speed"]
new_low["restless"] = lifeform.restless if new_low["restless"] >= lifeform.restless else new_low["restless"]
new_low["gestation"] = lifeform.gestation if new_low["gestation"] >= lifeform.gestation and not lifeform.male else new_low["gestation"]
new_low["hunger"] = lifeform.hunger if new_low["hunger"] >= lifeform.hunger else new_low["hunger"]
new_low["eat_rate"] = lifeform.eat_rate if new_low["eat_rate"] >= lifeform.eat_rate else new_low["eat_rate"]
new_low["food"] = lifeform.food if new_low["food"] >= lifeform.food else new_low["food"]
new_low["greed"] = lifeform.greed if new_low["greed"] >= lifeform.greed else new_low["greed"]
new_low["happiness"] = lifeform.happiness if new_low["happiness"] >= lifeform.happiness else new_low["happiness"]
new_low["stingy"] = lifeform.stingy if new_low["stingy"] >= lifeform.stingy else new_low["stingy"]
new_low["charm"] = lifeform.charm if new_low["charm"] >= lifeform.charm else new_low["charm"]
new_low["beauty"] = lifeform.beauty if new_low["beauty"] >= lifeform.beauty else new_low["beauty"]
new_low["reach"] = lifeform.reach if new_low["reach"] >= lifeform.reach else new_low["reach"]
new_low["kinship"] = lifeform.kinship if new_low["kinship"] >= lifeform.kinship else new_low["kinship"]
new_average["luck"] = round(new_average["luck"]/len(alive_list), precision)
new_average["resilence"] = round(new_average["resilence"]/len(alive_list), precision)
new_average["skill"] = round(new_average["skill"]/len(alive_list), precision)
new_average["intelligence"] = round(new_average["intelligence"]/len(alive_list), precision)
new_average["health"] = round(new_average["health"]/len(alive_list), precision)
new_average["lifetime"] = round(new_average["lifetime"]/len(alive_list), precision)
new_average["speed"] = round(new_average["speed"]/len(alive_list), precision)
new_average["restless"] = round(new_average["restless"]/len(alive_list), precision)
new_average["mature"] = round(new_average["mature"]/len(alive_list)*100, precision)
new_average["male"] = new_average["male"] + math.ceil(len(alive_list)/2)
new_average["pregnant"] = round(new_average["pregnant"]/(len(alive_list) - new_average["male"])*100, precision) if len(alive_list) - new_average["male"] > 0 else 0
new_average["gestation"] = round(new_average["gestation"]/(len(alive_list) - new_average["male"]), precision) if len(alive_list) - new_average["male"] > 0 else 0
new_average["male"] = round(new_average["male"]/len(alive_list)*100,precision)
new_average["hunger"] = round(new_average["hunger"]/len(alive_list), precision)
new_average["eat_rate"] = round(new_average["eat_rate"]/len(alive_list), precision)
new_average["food"] = round(new_average["food"]/len(alive_list), precision)
new_average["greed"] = round(new_average["greed"]/len(alive_list), precision)
new_average["happiness"] = round(new_average["happiness"]/len(alive_list), precision)
new_average["stingy"] = round(new_average["stingy"]/len(alive_list), precision)
new_average["charm"] = round(new_average["charm"]/len(alive_list), precision)
new_average["beauty"] = round(new_average["beauty"]/len(alive_list), precision)
new_average["reach"] = round(new_average["reach"]/len(alive_list), precision)
new_average["kinship"] = round(new_average["kinship"]/len(alive_list), precision)
month_avgs.append(new_average)
month_lows.append(new_low)
month_highs.append(new_high)
for creation in range(genesis_count): for creation in range(genesis_count):
local_x = random.randrange(0, world_size) local_x = random.randrange(0, world_size)
local_y = random.randrange(0, world_size) local_y = random.randrange(0, world_size)
@ -495,6 +709,7 @@ for creation in range(genesis_count):
speed=random.randrange(speed_min_start, speed_max_start), speed=random.randrange(speed_min_start, speed_max_start),
restless=random.randrange(restless_min_start, restless_max_start), restless=random.randrange(restless_min_start, restless_max_start),
mature=True, mature=True,
mature_age=random.randrange(maturity_min_start, maturity_max_start),
gestation=random.randrange(gestation_min_start, gestation_max_start), gestation=random.randrange(gestation_min_start, gestation_max_start),
hunger=hunger_start, hunger=hunger_start,
eat_rate=random.randrange(eat_rate_min_start, eat_rate_max_start), eat_rate=random.randrange(eat_rate_min_start, eat_rate_max_start),
@ -507,22 +722,24 @@ for creation in range(genesis_count):
reach=random.randrange(reach_min_start, reach_max_start), reach=random.randrange(reach_min_start, reach_max_start),
skill=random.randrange(skill_min_start, skill_max_start), skill=random.randrange(skill_min_start, skill_max_start),
name=names.get_first_name(gender=gender_text), name=names.get_first_name(gender=gender_text),
family=names.get_last_name() family=names.get_last_name(),
kinship=random.randrange(kinship_min_start, kinship_max_start),
birth_month=random.randrange(1, months_in_a_year + 1)
) )
world[local_x][local_y] = new_creature world[local_x][local_y] = new_creature
alive_list.append(new_creature) alive_list.append(new_creature)
last_id = creation last_id = creation
for year in range(apocalypse): for month in range(apocalypse):
for lifeform in alive_list: for lifeform in alive_list:
lifeform.take_turn() lifeform.take_turn(month)
print_world() print_world()
output = f"{year}\t" output = f"{int(month/months_in_a_year)}.{month % months_in_a_year + 1}\t"
output = f"{output}alive: {len(alive_list)}\t" output = f"{output}alive: {len(alive_list)}\t"
output = f"{output}begs: {begs}\t" # output = f"{output}begs: {begs}\t"
output = f"{output}gifts: {gifts}\t" # output = f"{output}gifts: {gifts}\t"
output = f"{output}thefts: {thefts}\t" # output = f"{output}thefts: {thefts}\t"
output = f"{output}finds: {finds}\t{lifeform.name} {lifeform.family} \t" output = f"{output}finds: {finds}\t{lifeform.name[:5]} {lifeform.family[:8]} \t"
output = f"{output}luck: {lifeform.luck}\t\t" output = f"{output}luck: {lifeform.luck}\t\t"
output = f"{output}food:\t{lifeform.food}\t" output = f"{output}food:\t{lifeform.food}\t"
output = f"{output}eat: {lifeform.eat_rate}\t\t" output = f"{output}eat: {lifeform.eat_rate}\t\t"
@ -530,6 +747,35 @@ for year in range(apocalypse):
output = f"{output}health: {lifeform.health}\t" output = f"{output}health: {lifeform.health}\t"
output = f"{output}happiness: {lifeform.happiness}\t" output = f"{output}happiness: {lifeform.happiness}\t"
output = f"{output}age: {lifeform.lifetime}\t" output = f"{output}age: {lifeform.lifetime}\t"
output = f"{output}adult: {lifeform.mature_age}\t"
output = f"{output}position: ({lifeform.x},{lifeform.y})" output = f"{output}position: ({lifeform.x},{lifeform.y})"
print(output) print(output)
if len(alive_list) > 0:
lifeform_stats(month)
# Make a report
for month in range(len(month_avgs)):
output = f"{int(month/months_in_a_year)}.{month % months_in_a_year + 1}:"
output = f"{output}\talive:\t\t\t[ \t{month_avgs[month]['alive']}\t ]\n"
output = f"{output}\tmale %:\t\t\t[ \t{month_avgs[month]['male']}\t ]\n"
output = f"{output}\tfemale pregnant %:\t[ \t{month_avgs[month]['pregnant']}\t ]\n"
output = f"{output}\tfemale gestation %:\t[{month_lows[month]['gestation']}\t{month_avgs[month]['gestation']}\t{month_highs[month]['gestation']}]\n"
output = f"{output}\tmaturity %:\t\t[ \t{month_avgs[month]['mature']}\t ]\n"
output = f"{output}\tluck:\t\t\t[{month_lows[month]['luck']}\t{month_avgs[month]['luck']}\t{month_highs[month]['luck']}]\n"
output = f"{output}\tresilence:\t\t[{month_lows[month]['resilence']}\t{month_avgs[month]['resilence']}\t{month_highs[month]['resilence']}]\n"
output = f"{output}\tskill:\t\t\t[{month_lows[month]['skill']}\t{month_avgs[month]['skill']}\t{month_highs[month]['skill']}]\n"
output = f"{output}\tintelligence:\t\t[{month_lows[month]['intelligence']}\t{month_avgs[month]['intelligence']}\t{month_highs[month]['intelligence']}]\n"
output = f"{output}\thealth:\t\t\t[{month_lows[month]['health']}\t{month_avgs[month]['health']}\t{month_highs[month]['health']}]\n"
output = f"{output}\tlifetime:\t\t[{month_lows[month]['lifetime']}\t{month_avgs[month]['lifetime']}\t{month_highs[month]['lifetime']}]\n"
output = f"{output}\tspeed:\t\t\t[{month_lows[month]['speed']}\t{month_avgs[month]['speed']}\t{month_highs[month]['speed']}]\n"
output = f"{output}\trestless:\t\t[{month_lows[month]['restless']}\t{month_avgs[month]['restless']}\t{month_highs[month]['restless']}]\n"
output = f"{output}\thunger:\t\t\t[{month_lows[month]['hunger']}\t{month_avgs[month]['hunger']}\t{month_highs[month]['hunger']}]\n"
output = f"{output}\teat_rate:\t\t[{month_lows[month]['eat_rate']}\t{month_avgs[month]['eat_rate']}\t{month_highs[month]['eat_rate']}]\n"
output = f"{output}\tfood:\t\t\t[{month_lows[month]['food']}\t{month_avgs[month]['food']}\t{month_highs[month]['food']}]\n"
output = f"{output}\tgreed:\t\t\t[{month_lows[month]['greed']}\t{month_avgs[month]['greed']}\t{month_highs[month]['greed']}]\n"
output = f"{output}\thappiness:\t\t[{month_lows[month]['happiness']}\t{month_avgs[month]['happiness']}\t{month_highs[month]['happiness']}]\n"
output = f"{output}\tstingy:\t\t\t[{month_lows[month]['stingy']}\t{month_avgs[month]['stingy']}\t{month_highs[month]['stingy']}]\n"
output = f"{output}\tcharm:\t\t\t[{month_lows[month]['charm']}\t{month_avgs[month]['charm']}\t{month_highs[month]['charm']}]\n"
output = f"{output}\tbeauty:\t\t\t[{month_lows[month]['beauty']}\t{month_avgs[month]['beauty']}\t{month_highs[month]['beauty']}]\n"
output = f"{output}\tkinship:\t\t[{month_lows[month]['kinship']}\t{month_avgs[month]['kinship']}\t{month_highs[month]['kinship']}]\n"
# print(output)