WorldSimulation / plugins /BirthPlugin.py
yingqianjiang-lingoace
update
0a0d866
raw
history blame
978 Bytes
import random
class BirthPlugin:
def __init__(self, birth_rate, min_birth_age=20, birth_age_range=15):
self.birth_rate = birth_rate
self.birth_age = min_birth_age
self.birth_age_range = birth_age_range
def perform_births(self, characters, register_character):
for character in characters:
if character.partner and character.apparent_age > self.birth_age and character.apparent_age < self.birth_age + self.birth_age_range and character.partner.apparent_age > self.birth_age and character.partner.apparent_age < self.birth_age + self.birth_age_range:
if random.random() < self.birth_rate:
child = character.give_birth()
if child:
register_character(child)
def set_birth_rate(self, birth_rate):
self.birth_rate = birth_rate
# 统一插件接口
def execute(self, *args, **kwargs):
self.perform_births(*args, **kwargs)