evo_fun/evo.py

784 lines
38 KiB
Python
Raw Normal View History

2022-07-24 13:39:56 -05:00
# To Do
# birth near moms
# non-random movements
# move away from theieves
# group by charming lifeforms
# group by kin
2022-07-24 13:42:23 -05:00
# intelligence grants predictive movements
2022-07-24 13:39:56 -05:00
# bonus for kin in requests
# bonus for children in requests
# world full apocalypse
# graphical output
# csv outputs
# rewrite stats method :(
2022-07-24 13:42:23 -05:00
# more happiness balancing
2022-07-24 13:39:56 -05:00
2022-07-23 02:33:45 -05:00
import random
2022-07-24 13:39:56 -05:00
import math
2022-07-23 11:01:06 -05:00
import names
2022-07-23 02:33:45 -05:00
2022-07-24 13:39:56 -05:00
genesis_count = 100 # how many lifeforms to start with
world_size = 75 # 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
2022-07-23 02:33:45 -05:00
roll_max = 100 # the upper bound for rolls
min_health = 800
max_health = 1000
lifetime_min_start = 20
lifetime_max_start = 50
2022-07-24 13:39:56 -05:00
maturity_min_start = 12
maturity_max_start = 19
2022-07-23 02:33:45 -05:00
luck_min_start = 1
luck_max_start = 8
resilence_min_start = 1
resilence_max_start = 5
2022-07-23 11:01:06 -05:00
intelligence_min_start = 1
intelligence_max_start = 3
2022-07-23 02:33:45 -05:00
speed_min_start = 1
speed_max_start = 5
restless_min_start = 0
restless_max_start = 4
2022-07-24 13:39:56 -05:00
gestation_min_start = 7
gestation_max_start = 10
2022-07-23 02:33:45 -05:00
hunger_start = 0
eat_rate_min_start = 2
eat_rate_max_start = 7
food_min_start = 20
food_max_start = 50
greed_min_start = 1
greed_max_start = 8
happiness_min_start = 0
happiness_max_start = 7
stingy_min_start = 1
2022-07-23 11:01:06 -05:00
stingy_max_start = 14
2022-07-23 02:33:45 -05:00
charm_min_start = 3
charm_max_start = 14
beauty_min_start = 20
beauty_max_start = 40
2022-07-23 11:01:06 -05:00
reach_min_start = 1
reach_max_start = 4
2022-07-23 02:33:45 -05:00
skill_min_start = 8
skill_max_start = 24
2022-07-24 13:39:56 -05:00
kinship_min_start = 7
kinship_max_start = 14
2022-07-23 02:33:45 -05:00
begs = 0
gifts = 0
thefts = 0
finds = 0
last_id = 0
2022-07-24 13:39:56 -05:00
month_avgs = []
month_lows = []
month_highs = []
2022-07-23 02:33:45 -05:00
2022-07-24 13:39:56 -05:00
apocalypse = apocalypse_years*months_in_a_year
2022-07-23 02:33:45 -05:00
world = [[None for i in range(world_size)] for j in range(world_size)]
alive_list = []
class LifeForm:
2022-07-23 12:48:27 -05:00
def __init__(self):
# broad properties
2022-07-24 13:39:56 -05:00
self.luck = 0 # catch all positive/negative value
self.resilence = 0 # how many failures a lifeform can tollerate in a turn
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
2022-07-23 12:48:27 -05:00
# death properties
2022-07-24 13:39:56 -05:00
self.health = 0 # how far from death the lifeform is
self.lifetime = 0 # how many turns a lifeform has been alive
2022-07-23 12:48:27 -05:00
# movement properties
2022-07-24 13:39:56 -05:00
self.speed = 0 # movements per round
self.restless = 0 # likihood of trying to move per round
2022-07-23 12:48:27 -05:00
# reproduction properties
2022-07-24 13:39:56 -05:00
self.mature = False # whether or not entity can reproduce
self.mature_age = 0 # age when mature
self.male = False # whether the lifeform is male or female
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
2022-07-23 12:48:27 -05:00
# energy properties
2022-07-24 13:39:56 -05:00
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.food = 0 # how much food a lifeform owns
self.greed = 0 # factor of actual need greater that lifeform requires
2022-07-23 12:48:27 -05:00
# social properties
2022-07-24 13:39:56 -05:00
self.happiness = 0 # how happy the lifeform is
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.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.kinship = 0 # how much a lifeform cares about its kin
2022-07-23 12:48:27 -05:00
self.family = ""
self.name = ""
# purely derivied meta properties
self.parents = []
self.children = []
self.prediction_success_rate = 0
self.x = 0 # current x position in the world
self.y = 0 # current y position in the world
self.id = 0
self.rounds_pregnant = 0
self.extra_pregnancy_food = 0
self.paternal_genes = {}
self.baby_daddy = None
self.mated_recently = False
2022-07-23 02:33:45 -05:00
# methods
2022-07-24 13:39:56 -05:00
def take_turn(self, month):
2022-07-23 02:33:45 -05:00
self.move()
self.forage()
self.mingle()
2022-07-24 13:39:56 -05:00
self.pregnancy(month)
2022-07-23 02:33:45 -05:00
self.eat()
2022-07-24 13:39:56 -05:00
self.age(month)
2022-07-23 02:33:45 -05:00
2022-07-24 13:39:56 -05:00
def spawn(self, x, y, id, male, birth_month, luck=0, resilence=0, intelligence=0, skill=0, health=0, lifetime=0,
speed=0,restless=0, mature=False, gestation=0, hunger=0, eat_rate=0, food=0, greed=0, happiness=0,
stingy=0, charm=0, beauty=0, reach=0, kinship=0, name="", family="", mature_age=0):
self.luck=luck
self.resilence=resilence
self.intelligence=intelligence
self.skill=skill
self.health=health
self.lifetime=lifetime
self.speed=speed
self.restless=restless
self.resilence=resilence
self.mature=mature
self.mature_age=mature_age
self.male=male
self.pregnant=False
self.gestation=gestation
self.hunger=hunger
self.eat_rate=eat_rate
self.food=food
self.greed=greed
self.happiness=happiness
self.stingy=stingy
self.charm=charm
self.beauty=beauty
self.reach=reach
self.kinship=kinship
2022-07-23 11:01:06 -05:00
self.name=name
self.family=family
2022-07-24 13:39:56 -05:00
self.birth_month=birth_month
self.x=x
self.y=y
self.id=id
2022-07-23 02:33:45 -05:00
2022-07-24 13:39:56 -05:00
def birth(self, x, y, id, male, food, mother_genes, father_genes, name, family, birth_month):
2022-07-23 02:33:45 -05:00
self.male = male
self.food = food
self.lifetime = 0
self.mature = False
self.pregnant = False
self.x = x
self.y = y
self.id = id
2022-07-23 11:01:06 -05:00
self.name = name
self.family = family
2022-07-24 13:39:56 -05:00
self.birth_month = birth_month
2022-07-23 02:33:45 -05:00
for key in mother_genes.keys():
mod = [mother_genes[key], father_genes[key]]
mod.sort()
2022-07-23 11:01:06 -05:00
if key == "skill":
mod[0] = round(mod[0]/2)
2022-07-23 02:33:45 -05:00
setattr(self, key, random.randrange(mod[0], mod[1] + 1))
luck_improve_roll = random.randrange(0, roll_max)
if luck_improve_roll <= self.luck:
self.luck = self.luck + 1
beauty_improve_roll = random.randrange(0, roll_max)
if beauty_improve_roll <= self.luck + self.beauty:
self.beauty = self.beauty + 1
2022-07-23 11:01:06 -05:00
intelligence_improve_roll = random.randrange(0, roll_max)
if intelligence_improve_roll <= self.luck + self.intelligence:
self.intelligence = self.intelligence + 1
2022-07-23 02:33:45 -05:00
resilence_improve_roll = random.randrange(0, roll_max)
if resilence_improve_roll <= self.luck + self.resilence:
self.resilence = self.resilence + 1
charm_improve_roll = random.randrange(0, roll_max)
if charm_improve_roll <= self.luck + self.charm:
self.charm = self.charm + 1
2022-07-24 13:39:56 -05:00
kinship_improve_roll = random.randrange(0, roll_max)
if kinship_improve_roll <= self.luck + self.kinship:
self.kinship = self.kinship + 1
2022-07-23 11:01:06 -05:00
greed_improve_roll = random.randrange(0, roll_max)
if greed_improve_roll <= self.luck + self.greed:
self.greed = self.greed - 1
stingy_improve_roll = random.randrange(0, roll_max)
if stingy_improve_roll <= self.luck + self.stingy:
self.stingy = self.stingy - 1
2022-07-23 02:33:45 -05:00
def die(self):
alive_list.remove(world[self.x][self.y])
world[self.x][self.y] = None
2022-07-23 11:01:06 -05:00
child_luck_sum = 0
for child in self.children:
child_luck_sum = child_luck_sum + child.luck
inheritance_roll = random.randrange(0, roll_max)
if inheritance_roll < child_luck_sum:
inheritance_split = len(self.children) + 1
for child in self.children:
child.food = child.food + round(self.food/inheritance_split)
self.food = 0
2022-07-23 02:33:45 -05:00
def move(self):
steps_taken = 0
while steps_taken < self.speed:
delta_x = random.randrange(-1, 2)
delta_y = random.randrange(-1, 2)
while self.x + delta_x >= world_size or self.x + delta_x < 0:
delta_x = random.randrange(-1, 2)
while self.y + delta_y >= world_size or self.y + delta_y < 0:
delta_y = random.randrange(-1, 2)
if world[self.x + delta_x][self.y + delta_y] == None:
2022-07-23 12:48:27 -05:00
world[self.x + delta_x][self.y + delta_y] = self
2022-07-23 02:33:45 -05:00
world[self.x][self.y] = None
self.x = self.x + delta_x
self.y = self.y + delta_y
steps_taken = steps_taken + 1
def give(self, target, ammount):
2022-07-23 12:48:27 -05:00
if self.food > self.greed*self.eat_rate + ammount - target.luck - target.charm \
and self.hunger >= 0 \
and self.happiness + target.luck + target.charm > self.stingy:
2022-07-23 02:33:45 -05:00
self.food = self.food - ammount
target.food = target.food + ammount
2022-07-24 13:39:56 -05:00
# print(f"happiness pre-bump give {self.happiness}")
2022-07-23 11:01:06 -05:00
self.happiness = self.happiness + self.luck + self.stingy + target.charm
2022-07-24 13:39:56 -05:00
# print(f"happiness post-bump give {self.happiness}")
2022-07-23 02:33:45 -05:00
stingy_roll = random.randrange(0, roll_max)
2022-07-23 11:01:06 -05:00
if stingy_roll < target.stingy:
target.stingy = target.stingy - 1
skill_up_roll = random.randrange(0, target.luck + target.skill)
if skill_up_roll > target.skill:
target.skill = target.skill + 1
2022-07-23 02:39:49 -05:00
global gifts; gifts = gifts + 1
global begs; begs = begs + 1
2022-07-23 02:33:45 -05:00
def take(self, target, ammount):
if self.health + self.luck > target.health + target.luck:
health_delta = self.health + self.luck - target.health - target.luck
target.health = target.health - health_delta
self.health = self.health - round(health_delta/2)
if target.happiness > ammount - target.luck:
2022-07-24 13:39:56 -05:00
# print(f"happiness pre-bump take target {target.happiness}")
2022-07-23 02:33:45 -05:00
target.happiness = target.happiness - ammount + target.luck
2022-07-24 13:39:56 -05:00
# print(f"happiness post-bump take target {target.happiness}")
2022-07-23 02:33:45 -05:00
else:
target.happiness = 0
if target.food > ammount:
target.food = target.food - ammount
self.food = self.food + ammount
else:
self.food = self.food + target.food
target.food = 0
else:
health_delta = target.health + target.luck - self.health - self.luck
target.health = target.health - round(health_delta/2)
self.health = self.health - health_delta
if self.happiness > ammount - self.luck:
2022-07-24 13:39:56 -05:00
# print(f"happiness pre-bump take self {self.happiness}")
2022-07-23 02:33:45 -05:00
self.happiness = self.happiness - ammount + self.luck
2022-07-24 13:39:56 -05:00
# print(f"happiness post-bump take self {self.happiness}")
2022-07-23 02:33:45 -05:00
else:
self.happiness = 0
if self.food > 0:
target.food = target.food + round(self.food/2)
self.food = round(self.food/2)
2022-07-23 02:39:49 -05:00
global thefts; thefts = thefts + 1
2022-07-23 02:33:45 -05:00
def forage(self):
if self.mature and self.food < self.greed*self.eat_rate:
food_found = False
attempts = 0
while attempts < self.resilence and not food_found:
food_roll = random.randrange(0, roll_max)
2022-07-23 11:01:06 -05:00
if food_roll < (self.luck + self.skill + self.intelligence):
2022-07-23 02:33:45 -05:00
food_found = True
attempts = attempts + 1
if food_found:
luck_imapct = random.randrange(0, self.luck)
2022-07-23 11:01:06 -05:00
found_ammount_found = luck_imapct*(self.skill*self.intelligence - attempts - 1)
2022-07-23 02:33:45 -05:00
self.food = self.food + found_ammount_found
2022-07-23 02:39:49 -05:00
global finds; finds = finds + 1
2022-07-24 13:39:56 -05:00
else:
self.happiness = self.happiness + self.hunger
2022-07-23 02:33:45 -05:00
2022-07-24 13:39:56 -05:00
def age(self, month):
if month > 0 and month % months_in_a_year == self.birth_month:
self.lifetime = self.lifetime + 1
2022-07-23 12:48:27 -05:00
self.mated_recently = False
2022-07-24 13:39:56 -05:00
age_roll = random.randrange(0, round(self.lifetime/months_in_a_year) + 1)
2022-07-23 02:33:45 -05:00
if age_roll > self.luck:
self.health = self.health - self.lifetime
maturity_offset = random.randrange(0, self.luck)
2022-07-24 13:39:56 -05:00
if not self.mature and self.mature_age <= self.lifetime + maturity_offset:
2022-07-23 02:33:45 -05:00
self.mature = True
if self.health < 0:
self.die()
def mingle(self):
neighbors = [world[i][j]
2022-07-23 11:01:06 -05:00
for i in range(self.x - self.reach, self.x + self.reach + 1)
for j in range(self.y - self.reach, self.y + self.reach + 1)
2022-07-23 02:33:45 -05:00
if i > -1 and j > -1 and j < len(world[0]) and i < len(world)]
random.shuffle(neighbors)
trade_requests = 0
for neighbor in neighbors:
if neighbor is not None:
# trade/steal
if self.hunger < 0:
2022-07-23 12:48:27 -05:00
neighbor.give(self, -1*self.hunger)
2022-07-23 02:33:45 -05:00
trade_requests = trade_requests + 1
if self.food < self.greed*self.eat_rate:
2022-07-23 12:48:27 -05:00
neighbor.give(self, self.greed*self.eat_rate - self.food)
2022-07-23 02:33:45 -05:00
trade_requests = trade_requests + 1
2022-07-23 12:48:27 -05:00
if trade_requests > self.resilence and \
(self.hunger < 0 or self.food < round(self.greed*self.eat_rate/2)):
2022-07-23 02:33:45 -05:00
self.take(neighbor, self.greed*self.eat_rate - self.food)
trade_requests = trade_requests + 1
# mate/conceive
2022-07-23 12:48:27 -05:00
if self.male is not neighbor.male and \
not self.mated_recently and \
not neighbor.pregnant and \
not self.pregnant and \
self.mature and \
neighbor.mature and \
neighbor.health + neighbor.beauty*neighbor.luck*neighbor.charm > self.health:
2022-07-23 02:33:45 -05:00
self.mate(neighbor)
# attack/ignore
def mate(self, target):
2022-07-24 13:39:56 -05:00
if self.health + self.beauty > target.beauty + target.health:
# 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}")
2022-07-23 02:33:45 -05:00
if self.male and not target.male and not target.pregnant:
target.pregnant = True
target.rounds_pregnant = 0
target.paternal_genes = {
"luck": self.luck,
"resilence": self.resilence,
2022-07-23 11:01:06 -05:00
"intelligence": self.intelligence,
"skill": self.skill,
2022-07-23 02:33:45 -05:00
"health": self.health,
"speed": self.speed,
"restless": self.restless,
"gestation": self.gestation,
"eat_rate": self.eat_rate,
"greed": self.greed,
"happiness": self.happiness,
"stingy": self.stingy,
"charm": self.charm,
"beauty": self.beauty,
2022-07-24 13:39:56 -05:00
"mature_age": self.mature_age,
2022-07-23 11:01:06 -05:00
"reach": self.reach,
"kinship": self.kinship,
2022-07-23 12:48:27 -05:00
"food": round(self.food/2) # This is not a property on the maternal list, daddy pays up front
2022-07-23 02:33:45 -05:00
}
self.food = round(self.food/2)
2022-07-23 12:48:27 -05:00
target.baby_daddy = self
2022-07-23 02:33:45 -05:00
elif target.male and not self.male and not self.pregnant:
self.pregnant = True
self.rounds_pregnant = 0
self.paternal_genes = {
"luck": target.luck,
"resilence": target.resilence,
2022-07-23 11:01:06 -05:00
"intelligence": target.intelligence,
"skill": target.skill,
2022-07-23 02:33:45 -05:00
"health": target.health,
"speed": target.speed,
"restless": target.restless,
"gestation": target.gestation,
"eat_rate": target.eat_rate,
"greed": target.greed,
"happiness": target.happiness,
"stingy": target.stingy,
"charm": target.charm,
"beauty": target.beauty,
2022-07-24 13:39:56 -05:00
"mature_age": target.mature_age,
2022-07-23 11:01:06 -05:00
"reach": target.reach,
"kinship": target.kinship,
2022-07-23 12:48:27 -05:00
"food": round(target.food/2) # This is not a property on the maternal list, daddy pays up front
2022-07-23 02:33:45 -05:00
}
2022-07-23 11:01:06 -05:00
self.baby_daddy = target
2022-07-23 02:33:45 -05:00
target.food = round(target.food/2)
2022-07-23 14:01:10 -05:00
self.mated_recently = self.luck*self.greed > random.randrange(0, roll_max)
2022-07-23 02:33:45 -05:00
else:
2022-07-23 12:48:27 -05:00
# if rejected, happiness transfer
2022-07-24 13:39:56 -05:00
# print(f"happiness pre-bump mate reject self {self.happiness}")
self.happiness = self.happiness + self.beauty - target.beauty
# print(f"happiness post-bump mate reject self {self.happiness}")
# 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, month):
2022-07-23 02:33:45 -05:00
if not self.male and self.pregnant:
if self.rounds_pregnant < self.gestation:
self.rounds_pregnant = self.rounds_pregnant + 1
self.extra_pregnancy_food = round(self.eat_rate*(self.rounds_pregnant/self.gestation))
else:
maternal_genes = {
"luck": self.luck,
"resilence": self.resilence,
2022-07-23 11:01:06 -05:00
"intelligence": self.intelligence,
"skill": self.skill,
2022-07-23 02:33:45 -05:00
"health": self.health,
"speed": self.speed,
"restless": self.restless,
"gestation": self.gestation,
"eat_rate": self.eat_rate,
"greed": self.greed,
"happiness": self.happiness,
"stingy": self.stingy,
"charm": self.charm,
"beauty": self.beauty,
2022-07-24 13:39:56 -05:00
"mature_age": self.mature_age,
2022-07-23 11:01:06 -05:00
"reach": self.reach,
"kinship": self.kinship
2022-07-23 02:33:45 -05:00
}
local_x = random.randrange(0, world_size)
local_y = random.randrange(0, world_size)
while world[local_x][local_y] is not None:
local_x = random.randrange(0, world_size)
local_y = random.randrange(0, world_size)
2022-07-23 02:39:49 -05:00
global last_id; last_id = last_id + 1
2022-07-23 11:01:06 -05:00
xy = random.choice([True, False])
gender_text = 'male' if xy else 'female'
family_name = self.baby_daddy.family if xy else self.family
2022-07-23 02:33:45 -05:00
child = LifeForm()
child.birth(
x=local_x,
y=local_y,
id=last_id,
2022-07-23 11:01:06 -05:00
male=xy,
2022-07-23 02:33:45 -05:00
food=round(self.food/2)+self.paternal_genes["food"],
mother_genes=maternal_genes,
2022-07-23 11:01:06 -05:00
father_genes=self.paternal_genes,
name=names.get_first_name(gender=gender_text),
2022-07-24 13:39:56 -05:00
family=family_name,
birth_month=month%months_in_a_year
2022-07-23 02:33:45 -05:00
)
2022-07-23 12:48:27 -05:00
child.parents.append(self)
child.parents.append(self.baby_daddy)
2022-07-23 02:33:45 -05:00
self.paternal_genes = {}
self.rounds_pregnant = 0
self.pregnant = False
self.food = round(self.food/2)
2022-07-23 11:01:06 -05:00
self.children.append(child)
2022-07-23 12:48:27 -05:00
self.baby_daddy.children.append(child)
world[local_x][local_y] = child
alive_list.append(child)
2022-07-23 02:33:45 -05:00
def eat(self):
if self.food > self.eat_rate + self.extra_pregnancy_food:
self.food = self.food - self.eat_rate - self.extra_pregnancy_food
if self.health + self.eat_rate + self.luck <= max_health:
self.health = self.health + self.eat_rate + self.luck
else:
self.health = max_health + self.luck
else:
self.hunger = self.hunger + self.food - self.eat_rate - self.extra_pregnancy_food
self.food = 0
if self.hunger < 0:
if self.food > 0:
if self.food <= -1*self.hunger:
self.hunger = self.hunger + self.food
self.food = 0
else:
self.food = self.food + self.hunger
self.hunger = 0
self.health = self.health + self.hunger
happiness_mods = [self.hunger, self.luck]
happiness_mods.sort()
2022-07-24 13:39:56 -05:00
# print(f"happiness pre-bump eat hungry {self.happiness}")
2022-07-23 02:33:45 -05:00
self.happiness = self.happiness + random.randrange(happiness_mods[0], happiness_mods[1] + 1)
2022-07-24 13:39:56 -05:00
# print(f"happiness post-bump eat hungry {self.happiness}")
2022-07-23 02:33:45 -05:00
elif self.luck > 0:
2022-07-24 13:39:56 -05:00
# print(f"happiness pre-bump eat hungerless {self.happiness}")
2022-07-23 02:33:45 -05:00
self.happiness = self.happiness + random.randrange(0, self.luck)
2022-07-24 13:39:56 -05:00
# print(f"happiness post-bump eat hungerless {self.happiness}")
2022-07-23 02:33:45 -05:00
def print_world():
pass
2022-07-24 13:39:56 -05:00
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)
2022-07-23 02:33:45 -05:00
for creation in range(genesis_count):
local_x = random.randrange(0, world_size)
local_y = random.randrange(0, world_size)
while world[local_x][local_y] is not None:
local_x = random.randrange(0, world_size)
local_y = random.randrange(0, world_size)
new_creature = LifeForm()
2022-07-23 11:01:06 -05:00
xy = random.choice([True, False])
gender_text = 'male' if xy else 'female'
new_creature.spawn(
x=local_x,
y=local_y,
id=creation,
male=xy,
2022-07-23 02:33:45 -05:00
luck=random.randrange(luck_min_start, luck_max_start),
resilence=random.randrange(resilence_min_start, resilence_max_start),
2022-07-23 11:01:06 -05:00
intelligence=random.randrange(intelligence_min_start, intelligence_max_start),
2022-07-23 02:33:45 -05:00
health=random.randrange(min_health, max_health),
lifetime=random.randrange(lifetime_min_start, lifetime_max_start),
speed=random.randrange(speed_min_start, speed_max_start),
restless=random.randrange(restless_min_start, restless_max_start),
mature=True,
2022-07-24 13:39:56 -05:00
mature_age=random.randrange(maturity_min_start, maturity_max_start),
2022-07-23 02:33:45 -05:00
gestation=random.randrange(gestation_min_start, gestation_max_start),
hunger=hunger_start,
eat_rate=random.randrange(eat_rate_min_start, eat_rate_max_start),
food=random.randrange(food_min_start, food_max_start),
greed=random.randrange(greed_min_start, greed_max_start),
happiness=random.randrange(happiness_min_start, happiness_max_start),
stingy=random.randrange(stingy_min_start, stingy_max_start),
charm=random.randrange(charm_min_start, charm_max_start),
beauty=random.randrange(beauty_min_start, beauty_max_start),
2022-07-23 11:01:06 -05:00
reach=random.randrange(reach_min_start, reach_max_start),
skill=random.randrange(skill_min_start, skill_max_start),
name=names.get_first_name(gender=gender_text),
2022-07-24 13:39:56 -05:00
family=names.get_last_name(),
kinship=random.randrange(kinship_min_start, kinship_max_start),
birth_month=random.randrange(1, months_in_a_year + 1)
2022-07-23 02:33:45 -05:00
)
world[local_x][local_y] = new_creature
alive_list.append(new_creature)
last_id = creation
2022-07-24 13:39:56 -05:00
for month in range(apocalypse):
2022-07-23 02:33:45 -05:00
for lifeform in alive_list:
2022-07-24 13:39:56 -05:00
lifeform.take_turn(month)
2022-07-23 02:33:45 -05:00
print_world()
2022-07-24 13:39:56 -05:00
output = f"{int(month/months_in_a_year)}.{month % months_in_a_year + 1}\t"
2022-07-23 12:48:27 -05:00
output = f"{output}alive: {len(alive_list)}\t"
2022-07-24 13:39:56 -05:00
# output = f"{output}begs: {begs}\t"
# output = f"{output}gifts: {gifts}\t"
# output = f"{output}thefts: {thefts}\t"
output = f"{output}finds: {finds}\t{lifeform.name[:5]} {lifeform.family[:8]} \t"
2022-07-23 12:48:27 -05:00
output = f"{output}luck: {lifeform.luck}\t\t"
output = f"{output}food:\t{lifeform.food}\t"
output = f"{output}eat: {lifeform.eat_rate}\t\t"
output = f"{output}hunger: {lifeform.hunger}\t"
output = f"{output}health: {lifeform.health}\t"
output = f"{output}happiness: {lifeform.happiness}\t"
output = f"{output}age: {lifeform.lifetime}\t"
2022-07-24 13:39:56 -05:00
output = f"{output}adult: {lifeform.mature_age}\t"
2022-07-23 12:48:27 -05:00
output = f"{output}position: ({lifeform.x},{lifeform.y})"
print(output)
2022-07-24 13:39:56 -05:00
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)