add sunflower grid planting / harvesting logic

This commit is contained in:
2026-01-10 01:12:11 -05:00
parent db310c2a19
commit 5a16e7a8a3
3 changed files with 127 additions and 7 deletions

View File

@@ -2,8 +2,24 @@ from __builtins__ import *
import utils
# Places sunflowers at random locations in the specified area.
#
# We cannot simply just use utils.plant_grid here, because we need to also keep track
# of the number of petals on each sunflower, and return a dictionary mapping petal count
# to a list of sunflower coordinates containing that petal count.
#
# Parameters:
# width (int): The number of columns in the grid.
# height (int): The number of rows in the grid.
#
# Returns:
# dictionary: A dictionary mapping petal count to a list of sunflower coordinates containing that petal count.
#
# Important:
# utils.plant_grid uses very similar logic with this function, so any changes to this function should be reflected in utils.plant_grid as well.
def place(width, height):
utils.plant_grid(width, height, [Entities.Sunflower], 0.75, True)
return utils.plant_grid_return_measurements(width, height, [Entities.Sunflower], 0.75, True)
# Harvests all sunflowers in the specified area.
#
@@ -13,5 +29,13 @@ def place(width, height):
# Parameters:
# width (int): The number of columns in the grid.
# height (int): The number of rows in the grid.
# flowers (list): A list of sunflower entities to be harvested.
def harvest(width, height, flowers):
# flowers (dictionary): A dictionary mapping petal count to a list of sunflower coordinates containing that petal count.
def harvest_grid(width, height, flowers):
result = {}
# in reverse order of petals
petals = [15, 14, 13, 12, 11, 10, 9, 8, 7]
for count in petals:
for coord in flowers[count]:
utils.move_to(coord[0], coord[1])
harvest()