编程农场向日葵代码 — 先找最高瓣,再刷 Power

按 1.0+ 重写。向日葵产 Power。只有田间至少 10 朵、且你收的是当前瓣数最高的那朵,才有 8× 奖励。收错一朵,这一次和下一次都会丢奖励。

1.0+ 向日葵规则

  • 种在耕过的土上。种植消耗胡萝卜。
  • `measure()` 返回瓣数 **7–15**(未完全成熟也能量)。
  • 田间 **≥10** 朵时收最高瓣 → **8×** Power。收错 → 这次**和**下次都没加成。
  • **不要**用普通循环把成熟花一收而光——这是最常见的复制粘贴错误。

单机:种满,再只收当前最高瓣

python
def go_to(x, y):
	while get_pos_x() != x:
		if get_pos_x() < x:
			move(East)
		else:
			move(West)
	while get_pos_y() != y:
		if get_pos_y() < y:
			move(North)
		else:
			move(South)

def plant_field():
	size = get_world_size()
	for y in range(size):
		for x in range(size):
			go_to(x, y)
			if get_ground_type() != Grounds.Soil:
				till()
			if can_harvest():
				harvest()
			if get_entity_type() != Entities.Sunflower:
				plant(Entities.Sunflower)
			if get_water() < 0.75:
				use_item(Items.Water)

def harvest_current_max():
	size = get_world_size()
	best = 0
	bx = -1
	by = -1
	found = False
	for y in range(size):
		for x in range(size):
			go_to(x, y)
			if get_entity_type() == Entities.Sunflower and can_harvest():
				petals = measure()
				if (not found) or petals > best:
					best = petals
					bx = x
					by = y
					found = True
	if not found:
		return False
	go_to(bx, by)
	harvest()
	return True

clear()
while True:
	plant_field()
	# Keep harvesting the current max until the field is empty
	while harvest_current_max():
		pass

多无人机做法(Reddit 2026-09)

  • **无共享内存。** 子无人机不共享全局。每架机返回瓣数列表,主无人机用 `wait_for(handle)` 收集。
  • **按瓣数分层同步:** 每列一架机;只收 15 瓣 → `wait_for` 全部完成 → 再收 14 → 13… 直到清空。
  • **全 15 瓣套路:** 种下后 `measure()`,不足 15 就收掉重种,直到整田都是 15,再当最高瓣收。刷 Power 快,跳过排序。