modularized planting logic by splitting f2.py into main.py, pumpkins.py, and sunflowers.py; updated utilities and added .gitignore
This commit is contained in:
86
utils.py
86
utils.py
@@ -1,62 +1,66 @@
|
||||
from __builtins__ import *
|
||||
|
||||
world_size = get_world_size()
|
||||
|
||||
def move_to(x, y):
|
||||
while x > get_pos_x():
|
||||
move(East)
|
||||
while x < get_pos_x():
|
||||
move(West)
|
||||
while x > get_pos_x():
|
||||
move(East)
|
||||
while x < get_pos_x():
|
||||
move(West)
|
||||
|
||||
while y > get_pos_y():
|
||||
move(North)
|
||||
while y < get_pos_y():
|
||||
move(South)
|
||||
|
||||
|
||||
while y > get_pos_y():
|
||||
move(North)
|
||||
while y < get_pos_y():
|
||||
move(South)
|
||||
|
||||
|
||||
# plant_grid will plant a square of the given list of entities. If the water level is below waterBelow,
|
||||
# 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()
|
||||
x = get_pos_x()
|
||||
y = get_pos_y()
|
||||
|
||||
gridSize = get_world_size()
|
||||
gridSize = get_world_size()
|
||||
|
||||
if (x + width) > gridSize:
|
||||
width = gridSize - x
|
||||
if (x + width) > gridSize:
|
||||
width = gridSize - x
|
||||
|
||||
if (y + height) > gridSize:
|
||||
height = gridSize - y
|
||||
if (y + height) > gridSize:
|
||||
height = gridSize - y
|
||||
|
||||
tracker = 0
|
||||
tracker = 0
|
||||
|
||||
others = {East:West, West:East}
|
||||
others = {East:West, West:East}
|
||||
|
||||
sideDir = East
|
||||
# first pass over, checking if anything can be harvested. if so, harvest.
|
||||
# then check what type of ground is down, if it's not soil then till.
|
||||
# then if it's below 75% water and i have some water, give it some.
|
||||
# then plant a pumpkin.
|
||||
for row in range(height):
|
||||
for col in range(width):
|
||||
if can_harvest():
|
||||
harvest()
|
||||
if requireSoil:
|
||||
if get_ground_type() != Grounds.Soil:
|
||||
till()
|
||||
sideDir = East
|
||||
# first pass over, checking if anything can be harvested. if so, harvest.
|
||||
# then check what type of ground is down, if it's not soil then till.
|
||||
# then if it's below 75% water and i have some water, give it some.
|
||||
# then plant a pumpkin.
|
||||
for row in range(height):
|
||||
for col in range(width):
|
||||
if can_harvest():
|
||||
harvest()
|
||||
if requireSoil:
|
||||
if get_ground_type() != Grounds.Soil:
|
||||
till()
|
||||
|
||||
while get_water() < waterBelow:
|
||||
if not use_item(Items.Water):
|
||||
break
|
||||
while get_water() < waterBelow:
|
||||
if not use_item(Items.Water):
|
||||
break
|
||||
|
||||
index = tracker % len(plantWith)
|
||||
tracker += 1
|
||||
plant(plantWith[index])
|
||||
index = tracker % len(plantWith)
|
||||
tracker += 1
|
||||
plant(plantWith[index])
|
||||
|
||||
# if it's not the last pass, then move
|
||||
if col < width - 1:
|
||||
move(sideDir)
|
||||
# if it's not the last pass, then move
|
||||
if col < width - 1:
|
||||
move(sideDir)
|
||||
|
||||
|
||||
if row < height - 1:
|
||||
sideDir = others[sideDir]
|
||||
move(North)
|
||||
if row < height - 1:
|
||||
sideDir = others[sideDir]
|
||||
move(North)
|
||||
Reference in New Issue
Block a user