Spaces:
Runtime error
Runtime error
import random | |
class DisasterPlugin: | |
def __init__(self, disaster_frequency, disaster_prob): | |
self.disaster_frequency = disaster_frequency | |
self.disaster_prob = disaster_prob | |
def trigger_disaster(self, characters, character_die_callback): | |
print("发生自然灾难...") | |
num_killed = int(len(characters) * self.disaster_prob) | |
killed = random.sample(characters, num_killed) | |
for c in killed: | |
c.history.append(f"{c.real_age}岁,死于自然灾难") | |
character_die_callback(c) | |
def execute(self, characters, round_num, character_die_callback): | |
if round_num % self.disaster_frequency == 0 and random.random() < self.disaster_prob: | |
self.trigger_disaster(characters, character_die_callback) | |