| @@ -0,0 +1,163 @@ | |||
| from random import randint, shuffle | |||
| class Sibling: | |||
| def __init__(self): | |||
| self.tragedy = 0 | |||
| self.masterpiece = 0 | |||
| self.brother = 0 | |||
| self.brother_count = 0 | |||
| self.brother_ok = True | |||
| self.alive = True | |||
| self.rounds = 0 | |||
| self.success = False | |||
| def round_check(self): | |||
| if self.tragedy >= 10: | |||
| self.alive = False | |||
| return False | |||
| self.rounds += 1 | |||
| if self.tragedy < 0: | |||
| self.tragedy = 0 | |||
| if self.masterpiece < 0: | |||
| self.masterpiece = 0 | |||
| if self.brother < 0: | |||
| self.brother = 0 | |||
| if self.masterpiece >= 5: | |||
| success = self.publication_attempt() | |||
| if success: | |||
| self.success = True | |||
| return True | |||
| else: | |||
| self.masterpiece = 0 | |||
| if self.brother_ok and self.brother >= 5: | |||
| self.brother_count += 1 | |||
| if self.brother_count >= 3: | |||
| self.brother_ok = False | |||
| self.brother = 0 | |||
| self.masterpiece = 0 | |||
| def publication_attempt(self): | |||
| if randint(1,6) == 6: | |||
| return True | |||
| return False | |||
| def __str__(self): | |||
| out_str = f"This sibling lasted {self.rounds} rounds. Their final scores were: Tragedy: {self.tragedy}, Masterpiece: {self.masterpiece}, Brother: {self.brother} (with {self.brother_count} resets)." | |||
| if self.success: | |||
| out_str += " They were successful in publishing their manuscript!" | |||
| return out_str | |||
| class Game: | |||
| def __init__(self, siblings=None, common_brother=None, brother_count=None): | |||
| self.num_siblings = int(siblings) if siblings else 3 | |||
| self.common_brother = bool(common_brother) if common_brother else False | |||
| self.brother_count = int(brother_count) if brother_count else self.num_siblings | |||
| self.siblings = [] | |||
| for _ in range(self.num_siblings): | |||
| self.siblings.append(Sibling()) | |||
| if self.common_brother: | |||
| self.brother_ok = True | |||
| def is_brother_ok(self, sibling): | |||
| if self.common_brother and self.brother_ok: | |||
| return True | |||
| elif sibling.brother_ok and not self.common_brother: | |||
| return True | |||
| return False | |||
| def bronte_event(self, sibling): | |||
| event_type = randint(1,6) | |||
| if event_type <= 2: | |||
| self.quiet_day(sibling) | |||
| elif event_type <= 5: | |||
| self.walk_moors(sibling) | |||
| else: | |||
| sibling.masterpiece += 1 | |||
| def quiet_day(self, sibling): | |||
| day_type = randint(1,6) | |||
| if day_type == 1: | |||
| sibling.tragedy += 1 | |||
| if self.is_brother_ok(sibling): | |||
| sibling.brother += 1 | |||
| elif day_type == 2: | |||
| sibling.masterpiece -= 1 | |||
| elif day_type == 3: | |||
| if self.is_brother_ok(sibling): | |||
| sibling.brother += 3 | |||
| elif day_type == 4: | |||
| sibling.masterpiece -= 3 | |||
| elif day_type == 5: | |||
| sibling.masterpiece += 2 | |||
| elif day_type == 6: | |||
| sibling.tragedy += 1 | |||
| if self.is_brother_ok(sibling): | |||
| sibling.brother += 2 | |||
| def walk_moors(self, sibling): | |||
| walk_type = randint(1,6) | |||
| if walk_type == 1: | |||
| sibling.tragedy += 1 | |||
| elif walk_type == 2: | |||
| if self.is_brother_ok(sibling): | |||
| sibling.brother += 2 | |||
| elif walk_type == 3: | |||
| sibling.tragedy += 2 | |||
| elif walk_type == 4: | |||
| sibling.masterpiece += 1 | |||
| elif walk_type == 5: | |||
| if self.is_brother_ok(sibling): | |||
| sibling.brother += 2 | |||
| elif walk_type == 6: | |||
| sibling.tragedy += 1 | |||
| def turn(self, sibling): | |||
| self.bronte_event(sibling) | |||
| check = sibling.round_check() | |||
| if check: | |||
| return True | |||
| return False | |||
| def round(self): | |||
| for sibling in self.siblings: | |||
| if sibling.alive: | |||
| break | |||
| else: | |||
| print("Everyone has died.") | |||
| for sibling in self.siblings: | |||
| print(sibling) | |||
| return False | |||
| temp_sibs = self.siblings[:] | |||
| shuffle(temp_sibs) | |||
| for current_sibling in temp_sibs: | |||
| cur_sib_num = self.siblings.index(current_sibling) + 1 | |||
| if current_sibling.alive: | |||
| success = self.turn(current_sibling) | |||
| if success: | |||
| print(f"Sibling #{cur_sib_num} has published their masterpiece!") | |||
| for sibling in self.siblings: | |||
| print(sibling) | |||
| return False | |||
| if self.common_brother and self.brother_ok and not current_sibling.brother_ok: | |||
| self.brother_count -= 1 | |||
| if self.brother_count <= 0: | |||
| self.brother_ok = False | |||
| return True | |||
| def play_game(self): | |||
| continue_playing = True | |||
| while continue_playing: | |||
| continue_playing = self.round() | |||
| if __name__ == "__main__": | |||
| # scores = {"Tragedy": {"Results": 0, "Brother OK": 0}, "Masterpiece": {"Results": 0, "Brother OK": 0}} | |||
| # for _ in range(100000): | |||
| # result, brother = play_brontes() | |||
| # scores[result]["Results"] = scores[result]["Results"] + 1 | |||
| # if brother: | |||
| # scores[result]["Brother OK"] = scores[result]["Brother OK"] + 1 | |||
| game = Game() | |||
| game.play_game() | |||
| # print(scores) | |||