Spaces:
Runtime error
Runtime error
File size: 978 Bytes
bcf0302 0a0d866 bcf0302 0a0d866 bcf0302 0a0d866 bcf0302 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
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) |