refactor: adjust planting logic to use grid sections and add grass planting
This commit is contained in:
50
f2.py
50
f2.py
@@ -1,12 +1,21 @@
|
|||||||
import utils
|
import utils
|
||||||
|
from __builtins__ import Entities
|
||||||
|
|
||||||
|
|
||||||
def plant_pumpkin(width, height):
|
def plant_pumpkin(width, height):
|
||||||
|
x = get_pos_x()
|
||||||
|
y = get_pos_y()
|
||||||
utils.plant_grid(width, height, [Entities.Pumpkin], 0.75, True)
|
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):
|
def plant_carrots(width, height):
|
||||||
utils.plant_grid(width, height, [Entities.Carrot], 0.75, True)
|
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):
|
def plant_alternating(width, height, plantWith):
|
||||||
utils.plant_grid(width, height, plantWith, 0.75, False)
|
utils.plant_grid(width, height, plantWith, 0.75, False)
|
||||||
|
|
||||||
@@ -42,24 +51,31 @@ def verify_pumpkin(width, height):
|
|||||||
while True:
|
while True:
|
||||||
worldSize = get_world_size()
|
worldSize = get_world_size()
|
||||||
|
|
||||||
|
sectionSize = worldSize // 3
|
||||||
|
|
||||||
utils.move_to(0, 0)
|
utils.move_to(0, 0)
|
||||||
plant_pumpkin(worldSize / 2, worldSize / 2)
|
plant_pumpkin(sectionSize, sectionSize)
|
||||||
utils.move_to(0, 0)
|
|
||||||
while verify_pumpkin(worldSize / 2, worldSize / 2):
|
|
||||||
utils.move_to(0, 0)
|
|
||||||
|
|
||||||
utils.move_to(worldSize / 2, 0)
|
utils.move_to(sectionSize+1, 0)
|
||||||
plant_carrots(worldSize / 2, worldSize / 2)
|
plant_carrots(sectionSize, sectionSize)
|
||||||
|
|
||||||
utils.move_to(0, worldSize / 2)
|
utils.move_to(sectionSize*2+1, 0)
|
||||||
plant_alternating(worldSize / 2, worldSize / 2, [ Entities.Tree, Entities.Bush ])
|
plant_grass(sectionSize, sectionSize)
|
||||||
|
|
||||||
utils.move_to(worldSize / 2, worldSize / 2)
|
utils.move_to(0, sectionSize+1)
|
||||||
# the top right quadrant is 50% of the time pumpkin, 50% of the time carrots
|
plant_alternating(sectionSize, sectionSize, [ Entities.Tree, Entities.Bush ])
|
||||||
if random() < 0.5:
|
|
||||||
plant_carrots(worldSize / 2, worldSize / 2)
|
utils.move_to(sectionSize+1, sectionSize+1)
|
||||||
else:
|
plant_pumpkin(sectionSize, sectionSize)
|
||||||
plant_pumpkin(worldSize / 2, worldSize / 2)
|
|
||||||
utils.move_to(worldSize / 2, worldSize / 2)
|
utils.move_to(sectionSize*2+1, sectionSize+1)
|
||||||
while verify_pumpkin(worldSize / 2, worldSize / 2):
|
plant_carrots(sectionSize, sectionSize)
|
||||||
utils.move_to(worldSize / 2, worldSize / 2)
|
|
||||||
|
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)
|
||||||
11
utils.py
11
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.
|
# 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.
|
# plantWith - list of entities to plant. The entities will alternate if repeated.
|
||||||
def plant_grid(width, height, plantWith, waterBelow, requireSoil):
|
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
|
tracker = 0
|
||||||
|
|
||||||
others = {East:West, West:East}
|
others = {East:West, West:East}
|
||||||
|
|||||||
Reference in New Issue
Block a user