Based on the one-page RPG "Battle of the Brontës", by Oliver at Henry Sotheran Ltd. https://twitter.com/sotherans/status/1510361300945321994
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

brontes.py 7.9KB

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