91 lines
2.4 KiB
Python
91 lines
2.4 KiB
Python
import utils
|
|
import sunflower
|
|
|
|
def drone_plant(start_x, start_y, world_size_x, world_size_y):
|
|
for y in range(world_size_y):
|
|
for x in range(world_size_x):
|
|
utils.go_to_xy(start_x + x, start_y + y)
|
|
|
|
if (((start_x + x) + (start_y + y)) % 2) == 0:
|
|
plant(Entities.Tree)
|
|
else:
|
|
plant(Entities.Bush)
|
|
|
|
def get_best_companion():
|
|
companion = get_companion()
|
|
|
|
if (companion != None and
|
|
((companion[1][0] + companion[1][1]) % 2) == 1
|
|
and companion[0] == Entities.Bush):
|
|
return companion
|
|
|
|
while True:
|
|
harvest()
|
|
plant(Entities.Tree)
|
|
companion = get_companion()
|
|
|
|
if (companion != None and
|
|
((companion[1][0] + companion[1][1]) % 2) == 1
|
|
and companion[0] == Entities.Bush):
|
|
return companion
|
|
|
|
def drone_poly(needed, start_x, start_y, world_size_x, world_size_y):
|
|
while num_items(Items.Wood) < needed:
|
|
if num_items(Items.Power) == 0:
|
|
return
|
|
|
|
for y in range(world_size_y):
|
|
for x in range(world_size_x):
|
|
utils.go_to_xy(start_x + x, start_y + y)
|
|
|
|
if ((start_x + x) + (start_y + y)) % 2 == 0:
|
|
get_best_companion()
|
|
|
|
for y in range(world_size_y):
|
|
for x in range(world_size_x):
|
|
utils.go_to_xy(start_x + x, start_y + y)
|
|
|
|
harvest()
|
|
|
|
if (((start_x + x) + (start_y + y)) % 2) == 0:
|
|
plant(Entities.Tree)
|
|
|
|
while (num_items(Items.Water) > 0 and
|
|
get_water() < 0.7):
|
|
use_item(Items.Water)
|
|
else:
|
|
plant(Entities.Bush)
|
|
|
|
def farm(needed):
|
|
if num_items(Items.Wood) >= needed:
|
|
return
|
|
|
|
sunflower.farm(10000)
|
|
|
|
set_world_size(max_drones())
|
|
|
|
utils.clear_field(True)
|
|
|
|
def task_plant(id):
|
|
drone_plant(id, 0, 1, get_world_size())
|
|
|
|
utils.parallel_run(get_world_size(), task_plant)
|
|
|
|
def task_companion(id):
|
|
drone_poly(needed, id, 0, 1, get_world_size())
|
|
|
|
utils.parallel_run(get_world_size(), task_companion)
|
|
|
|
if num_items(Items.Wood) < needed:
|
|
return farm(needed)
|
|
|
|
if __name__ == "__main__":
|
|
ts_start = get_time()
|
|
|
|
farm(10000000000)
|
|
|
|
ts_end = get_time()
|
|
|
|
quick_print(ts_end - ts_start)
|
|
quick_print(num_items(Items.Wood))
|