moved move_to and plant_grid to utils.py and updated references
This commit is contained in:
120
f2.py
120
f2.py
@@ -1,110 +1,14 @@
|
||||
def carrots(worldSize):
|
||||
simple_column(worldSize, True, Entities.Carrot)
|
||||
import utils
|
||||
|
||||
|
||||
def pumpkins(worldSize):
|
||||
simple_column(worldSize, True, Entities.Pumpkin)
|
||||
|
||||
|
||||
def bushes_and_trees(worldSize):
|
||||
for row in range(worldSize):
|
||||
if can_harvest():
|
||||
harvest()
|
||||
if row % 2 == 0:
|
||||
plant(Entities.Bush)
|
||||
else:
|
||||
plant(Entities.Tree)
|
||||
move(North)
|
||||
|
||||
|
||||
def simple_column(worldSize, shouldTill, entity):
|
||||
for row in range(worldSize):
|
||||
if can_harvest():
|
||||
harvest()
|
||||
|
||||
if shouldTill:
|
||||
till()
|
||||
|
||||
plant(entity)
|
||||
move(North)
|
||||
|
||||
def move_to(x, y):
|
||||
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)
|
||||
|
||||
def reset_pos():
|
||||
while get_pos_y() > 0:
|
||||
move(North)
|
||||
while get_pos_x() > 0:
|
||||
move(West)
|
||||
|
||||
|
||||
def runWorld():
|
||||
worldSize = get_world_size()
|
||||
for col in range(worldSize):
|
||||
runColumn(col, worldSize)
|
||||
move(East)
|
||||
|
||||
|
||||
def runColumn(col, worldSize):
|
||||
# 1 in 3 is carrots
|
||||
if col % 3 == 0:
|
||||
carrots(worldSize)
|
||||
|
||||
elif col % 3 == 1:
|
||||
pumpkins(worldSize)
|
||||
else:
|
||||
bushes_and_trees(worldSize)
|
||||
|
||||
def plant_grid(width, height, plantWith, waterBelow, requireSoil):
|
||||
tracker = 0
|
||||
|
||||
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()
|
||||
|
||||
if get_water() < waterBelow:
|
||||
use_item(Items.Water)
|
||||
|
||||
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 row < height - 1:
|
||||
sideDir = others[sideDir]
|
||||
move(North)
|
||||
|
||||
def plant_pumpkin(width, height):
|
||||
plant_grid(width, height, [Entities.Pumpkin], 0.75, True)
|
||||
utils.plant_grid(width, height, [Entities.Pumpkin], 0.75, True)
|
||||
|
||||
def plant_carrots(width, height):
|
||||
plant_grid(width, height, [Entities.Carrot], 0.75, True)
|
||||
utils.plant_grid(width, height, [Entities.Carrot], 0.75, True)
|
||||
|
||||
def plant_alternating(width, height, plantWith):
|
||||
plant_grid(width, height, plantWith, 0.75, False)
|
||||
utils.plant_grid(width, height, plantWith, 0.75, False)
|
||||
|
||||
# verify_pumpkin will verify that a pumpkin is planted in all tiles of a quadrant, and it will check that
|
||||
# the pumpkin isn't dead. if it's dead it will replant it. Returns whether any dead pumpkins were found.
|
||||
@@ -138,21 +42,21 @@ def verify_pumpkin(width, height):
|
||||
while True:
|
||||
worldSize = get_world_size()
|
||||
|
||||
move_to(0, 0)
|
||||
utils.move_to(0, 0)
|
||||
plant_pumpkin(worldSize / 2, worldSize / 2)
|
||||
move_to(0, 0)
|
||||
utils.move_to(0, 0)
|
||||
while verify_pumpkin(worldSize / 2, worldSize / 2):
|
||||
move_to(0, 0)
|
||||
utils.move_to(0, 0)
|
||||
|
||||
move_to(worldSize / 2, 0)
|
||||
utils.move_to(worldSize / 2, 0)
|
||||
plant_carrots(worldSize / 2, worldSize / 2)
|
||||
|
||||
move_to(0, worldSize / 2)
|
||||
utils.move_to(0, worldSize / 2)
|
||||
plant_alternating(worldSize / 2, worldSize / 2, [ Entities.Tree, Entities.Bush ])
|
||||
|
||||
|
||||
move_to(worldSize / 2, worldSize / 2)
|
||||
utils.move_to(worldSize / 2, worldSize / 2)
|
||||
plant_pumpkin(worldSize / 2, worldSize / 2)
|
||||
move_to(worldSize / 2, worldSize / 2)
|
||||
utils.move_to(worldSize / 2, worldSize / 2)
|
||||
while verify_pumpkin(worldSize / 2, worldSize / 2):
|
||||
move_to(worldSize / 2, worldSize / 2)
|
||||
utils.move_to(worldSize / 2, worldSize / 2)
|
||||
50
utils.py
Normal file
50
utils.py
Normal file
@@ -0,0 +1,50 @@
|
||||
|
||||
|
||||
def move_to(x, y):
|
||||
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)
|
||||
|
||||
|
||||
# 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):
|
||||
tracker = 0
|
||||
|
||||
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()
|
||||
|
||||
if get_water() < waterBelow:
|
||||
use_item(Items.Water)
|
||||
|
||||
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 row < height - 1:
|
||||
sideDir = others[sideDir]
|
||||
move(North)
|
||||
Reference in New Issue
Block a user