From cb702bed32e845bf3d26670fcd08df321b79685e Mon Sep 17 00:00:00 2001 From: steve Date: Sun, 4 Jan 2026 18:36:26 -0500 Subject: [PATCH] refactor: adjust planting logic to use grid sections and add grass planting --- f2.py | 50 +++++++++++++++++++++++++++++++++----------------- utils.py | 11 +++++++++++ 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/f2.py b/f2.py index f4e89ab..d6517c9 100644 --- a/f2.py +++ b/f2.py @@ -1,12 +1,21 @@ import utils +from __builtins__ import Entities def plant_pumpkin(width, height): + x = get_pos_x() + y = get_pos_y() utils.plant_grid(width, height, [Entities.Pumpkin], 0.75, True) + utils.move_to(x, y) + while verify_pumpkin(sectionSize, sectionSize): + utils.move_to(x, y) def plant_carrots(width, height): utils.plant_grid(width, height, [Entities.Carrot], 0.75, True) +def plant_grass(width, height): + utils.plant_grid(width, height, [Entities.Grass], 0.75, False) + def plant_alternating(width, height, plantWith): utils.plant_grid(width, height, plantWith, 0.75, False) @@ -42,24 +51,31 @@ def verify_pumpkin(width, height): while True: worldSize = get_world_size() + sectionSize = worldSize // 3 + utils.move_to(0, 0) - plant_pumpkin(worldSize / 2, worldSize / 2) - utils.move_to(0, 0) - while verify_pumpkin(worldSize / 2, worldSize / 2): - utils.move_to(0, 0) + plant_pumpkin(sectionSize, sectionSize) - utils.move_to(worldSize / 2, 0) - plant_carrots(worldSize / 2, worldSize / 2) + utils.move_to(sectionSize+1, 0) + plant_carrots(sectionSize, sectionSize) - utils.move_to(0, worldSize / 2) - plant_alternating(worldSize / 2, worldSize / 2, [ Entities.Tree, Entities.Bush ]) + utils.move_to(sectionSize*2+1, 0) + plant_grass(sectionSize, sectionSize) - utils.move_to(worldSize / 2, worldSize / 2) - # the top right quadrant is 50% of the time pumpkin, 50% of the time carrots - if random() < 0.5: - plant_carrots(worldSize / 2, worldSize / 2) - else: - plant_pumpkin(worldSize / 2, worldSize / 2) - utils.move_to(worldSize / 2, worldSize / 2) - while verify_pumpkin(worldSize / 2, worldSize / 2): - utils.move_to(worldSize / 2, worldSize / 2) \ No newline at end of file + utils.move_to(0, sectionSize+1) + plant_alternating(sectionSize, sectionSize, [ Entities.Tree, Entities.Bush ]) + + utils.move_to(sectionSize+1, sectionSize+1) + plant_pumpkin(sectionSize, sectionSize) + + utils.move_to(sectionSize*2+1, sectionSize+1) + plant_carrots(sectionSize, sectionSize) + + utils.move_to(0, sectionSize*2+1) + plant_alternating(sectionSize, sectionSize, [ Entities.Tree, Entities.Bush ]) + + utils.move_to(sectionSize+1, sectionSize*2+1) + plant_alternating(sectionSize, sectionSize, [ Entities.Tree, Entities.Bush ]) + + utils.move_to(sectionSize*2+1, sectionSize*2+1) + plant_pumpkin(sectionSize, sectionSize) \ No newline at end of file diff --git a/utils.py b/utils.py index d90fabe..c3f8ed7 100644 --- a/utils.py +++ b/utils.py @@ -16,6 +16,17 @@ def move_to(x, y): # it will water the tile. If requireSoil is true, it will till the tile if it's not soil. # plantWith - list of entities to plant. The entities will alternate if repeated. def plant_grid(width, height, plantWith, waterBelow, requireSoil): + x = get_pos_x() + y = get_pos_y() + + gridSize = get_world_size() + + if (x + width) > gridSize: + width = gridSize - x + + if (y + height) > gridSize: + height = gridSize - y + tracker = 0 others = {East:West, West:East}