The Farmer Was Replaced

The Farmer Was Replaced

About Using Multiple Drones
I’m new to Python and I love this game. But I’m confused about how to use multiple drones in it.
The game just shows examples like this directly:
def drone_function():
move(North)
do_a_flip()
spawn_drone(drone_function)
But if I define a function like this—
def harvest_sunflower(pos): # Harvest sunflower at position pos
x, y = pos
—when I try to use a drone to run this function, I can only write spawn_drone(harvest_sunflower). This way, I can’t pass the pos data to the function. As a result, I can’t use multiple drones to harvest together. I want to ask all the experts: how can I solve this problem?
Additionally, I’ve attached my code and my thought process below. My idea is to first plant my entire field with sunflowers, then use the measure() function to get the positions of sunflowers with values like 7, 8, 9, 10, etc., and store these positions in lists. Finally, I want to use multiple drones to uniformly harvest the sunflowers with the largest leaf count based on these collections.
Here’s my problematic code:
import y_fx

def harvest_sunflower(x, y): # Harvest sunflower at (x, y)
y_fx.move_n_n(x, y)
if can_harvest():
harvest()

def sunflower_plant():
for i in range(get_world_size()):
for j in range(get_world_size() - 1):
if i % 2 == 0:
if get_ground_type() == Grounds.Grassland:
till()
plant(Entities.Sunflower)
move(North)
else:
if get_ground_type() == Grounds.Grassland:
till()
plant(Entities.Sunflower)
move(South)
if get_ground_type() == Grounds.Grassland:
till()
plant(Entities.Sunflower)
move(East)

def sunflower_cheak(): # Note: "cheak" should be "check" (spelling error)
for i in range(get_world_size()):
for j in range(get_world_size() - 1):
if i % 2 == 0:
if measure() == 7:
list7.append() # Error: No value passed to append()
move(North)
else:
move(South)
move(East)

def main():
while True:
spawn_drone(sunflower_plant)
drone1 = spawn_drone(sunflower_plant)
wait_for(drone) # Error: "drone" is not defined (should be "drone1")
list7 = []
count_7 = 0
list8 = []
count_8 = 0
list9 = []
count_9 = 0
list10 = []
count_10 = 0
list11 = []
count_11 = 0
list12 = []
count_12 = 0
list13 = []
count_13 = 0
list14 = []
count_14 = 0
list15 = []
count_15 = 0

for i in range(get_world_size()):
for j in range(get_world_size() - 1):
if i % 2 == 0:
if measure() == 7:
count_7 += 1
x = get_pos_x()
y = get_pos_y()
list7.append((x, y))
if measure() == 8:
count_8 += 1
x = get_pos_x()
y = get_pos_y()
list8.append((x, y))
if measure() == 9:
count_9 += 1
x = get_pos_x()
y = get_pos_y()
list9.append((x, y))
if measure() == 10:
count_10 += 1
x = get_pos_x()
y = get_pos_y()
list10.append((x, y))
if measure() == 11:
count_11 += 1
x = get_pos_x()
y = get_pos_y()
list11.append((x, y))
if measure() == 12:
count_12 += 1
x = get_pos_x()
y = get_pos_y()
list12.append((x, y))
if measure() == 13:
count_13 += 1
x = get_pos_x()
y = get_pos_y()
list13.append((x, y))
if measure() == 14:
count_14 += 1
x = get_pos_x()
y = get_pos_y()
list14.append((x, y))
if measure() == 15:
count_15 += 1
x = get_pos_x()
y = get_pos_y()
list15.append((x, y))
move(North)
else:
if measure() == 7:
count_7 += 1
x = get_pos_x()
y = get_pos_y()
list7.append((x, y))
if measure() == 8:
count_8 += 1
x = get_pos_x()
y = get_pos_y()
list8.append((x, y))
if measure() == 9:
count_9 += 1
x = get_pos_x()
y = get_pos_y()
list9.append((x, y))
if measure() == 10:
count_10 += 1
x = get_pos_x()
y = get_pos_y()
list10.append((x, y))
if measure() == 11:
count_11 += 1
x = get_pos_x()
y = get_pos_y()
list11.append((x, y))
if measure() == 12:
count_12 += 1
x = get_pos_x()
y = get_pos_y()
list12.append((x, y))
if measure() == 13:
count_13 += 1
x = get_pos_x()
y = get_pos_y()
list13.append((x, y))
if measure() == 14:
count_14 += 1
x = get_pos_x()
y = get_pos_y()
list14.append((x, y))
if measure() == 15:
count_15 += 1
x = get_pos_x()
y = get_pos_y()
list15.append((x, y))
move(South)
move(East)

for i in range(count_7):
spawn_drone(harvest_sunflower(list7)) # Error: Passes entire list instead of a tuple
spawn_drone(harvest_sunflower(list7[i+1])) # Risk of index out of range
spawn_drone(harvest_sunflower(list7[i+2])) # Risk of index out of range
spawn_drone(harvest_sunflower(list7[i+3])) # Risk of index out of range
if i + 4 == count_7:
break

if __name__ == "__main__":
main()
Please go easy on me with the criticism :steamsad::steamsalty::steamsad:
< >
Showing 1-4 of 4 comments
first of all use 'code' and '/code' for code section , so your code becomes readable :BMW_GLASSESPUSH:
and what you need is to define one function inside other f.e.
def dron_work_on_pos(x,y): def inner_func(): move_to(x,y) do_some_work() return inner_func spawn_drone(dron_work_on_pos(x,y))
since 'inner_func' take no arguments we are fine, and to crate it we use other functions, it cooulkd be easirer, if we could use * and ** inside the game (but we cant).
as workaround you could use smt like this, pass to it name of function to execute and list of it's arguments and unpack arguments from list inside "func"
#common def some_work(x,y , entitity): move_to(x,y) plant(entitity) #for dron to use same wrapper to diffenrent funcs def some_work_for_drones(args): x, y, entitity = args move_to(x,y) plant(entitity) check_water() def other_work_for_drones(args): x, y= args move_to(x,y) do_a_flip() #wrapper for create funcs without args def wrap_func_for_drone(func, arguments) def inner(): func(arguments) return inner spawn_dron(wrap_func_for_drone(some_work_for_drones, [1,2, Tree])) spawn_dron(wrap_func_for_drone(other_work_for_drones, [1,2]))
Originally posted by LLIaMaHa:
first of all use 'code' and '/code' for code section , so your code becomes readable :BMW_GLASSESPUSH:
and what you need is to define one function inside other f.e.
def dron_work_on_pos(x,y): def inner_func(): move_to(x,y) do_some_work() return inner_func spawn_drone(dron_work_on_pos(x,y))
since 'inner_func' take no arguments we are fine, and to crate it we use other functions, it cooulkd be easirer, if we could use * and ** inside the game (but we cant).
as workaround you could use smt like this, pass to it name of function to execute and list of it's arguments and unpack arguments from list inside "func"
#common def some_work(x,y , entitity): move_to(x,y) plant(entitity) #for dron to use same wrapper to diffenrent funcs def some_work_for_drones(args): x, y, entitity = args move_to(x,y) plant(entitity) check_water() def other_work_for_drones(args): x, y= args move_to(x,y) do_a_flip() #wrapper for create funcs without args def wrap_func_for_drone(func, arguments) def inner(): func(arguments) return inner spawn_dron(wrap_func_for_drone(some_work_for_drones, [1,2, Tree])) spawn_dron(wrap_func_for_drone(other_work_for_drones, [1,2]))
A huge thank-you to all the masters in the community for stepping in and solving the tough code problems I was stuck on.
Originally posted by Klauß 🍔🍻:
You need a wrapper function to give drones vars/args.

global x global y global arg clear() def Drone(a, b, c): #--- Receive x,y,arg as a,b,c while get_pos_x() != a: move(East) while get_pos_y() != b: move(North) harvest() plant(c) while True: do_a_flip() return def Wrapper(): #--- run Drone() with x,y,arg Drone( x, y, arg ) return while True: do_a_flip() x = random()*10//1 y = random()*10//1 arg = Entities.Bush #--- Spawn Drone & give random x,y spawn_drone(Wrapper)
I can’t express enough gratitude to the community’s experts—your help with my coding difficulties has been a total game-changer.
spawn_drone does a unix-style fork() with a full COW snapshot of the spawning drone's variables.
So you can set it up in the drone that spawns them, and have the spawned drone read from those variables, using either its position or num_drones() to figure out which contains its instructions.

Or you can use a closure as suggested above.
< >
Showing 1-4 of 4 comments
Per page: 1530 50

Date Posted: Nov 3, 2025 @ 5:09am
Posts: 4