Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- This program bruteforces every garden combination to find the most optimal
- golden clover and nursetulip setup for a given garden size.
- 0 means golden clover, 1 means nursetulip, and 2 means empty/locked space.
- This does not take "ghosttulips" into account.
- All plants are mature and the soil is always clay. The nursetulips have matured
- more than 1 tick ago so they have their full effect.
- Orientation of setups does not matter. Earlytick/latetick only matters for
- mutation setup, not when using plant effects. I technically could have made
- this faster by not testing for rotated and/or flipped setups, but I don't
- know enough Python to do that. Feel free to try.
- """
- import time as m
- # Function for calculating GC frequency boost
- def calculate_gc_boost(garden):
- # res is the final result, clover_boost is for one clover at a time
- res = 0
- clover_boost = 0
- # For loops to calculate boost for every square in the garden
- for x in range(6):
- for y in range(6):
- clover_boost = 3.75
- # Jumbled mess of if/elif/elses, though basically just checks
- # how many nursetulips are surround the clover
- if garden[x][y] == 0:
- if y == 0:
- if x == 0:
- if garden[x+1][y] == 1:
- clover_boost*=1.25
- if garden[x][y+1] == 1:
- clover_boost*=1.25
- if garden[x+1][y+1] == 1:
- clover_boost*=1.25
- elif x == 5:
- if garden[x-1][y] == 1:
- clover_boost*=1.25
- if garden[x][y+1] == 1:
- clover_boost*=1.25
- if garden[x-1][y+1] == 1:
- clover_boost*=1.25
- else:
- if garden[x-1][y] == 1:
- clover_boost*=1.25
- if garden[x-1][y+1] == 1:
- clover_boost*=1.25
- if garden[x][y+1] == 1:
- clover_boost*=1.25
- if garden[x+1][y+1] == 1:
- clover_boost*=1.25
- if garden[x+1][y] == 1:
- clover_boost*=1.25
- elif y == 5:
- if x == 0:
- if garden[x+1][y] == 1:
- clover_boost*=1.25
- if garden[x][y-1] == 1:
- clover_boost*=1.25
- if garden[x+1][y-1] == 1:
- clover_boost*=1.25
- elif x == 5:
- if garden[x-1][y] == 1:
- clover_boost*=1.25
- if garden[x][y-1] == 1:
- clover_boost*=1.25
- if garden[x-1][y-1] == 1:
- clover_boost*=1.25
- else:
- if garden[x-1][y] == 1:
- clover_boost*=1.25
- if garden[x-1][y-1] == 1:
- clover_boost*=1.25
- if garden[x][y-1] == 1:
- clover_boost*=1.25
- if garden[x+1][y-1] == 1:
- clover_boost*=1.25
- if garden[x+1][y] == 1:
- clover_boost*=1.25
- else:
- if x == 0:
- if garden[x][y-1] == 1:
- clover_boost*=1.25
- if garden[x+1][y-1] == 1:
- clover_boost*=1.25
- if garden[x+1][y] == 1:
- clover_boost*=1.25
- if garden[x+1][y+1] == 1:
- clover_boost*=1.25
- if garden[x][y+1] == 1:
- clover_boost*=1.25
- elif x == 5:
- if garden[x][y-1] == 1:
- clover_boost*=1.25
- if garden[x-1][y-1] == 1:
- clover_boost*=1.25
- if garden[x-1][y] == 1:
- clover_boost*=1.25
- if garden[x-1][y+1] == 1:
- clover_boost*=1.25
- if garden[x][y+1] == 1:
- clover_boost*=1.25
- else:
- if garden[x-1][y-1] == 1:
- clover_boost*=1.25
- if garden[x][y-1] == 1:
- clover_boost*=1.25
- if garden[x+1][y-1] == 1:
- clover_boost*=1.25
- if garden[x+1][y] == 1:
- clover_boost*=1.25
- if garden[x+1][y+1] == 1:
- clover_boost*=1.25
- if garden[x][y+1] == 1:
- clover_boost*=1.25
- if garden[x-1][y+1] == 1:
- clover_boost*=1.25
- if garden[x-1][y] == 1:
- clover_boost*=1.25
- res+=clover_boost
- return res
- # Asks for rows+columns of garden
- print("Welcome to the Golden Clover Bruteforcer!")
- rows = int(input("How many rows?: "))
- cols = int(input("How many columns?: "))
- # Declares a 2D list for the garden
- col0 = [2, 2, 2, 2, 2, 2]
- col1 = [2, 2, 2, 2, 2, 2]
- col2 = [2, 2, 2, 2, 2, 2]
- col3 = [2, 2, 2, 2, 2, 2]
- col4 = [2, 2, 2, 2, 2, 2]
- col5 = [2, 2, 2, 2, 2, 2]
- garden = [col0, col1, col2, col3, col4, col5]
- best_col0 = [2, 2, 2, 2, 2, 2]
- best_col1 = [2, 2, 2, 2, 2, 2]
- best_col2 = [2, 2, 2, 2, 2, 2]
- best_col3 = [2, 2, 2, 2, 2, 2]
- best_col4 = [2, 2, 2, 2, 2, 2]
- best_col5 = [2, 2, 2, 2, 2, 2]
- best_garden = [best_col0, best_col1, best_col2, best_col3, best_col4, best_col5]
- # Declares variables
- timestamp = round(m.time())
- highest_boost = 0
- gardens_tested = 0
- # For loop to test every possible garden
- for i in range(2**(rows*cols)):
- # Creates a binary "seed" based on the current repetition of the loop
- seed = bin(i)[2:]
- while len(seed) < rows*cols:
- seed = "0" + str(seed)
- # Changes the garden in accordance to the seed
- for x in range(rows):
- for y in range(cols):
- garden[x][y] = int(seed[-(x*cols+y+1)])
- boost = calculate_gc_boost(garden)
- # Prints the garden if it has reached the highest boost yet
- if boost > highest_boost:
- highest_boost = boost
- print("This garden has the highest boost yet, at +" + str(round(boost, 2)) + "%.")
- for i in range(6):
- print(garden[i])
- best_garden[i] = garden[i][0:]
- # Gives progress updates every 100000 gardens
- gardens_tested+=1
- if gardens_tested % 100000 == 0 and rows*cols >= 25:
- print("Gardens tested: " + str(gardens_tested) + " / " + str(2**(rows*cols)))
- print("In binary: " + seed + " / " + "1"*(rows*cols))
- print("Time elapsed: " + str(round(m.time())-timestamp) + " seconds")
- # Prints the final best garden
- print("Program finished!")
- print("The best garden, with a boost of " + str(round(highest_boost, 2)) + "%, was this:")
- for i in range(6):
- print(best_garden[i])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement