Chore: checkpoint
This commit is contained in:
1307
__builtins__.py
Normal file
1307
__builtins__.py
Normal file
File diff suppressed because it is too large
Load Diff
103
cactus.py
Normal file
103
cactus.py
Normal file
@@ -0,0 +1,103 @@
|
||||
import utils, solve
|
||||
|
||||
def grow(xl, xr, yl, yr):
|
||||
def init():
|
||||
def fillx(x):
|
||||
def ret():
|
||||
for y in range(yl, yr):
|
||||
utils.mv(x, y)
|
||||
utils.soil()
|
||||
utils.water()
|
||||
utils.replant(Entities.Cactus)
|
||||
return ret
|
||||
|
||||
drowns = list()
|
||||
for x in range(xl+1, xr):
|
||||
drown = None
|
||||
while drown == None:
|
||||
drown = spawn_drone(fillx(x))
|
||||
drowns.append(drown)
|
||||
fillx(xl)()
|
||||
for drown in drowns:
|
||||
wait_for(drown)
|
||||
|
||||
def run():
|
||||
def sortx(x):
|
||||
def ret():
|
||||
l, r = yl, yr-1
|
||||
while l < r:
|
||||
for i in range(l, r):
|
||||
utils.mv(x, i)
|
||||
cur, nxt = utils.meas(), utils.meas(North)
|
||||
if nxt < cur:
|
||||
swap(North)
|
||||
r -= 1
|
||||
for i in range(r, l, -1):
|
||||
utils.mv(x, i)
|
||||
cur, nxt = utils.meas(), utils.meas(South)
|
||||
if nxt > cur:
|
||||
swap(South)
|
||||
l += 1
|
||||
return ret
|
||||
|
||||
drowns = list()
|
||||
for x in range(xl+1, xr):
|
||||
drown = None
|
||||
while drown == None:
|
||||
drown = spawn_drone(sortx(x))
|
||||
drowns.append(drown)
|
||||
sortx(xl)()
|
||||
for drown in drowns:
|
||||
wait_for(drown)
|
||||
|
||||
def sorty(y):
|
||||
def ret():
|
||||
l, r = xl, xr-1
|
||||
while l < r:
|
||||
for i in range(l, r):
|
||||
utils.mv(i, y)
|
||||
cur, nxt = utils.meas(), utils.meas(East)
|
||||
if nxt < cur:
|
||||
swap(East)
|
||||
r -= 1
|
||||
for i in range(r, l, -1):
|
||||
utils.mv(i, y)
|
||||
cur, nxt = utils.meas(), utils.meas(West)
|
||||
if nxt > cur:
|
||||
swap(West)
|
||||
l += 1
|
||||
return ret
|
||||
|
||||
drowns = list()
|
||||
for y in range(yl+1, yr):
|
||||
drown = None
|
||||
while drown == None:
|
||||
drown = spawn_drone(sorty(y))
|
||||
drowns.append(drown)
|
||||
sorty(yl)()
|
||||
for drown in drowns:
|
||||
wait_for(drown)
|
||||
|
||||
utils.harv()
|
||||
|
||||
init()
|
||||
|
||||
return (init, run)
|
||||
|
||||
def check():
|
||||
def init():
|
||||
pass
|
||||
|
||||
def run():
|
||||
if num_items(Items.Cactus) >= 33554432:
|
||||
return True
|
||||
return (init, run)
|
||||
|
||||
if __name__ == '__main__':
|
||||
set_world_size(32)
|
||||
clear()
|
||||
|
||||
solve.run([
|
||||
grow.cactus(0, 32, 0, 32),
|
||||
check(),
|
||||
])()
|
||||
37
farm24.py
Normal file
37
farm24.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import solve, utils
|
||||
import sunflower, mix, pumpkin, cactus, maze
|
||||
|
||||
base24 = [
|
||||
sunflower.growbase(0, 8, 0, 2),
|
||||
sunflower.grow(0, 8, 2, 8),
|
||||
]
|
||||
|
||||
mixs24 = [
|
||||
[mix.grow(0, 4, 8, 16)],
|
||||
[mix.grow(4, 8, 8, 16)],
|
||||
[mix.grow(0, 4, 16, 24)],
|
||||
[mix.grow(4, 8, 16, 24)],
|
||||
|
||||
[pumpkin.grow(8, 16, 8)],
|
||||
[pumpkin.grow(16, 8, 8)],
|
||||
|
||||
[cactus.grow( 8, 16, 8, 16)],
|
||||
[cactus.grow(16, 24, 16, 24)],
|
||||
]
|
||||
|
||||
mazes24 = [
|
||||
[maze.grow( 8, 0, 8)],
|
||||
[maze.grow(16, 0, 8)],
|
||||
]
|
||||
|
||||
def farm24():
|
||||
set_world_size(24)
|
||||
clear()
|
||||
|
||||
for maze in mazes24:
|
||||
utils.spawn(solve.run(maze, 4000))
|
||||
for mix in mixs24:
|
||||
utils.spawn(solve.run(mix))
|
||||
solve.run(base24)()
|
||||
|
||||
farm24()
|
||||
44
farm32.py
Normal file
44
farm32.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import solve, grow, utils
|
||||
|
||||
base32 = [
|
||||
grow.sunflower_base(0, 2, 24, 32),
|
||||
grow.sunflower(2, 8, 24, 32),
|
||||
]
|
||||
|
||||
mixs32 = [
|
||||
[grow.three_mix(0, 4, 0, 8)],
|
||||
[grow.three_mix(4, 8, 0, 8)],
|
||||
[grow.three_mix(0, 4, 8, 16)],
|
||||
[grow.three_mix(4, 8, 8, 16)],
|
||||
[grow.three_mix(0, 4, 16, 24)],
|
||||
[grow.three_mix(4, 8, 16, 24)],
|
||||
|
||||
[grow.pumpkin( 8, 0, 8)],
|
||||
[grow.pumpkin(16, 8, 8)],
|
||||
[grow.pumpkin( 8, 16, 8)],
|
||||
[grow.pumpkin(16, 24, 8)],
|
||||
|
||||
[grow.cactus(16, 24, 0, 8)],
|
||||
[grow.cactus( 8, 16, 8, 16)],
|
||||
[grow.cactus(16, 24, 16, 24)],
|
||||
[grow.cactus( 8, 16, 24, 32)],
|
||||
]
|
||||
|
||||
mazes32 = [
|
||||
[grow.maze(24, 0, 8)],
|
||||
[grow.maze(24, 8, 8)],
|
||||
[grow.maze(24, 16, 8)],
|
||||
[grow.maze(24, 24, 8)],
|
||||
]
|
||||
|
||||
def farm32():
|
||||
set_world_size(32)
|
||||
clear()
|
||||
|
||||
for maze in mazes32:
|
||||
utils.spawn(solve.run(maze, 4000))
|
||||
for mix in mixs32:
|
||||
utils.spawn(solve.run(mix))
|
||||
solve.run(base32)()
|
||||
|
||||
farm32()
|
||||
15
hats.py
Normal file
15
hats.py
Normal file
@@ -0,0 +1,15 @@
|
||||
def poop(hat):
|
||||
def ret():
|
||||
change_hat(hat)
|
||||
while True:
|
||||
do_a_flip()
|
||||
return ret
|
||||
|
||||
spawn_drone(poop(Hats.Gray_hat))
|
||||
spawn_drone(poop(Hats.Purple_hat))
|
||||
spawn_drone(poop(Hats.Green_hat))
|
||||
spawn_drone(poop(Hats.Brown_hat))
|
||||
spawn_drone(poop(Hats.Dinosaur_hat))
|
||||
change_hat(Hats.The_Farmers_Remains)
|
||||
while True:
|
||||
do_a_flip()
|
||||
1
leaderboard.py
Normal file
1
leaderboard.py
Normal file
@@ -0,0 +1 @@
|
||||
leaderboard_run(Leaderboards.Dinosaur, "snake", 10000)
|
||||
54
maze.py
Normal file
54
maze.py
Normal file
@@ -0,0 +1,54 @@
|
||||
import solve, utils
|
||||
import sunflower
|
||||
|
||||
d = [North, West, South, East]
|
||||
def grow(xl, yl, n, repeat=1):
|
||||
cd = 0
|
||||
cnt = 0
|
||||
substance = n * 2**(num_unlocked(Unlocks.Mazes) - 1)
|
||||
|
||||
def init():
|
||||
global cnt
|
||||
|
||||
cnt = 0
|
||||
utils.mv(xl+n/2, yl+n/2)
|
||||
utils.grass()
|
||||
plant(Entities.Bush)
|
||||
|
||||
def run():
|
||||
global cd
|
||||
global cnt
|
||||
|
||||
if cnt == 0:
|
||||
init()
|
||||
use_item(Items.Weird_Substance, substance)
|
||||
|
||||
typ = get_entity_type()
|
||||
while typ != Entities.Treasure:
|
||||
if typ != Entities.Hedge:
|
||||
init()
|
||||
use_item(Items.Weird_Substance, substance)
|
||||
if can_move(d[(cd+1)%4]):
|
||||
cd = (cd+1)%4
|
||||
if move(d[cd]):
|
||||
typ = get_entity_type()
|
||||
continue
|
||||
else:
|
||||
cd = (cd+3)%4
|
||||
|
||||
cnt += 1
|
||||
if cnt >= repeat:
|
||||
harvest()
|
||||
cnt = 0
|
||||
else:
|
||||
use_item(Items.Weird_Substance, substance)
|
||||
|
||||
return (init, run)
|
||||
|
||||
if __name__ == '__main__':
|
||||
set_world_size(32)
|
||||
utils.spawn(solve.run([
|
||||
sunflower.growbase(0, 2, 0, 8),
|
||||
sunflower.grow(2, 8, 0, 8),
|
||||
]))
|
||||
solve.run([grow(0, 0, 32)])()
|
||||
39
mix.py
Normal file
39
mix.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import utils
|
||||
|
||||
def grow(xl, xr, yl, yr):
|
||||
def init():
|
||||
for x in range(xl, xr):
|
||||
l, r, d = yl, yr, 1
|
||||
if x%2 == 1:
|
||||
l, r, d = yr-1, yl-1, -1
|
||||
for y in range(l, r, d):
|
||||
utils.mv(x, y)
|
||||
typ = x%2 + y%2
|
||||
if typ == 0:
|
||||
utils.grass()
|
||||
if typ == 1:
|
||||
utils.grass()
|
||||
if typ == 2:
|
||||
utils.soil()
|
||||
|
||||
def run():
|
||||
for x in range(xl, xr):
|
||||
l, r, d = yl, yr, 1
|
||||
if x%2 == 1:
|
||||
l, r, d = yr-1, yl-1, -1
|
||||
for y in range(l, r, d):
|
||||
utils.mv(x, y)
|
||||
utils.water()
|
||||
utils.harv()
|
||||
typ = x%2 + y%2
|
||||
if typ == 0:
|
||||
pass # weed
|
||||
if typ == 1:
|
||||
if get_entity_type() == Entities.Grass:
|
||||
plant(Entities.Tree)
|
||||
if typ == 2:
|
||||
utils.replant(Entities.Carrot)
|
||||
return (init, run)
|
||||
|
||||
if __name__ == '__main__':
|
||||
pass
|
||||
38
pumpkin.py
Normal file
38
pumpkin.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import utils
|
||||
|
||||
def grow(xl, yl, n):
|
||||
def init():
|
||||
for x in range(xl, xl+n):
|
||||
l, r, d = yl, yl+n, 1
|
||||
if x%2 == 1:
|
||||
l, r, d = yl+n-1, yl-1, -1
|
||||
for y in range(l, r, d):
|
||||
utils.mv(x, y)
|
||||
utils.soil()
|
||||
|
||||
def run():
|
||||
check = list()
|
||||
for x in range(xl, xl+n):
|
||||
l, r, d = yl, yl+n, 1
|
||||
if x%2 == 1:
|
||||
l, r, d = yl+n-1, yl-1, -1
|
||||
for y in range(l, r, d):
|
||||
utils.mv(x, y)
|
||||
utils.water()
|
||||
utils.replant(Entities.Pumpkin)
|
||||
check.append((x, y))
|
||||
|
||||
while len(check):
|
||||
nxt = list()
|
||||
for x, y in check:
|
||||
utils.mv(x, y)
|
||||
if not can_harvest():
|
||||
nxt.append((x, y))
|
||||
if get_entity_type() == Entities.Dead_Pumpkin:
|
||||
plant(Entities.Pumpkin)
|
||||
check = nxt
|
||||
|
||||
utils.mv(xl, yl)
|
||||
utils.harv()
|
||||
|
||||
return (init, run)
|
||||
1
save.json
Normal file
1
save.json
Normal file
@@ -0,0 +1 @@
|
||||
{"items":{"serializeList":[{"name":"hay","nr":732862776.0},{"name":"wood","nr":4085470918.0},{"name":"carrot","nr":1111796064.0},{"name":"pumpkin","nr":109301095.0},{"name":"cactus","nr":371811694.0},{"name":"bone","nr":30887608.0},{"name":"weird_substance","nr":428014.0},{"name":"gold","nr":20484298.0},{"name":"water","nr":1232080.0},{"name":"fertilizer","nr":25358.0}]},"dockedFiles":[{"key":"cactus","value":"maze"},{"key":"farm24","value":"farm32"},{"key":"hats","value":"utils"},{"key":"leaderboard","value":"farm24"},{"key":"maze","value":"snake"},{"key":"pumpkin","value":"mix"},{"key":"sunflower","value":"pumpkin"},{"key":"utils","value":"solve"}],"minimizedFiles":["farm24","farm32","leaderboard"],"openFilePositions":[{"key":"cactus","value":{"x":825.1744995117188,"y":158.076904296875}},{"key":"farm24","value":{"x":825.1744995117188,"y":158.076904296875}},{"key":"farm32","value":{"x":-634.2324829101563,"y":2230.040283203125}},{"key":"hats","value":{"x":825.1744995117188,"y":158.076904296875}},{"key":"leaderboard","value":{"x":825.1744995117188,"y":158.076904296875}},{"key":"maze","value":{"x":825.1744995117188,"y":158.076904296875}},{"key":"mix","value":{"x":-1656.432861328125,"y":1936.912841796875}},{"key":"pumpkin","value":{"x":825.1744995117188,"y":158.076904296875}},{"key":"snake","value":{"x":-693.8130493164063,"y":1927.7490234375}},{"key":"solve","value":{"x":-2349.65087890625,"y":2051.2119140625}},{"key":"sunflower","value":{"x":825.1744995117188,"y":158.076904296875}},{"key":"utils","value":{"x":825.1744995117188,"y":158.076904296875}}],"openFileScrollPositions":[{"key":"cactus","value":1007.769775390625},{"key":"farm24","value":450.0},{"key":"farm32","value":149.98077392578126},{"key":"hats","value":0.0},{"key":"leaderboard","value":0.0},{"key":"maze","value":299.99945068359377},{"key":"mix","value":0.0},{"key":"pumpkin","value":-0.0008544921875},{"key":"snake","value":2418.223388671875},{"key":"solve","value":0.00030517578125},{"key":"sunflower","value":0.0},{"key":"utils","value":599.9998779296875}],"openFileSizes":[{"key":"cactus","value":{"x":0.0,"y":0.0}},{"key":"farm24","value":{"x":0.0,"y":0.0}},{"key":"farm32","value":{"x":0.0,"y":0.0}},{"key":"hats","value":{"x":0.0,"y":0.0}},{"key":"leaderboard","value":{"x":0.0,"y":0.0}},{"key":"maze","value":{"x":0.0,"y":0.0}},{"key":"mix","value":{"x":0.0,"y":0.0}},{"key":"pumpkin","value":{"x":0.0,"y":0.0}},{"key":"snake","value":{"x":0.0,"y":0.0}},{"key":"solve","value":{"x":0.0,"y":0.0}},{"key":"sunflower","value":{"x":0.0,"y":0.0}},{"key":"utils","value":{"x":0.0,"y":0.0}}],"openDocPages":[],"unlocks":["grass_10","soil","harvest","pass","do_a_flip","pet_the_piggy","grassland","hay","straw_hat","while","true","false","break","continue","loops","speed_5","can_harvest","if","else","elif","expand_9","move","north","south","east","west","for","range","get_world_size","wood","bush","entities","clear","plant","change_hat","gray_hat","purple_hat","green_hat","brown_hat","hats","traffic_cone","and","or","not","operators","carrots_10","carrot","till","can_trade","trade","items","carrot_seed","get_entity_type","get_ground_type","grounds","get_pos_x","get_pos_y","none","num_items","num_unlocked","senses","watering_9","water","use_item","get_water","trees_10","tree","tree_hat","sunflower_seed","sunflower","power","get_active_power","measure","sunflowers","pumpkins_10","pumpkin","pumpkin_seed","dead_pumpkin","carrot_hat","variables","functions","def","return","global","from","import","fertilizer_4","weird_substance","append","remove","pop","insert","len","list","lists","traffic_cone_stack","print","quick_print","unlocks","str","debug","pumpkin_hat","sunflower_hat","swap","cactus_seed","cactus_6","get_companion","polyculture_5","hedge","treasure","gold","can_move","mazes_6","dicts","sets","add","dict","set","dictionaries","get_cost","costs","min","max","abs","random","utilities","get_time","get_tick_count","timing","unlock","auto_unlock","wizard_hat","cactus_hat","gold_hat","megafarm_5","get_drone_id","num_drones","max_drones","wait_for","spawn_drone","has_finished","dinosaurs_6","dinosaur","egg","bone","dinosaur_hat","apple","set_execution_speed","set_world_size","debug_2","simulate","simulation","leaderboard_run","leaderboards","leaderboard","golden_cactus_hat","the_farmers_remains"],"version":3}
|
||||
135
snake.py
Normal file
135
snake.py
Normal file
@@ -0,0 +1,135 @@
|
||||
import solve, utils
|
||||
|
||||
def grow():
|
||||
N = get_world_size()
|
||||
apple = None
|
||||
path = 0
|
||||
length = 0
|
||||
|
||||
def mv(x, y, d, irq=False):
|
||||
global apple
|
||||
global path
|
||||
global length
|
||||
|
||||
move(d)
|
||||
path += 1
|
||||
if (x, y) == apple:
|
||||
apple = measure()
|
||||
length += 1
|
||||
return irq and path >= length
|
||||
|
||||
def goto(tx, ty, irq=False):
|
||||
if irq and path >= length:
|
||||
return
|
||||
|
||||
x, y = get_pos_x(), get_pos_y()
|
||||
|
||||
for i in range(max(0, tx-x)):
|
||||
x += 1
|
||||
if mv(x, y, East, irq):
|
||||
return
|
||||
for i in range(max(0, x-tx)):
|
||||
x -= 1
|
||||
if mv(x, y, West, irq):
|
||||
return
|
||||
|
||||
for i in range(max(0, ty-y)):
|
||||
y += 1
|
||||
if mv(x, y, North, irq):
|
||||
return
|
||||
for i in range(max(0, y-ty)):
|
||||
y -= 1
|
||||
if mv(x, y, South, irq):
|
||||
return
|
||||
|
||||
|
||||
def init():
|
||||
global apple
|
||||
global length
|
||||
|
||||
change_hat(Hats.Gray_Hat)
|
||||
utils.mv(0, 0)
|
||||
change_hat(Hats.Dinosaur_Hat)
|
||||
|
||||
apple = measure()
|
||||
path = 0
|
||||
length = 1
|
||||
|
||||
def run():
|
||||
global apple
|
||||
global path
|
||||
|
||||
if apple == None or length == N*N:
|
||||
init()
|
||||
return
|
||||
|
||||
path = 0
|
||||
for x in range(N):
|
||||
if x%2 == 0:
|
||||
goto(x, 1, True)
|
||||
goto(x, N-1, True)
|
||||
else:
|
||||
goto(x, N-1, True)
|
||||
goto(x, 1, True)
|
||||
|
||||
x, y = apple
|
||||
if within((x, y), (0, N-1, 1, N)):
|
||||
goto(x, y)
|
||||
|
||||
goto(N-1, 1)
|
||||
goto(N-1, 0)
|
||||
goto(0, 0)
|
||||
|
||||
x, y = apple
|
||||
|
||||
return (init, run)
|
||||
|
||||
def growlong():
|
||||
N = get_world_size()
|
||||
|
||||
def init():
|
||||
change_hat(Hats.Gray_Hat)
|
||||
utils.mv(0, 0)
|
||||
change_hat(Hats.Dinosaur_Hat)
|
||||
|
||||
def run():
|
||||
for i in range(N):
|
||||
if i%2 == 0:
|
||||
if not utils.mv(i, 1):
|
||||
init()
|
||||
return
|
||||
if not utils.mv(i, N-1):
|
||||
init()
|
||||
return
|
||||
else:
|
||||
if not utils.mv(i, N-1):
|
||||
init()
|
||||
return
|
||||
if not utils.mv(i, 1):
|
||||
init()
|
||||
return
|
||||
if not utils.mv(N-1, 0):
|
||||
init()
|
||||
return
|
||||
if not utils.mv(0, 0):
|
||||
init()
|
||||
return
|
||||
|
||||
return (init, run)
|
||||
|
||||
def check():
|
||||
def init():
|
||||
pass
|
||||
|
||||
def run():
|
||||
if num_items(Items.Bone) >= 33488928:
|
||||
return True
|
||||
|
||||
return (init, run)
|
||||
|
||||
if __name__ == '__main__':
|
||||
set_world_size(2)
|
||||
solve.run([
|
||||
growlong(),
|
||||
# check(),
|
||||
])()
|
||||
16
solve.py
Normal file
16
solve.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import utils
|
||||
|
||||
def run(ops, delay=0):
|
||||
def ret():
|
||||
for init, run in ops:
|
||||
init()
|
||||
|
||||
begin = get_tick_count()
|
||||
while get_tick_count()-begin < delay:
|
||||
do_a_flip()
|
||||
|
||||
while True:
|
||||
for init, run in ops:
|
||||
if run():
|
||||
return
|
||||
return ret
|
||||
133
sunflower.py
Normal file
133
sunflower.py
Normal file
@@ -0,0 +1,133 @@
|
||||
import utils, solve
|
||||
|
||||
def growbase(xl, xr, yl, yr):
|
||||
def init():
|
||||
utils.mv(xl, yl)
|
||||
def fillx(x):
|
||||
def ret():
|
||||
for y in range(yl, yr):
|
||||
utils.mv(x, y)
|
||||
utils.soil()
|
||||
utils.replant(Entities.Sunflower)
|
||||
while utils.meas() != 7:
|
||||
harvest()
|
||||
plant(Entities.Sunflower)
|
||||
return ret
|
||||
|
||||
drowns = list()
|
||||
for x in range(xl+1, xr):
|
||||
drown = None
|
||||
while drown == None:
|
||||
drown = spawn_drone(fillx(x))
|
||||
drowns.append(drown)
|
||||
fillx(xl)()
|
||||
for drown in drowns:
|
||||
wait_for(drown)
|
||||
|
||||
def run():
|
||||
pass
|
||||
|
||||
return (init, run)
|
||||
|
||||
|
||||
def grow(xl, xr, yl, yr):
|
||||
def init():
|
||||
utils.mv(xl, yl)
|
||||
def fillx(x):
|
||||
def ret():
|
||||
for y in range(yl, yr):
|
||||
utils.mv(x, y)
|
||||
utils.water()
|
||||
utils.soil()
|
||||
utils.replant(Entities.Sunflower)
|
||||
return ret
|
||||
|
||||
drowns = list()
|
||||
for x in range(xl+1, xr):
|
||||
drown = None
|
||||
while drown == None:
|
||||
drown = spawn_drone(fillx(x))
|
||||
drowns.append(drown)
|
||||
fillx(xl)()
|
||||
for drown in drowns:
|
||||
wait_for(drown)
|
||||
|
||||
def run():
|
||||
pos = list()
|
||||
for i in range(7, 15+1):
|
||||
pos.append(list())
|
||||
|
||||
for x in range(xl, xr):
|
||||
l, r, d = yl, yr, 1
|
||||
if x%2 == 1:
|
||||
l, r, d = yr-1, yl-1, -1
|
||||
for y in range(l, r, d):
|
||||
utils.mv(x, y)
|
||||
cur = measure()-7
|
||||
pos[cur].append((x, y))
|
||||
|
||||
for p in pos:
|
||||
for x, y in p:
|
||||
utils.mv(x, y)
|
||||
while not utils.harv():
|
||||
pass
|
||||
|
||||
init()
|
||||
|
||||
return (init, run)
|
||||
|
||||
def growparallel(xl, xr, yl, yr):
|
||||
def init():
|
||||
utils.mv(xl, yl)
|
||||
def fillx(x):
|
||||
def ret():
|
||||
for y in range(yl, yr):
|
||||
utils.mv(x, y)
|
||||
utils.water()
|
||||
utils.soil()
|
||||
utils.replant(Entities.Sunflower)
|
||||
return ret
|
||||
|
||||
drowns = list()
|
||||
for x in range(xl+1, xr):
|
||||
drown = None
|
||||
while drown == None:
|
||||
drown = spawn_drone(fillx(x))
|
||||
drowns.append(drown)
|
||||
fillx(xl)()
|
||||
for drown in drowns:
|
||||
wait_for(drown)
|
||||
|
||||
def run():
|
||||
def harvx(k, x):
|
||||
def ret():
|
||||
for y in range(yl, yr):
|
||||
utils.mv(x, y)
|
||||
if measure() == k:
|
||||
while not utils.harv():
|
||||
pass
|
||||
return ret
|
||||
|
||||
for k in range(15, 6, -1):
|
||||
drowns = list()
|
||||
for x in range(xl+1, xr):
|
||||
drown = None
|
||||
while drown == None:
|
||||
drown = spawn_drone(harvx(k, x))
|
||||
drowns.append(drown)
|
||||
harvx(k, xl)()
|
||||
for drown in drowns:
|
||||
wait_for(drown)
|
||||
|
||||
init()
|
||||
|
||||
return (init, run)
|
||||
|
||||
if __name__ == '__main__':
|
||||
set_world_size(8)
|
||||
clear()
|
||||
|
||||
solve.run([
|
||||
growbase(0, 8, 0, 2),
|
||||
grow(0, 8, 2, 8),
|
||||
])()
|
||||
91
utils.py
Normal file
91
utils.py
Normal file
@@ -0,0 +1,91 @@
|
||||
N = get_world_size()
|
||||
|
||||
def within(p, r):
|
||||
return (
|
||||
r[0] <= p[0] and
|
||||
p[0] < r[1] and
|
||||
r[2] <= p[1] and
|
||||
p[1] < r[3]
|
||||
)
|
||||
|
||||
def mv(tx, ty, wrap=False):
|
||||
x = get_pos_x()
|
||||
if wrap:
|
||||
east_step = (tx + N - x) % N
|
||||
west_step = (x + N - tx) % N
|
||||
|
||||
if east_step < west_step:
|
||||
for i in range(east_step):
|
||||
if not move(East):
|
||||
return False
|
||||
else:
|
||||
for i in range(west_step):
|
||||
if not move(West):
|
||||
return False
|
||||
else:
|
||||
for i in range(max(0, tx-x)):
|
||||
if not move(East):
|
||||
return False
|
||||
for i in range(max(0, x-tx)):
|
||||
if not move(West):
|
||||
return False
|
||||
|
||||
y = get_pos_y()
|
||||
|
||||
if wrap:
|
||||
north_step = (ty + N - y) % N
|
||||
south_step = (y + N - ty) % N
|
||||
|
||||
if north_step < south_step:
|
||||
for i in range(north_step):
|
||||
if not move(North):
|
||||
return False
|
||||
else:
|
||||
for i in range(south_step):
|
||||
if not move(South):
|
||||
return False
|
||||
else:
|
||||
for i in range(max(0, ty-y)):
|
||||
if not move(North):
|
||||
return False
|
||||
for i in range(max(0, y-ty)):
|
||||
if not move(South):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def water():
|
||||
if get_water() < 0.5:
|
||||
use_item(Items.Water)
|
||||
|
||||
def grass():
|
||||
typ = get_ground_type()
|
||||
if typ != Grounds.Grassland:
|
||||
till()
|
||||
|
||||
def soil():
|
||||
typ = get_ground_type()
|
||||
if typ != Grounds.Soil:
|
||||
till()
|
||||
|
||||
def harv():
|
||||
if can_harvest():
|
||||
harvest()
|
||||
return True
|
||||
return False
|
||||
|
||||
def replant(entity):
|
||||
typ = get_entity_type()
|
||||
if typ != entity:
|
||||
harvest()
|
||||
plant(entity)
|
||||
|
||||
def spawn(func, x=0, y=0):
|
||||
mv(x, y)
|
||||
spawn_drone(func)
|
||||
|
||||
def meas(arg=None):
|
||||
ret = None
|
||||
while ret == None:
|
||||
ret = measure(arg)
|
||||
return ret
|
||||
Reference in New Issue
Block a user