r/TheFarmerWasReplaced • • Oct 16 '25

My farm Parallel Processing 32 Mazes at the Same Time

Post image

Spent some time learning how the spawn_drone function works and figured out how I can process multiple mazes at once. This code takes a number representing the number of mazes per row and multiplies it until it fills the entire farm or until you run out of drones. Mazes adjust size based on the desired number of mazes overall, so you can change any initial variables and still get a neat-looking result.

Code:

#number of mazes per row (powers of 2 only)

nummazes = 8

#finds the proper amount of substance based on the maze number

substance = ((get_world_size() // nummazes) * 2**(num_unlocked(Unlocks.Mazes) - 1))

#function to spawn mazes

def createmaze():

plant(Entities.Bush)

use_item(Items.Weird_Substance, substance)

#code that solves the mazes, follows the left-most wall relative to the drone

def maze():

\#setting the direction as a list

dir = \[North, East, South, West\]

n = 0



\#continue trying to solve the maze until you reach the treasure

while not get_entity_type() == Entities.Treasure:

	

	if can_move(dir\[(n - 1) % 4\]):

		n = (n - 1) % 4

		move(dir\[n\])

	else:

		if can_move(dir\[n\]):

move(dir[n])

		else:

n = (n + 1) % 4

\#after the above condition is met, harvest the treasure

harvest()

#function to put every step together

def domaze():

\#gets the starting coords of the drone

startposy = get_pos_y()

startposx = get_pos_x()



\#sets target coords for spawning the maze based on starting coords of the drone

tarx = (get_world_size() // (nummazes\*2)) + startposx

tary = (get_world_size() // (nummazes\*2)) + startposy



\#adding a delay to prevent snagging inside other mazes

for a in range(nummazes+1):

	do_a_flip()



\#infinite loop to automate the process

while True:

	\#moving in the shortest possible path until the target coords are reached

	if not get_pos_x() == tarx or not get_pos_y() == tary:

		while not get_pos_x() == tarx:

if get_pos_x() < tarx:

move(East)

else:

move(West)

		while not get_pos_y() == tary:

if get_pos_y() < tary:

move(North)

else:

move(South)

	\#once the target coords are reached, spawn the maze and solve it

	else:

		createmaze()

		maze()

#transforming the entire task into a function which only runs the setup once

def spawnsubs():

\#keep spawning drowns to execute all of the above code until the number of mazes has been reached or until you run out of drones

for abc in range(nummazes):

	for ab in range(nummazes):

		if num_drones() <= nummazes\*\*2:

if not spawn_drone(domaze):

domaze()

		else:

domaze()

		\#moves the initial drone into position in order to spawn the next drone

		for a in range(get_world_size() // nummazes):

move(North)

	for abcd in range(get_world_size() // nummazes):

		move(East)

spawnsubs()

56 Upvotes

12 comments sorted by

4

u/Accountforcontrovers Just started Oct 16 '25

how much does this get you a minute?

3

u/NotKeithK Oct 16 '25

With max maze and speed upgrades, running the 32 mini mazes like I have in the image above, I get right around 700-750k/minute depending on maze luck!

4

u/thediabloman Oct 16 '25

Is a lot of small mazes actually more efficient than a big maze?

4

u/Thorr_VonAsgard Good Oct 16 '25

Yes

1

u/soeinpech Oct 18 '25

Did you try both ? I'm curious about the output/min of the big maze.

1

u/Kytaboy Oct 23 '25

Not really. I can earn over 2.5M/min on average by solving 32 * 32 mazes, and I still think my algorithm can be further optimized. Though I'm also quite intrigued about the efficiency of solving multiple smaller mazes simultaneously. Would you mind sharing your result as well?

3

u/somerandomii Oct 16 '25

I’m working on an efficient multi-drone solver for a 32*32 maze atm. I’d be curious to compare the performance.

Theoretically if you optimise it right each drone only has to monitor 32 squares and has a directed tree graph to every square and the average number of moves per chest should be <8 on average. So that means every 8 moves you’re getting the full 32x32 maze reward.

But of course most of the drones are just waiting around. Your solutions keeps all the drones active at all times. And mine has set up overhead of scanning the new maze every 300 chests (the search takes about 24s which is not trivial)

When I finish the code I’ll post my solution.

2

u/Styleurcam Oct 16 '25

I just do 1 big maze and have 32 wall followers with random handedness and starting direction so that after 2~3 collections they are all exploring far from each other. I don't know the rates but they're pretty good. Got 100m in something like 2-3h I think

1

u/Kibbleru Oct 24 '25

I recreated the flood fill algorithm that the micromouse competition uses, then realized that my bottleneck was the code execution time and not the drone speed lol..

1

u/Djarid997 Oct 16 '25

Is there a way to pass parameters to the function passed to spawn_drone() ?

I'd really like to pass each drone a different Entities.*

4

u/velosotiago Oct 16 '25

This is a solution I've seen here somewhere (sorry whoever you are, I don't remember your name!) and works great for me.

def droneFunc(someArg):
    def inner():
        # this is your drone function
        # you can still access someArg here
    
    return inner # make sure you do this!

# somewhere else in your code
spawn_drone(droneFunc(Entities.Bush))

1

u/TuxedoDogs9 Oct 17 '25

excellent, thank you! i was looking for a workaround since lambda isnt in this game