南瓜
clear()
set_execution_speed(8)
set_world_size(6)
while True:
all_ready = True
for x in range(get_world_size()):
for y in range(get_world_size()):
#书写的代码
if get_ground_type() != Grounds.Soil:
till()
plant(Entities.Pumpkin)
if get_entity_type() == None or not can_harvest():
plant(Entities.Pumpkin)
all_ready = False
move(North)
move(East)
# 如果全熟了,去 0,0 位置收割巨型南瓜
if all_ready:
harvest()
向日葵
clear()
set_execution_speed(8)
set_world_size(9)
while True:
for x in range(get_world_size()):
for y in range(get_world_size()):
if get_ground_type() != Grounds.Soil:
till()
plant(Entities.Sunflower)
move(North)
move(East)
power = 15
for i in range(9):
for x in range(get_world_size()):
for y in range(get_world_size()):
if measure() == power:
harvest()
print(power)
move(North)
move(East)
power = power - 1
工具
def move_to(target_x, target_y):
while get_pos_x() < target_x:
move(East)
while get_pos_x() > target_x:
move(West)
while get_pos_y() < target_y:
move(North)
while get_pos_y() > target_y:
move(South)
def auto_till():
if get_ground_type() == Grounds.Grassland:
till()
def prepare_all_soil():
size = get_world_size()
for i in range(size):
for j in range(size):
# 继续使用你高效的 S 形走位
if i % 2 == 0:
y = j
else:
y = size - 1 - j
move_to(i, y)
# 如果上面有杂草或灌木,先顺手收割掉清理场地
if can_harvest():
harvest()
# 调用我们刚写的翻土函数
auto_till()
def auto_water():
#智能浇水逻辑:保持地块湿润以获得5倍加速
# 只有当有水罐 且 水位低于 0.75 时才使用
if num_items(Items.Water) > 0:
if get_water() < 0.75:
use_item(Items.Water)
def sway():
size = get_world_size()
for i in range(size):
for j in range(size):
# 继续使用你高效的 S 形走位
if i % 2 == 0:
y = j
else:
y = size - 1 - j
move_to(i, y)
混合种植
import tool
set_execution_speed(8)
set_world_size(9)
tool.prepare_all_soil()
size = get_world_size()
while True:
for x in range(size):
for y in range(size):
if get_entity_type() == None:
plant(Entities.Grass)
companion_data = get_companion()
if companion_data != None:
p_type, (t_x, t_y) = companion_data
tool.move_to(t_x, t_y)
plant(p_type)
tool.move_to(x, y)
tool.auto_water()
if can_harvest():
harvest()
仙人掌
set_execution_speed(10)
set_world_size(9)
import tool
def plant_all_cactus():
for x in range(get_world_size()):
for y in range(get_world_size()):
tool.move_to(x, y)
if get_ground_type() != Grounds.Soil:
till()
plant(Entities.Cactus)
def have_sorted():
is_sorted = False
while not is_sorted:
is_sorted = True
for x in range(get_world_size()):
for y in range(get_world_size()):
tool.move_to(x, y)
# 获取当前仙人掌的大小
current_size = measure()
# 1. 与右侧 (East) 的仙人掌比较
# 如果当前比右侧大,则交换它们,让大的向右移
if x < get_world_size() - 1:
east_size = measure(East)
if east_size != None and current_size > east_size:
swap(East)
is_sorted = False
# 2. 与上方 (North) 的仙人掌比较
# 如果当前比上方大,则交换它们,让大的向上移
if y < get_world_size() - 1:
north_size = measure(North)
if north_size != None and current_size > north_size:
swap(North)
is_sorted = False
while True:
plant_all_cactus()
have_sorted()
tool.move_to(0,0)
harvest()
走迷宫
def solve_maze():
plant(Entities.Bush)
substance = get_world_size() * 2**(num_unlocked(Unlocks.Mazes) - 1)
use_item(Items.Weird_Substance, substance)
# ================= 2. 右手法则寻路 =================
dirs = [North, East, South, West]
current_dir_idx = 0 # 初始面向 North
# 只要脚下不是宝藏,就一直找
while get_entity_type() != Entities.Treasure:
# 计算各个方向在列表中的索引 (% 4 确保索引在 0-3 之间循环)
right_idx = (current_dir_idx + 1) % 4
left_idx = (current_dir_idx - 1) % 4
back_idx = (current_dir_idx + 2) % 4
# 优先级 1:尝试向右走
if move(dirs[right_idx]):
current_dir_idx = right_idx # 成功向右,更新当前朝向
# 优先级 2:右边有墙,尝试直走
elif move(dirs[current_dir_idx]):
pass # 方向不变
# 优先级 3:右边和前面都有墙,尝试向左走
elif move(dirs[left_idx]):
current_dir_idx = left_idx
# 优先级 4:进了死胡同,掉头向后走
else:
move(dirs[back_idx])
current_dir_idx = back_idx
# ================= 3. 拿到宝藏! =================
harvest()
# 开始寻宝
while True:
solve_maze()
贪吃蛇
set_execution_speed(10)
set_world_size(6)
clear()
change_hat(Hats.Dinosaur_Hat)
# 核心循环:无脑跑圈 (哈密顿路径思想)
def move_next_step():
x = get_pos_x()
y = get_pos_y()
n = get_world_size() # 获取地图大小,通常是 10
# 1. 底部“返程高速公路” (y == 0)
if y == 0:
if x == 0:
move(North) # 回到起点后,开始新一轮的北上
else:
move(West) # 沿着底部一路向西返回
# 2. 最左侧“首发公路” (x == 0)
elif x == 0:
if y < n - 1:
move(North) # 一路向北
else:
move(East) # 到达左上角,准备进入 S 型扫荡区
# 3. 奇数列向下扫荡 (x = 1, 3, 5, 7, 9)
elif x % 2 == 1:
if y > 1:
move(South) # 向下走
elif y == 1:
# 如果是最后一列(x=9),直接走到最底下的返程公路
if x == n - 1:
move(South)
else:
move(East) # 切换到下一个偶数列
# 4. 偶数列向上扫荡 (x = 2, 4, 6, 8)
elif x % 2 == 0:
if y < n - 1:
move(North) # 向上走
elif y == n - 1:
move(East) # 到达顶部,切换到下一个奇数列
while True:
start_x, start_y = get_pos_x(), get_pos_y()
move_next_step()
if start_x == get_pos_x() and start_y == get_pos_y():
break