All scripts for my personal run
This commit is contained in:
commit
dbad5d9c39
90
cactus.py
Normal file
90
cactus.py
Normal file
@ -0,0 +1,90 @@
|
||||
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()
|
||||
59
carrot.py
Normal file
59
carrot.py
Normal file
@ -0,0 +1,59 @@
|
||||
import utils
|
||||
import mappings
|
||||
import sunflower
|
||||
|
||||
def drone_main(needed, start_x, start_y, world_size_x, world_size_y):
|
||||
while num_items(Items.Carrot) < 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 utils.is_empty():
|
||||
plant(Entities.Carrot)
|
||||
else:
|
||||
if can_harvest():
|
||||
harvest()
|
||||
plant(Entities.Carrot)
|
||||
|
||||
while (num_items(Items.Water) > 0 and
|
||||
get_water() < 0.7):
|
||||
use_item(Items.Water)
|
||||
|
||||
for y in range(world_size_y - 1):
|
||||
for x in range(world_size_x):
|
||||
utils.go_to_xy(start_x + x, start_y + world_size_y - y - 1)
|
||||
if utils.is_empty():
|
||||
plant(Entities.Carrot)
|
||||
else:
|
||||
if can_harvest():
|
||||
harvest()
|
||||
plant(Entities.Carrot)
|
||||
|
||||
while (num_items(Items.Water) > 0 and
|
||||
get_water() < 0.7):
|
||||
use_item(Items.Water)
|
||||
|
||||
def farm(needed):
|
||||
if num_items(Items.Carrot) >= needed:
|
||||
return
|
||||
|
||||
cost = get_cost(Entities.Carrot)
|
||||
|
||||
for item in cost:
|
||||
mappings.get_farm_function(item)(needed)
|
||||
|
||||
sunflower.farm(10000)
|
||||
|
||||
set_world_size(max_drones())
|
||||
|
||||
utils.clear_field(True)
|
||||
|
||||
def task(id):
|
||||
drone_main(needed, id, 0, 1, get_world_size())
|
||||
|
||||
utils.parallel_run(max_drones(), task)
|
||||
|
||||
if num_items(Items.Carrot) < needed:
|
||||
farm(needed)
|
||||
72
dinosaur.py
Normal file
72
dinosaur.py
Normal file
@ -0,0 +1,72 @@
|
||||
import utils
|
||||
import sunflower
|
||||
|
||||
sunflower.farm(10000)
|
||||
|
||||
set_world_size(32)
|
||||
utils.clear_field(True)
|
||||
|
||||
utils.go_to_00()
|
||||
|
||||
change_hat(Hats.Dinosaur_Hat)
|
||||
|
||||
tail_size = 0
|
||||
|
||||
ax, ay = measure()
|
||||
|
||||
vdir = North
|
||||
|
||||
def update_apple_tail():
|
||||
global ax
|
||||
global ay
|
||||
global vdir
|
||||
global tail_size
|
||||
|
||||
if (get_pos_x() == ax and
|
||||
get_pos_y() == ay):
|
||||
|
||||
ax, ay = measure()
|
||||
tail_size += 1
|
||||
|
||||
if tail_size == (get_world_size() * get_world_size() - 1):
|
||||
change_hat(Hats.Pumpkin_Hat)
|
||||
utils.go_to_00()
|
||||
vdir = North
|
||||
tail_size = 0
|
||||
change_hat(Hats.Dinosaur_Hat)
|
||||
ax, ay = measure()
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
while True:
|
||||
move(vdir)
|
||||
|
||||
if update_apple_tail():
|
||||
continue
|
||||
|
||||
if (get_pos_x() == (get_world_size() - 1) and
|
||||
get_pos_y() == 1):
|
||||
move(South)
|
||||
if update_apple_tail():
|
||||
continue
|
||||
continue_outer = False
|
||||
while get_pos_x() > 0:
|
||||
move(West)
|
||||
if update_apple_tail():
|
||||
continue_outer = True
|
||||
break
|
||||
if continue_outer:
|
||||
continue
|
||||
vdir = North
|
||||
continue
|
||||
|
||||
if ((get_pos_y() == 1 and get_pos_x() != 0) or
|
||||
(get_pos_y() == (get_world_size() - 1))):
|
||||
move(East)
|
||||
if update_apple_tail():
|
||||
continue
|
||||
if vdir == North:
|
||||
vdir = South
|
||||
else:
|
||||
vdir = North
|
||||
27
gold_brute_force.py
Normal file
27
gold_brute_force.py
Normal file
@ -0,0 +1,27 @@
|
||||
import utils
|
||||
import maze_common
|
||||
|
||||
set_world_size(5)
|
||||
|
||||
gold_target = 100000000
|
||||
|
||||
drones = []
|
||||
|
||||
def task(id):
|
||||
while num_items(Items.Gold) < gold_target:
|
||||
utils.go_to_xy(id // 5, id % 5)
|
||||
|
||||
entity = get_entity_type()
|
||||
|
||||
if entity == Entities.Treasure:
|
||||
harvest()
|
||||
|
||||
def maze_spawner():
|
||||
while num_items(Items.Gold) < gold_target:
|
||||
utils.go_to_00()
|
||||
|
||||
if get_entity_type() != Entities.Hedge or Entities.Treasure:
|
||||
maze_common.spawn_maze()
|
||||
|
||||
spawn_drone(maze_spawner)
|
||||
utils.parallel_run(25, task)
|
||||
35
hay.py
Normal file
35
hay.py
Normal file
@ -0,0 +1,35 @@
|
||||
import utils
|
||||
import sunflower
|
||||
|
||||
def drone_main(needed, start_x, start_y, world_size_x, world_size_y):
|
||||
while num_items(Items.Hay) < 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)
|
||||
harvest()
|
||||
|
||||
for y in range(world_size_y - 1):
|
||||
for x in range(world_size_x):
|
||||
utils.go_to_xy(start_x + x, start_y + world_size_y - y - 1)
|
||||
harvest()
|
||||
|
||||
def farm(needed):
|
||||
if num_items(Items.Hay) >= needed:
|
||||
return
|
||||
|
||||
sunflower.farm(10000)
|
||||
|
||||
set_world_size(max_drones())
|
||||
|
||||
utils.clear_field(False)
|
||||
|
||||
def task(id):
|
||||
drone_main(needed, id, 0, 1, get_world_size())
|
||||
|
||||
utils.parallel_run(max_drones(), task)
|
||||
|
||||
if num_items(Items.Hay) < needed:
|
||||
farm(needed)
|
||||
53
main.py
Normal file
53
main.py
Normal file
@ -0,0 +1,53 @@
|
||||
from mappings import get_farm_function
|
||||
|
||||
def auto_unlock(element):
|
||||
prev_level = num_unlocked(element) - 1
|
||||
level = num_unlocked(element)
|
||||
|
||||
while prev_level != level:
|
||||
cost = get_cost(element, level)
|
||||
|
||||
for item in cost:
|
||||
farm(item, cost[item])
|
||||
|
||||
unlock(element)
|
||||
|
||||
prev_level = level
|
||||
level = num_unlocked(element)
|
||||
|
||||
def farm(item, amount):
|
||||
cb = get_farm_function(item)
|
||||
cb(amount)
|
||||
|
||||
def main():
|
||||
ten = 10
|
||||
hundred = ten * ten
|
||||
thousand = ten * hundred
|
||||
million = thousand * thousand
|
||||
billion = thousand * million
|
||||
|
||||
farm(Items.Gold, 10 * million)
|
||||
farm(Items.Wood, 10 * billion)
|
||||
farm(Items.Power, 10 * thousand)
|
||||
farm(Items.Cactus, 10 * million)
|
||||
farm(Items.Pumpkin, 10 * million)
|
||||
farm(Items.Carrot, 10 * billion)
|
||||
farm(Items.Hay, 10 * billion)
|
||||
|
||||
def simulation_main():
|
||||
unlocks = Unlocks
|
||||
items = {
|
||||
Items.Weird_Substance: 1000000000.0,
|
||||
Items.Power: 1000000000.0
|
||||
}
|
||||
globals = {}
|
||||
seed = -1
|
||||
simulate("main_leaderboard", unlocks, items, globals, seed, 1024 ** 2)
|
||||
|
||||
def leaderboard_main():
|
||||
leaderboard_run(Leaderboards.Maze_Single, "main_leaderboard", 1024 ** 2)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
# simulation_main()
|
||||
# leaderboard_main()
|
||||
10
main_leaderboard.py
Normal file
10
main_leaderboard.py
Normal file
@ -0,0 +1,10 @@
|
||||
from mappings import get_farm_function
|
||||
|
||||
ts_start = get_time()
|
||||
|
||||
get_farm_function(Items.Gold)(616448)
|
||||
|
||||
ts_end = get_time()
|
||||
|
||||
quick_print(ts_end - ts_start)
|
||||
quick_print(num_items(Items.Gold))
|
||||
27
mappings.py
Normal file
27
mappings.py
Normal file
@ -0,0 +1,27 @@
|
||||
import sunflower
|
||||
import cactus
|
||||
import pumpkin
|
||||
import reusable_maze
|
||||
import poly_hay
|
||||
import poly_wood
|
||||
import poly_carrot
|
||||
|
||||
def get_farm_function(item):
|
||||
if item == Items.Hay:
|
||||
return poly_hay.farm
|
||||
elif item == Items.Wood:
|
||||
return poly_wood.farm
|
||||
elif item == Items.Carrot:
|
||||
return poly_carrot.farm
|
||||
elif item == Items.Pumpkin:
|
||||
return pumpkin.farm
|
||||
elif item == Items.Cactus:
|
||||
return cactus.farm
|
||||
elif item == Items.Power:
|
||||
return sunflower.farm
|
||||
elif item == Items.Gold:
|
||||
def farm_gold(needed):
|
||||
while num_items(Items.Gold) < needed:
|
||||
if not reusable_maze.run(32):
|
||||
print("FAILED!!!")
|
||||
return farm_gold
|
||||
68
maze.py
Normal file
68
maze.py
Normal file
@ -0,0 +1,68 @@
|
||||
import utils
|
||||
|
||||
from maze_common import MOVEMENTS
|
||||
from maze_common import spawn_maze
|
||||
|
||||
def cmp_function(lhs, rhs):
|
||||
treasure_x, treasure_y = measure()
|
||||
|
||||
lhs_heuristic = abs(lhs[0] - treasure_x) + abs(lhs[1] - treasure_y)
|
||||
rhs_heuristic = abs(rhs[0] - treasure_x) + abs(rhs[1] - treasure_y)
|
||||
|
||||
return lhs_heuristic < rhs_heuristic
|
||||
|
||||
def run(size):
|
||||
if (get_world_size() != size):
|
||||
set_world_size(size)
|
||||
|
||||
if not spawn_maze():
|
||||
return False
|
||||
|
||||
stack = []
|
||||
visited = {}
|
||||
|
||||
treasure_found = False
|
||||
|
||||
visited[(get_pos_x(),get_pos_y())] = (get_pos_x(), get_pos_y())
|
||||
|
||||
while not treasure_found:
|
||||
if get_entity_type() == Entities.Treasure:
|
||||
treasure_found = True
|
||||
continue
|
||||
|
||||
x = get_pos_x()
|
||||
y = get_pos_y()
|
||||
|
||||
possible_moves = []
|
||||
|
||||
if (x - 1, y) not in visited and can_move(West):
|
||||
possible_moves.append((x - 1, y))
|
||||
|
||||
if (x + 1, y) not in visited and can_move(East):
|
||||
possible_moves.append((x + 1, y))
|
||||
|
||||
if (x, y - 1) not in visited and can_move(South):
|
||||
possible_moves.append((x, y - 1))
|
||||
|
||||
if (x, y + 1) not in visited and can_move(North):
|
||||
possible_moves.append((x, y + 1))
|
||||
|
||||
if (len(possible_moves) == 0):
|
||||
hx, hy = utils.list_back(stack)
|
||||
stack.pop()
|
||||
|
||||
move(MOVEMENTS[(hx - x, hy - y)])
|
||||
|
||||
continue
|
||||
|
||||
utils.sort(possible_moves, cmp_function)
|
||||
|
||||
(nx, ny) = utils.list_back(possible_moves)
|
||||
|
||||
stack.append((x, y))
|
||||
visited[(nx, ny)] = (x, y)
|
||||
move(MOVEMENTS[(nx - x, ny - y)])
|
||||
|
||||
harvest()
|
||||
|
||||
return True
|
||||
37
maze_common.py
Normal file
37
maze_common.py
Normal file
@ -0,0 +1,37 @@
|
||||
import utils
|
||||
|
||||
MOVEMENTS = {
|
||||
(-1, 0): West,
|
||||
( 1, 0): East,
|
||||
( 0, -1): South,
|
||||
( 0, 1): North
|
||||
}
|
||||
|
||||
DIRECTIONS = {
|
||||
West: (-1, 0),
|
||||
East: ( 1, 0),
|
||||
South: ( 0, -1),
|
||||
North: ( 0, 1)
|
||||
}
|
||||
|
||||
def get_maze_level():
|
||||
return num_unlocked(Unlocks.Mazes) - 1
|
||||
|
||||
def get_substance_needed():
|
||||
return get_world_size() * 2 ** get_maze_level()
|
||||
|
||||
def spawn_maze():
|
||||
substance_required = get_substance_needed()
|
||||
|
||||
if num_items(Items.Weird_Substance) < substance_required:
|
||||
return False
|
||||
|
||||
utils.go_to_00()
|
||||
|
||||
if can_harvest():
|
||||
harvest()
|
||||
|
||||
plant(Entities.Bush)
|
||||
use_item(Items.Weird_Substance, substance_required)
|
||||
return True
|
||||
|
||||
75
poly_carrot.py
Normal file
75
poly_carrot.py
Normal file
@ -0,0 +1,75 @@
|
||||
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)
|
||||
|
||||
if not utils.is_empty():
|
||||
harvest()
|
||||
|
||||
plant(Entities.Carrot)
|
||||
|
||||
while (num_items(Items.Water) > 0 and
|
||||
get_water() < 0.7):
|
||||
use_item(Items.Water)
|
||||
|
||||
def drone_poly(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)
|
||||
|
||||
entity = get_entity_type()
|
||||
|
||||
if entity == Entities.Carrot:
|
||||
companion = get_companion()
|
||||
|
||||
if companion != None:
|
||||
ecom, (ecx, ecy) = companion
|
||||
|
||||
utils.go_to_xy(ecx, ecy)
|
||||
|
||||
if can_harvest():
|
||||
harvest()
|
||||
|
||||
plant(ecom)
|
||||
|
||||
utils.go_to_xy(start_x + x, start_y + y)
|
||||
|
||||
harvest()
|
||||
else:
|
||||
if can_harvest():
|
||||
harvest()
|
||||
|
||||
def farm(needed):
|
||||
if num_items(Items.Carrot) >= needed:
|
||||
return
|
||||
|
||||
cost = get_cost(Entities.Carrot)
|
||||
|
||||
for item in cost:
|
||||
mappings.get_farm_function(item)(needed)
|
||||
|
||||
sunflower.farm(10000)
|
||||
|
||||
set_world_size(max_drones())
|
||||
|
||||
utils.clear_field(True)
|
||||
|
||||
while num_items(Items.Carrot) < needed:
|
||||
if num_items(Items.Power) == 0:
|
||||
return farm(needed)
|
||||
|
||||
def task_plant(id):
|
||||
drone_plant(id, 0, 1, get_world_size())
|
||||
|
||||
def task_companion(id):
|
||||
drone_poly(id, 0, 1, get_world_size())
|
||||
|
||||
utils.parallel_run(get_world_size(), task_plant)
|
||||
utils.parallel_run(get_world_size(), task_companion)
|
||||
|
||||
if __name__ == "__main__":
|
||||
farm(10000000000)
|
||||
62
poly_hay.py
Normal file
62
poly_hay.py
Normal file
@ -0,0 +1,62 @@
|
||||
import utils
|
||||
import sunflower
|
||||
|
||||
def drone_poly(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)
|
||||
|
||||
entity = get_entity_type()
|
||||
|
||||
if entity == Entities.Grass:
|
||||
companion = get_companion()
|
||||
|
||||
if companion != None:
|
||||
ecom, (ecx, ecy) = companion
|
||||
|
||||
utils.go_to_xy(ecx, ecy)
|
||||
|
||||
if can_harvest():
|
||||
harvest()
|
||||
|
||||
if ecom == Entities.Carrot:
|
||||
till()
|
||||
|
||||
plant(ecom)
|
||||
|
||||
utils.go_to_xy(start_x + x, start_y + y)
|
||||
|
||||
harvest()
|
||||
else:
|
||||
if can_harvest():
|
||||
harvest()
|
||||
|
||||
def farm(needed):
|
||||
if num_items(Items.Hay) >= needed:
|
||||
return
|
||||
|
||||
sunflower.farm(10000)
|
||||
|
||||
set_world_size(max_drones())
|
||||
|
||||
utils.clear_field(True)
|
||||
|
||||
while num_items(Items.Hay) < needed:
|
||||
if num_items(Items.Power) == 0:
|
||||
return farm(needed)
|
||||
|
||||
def task_companion(id):
|
||||
drone_poly(id, 0, 1, get_world_size())
|
||||
|
||||
clear()
|
||||
utils.parallel_run(get_world_size(), task_companion)
|
||||
|
||||
if __name__ == "__main__":
|
||||
ts_start = get_time()
|
||||
|
||||
farm(2000000000)
|
||||
|
||||
ts_end = get_time()
|
||||
|
||||
quick_print(ts_end - ts_start)
|
||||
quick_print(num_items(Items.Hay))
|
||||
90
poly_wood.py
Normal file
90
poly_wood.py
Normal file
@ -0,0 +1,90 @@
|
||||
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))
|
||||
46
pumpkin.py
Normal file
46
pumpkin.py
Normal file
@ -0,0 +1,46 @@
|
||||
import utils
|
||||
import mappings
|
||||
import sunflower
|
||||
|
||||
def drone_main(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)
|
||||
|
||||
entity = get_entity_type()
|
||||
|
||||
if entity != Entities.Pumpkin:
|
||||
harvest()
|
||||
plant(Entities.Pumpkin)
|
||||
|
||||
while not can_harvest():
|
||||
entity = get_entity_type()
|
||||
|
||||
if (entity == None or
|
||||
entity == Entities.Dead_Pumpkin):
|
||||
plant(Entities.Pumpkin)
|
||||
|
||||
if (get_water() < 0.75 and
|
||||
num_items(Items.Water) > 0):
|
||||
use_item(Items.Water)
|
||||
|
||||
def farm(needed):
|
||||
if num_items(Items.Pumpkin) >= needed:
|
||||
return
|
||||
|
||||
cost = get_cost(Entities.Pumpkin)
|
||||
|
||||
for item in cost:
|
||||
mappings.get_farm_function(item)((needed * 1.2) // 6)
|
||||
|
||||
def task(id):
|
||||
drone_main(id, 0, 1, get_world_size())
|
||||
|
||||
while num_items(Items.Pumpkin) < needed:
|
||||
if num_items(Items.Power) < 3000:
|
||||
sunflower.farm(3000)
|
||||
set_world_size(max_drones())
|
||||
utils.clear_field(True)
|
||||
utils.parallel_run(max_drones(), task)
|
||||
utils.go_to_00()
|
||||
harvest()
|
||||
217
reusable_maze.py
Normal file
217
reusable_maze.py
Normal file
@ -0,0 +1,217 @@
|
||||
import utils
|
||||
from utils import PQ_PUSH, PQ_POP
|
||||
|
||||
from maze_common import MOVEMENTS, DIRECTIONS
|
||||
from maze_common import get_substance_needed, spawn_maze
|
||||
|
||||
treasure_x = 0
|
||||
treasure_y = 0
|
||||
|
||||
def explore_maze():
|
||||
maze = {}
|
||||
|
||||
stack = []
|
||||
visited = {}
|
||||
|
||||
x = get_pos_x()
|
||||
y = get_pos_y()
|
||||
|
||||
visited[(x, y)] = True
|
||||
|
||||
explored_all = False
|
||||
|
||||
while not explored_all:
|
||||
x = get_pos_x()
|
||||
y = get_pos_y()
|
||||
|
||||
possible_moves = []
|
||||
|
||||
if (x - 1, y) not in visited and can_move(West):
|
||||
possible_moves.append((x - 1, y))
|
||||
|
||||
if (x + 1, y) not in visited and can_move(East):
|
||||
possible_moves.append((x + 1, y))
|
||||
|
||||
if (x, y - 1) not in visited and can_move(South):
|
||||
possible_moves.append((x, y - 1))
|
||||
|
||||
if (x, y + 1) not in visited and can_move(North):
|
||||
possible_moves.append((x, y + 1))
|
||||
|
||||
if (len(possible_moves) == 0):
|
||||
if len(stack) == 0:
|
||||
explored_all = True
|
||||
continue
|
||||
|
||||
hx, hy = utils.list_back(stack)
|
||||
stack.pop()
|
||||
|
||||
move(MOVEMENTS[(hx - x, hy - y)])
|
||||
|
||||
continue
|
||||
|
||||
(nx, ny) = utils.list_back(possible_moves)
|
||||
|
||||
stack.append((x, y))
|
||||
visited[(nx, ny)] = True
|
||||
move(MOVEMENTS[(nx - x, ny - y)])
|
||||
|
||||
if (x, y) not in maze:
|
||||
maze[(x, y)] = {}
|
||||
|
||||
if (nx, ny) not in maze:
|
||||
maze[(nx, ny)] = {}
|
||||
|
||||
maze[(x, y)][(nx, ny)] = True
|
||||
maze[(nx, ny)][(x, y)] = True
|
||||
|
||||
return maze
|
||||
|
||||
def backtrace(parents, start, end):
|
||||
path = [end]
|
||||
|
||||
while utils.list_back(path) != start:
|
||||
path.append(parents[utils.list_back(path)])
|
||||
|
||||
return path
|
||||
|
||||
def bfs(graph, start, end):
|
||||
parents = {}
|
||||
queue = []
|
||||
visited = {}
|
||||
|
||||
queue.append(start)
|
||||
|
||||
while len(queue) > 0:
|
||||
node = queue[0]
|
||||
queue.pop(0)
|
||||
|
||||
if node == end:
|
||||
return backtrace(parents, start, end)
|
||||
|
||||
if node in graph:
|
||||
for adjacent in graph[node]:
|
||||
if adjacent not in visited:
|
||||
visited[adjacent] = True
|
||||
parents[adjacent] = node
|
||||
queue.append(adjacent)
|
||||
|
||||
return []
|
||||
|
||||
def heuristic(node):
|
||||
global treasure_x
|
||||
global treasure_y
|
||||
|
||||
x_heuristic = abs(node[0] - treasure_x)
|
||||
y_heuristic = abs(node[1] - treasure_y)
|
||||
|
||||
return x_heuristic + y_heuristic
|
||||
|
||||
def cmp_function(lhs, rhs):
|
||||
return lhs[0] < rhs[0]
|
||||
|
||||
|
||||
def a_star(graph, start, end):
|
||||
pq = utils.priority_queue(cmp_function)
|
||||
pqlen = 0
|
||||
|
||||
parents = {}
|
||||
costs = {}
|
||||
|
||||
pq[PQ_PUSH]((0, start))
|
||||
pqlen += 1
|
||||
|
||||
parents[start] = start
|
||||
costs[start] = 0
|
||||
|
||||
while pqlen > 0:
|
||||
_, curr = pq[PQ_POP]()
|
||||
pqlen -= 1
|
||||
|
||||
if curr == end:
|
||||
return backtrace(parents, start, end)
|
||||
|
||||
for next in graph[curr]:
|
||||
new_cost = costs[curr] + 1
|
||||
if next not in costs or new_cost < costs[next]:
|
||||
costs[next] = new_cost
|
||||
parents[next] = curr
|
||||
pq[PQ_PUSH]((new_cost + heuristic(next), next))
|
||||
pqlen += 1
|
||||
|
||||
return []
|
||||
|
||||
def main(max_iters):
|
||||
global treasure_x
|
||||
global treasure_y
|
||||
|
||||
utils.go_to_00()
|
||||
|
||||
if not spawn_maze():
|
||||
return False
|
||||
|
||||
maze = explore_maze()
|
||||
|
||||
x = get_pos_x()
|
||||
y = get_pos_y()
|
||||
|
||||
for iter in range(max_iters):
|
||||
treasure_x, treasure_y = measure()
|
||||
|
||||
x = get_pos_x()
|
||||
y = get_pos_y()
|
||||
|
||||
ts_start = get_time()
|
||||
if iter < 120:
|
||||
path = bfs(maze, (x, y), (treasure_x, treasure_y))
|
||||
else:
|
||||
path = a_star(maze, (x, y), (treasure_x, treasure_y))
|
||||
ts_end = get_time()
|
||||
|
||||
quick_print(iter, ts_end - ts_start)
|
||||
|
||||
path.pop()
|
||||
|
||||
def add_if_missing(direction):
|
||||
if iter > 200:
|
||||
return
|
||||
|
||||
if can_move(direction):
|
||||
dx, dy = DIRECTIONS[direction]
|
||||
|
||||
if (x, y) not in maze:
|
||||
maze[(x, y)] = {}
|
||||
|
||||
if (x + dx, y + dy) not in maze:
|
||||
maze[(x + dx, y + dy)] = {}
|
||||
|
||||
maze[(x, y)][(x + dx, y + dy)] = True
|
||||
maze[(x + dx, y + dy)][(x, y)] = True
|
||||
|
||||
for i in range(len(path)):
|
||||
add_if_missing(East)
|
||||
add_if_missing(West)
|
||||
add_if_missing(North)
|
||||
add_if_missing(South)
|
||||
|
||||
nx, ny = path[(i + 1) * -1]
|
||||
move(MOVEMENTS[(nx - x, ny - y)])
|
||||
x = get_pos_x()
|
||||
y = get_pos_y()
|
||||
|
||||
substance_needed = get_substance_needed()
|
||||
|
||||
if num_items(Items.Weird_Substance) < substance_needed:
|
||||
harvest()
|
||||
elif iter == (max_iters - 1):
|
||||
harvest()
|
||||
else:
|
||||
use_item(Items.Weird_Substance, substance_needed)
|
||||
|
||||
return True
|
||||
|
||||
def run(size, iterations = 300):
|
||||
set_world_size(size)
|
||||
if not main(iterations + 1):
|
||||
return False
|
||||
return True
|
||||
44
sunflower.py
Normal file
44
sunflower.py
Normal file
@ -0,0 +1,44 @@
|
||||
import utils
|
||||
|
||||
def drone_main(needed, start_x, start_y, world_size_x, world_size_y):
|
||||
while num_items(Items.Power) < needed:
|
||||
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 utils.is_empty():
|
||||
plant(Entities.Sunflower)
|
||||
else:
|
||||
if can_harvest():
|
||||
harvest()
|
||||
plant(Entities.Sunflower)
|
||||
|
||||
while (num_items(Items.Water) > 0 and
|
||||
get_water() < 0.7):
|
||||
use_item(Items.Water)
|
||||
|
||||
for y in range(world_size_y - 1):
|
||||
for x in range(world_size_x):
|
||||
utils.go_to_xy(start_x + x, start_y + world_size_y - y - 1)
|
||||
if utils.is_empty():
|
||||
plant(Entities.Sunflower)
|
||||
else:
|
||||
if can_harvest():
|
||||
harvest()
|
||||
plant(Entities.Sunflower)
|
||||
|
||||
while (num_items(Items.Water) > 0 and
|
||||
get_water() < 0.7):
|
||||
use_item(Items.Water)
|
||||
|
||||
def farm(needed):
|
||||
if num_items(Items.Power) >= needed:
|
||||
return
|
||||
|
||||
set_world_size(max_drones())
|
||||
|
||||
utils.clear_field(True)
|
||||
|
||||
def task(id):
|
||||
drone_main(needed, id, 0, 1, get_world_size())
|
||||
|
||||
utils.parallel_run(max_drones(), task)
|
||||
71
sunflower_algorithm.py
Normal file
71
sunflower_algorithm.py
Normal file
@ -0,0 +1,71 @@
|
||||
import utils
|
||||
|
||||
def farm(needed):
|
||||
if num_items(Items.Power) >= needed:
|
||||
return
|
||||
|
||||
set_world_size(10)
|
||||
|
||||
utils.clear_field(True)
|
||||
|
||||
sunflowers = []
|
||||
|
||||
for _ in range(9):
|
||||
sunflowers.append([])
|
||||
|
||||
for y in range(get_world_size()):
|
||||
for x in range(get_world_size()):
|
||||
utils.go_to_xy(x, y)
|
||||
plant(Entities.Sunflower)
|
||||
petals = measure()
|
||||
sunflowers[petals - 7].append((x, y))
|
||||
|
||||
while (num_items(Items.Water) > 0 and
|
||||
get_water() < 0.7):
|
||||
use_item(Items.Water)
|
||||
|
||||
while num_items(Items.Power) < needed:
|
||||
for i in range(9):
|
||||
if len(sunflowers[8 - i]) == 0:
|
||||
continue
|
||||
|
||||
it = -1
|
||||
|
||||
while len(sunflowers[8 - i]) > 0:
|
||||
it = (it + 1) % len(sunflowers[8 - i])
|
||||
|
||||
sx, sy = sunflowers[8 - i][it]
|
||||
|
||||
utils.go_to_xy(sx, sy)
|
||||
|
||||
if not can_harvest():
|
||||
if len(sunflowers[8 - i]) == 1:
|
||||
if num_items(Items.Fertilizer) > 0:
|
||||
use_item(Items.Fertilizer)
|
||||
else:
|
||||
while (num_items(Items.Water) > 0 and
|
||||
get_water() < 0.7):
|
||||
use_item(Items.Water)
|
||||
|
||||
while not can_harvest():
|
||||
pass
|
||||
else:
|
||||
continue
|
||||
|
||||
harvest()
|
||||
|
||||
sunflowers[8 - i].pop(it)
|
||||
|
||||
plant(Entities.Sunflower)
|
||||
petals = measure()
|
||||
|
||||
sunflowers[petals - 7].append((sx, sy))
|
||||
|
||||
while (num_items(Items.Water) > 0 and
|
||||
get_water() < 0.7):
|
||||
use_item(Items.Water)
|
||||
|
||||
if (petals - 7) > (8 - i):
|
||||
break
|
||||
|
||||
break
|
||||
206
utils.py
Normal file
206
utils.py
Normal file
@ -0,0 +1,206 @@
|
||||
HATS = [
|
||||
Hats.Brown_Hat,
|
||||
Hats.Cactus_Hat,
|
||||
Hats.Carrot_Hat,
|
||||
Hats.Gold_Hat,
|
||||
# Hats.Gold_Trophy_Hat,
|
||||
Hats.Golden_Cactus_Hat,
|
||||
Hats.Golden_Carrot_Hat,
|
||||
# Hats.Golden_Gold_Hat,
|
||||
# Hats.Golden_Pumpkin_Hat,
|
||||
Hats.Golden_Sunflower_Hat,
|
||||
# Hats.Golden_Tree_Hat,
|
||||
Hats.Gray_Hat,
|
||||
Hats.Green_Hat,
|
||||
Hats.Pumpkin_Hat,
|
||||
Hats.Purple_Hat,
|
||||
# Hats.Silver_Trophy_Hat,
|
||||
Hats.Straw_Hat,
|
||||
Hats.Sunflower_Hat,
|
||||
# Hats.The_Farmers_Remains,
|
||||
Hats.Top_Hat,
|
||||
Hats.Traffic_Cone,
|
||||
# Hats.Traffic_Cone_Stack,
|
||||
Hats.Tree_Hat,
|
||||
Hats.Wizard_Hat,
|
||||
# Hats.Wood_Trophy_Hat
|
||||
]
|
||||
|
||||
def get_cells_count():
|
||||
return get_world_size() * get_world_size()
|
||||
|
||||
def go_to_00():
|
||||
go_to_xy(0, 0)
|
||||
|
||||
def go_to_xy(x, y):
|
||||
dist_east = (x - get_pos_x()) % get_world_size()
|
||||
dist_west = (get_pos_x() - x) % get_world_size()
|
||||
|
||||
if dist_east <= dist_west:
|
||||
for _ in range(dist_east):
|
||||
if not move(East):
|
||||
return False
|
||||
else:
|
||||
for _ in range(dist_west):
|
||||
if not move(West):
|
||||
return False
|
||||
|
||||
dist_north = (y - get_pos_y()) % get_world_size()
|
||||
dist_south = (get_pos_y() - y) % get_world_size()
|
||||
|
||||
if dist_south <= dist_north:
|
||||
for _ in range(dist_south):
|
||||
if not move(South):
|
||||
return False
|
||||
else:
|
||||
for _ in range(dist_north):
|
||||
if not move(North):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def is_empty():
|
||||
return get_entity_type() == None
|
||||
|
||||
def clear_field(tilled = False):
|
||||
go_to_00()
|
||||
|
||||
ground_type = Grounds.Grassland
|
||||
|
||||
if tilled:
|
||||
ground_type = Grounds.Soil
|
||||
|
||||
def clear_column(id):
|
||||
go_to_xy(id, 0)
|
||||
|
||||
for i in range(get_world_size()):
|
||||
entity = get_entity_type()
|
||||
|
||||
if get_entity_type() == Entities.Dead_Pumpkin:
|
||||
harvest()
|
||||
elif entity != None and entity != Entities.Grass:
|
||||
entity = get_entity_type()
|
||||
|
||||
while entity != None and not can_harvest():
|
||||
entity = get_entity_type()
|
||||
|
||||
harvest()
|
||||
|
||||
if get_ground_type() != ground_type:
|
||||
till()
|
||||
|
||||
if (i != get_world_size() - 1):
|
||||
move(North)
|
||||
|
||||
parallel_run(get_world_size(), clear_column)
|
||||
|
||||
def sort(arr, compare_func):
|
||||
def _partition(low, high):
|
||||
i = low - 1
|
||||
pivot = arr[high]
|
||||
|
||||
for j in range(low, high):
|
||||
if compare_func(arr[j], pivot):
|
||||
i += 1
|
||||
arr[i], arr[j] = arr[j], arr[i]
|
||||
|
||||
arr[i + 1], arr[high] = arr[high], arr[i + 1]
|
||||
|
||||
return i + 1
|
||||
|
||||
def _quick_sort(low, high):
|
||||
if low < high:
|
||||
pi = _partition(low, high)
|
||||
|
||||
_quick_sort(low, pi - 1)
|
||||
_quick_sort(pi + 1, high)
|
||||
|
||||
if arr != None and len(arr) > 1:
|
||||
_quick_sort(0, len(arr) - 1)
|
||||
|
||||
def list_back(l):
|
||||
return l[len(l) - 1]
|
||||
|
||||
def parallel_run(ndrones, taskcb, hat = None):
|
||||
drones = []
|
||||
|
||||
go_to_00()
|
||||
|
||||
for i in range(ndrones):
|
||||
def task():
|
||||
if hat:
|
||||
change_hat(hat)
|
||||
else:
|
||||
random_hat = ((random() * (len(HATS) + 1)) // 1) % len(HATS)
|
||||
change_hat(HATS[random_hat])
|
||||
taskcb(i)
|
||||
|
||||
if i == ndrones - 1:
|
||||
task()
|
||||
else:
|
||||
drone = spawn_drone(task)
|
||||
while drone == None:
|
||||
drone = spawn_drone(task)
|
||||
drones.append(drone)
|
||||
|
||||
finished = 0
|
||||
|
||||
while finished != len(drones):
|
||||
finished = 0
|
||||
|
||||
for d in range(len(drones)):
|
||||
if has_finished(drones[d]):
|
||||
finished += 1
|
||||
|
||||
PQ_PUSH = 0
|
||||
PQ_POP = 1
|
||||
|
||||
def priority_queue(comparator):
|
||||
queue = []
|
||||
|
||||
def swap(ia, ib):
|
||||
temp = queue[ia]
|
||||
queue[ia] = queue[ib]
|
||||
queue[ib] = temp
|
||||
|
||||
def parent(i):
|
||||
i = (i - 1) / 2
|
||||
return i - (i // 1)
|
||||
|
||||
def heapify(i = 0):
|
||||
cmp = i
|
||||
l = i * 2 + 1
|
||||
r = l + 1
|
||||
if l < len(queue):
|
||||
if comparator(queue[l], queue[cmp]):
|
||||
cmp = l
|
||||
if r < len(queue) and comparator(queue[r], queue[cmp]):
|
||||
cmp = r
|
||||
if cmp != i:
|
||||
swap(i, cmp)
|
||||
heapify(cmp)
|
||||
|
||||
def yoink():
|
||||
if len(queue) == 0:
|
||||
return None
|
||||
ret = queue[0]
|
||||
swap(0, len(queue) - 1)
|
||||
queue.pop()
|
||||
heapify()
|
||||
return ret
|
||||
|
||||
def insert(elm):
|
||||
i = len(queue)
|
||||
queue.append(elm)
|
||||
while i != 0:
|
||||
p = parent(i)
|
||||
if comparator(queue, queue):
|
||||
swap(i, p)
|
||||
i = p
|
||||
else:
|
||||
break
|
||||
|
||||
return {
|
||||
PQ_POP: yoink,
|
||||
PQ_PUSH: insert
|
||||
}
|
||||
75
wood.py
Normal file
75
wood.py
Normal file
@ -0,0 +1,75 @@
|
||||
import utils
|
||||
import sunflower
|
||||
|
||||
def drone_main(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 utils.is_empty():
|
||||
if (get_pos_y() % 2) == 0:
|
||||
if (get_pos_x() % 2) == 0:
|
||||
plant(Entities.Tree)
|
||||
else:
|
||||
plant(Entities.Bush)
|
||||
else:
|
||||
if (get_pos_x() % 2) == 1:
|
||||
plant(Entities.Tree)
|
||||
else:
|
||||
plant(Entities.Bush)
|
||||
else:
|
||||
if can_harvest():
|
||||
to_plant = get_entity_type()
|
||||
harvest()
|
||||
plant(to_plant)
|
||||
|
||||
while (num_items(Items.Water) > 0 and
|
||||
get_water() < 0.7):
|
||||
use_item(Items.Water)
|
||||
|
||||
for y in range(world_size_y - 1):
|
||||
for x in range(world_size_x):
|
||||
utils.go_to_xy(start_x + x, start_y + world_size_y - y - 1)
|
||||
|
||||
if utils.is_empty():
|
||||
if (get_pos_y() % 2) == 0:
|
||||
if (get_pos_x() % 2) == 0:
|
||||
plant(Entities.Tree)
|
||||
else:
|
||||
plant(Entities.Bush)
|
||||
else:
|
||||
if (get_pos_x() % 2) == 1:
|
||||
plant(Entities.Tree)
|
||||
else:
|
||||
plant(Entities.Bush)
|
||||
else:
|
||||
if can_harvest():
|
||||
to_plant = get_entity_type()
|
||||
harvest()
|
||||
plant(to_plant)
|
||||
|
||||
while (num_items(Items.Water) > 0 and
|
||||
get_water() < 0.7):
|
||||
use_item(Items.Water)
|
||||
|
||||
def farm(needed):
|
||||
if num_items(Items.Wood) >= needed:
|
||||
return
|
||||
|
||||
sunflower.farm(10000)
|
||||
|
||||
set_world_size(max_drones())
|
||||
|
||||
utils.clear_field(True)
|
||||
|
||||
def task(id):
|
||||
drone_main(needed, id, 0, 1, get_world_size())
|
||||
|
||||
utils.parallel_run(max_drones(), task)
|
||||
|
||||
if num_items(Items.Wood) < needed:
|
||||
farm(needed)
|
||||
Loading…
x
Reference in New Issue
Block a user