Based on the one-page RPG "Battle of the Brontës", by Oliver at Henry Sotheran Ltd. https://twitter.com/sotherans/status/1510361300945321994
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

brontes.py 7.1KB

2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. from random import randint, shuffle
  2. class Sibling:
  3. def __init__(self, state=None):
  4. self.tragedy = 0
  5. self.masterpiece = 0
  6. self.brother = 0
  7. self.brother_count = 0
  8. self.brother_ok = True
  9. self.alive = True
  10. self.rounds = 0
  11. self.success = False
  12. self.state = state
  13. def round_check(self):
  14. if self.tragedy >= 10:
  15. self.alive = False
  16. return False
  17. self.rounds += 1
  18. if self.tragedy < 0:
  19. self.tragedy = 0
  20. if self.masterpiece < 0:
  21. self.masterpiece = 0
  22. if self.brother < 0:
  23. self.brother = 0
  24. if self.masterpiece >= 5:
  25. success = self.publication_attempt()
  26. if success:
  27. self.success = True
  28. return True
  29. else:
  30. self.masterpiece = 0
  31. if self.brother_ok and self.brother >= 5:
  32. self.brother_count += 1
  33. if self.brother_count >= 3:
  34. self.brother_ok = False
  35. self.brother = 0
  36. self.masterpiece = 0
  37. def publication_attempt(self):
  38. if randint(1,6) == 6:
  39. return True
  40. self.state.failed_manuscripts += 1
  41. return False
  42. def __str__(self):
  43. 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)."
  44. if self.success:
  45. out_str += " They were successful in publishing their manuscript!"
  46. return out_str
  47. class Game:
  48. def __init__(self, siblings=None, common_brother=None, brother_count=None, verbose=None, state=None):
  49. self.num_siblings = int(siblings) if siblings != None else 3
  50. self.common_brother = bool(common_brother) if common_brother != None else False
  51. self.brother_count = int(brother_count) if brother_count != None else self.num_siblings
  52. self.verbose = bool(verbose) if verbose != None else True
  53. self.state = state
  54. self.siblings = []
  55. for _ in range(self.num_siblings):
  56. self.siblings.append(Sibling(state=self.state))
  57. if self.common_brother:
  58. self.brother_ok = True
  59. self.per_sibling_brother = []
  60. for _ in range(self.num_siblings):
  61. self.per_sibling_brother.append(True)
  62. self.success = False
  63. def is_brother_ok(self, sibling):
  64. if self.common_brother and self.brother_ok:
  65. return True
  66. elif sibling.brother_ok and not self.common_brother:
  67. return True
  68. return False
  69. def bronte_event(self, sibling):
  70. event_type = randint(1,6)
  71. if event_type <= 2:
  72. self.quiet_day(sibling)
  73. elif event_type <= 5:
  74. self.walk_moors(sibling)
  75. else:
  76. # This is remaining instead of being relegated to git commit history
  77. # because it's being actively investigated as a way to manipulate
  78. # success rates.
  79. # inc_chance = randint(1,6)
  80. # if inc_chance == 6:
  81. # sibling.masterpiece += 1
  82. sibling.masterpiece += 1
  83. def quiet_day(self, sibling):
  84. day_type = randint(1,6)
  85. if day_type == 1:
  86. sibling.tragedy += 1
  87. if self.is_brother_ok(sibling):
  88. sibling.brother += 1
  89. elif day_type == 2:
  90. sibling.masterpiece -= 1
  91. elif day_type == 3:
  92. if self.is_brother_ok(sibling):
  93. sibling.brother += 3
  94. elif day_type == 4:
  95. sibling.masterpiece -= 3
  96. elif day_type == 5:
  97. sibling.masterpiece += 2
  98. elif day_type == 6:
  99. sibling.tragedy += 1
  100. if self.is_brother_ok(sibling):
  101. sibling.brother += 2
  102. def walk_moors(self, sibling):
  103. walk_type = randint(1,6)
  104. if walk_type == 1:
  105. sibling.tragedy += 1
  106. elif walk_type == 2:
  107. if self.is_brother_ok(sibling):
  108. sibling.brother += 2
  109. elif walk_type == 3:
  110. sibling.tragedy += 2
  111. elif walk_type == 4:
  112. sibling.masterpiece += 1
  113. elif walk_type == 5:
  114. if self.is_brother_ok(sibling):
  115. sibling.brother += 2
  116. elif walk_type == 6:
  117. sibling.tragedy += 1
  118. def turn(self, sibling):
  119. self.bronte_event(sibling)
  120. check = sibling.round_check()
  121. if check:
  122. return True
  123. return False
  124. def round(self):
  125. for sibling in self.siblings:
  126. if sibling.alive:
  127. break
  128. else:
  129. self.vprint("Everyone has died.")
  130. for sibling in self.siblings:
  131. self.vprint(sibling)
  132. self.success = False
  133. return False
  134. temp_sibs = self.siblings[:]
  135. shuffle(temp_sibs)
  136. for current_sibling in temp_sibs:
  137. cur_sib_num = self.siblings.index(current_sibling)
  138. if current_sibling.alive:
  139. success = self.turn(current_sibling)
  140. if success:
  141. self.vprint(f"Sibling #{cur_sib_num+1} has published their masterpiece!")
  142. for sibling in self.siblings:
  143. self.vprint(sibling)
  144. self.success = True
  145. return False
  146. if self.common_brother and self.brother_ok and not current_sibling.brother_ok and self.per_sibling_brother[cur_sib_num]:
  147. self.brother_count -= 1
  148. self.per_sibling_brother[cur_sib_num] = False
  149. if self.brother_count <= 0:
  150. self.brother_ok = False
  151. return True
  152. def vprint(self, text):
  153. if self.verbose:
  154. print(text)
  155. def play_game(self):
  156. continue_playing = True
  157. while continue_playing:
  158. continue_playing = self.round()
  159. return self.success
  160. class GameState:
  161. def __init__(self, rounds=None, siblings=None, common_brother=None, brother_count=None, verbose=None):
  162. self.rounds = int(rounds) if rounds else 10000
  163. self.successes = 0
  164. self.failures = 0
  165. self.failed_manuscripts = 0
  166. for _ in range(self.rounds):
  167. game = Game(siblings=siblings, common_brother=common_brother, brother_count=brother_count, verbose=verbose, state=self)
  168. success = game.play_game()
  169. if success:
  170. self.successes += 1
  171. else:
  172. self.failures += 1
  173. out_str = f"Across {self.rounds} families of {siblings} sisters and "
  174. if common_brother:
  175. out_str += "one brother"
  176. else:
  177. out_str += "as many brothers"
  178. out_str += f", there were {self.successes} successfully-published masterpieces, and {self.failures} tragic deaths for everybody involved."
  179. out_str += f" In addition, there were {self.failed_manuscripts} manuscripts submitted that were refused by all publishers."
  180. print(out_str)
  181. if __name__ == "__main__":
  182. gs = GameState(rounds=100000, siblings=3, common_brother=True, verbose=False)