Based on the one-page RPG "Battle of the Brontës", by Oliver at Henry Sotheran Ltd. https://twitter.com/sotherans/status/1510361300945321994
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. from random import randint, shuffle
  2. class Sibling:
  3. def __init__(self):
  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. def round_check(self):
  13. if self.tragedy >= 10:
  14. self.alive = False
  15. return False
  16. self.rounds += 1
  17. if self.tragedy < 0:
  18. self.tragedy = 0
  19. if self.masterpiece < 0:
  20. self.masterpiece = 0
  21. if self.brother < 0:
  22. self.brother = 0
  23. if self.masterpiece >= 5:
  24. success = self.publication_attempt()
  25. if success:
  26. self.success = True
  27. return True
  28. else:
  29. self.masterpiece = 0
  30. if self.brother_ok and self.brother >= 5:
  31. self.brother_count += 1
  32. if self.brother_count >= 3:
  33. self.brother_ok = False
  34. self.brother = 0
  35. self.masterpiece = 0
  36. def publication_attempt(self):
  37. if randint(1,6) == 6:
  38. return True
  39. return False
  40. def __str__(self):
  41. 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)."
  42. if self.success:
  43. out_str += " They were successful in publishing their manuscript!"
  44. return out_str
  45. class Game:
  46. def __init__(self, siblings=None, common_brother=None, brother_count=None):
  47. self.num_siblings = int(siblings) if siblings else 3
  48. self.common_brother = bool(common_brother) if common_brother else False
  49. self.brother_count = int(brother_count) if brother_count else self.num_siblings
  50. self.siblings = []
  51. for _ in range(self.num_siblings):
  52. self.siblings.append(Sibling())
  53. if self.common_brother:
  54. self.brother_ok = True
  55. def is_brother_ok(self, sibling):
  56. if self.common_brother and self.brother_ok:
  57. return True
  58. elif sibling.brother_ok and not self.common_brother:
  59. return True
  60. return False
  61. def bronte_event(self, sibling):
  62. event_type = randint(1,6)
  63. if event_type <= 2:
  64. self.quiet_day(sibling)
  65. elif event_type <= 5:
  66. self.walk_moors(sibling)
  67. else:
  68. sibling.masterpiece += 1
  69. def quiet_day(self, sibling):
  70. day_type = randint(1,6)
  71. if day_type == 1:
  72. sibling.tragedy += 1
  73. if self.is_brother_ok(sibling):
  74. sibling.brother += 1
  75. elif day_type == 2:
  76. sibling.masterpiece -= 1
  77. elif day_type == 3:
  78. if self.is_brother_ok(sibling):
  79. sibling.brother += 3
  80. elif day_type == 4:
  81. sibling.masterpiece -= 3
  82. elif day_type == 5:
  83. sibling.masterpiece += 2
  84. elif day_type == 6:
  85. sibling.tragedy += 1
  86. if self.is_brother_ok(sibling):
  87. sibling.brother += 2
  88. def walk_moors(self, sibling):
  89. walk_type = randint(1,6)
  90. if walk_type == 1:
  91. sibling.tragedy += 1
  92. elif walk_type == 2:
  93. if self.is_brother_ok(sibling):
  94. sibling.brother += 2
  95. elif walk_type == 3:
  96. sibling.tragedy += 2
  97. elif walk_type == 4:
  98. sibling.masterpiece += 1
  99. elif walk_type == 5:
  100. if self.is_brother_ok(sibling):
  101. sibling.brother += 2
  102. elif walk_type == 6:
  103. sibling.tragedy += 1
  104. def turn(self, sibling):
  105. self.bronte_event(sibling)
  106. check = sibling.round_check()
  107. if check:
  108. return True
  109. return False
  110. def round(self):
  111. for sibling in self.siblings:
  112. if sibling.alive:
  113. break
  114. else:
  115. print("Everyone has died.")
  116. for sibling in self.siblings:
  117. print(sibling)
  118. return False
  119. temp_sibs = self.siblings[:]
  120. shuffle(temp_sibs)
  121. for current_sibling in temp_sibs:
  122. cur_sib_num = self.siblings.index(current_sibling) + 1
  123. if current_sibling.alive:
  124. success = self.turn(current_sibling)
  125. if success:
  126. print(f"Sibling #{cur_sib_num} has published their masterpiece!")
  127. for sibling in self.siblings:
  128. print(sibling)
  129. return False
  130. if self.common_brother and self.brother_ok and not current_sibling.brother_ok:
  131. self.brother_count -= 1
  132. if self.brother_count <= 0:
  133. self.brother_ok = False
  134. return True
  135. def play_game(self):
  136. continue_playing = True
  137. while continue_playing:
  138. continue_playing = self.round()
  139. if __name__ == "__main__":
  140. # scores = {"Tragedy": {"Results": 0, "Brother OK": 0}, "Masterpiece": {"Results": 0, "Brother OK": 0}}
  141. # for _ in range(100000):
  142. # result, brother = play_brontes()
  143. # scores[result]["Results"] = scores[result]["Results"] + 1
  144. # if brother:
  145. # scores[result]["Brother OK"] = scores[result]["Brother OK"] + 1
  146. game = Game()
  147. game.play_game()
  148. # print(scores)