Advertisement
XYntercept

Golden Clover Code

Oct 30th, 2023
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.50 KB | Gaming | 0 0
  1. """
  2. This program bruteforces every garden combination to find the most optimal
  3. golden clover and nursetulip setup for a given garden size.
  4.  
  5. 0 means golden clover, 1 means nursetulip, and 2 means empty/locked space.
  6.  
  7. This does not take "ghosttulips" into account.
  8.  
  9. All plants are mature and the soil is always clay. The nursetulips have matured
  10. more than 1 tick ago so they have their full effect.
  11.  
  12. Orientation of setups does not matter. Earlytick/latetick only matters for
  13. mutation setup, not when using plant effects. I technically could have made
  14. this faster by not testing for rotated and/or flipped setups, but I don't
  15. know enough Python to do that. Feel free to try.
  16. """
  17.  
  18. import time as m
  19.  
  20. # Function for calculating GC frequency boost
  21. def calculate_gc_boost(garden):
  22. # res is the final result, clover_boost is for one clover at a time
  23. res = 0
  24. clover_boost = 0
  25. # For loops to calculate boost for every square in the garden
  26. for x in range(6):
  27. for y in range(6):
  28. clover_boost = 3.75
  29. # Jumbled mess of if/elif/elses, though basically just checks
  30. # how many nursetulips are surround the clover
  31. if garden[x][y] == 0:
  32. if y == 0:
  33. if x == 0:
  34. if garden[x+1][y] == 1:
  35. clover_boost*=1.25
  36. if garden[x][y+1] == 1:
  37. clover_boost*=1.25
  38. if garden[x+1][y+1] == 1:
  39. clover_boost*=1.25
  40. elif x == 5:
  41. if garden[x-1][y] == 1:
  42. clover_boost*=1.25
  43. if garden[x][y+1] == 1:
  44. clover_boost*=1.25
  45. if garden[x-1][y+1] == 1:
  46. clover_boost*=1.25
  47. else:
  48. if garden[x-1][y] == 1:
  49. clover_boost*=1.25
  50. if garden[x-1][y+1] == 1:
  51. clover_boost*=1.25
  52. if garden[x][y+1] == 1:
  53. clover_boost*=1.25
  54. if garden[x+1][y+1] == 1:
  55. clover_boost*=1.25
  56. if garden[x+1][y] == 1:
  57. clover_boost*=1.25
  58. elif y == 5:
  59. if x == 0:
  60. if garden[x+1][y] == 1:
  61. clover_boost*=1.25
  62. if garden[x][y-1] == 1:
  63. clover_boost*=1.25
  64. if garden[x+1][y-1] == 1:
  65. clover_boost*=1.25
  66. elif x == 5:
  67. if garden[x-1][y] == 1:
  68. clover_boost*=1.25
  69. if garden[x][y-1] == 1:
  70. clover_boost*=1.25
  71. if garden[x-1][y-1] == 1:
  72. clover_boost*=1.25
  73. else:
  74. if garden[x-1][y] == 1:
  75. clover_boost*=1.25
  76. if garden[x-1][y-1] == 1:
  77. clover_boost*=1.25
  78. if garden[x][y-1] == 1:
  79. clover_boost*=1.25
  80. if garden[x+1][y-1] == 1:
  81. clover_boost*=1.25
  82. if garden[x+1][y] == 1:
  83. clover_boost*=1.25
  84. else:
  85. if x == 0:
  86. if garden[x][y-1] == 1:
  87. clover_boost*=1.25
  88. if garden[x+1][y-1] == 1:
  89. clover_boost*=1.25
  90. if garden[x+1][y] == 1:
  91. clover_boost*=1.25
  92. if garden[x+1][y+1] == 1:
  93. clover_boost*=1.25
  94. if garden[x][y+1] == 1:
  95. clover_boost*=1.25
  96. elif x == 5:
  97. if garden[x][y-1] == 1:
  98. clover_boost*=1.25
  99. if garden[x-1][y-1] == 1:
  100. clover_boost*=1.25
  101. if garden[x-1][y] == 1:
  102. clover_boost*=1.25
  103. if garden[x-1][y+1] == 1:
  104. clover_boost*=1.25
  105. if garden[x][y+1] == 1:
  106. clover_boost*=1.25
  107. else:
  108. if garden[x-1][y-1] == 1:
  109. clover_boost*=1.25
  110. if garden[x][y-1] == 1:
  111. clover_boost*=1.25
  112. if garden[x+1][y-1] == 1:
  113. clover_boost*=1.25
  114. if garden[x+1][y] == 1:
  115. clover_boost*=1.25
  116. if garden[x+1][y+1] == 1:
  117. clover_boost*=1.25
  118. if garden[x][y+1] == 1:
  119. clover_boost*=1.25
  120. if garden[x-1][y+1] == 1:
  121. clover_boost*=1.25
  122. if garden[x-1][y] == 1:
  123. clover_boost*=1.25
  124. res+=clover_boost
  125. return res
  126.  
  127. # Asks for rows+columns of garden
  128. print("Welcome to the Golden Clover Bruteforcer!")
  129. rows = int(input("How many rows?: "))
  130. cols = int(input("How many columns?: "))
  131.  
  132. # Declares a 2D list for the garden
  133. col0 = [2, 2, 2, 2, 2, 2]
  134. col1 = [2, 2, 2, 2, 2, 2]
  135. col2 = [2, 2, 2, 2, 2, 2]
  136. col3 = [2, 2, 2, 2, 2, 2]
  137. col4 = [2, 2, 2, 2, 2, 2]
  138. col5 = [2, 2, 2, 2, 2, 2]
  139. garden = [col0, col1, col2, col3, col4, col5]
  140.  
  141. best_col0 = [2, 2, 2, 2, 2, 2]
  142. best_col1 = [2, 2, 2, 2, 2, 2]
  143. best_col2 = [2, 2, 2, 2, 2, 2]
  144. best_col3 = [2, 2, 2, 2, 2, 2]
  145. best_col4 = [2, 2, 2, 2, 2, 2]
  146. best_col5 = [2, 2, 2, 2, 2, 2]
  147. best_garden = [best_col0, best_col1, best_col2, best_col3, best_col4, best_col5]
  148.  
  149. # Declares variables
  150. timestamp = round(m.time())
  151. highest_boost = 0
  152. gardens_tested = 0
  153.  
  154. # For loop to test every possible garden
  155. for i in range(2**(rows*cols)):
  156. # Creates a binary "seed" based on the current repetition of the loop
  157. seed = bin(i)[2:]
  158. while len(seed) < rows*cols:
  159. seed = "0" + str(seed)
  160. # Changes the garden in accordance to the seed
  161. for x in range(rows):
  162. for y in range(cols):
  163. garden[x][y] = int(seed[-(x*cols+y+1)])
  164. boost = calculate_gc_boost(garden)
  165. # Prints the garden if it has reached the highest boost yet
  166. if boost > highest_boost:
  167. highest_boost = boost
  168. print("This garden has the highest boost yet, at +" + str(round(boost, 2)) + "%.")
  169. for i in range(6):
  170. print(garden[i])
  171. best_garden[i] = garden[i][0:]
  172.  
  173. # Gives progress updates every 100000 gardens
  174. gardens_tested+=1
  175. if gardens_tested % 100000 == 0 and rows*cols >= 25:
  176. print("Gardens tested: " + str(gardens_tested) + " / " + str(2**(rows*cols)))
  177. print("In binary: " + seed + " / " + "1"*(rows*cols))
  178. print("Time elapsed: " + str(round(m.time())-timestamp) + " seconds")
  179. # Prints the final best garden
  180. print("Program finished!")
  181. print("The best garden, with a boost of " + str(round(highest_boost, 2)) + "%, was this:")
  182. for i in range(6):
  183. print(best_garden[i])
  184.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement