I'm looking for serious feedback on my first serious program.
This is a program to calculate PvZ income over time of sunflowers and sunshrooms on nighttime pool levels.
Shrooms might have an obvious advantage but this program was borne over the idea that once all space allocated to income plants fills up, they are operating at lower rates until they are two minutes old and thus it, might be possible that sunflowers end up earning more over the course of a few minutes if they fill up the same area and when shrooms scale worse with lily pad costs
The hypothesis was false :( but they're so close that there is no functional gameplay difference
The program assumes 16 income plants, 3 rows on land and 2 in water because water is harder to defend. Changes in maximum number of income plants changed the results by little to nothing. Attempts to use both plants gave no profits.
time = 0 sun_f = 50 # spendable sun for sunflower simulation sun_f_total = 0 # total earned sun for sunflowers sun_s = 50 # spendable sun for sunshroom simulation sun_s_total = 0 # total earned sun for sunshrooms cooldownflower = 0 cooldownshroom = 0 sunflowers = 0 sunshrooms = 0 ageflower =  # lists for calculating income timing and shroom evolving ageshroom = 
Just the variables
def buildsunflower(): global sun_f global sunflowers global cooldownflower if sunflowers < 12: sun_f -= 50 # normal cost elif sunflowers > 11: sun_f -= 75 # adjusted lily pad cost for water placement after 12 land spots fill sunflowers += 1 # running total for sunflowers ageflower.append(12) # the first income packet only requires 12 instead of 24 seconds cooldownflower = 9 # sets sunflower build cooldown to 8 + 1 second of human error def buildsunshroom(): global sun_s global sunshrooms global cooldownshroom if sunshrooms < 12: sun_s -= 25 elif sunshrooms > 11: sun_s -= 50 sunshrooms += 1 ageshroom.append(12) cooldownshroom = 9
These are the functions that simulate building the plants. I'm not sure if the global thing is ideal here.
def update(): global time global cooldownflower global cooldownshroom global ageflower global ageshroom print('\t', time, '\t\t', sun_f, '/', sun_s, '\t\t', sun_f_total, '/', sun_s_total, '\t\t', sunflowers, '/', sunshrooms) # per second readout time += 1 # running total of seconds cooldownflower -= 1 # reduces build cooldowns from 9 cooldownshroom -= 1 ageflower = [x + 1 for x in ageflower] # magical aging code I don't understand yet ageshroom = [x + 1 for x in ageshroom]
Figuring out how to program the income was the hardest part for me by far as the exact [average] moment you get the income depends on when you first build the plant. I solved it by appending a list after each sunflower/shroom was planted and by having my loop age the list with +1 to every value, and then adding income whenever the loop finds a value that's a multiple of 24. It works swell but I feel there are much better ways to accomplish this. I'm not even entirely sure how the list aging code works, I've never seen it like that before.
for n in range(300): if sun_f >= 50 and cooldownflower <= 0 and sunflowers < 16: # plants flower if currency, buildsunflower() # cooldown, and room allow for x in ageflower: if x % 24 == 0: # adds income in multiples of 24 seconds sun_f += 25 sun_f_total += 25 if sun_s >= 25 and cooldownshroom <= 0 and sunshrooms < 16: buildsunshroom() for x in ageshroom: if x % 24 == 0 and x > 120: # the 120 is to check for evolved shroom sun_s += 25 sun_s_total += 25 elif x % 24 == 0: sun_s += 15 sun_s_total += 15 update() # recalculates before new loop
The loop tying it all together.