91 lines
2.5 KiB
Python
91 lines
2.5 KiB
Python
import utils
|
|
import mappings
|
|
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)
|
|
plant(Entities.Cactus)
|
|
|
|
def drone_sort(start_x, start_y, world_size_x, world_size_y):
|
|
is_sorted = False
|
|
|
|
last_x = start_x + world_size_x
|
|
last_y = start_y + world_size_y
|
|
|
|
new_last_x = last_x
|
|
new_last_y = last_y
|
|
|
|
iteration_done = False
|
|
|
|
while not is_sorted:
|
|
is_sorted = True
|
|
iteration_done = False
|
|
|
|
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 (get_pos_x() == last_x and
|
|
get_pos_y() == last_y):
|
|
iteration_done = True
|
|
break
|
|
|
|
curr_size = measure()
|
|
|
|
if (get_pos_y() - start_y) > 0:
|
|
south_size = measure(South)
|
|
|
|
if curr_size < south_size:
|
|
is_sorted = False
|
|
new_last_x = get_pos_x()
|
|
new_last_y = get_pos_y()
|
|
swap(South)
|
|
|
|
if (get_pos_x() - start_x) > 0:
|
|
west_size = measure(West)
|
|
|
|
if curr_size < west_size:
|
|
is_sorted = False
|
|
new_last_x = get_pos_x()
|
|
new_last_y = get_pos_y()
|
|
swap(West)
|
|
|
|
if iteration_done:
|
|
break
|
|
|
|
last_x = new_last_x
|
|
last_y = new_last_y
|
|
|
|
def farm(needed):
|
|
if num_items(Items.Cactus) >= needed:
|
|
return
|
|
|
|
cost = get_cost(Entities.Cactus)
|
|
|
|
for item in cost:
|
|
mappings.get_farm_function(item)(needed // (max_drones() ** 2))
|
|
|
|
while num_items(Items.Cactus) < needed:
|
|
sunflower.farm(3500)
|
|
set_world_size(max_drones())
|
|
utils.clear_field(True)
|
|
|
|
def plant_task(id):
|
|
drone_plant(id, 0, 1, get_world_size())
|
|
|
|
def sort_horizontal_task(id):
|
|
drone_sort(id, 0, 1, get_world_size())
|
|
|
|
def sort_vertical_task(id):
|
|
drone_sort(0, id, get_world_size(), 1)
|
|
|
|
utils.parallel_run(max_drones(), plant_task)
|
|
utils.parallel_run(max_drones(), sort_horizontal_task)
|
|
utils.parallel_run(max_drones(), sort_vertical_task)
|
|
|
|
utils.go_to_00()
|
|
|
|
harvest()
|