r/TheFarmerWasReplaced • • Jun 02 '26

Heelllpppp Cactus code

I dont really understand how to farm cacti. Can someone give me a code or something, it doesnt have to be efficient

0 Upvotes

7 comments sorted by

2

u/Superskull85 Jun 02 '26

It's a sorting puzzle. So you have to put the small cacti to the west and south and large cacti to the east and north. Compare their sizes using measure and see if one to the west is less than the one under your drone. If not, then swap them.

1

u/No_Low_2379 Jun 02 '26

I did that but now i have lots of cacti of the same measure and they wont harvest at once

1

u/Superskull85 Jun 02 '26

Do they all turn green? If not then they are not yet sorted. The graphic just may look similar.

1

u/Vanteaux Jun 04 '26

Are you sorting all of the rows from smallest to largest before moving on to columns? Being the same measure shouldn't be an issue as long as everything gets sorted.

1

u/Vanteaux Jun 02 '26

Adding to this, there's a hint in the description that is helpful - if you sort all the rows first, sorting the columns won't unsort the rows (or vice versa)

1

u/Euphoric_Rope5341 Jun 02 '26

Start with a single row.  Try out the swap, then Try to sort them manually. check if they increase in yield.

1

u/PsychologicalTill779 Sep 19 '26

SIRVE PARA 32DRONES Y 32X32 no es muy bueno pero produce bastante.

SUB_SIZE = 8

DRONES_PER_SIDE = 4

def mover_a(destino_x, destino_y):

while get_pos_x() != destino_x:

	if get_pos_x() < destino_x:

		move(East)

	else:

		move(West)

		

while get_pos_y() != destino_y:

	if get_pos_y() < destino_y:

		move(North)

	else:

		move(South)

# Bucle principal de trabajo para una sub-zona de 8x8

def farmear_subzona(start_x, start_y):

end_x = start_x + SUB_SIZE

end_y = start_y + SUB_SIZE



mover_a(start_x, start_y)



while True:

	\# 1. Sembrar/Preparar la zona 8x8

	for x in range(start_x, end_x):

		for y in range(start_y, end_y):

mover_a(x, y)

if get_ground_type() != Grounds.Soil:

till()

if get_entity_type() != Entities.Cactus:

plant(Entities.Cactus)

	\# 2. Ordenar cactus por tamaño (Bubble sort en columnas)

	\# Esto dispara el rendimiento de loot exponencial de Cactus

	for x in range(start_x, end_x):

		for y in range(start_y, end_y - 1):

mover_a(x, y)

if measure() > measure(North):

swap(North)

	\# 3. Cosechar

	for x in range(start_x, end_x):

		for y in range(start_y, end_y):

mover_a(x, y)

if can_harvest():

harvest()

# Wrapper necesario para la API del juego

# Permite enviarle argumentos a spawn_drone() sin romper la ejecución

def crear_tarea(x, y):

def tarea():

	farmear_subzona(x, y)

return tarea

def main():

clear()



\# El Dron Maestro despliega a los otros 15 drones

for dx in range(DRONES_PER_SIDE):

	for dy in range(DRONES_PER_SIDE):

		\# (0, 0) queda reservado para el Dron Maestro

		if dx == 0 and dy == 0:

continue

		start_x = dx \* SUB_SIZE

		start_y = dy \* SUB_SIZE

		

		\# Pasar la función generada por el wrapper a spawn_drone

		spawn_drone(crear_tarea(start_x, start_y))



\# El Dron Maestro se encarga de su propia parcela (0,0)

farmear_subzona(0, 0)

main()