r/TheFarmerWasReplaced • • Jul 24 '26

🥳Thank you for joining r/TheFarmerWasReplaced🥳

16 Upvotes

🥳Thank you for joining r/TheFarmerWasReplaced🥳

Hi :D, I'm u/Any-Ad-4072, the main moderator of this sub reddit, if you have an issue, don't hesitate to contact me or the rest of the mod team through Mod mail.

Welcome to this community of geeks obsessed with a drone that replaced the farmer (and definitely didn't kill him🫪).

Here, you can share your thoughts about the game, show your code that you definitely didn't steal from someone else like any good code writter🤨. You can also report bugs and share update ideas. (Note: the game's main developer, Timon, is not part of the moderation team and doesn't see what is being said here, if you want to talk to Timon, you can go to the TheFarmerWasReplaced discord Unfortunately, the discord link goes to https://discord.gg/kj33cJkeJn


r/TheFarmerWasReplaced • • 1d ago

I am so proud of myself.

Post image
34 Upvotes

I went from knowing nothing about Python, and extremely little about coding in general, to what I have in the screenshot.
I started with 1 window with a long code that harvested different stuff and now I can harvest stuff with multiple bots and solving 3 simple mazes with the "left hand on wall" technique.

Just wanted to share and show it.

This game is awesome.


r/TheFarmerWasReplaced • • 2d ago

Question Sunflower farm

5 Upvotes

I have my first sunflower farm code, I was curious if there is anything glaringly bad for why I shouldn't use this?
I don't love getting stuck waiting on a singular largest flower, but not sure how I could better than my current "if I can't harvest this highest flower, look for a different one" that I have going on.

petals = []
while num_items(Items.Power) < 5000:
  for i in range(get_world_size()):
    if get_water() < .5:
      use_item(Items.Water)
    if get_ground_type() != Grounds.Soil:
      till()
      plant(Entities.Sunflower)
      petals.append(measure())
      move(North)
    else:
      plant(Entities.Sunflower)
      petals.append(measure())
      move(North)
  move(East)
  highest = 15
  while len(petals) == 36:
    if num_items(Items.Power) > 5000:
      break
    for i in range(len(petals)):
      if petals[i] == highest:
        x = i // get_world_size()
        y = i % get_world_size()
        goto(x,y)
        if not can_harvest():
          continue
        harvest()
        if get_water() < .5:
          use_item(Items.Water)
        plant(Entities.Sunflower)
        petals.pop(i)
        petals.insert(i, measure())
        if measure() == 15:
          highest = 15
      if highest not in petals:
        highest -= 1

r/TheFarmerWasReplaced • • 3d ago

Help needed on Treasure Map

2 Upvotes

Hello all! I've been trying out the new DLC, and I've gotten pretty far. Today, I've been trying to code a solution for the "Treasure Map" puzzle, and the game is being weird.

So, my drone is fine at all of the setup processes. It can find its way to the treasure map and read it, then start the maze. However, whenever I start the maze, it's weird. With the seed I'm using for testing, the first motion is "d", for "dig" I assume. Then, it's about ~15 W's in a row, but whenever I move west that many times, the maze breaks.

I'm not sure what's going on, but it's weird. As far as I know, the drone just digs down and goes west a bunch of times, but the maze keeps breaking when I attempt to do so. Do y'all have any guidance?


r/TheFarmerWasReplaced • • 3d ago

Update idea Iron and Quartz Prospecting should be affected by hover height

1 Upvotes

It just kind of feels like a missed interaction to me. If prospecting returns the direction or distance to the closest ore block, then which one is closest intuitively feels like it should depend on the vertical location of the drone too.
Also, that would fix a major problem with my current iron and quartz mining algorithms, just for full disclosure.


r/TheFarmerWasReplaced • • 3d ago

Does anybody know how to get the golden carrot, golden pumpkin, golden tree, and golden gold hat?

4 Upvotes

r/TheFarmerWasReplaced • • 4d ago

Why isn't this measure() working?

2 Upvotes

I know there are better ways to do it, but i only want to know what i have wrong with this syntax

for i in range(12):
  if measure() > 10:
    harvest()
    plant(Entities.Sunflower)

r/TheFarmerWasReplaced • • 4d ago

Question Am I missing something with Fertilizer?

1 Upvotes

I made now a Polyculture code. 32 drones working independently.

For grass no problem.
For wood and carrots, or I need to wait for them to grow, or I need to use fertilizer. But the production of fertilizer cannot keep up with the usage.
Are the upgrades from polyculture, in the future, going to compensate the time waiting for plants to grow?

Or am I missing something?

cheers


r/TheFarmerWasReplaced • • 5d ago

Bug report/support Is this a bug? (Issues with measure() wearing Dino hat)

Thumbnail
gallery
0 Upvotes

Hello world!

Os: android

Device: Samsung galaxy s24

Game version: mobile 1.1.32 (21)

Im new to the game and trying to get the Dino running and I mostly have. With one main hold up that seems pretty consistent of where my code crashes.

When the Dino is headed south and it collects an apple and it goes to measure the new apple which is directly east (same y) then it fails to compute x, y = measure()

Is this a bug? Am I doing something wrong?


r/TheFarmerWasReplaced • • 6d ago

Question multiple drones

Post image
3 Upvotes

I'm havine isusses with my code, the last drone doesn't go untill the fist one desponse. I'm not sure what to change. I'm very new to this.

ignore the fertiliser, I ran out and didn't want to take it out of the code


r/TheFarmerWasReplaced • • 6d ago

Dino thing pt.2

3 Upvotes

Some of you gave me amazing tips that helped me out so thank you first of all.

Some of you told me that having the snake initially chasing the apple and then after a certain length start zig zagging so I coded it and it works amazingly (unless it gets boxed)

I was working on a reset code but I can’t understand why it fails, pls help 😭😭


r/TheFarmerWasReplaced • • 6d ago

Program your Rats and watch them Fight [AD]

5 Upvotes

Hey everyone!

I asked one of your mods if I could share my game here because I figured people who enjoy The Farmer Was Replaced might actually be into this.

I'm solo developing Ratiator, a game where you program your rats' combat tactics in a simplified visual programming language best compared to unreal blueprints (and for the more technical folks out there MatLab) and watch them try to survive in the arena.

There's a free browser demo here: https://akandogames.com/play/ratiator/

Steam Page: https://store.steampowered.com/app/5335480/Ratiator/

I'd really appreciate some honest feedback from people who have not actively been involved in the development of this game because I'm ... pretty biased

I'm also looking for a few testers for the full game, so if you're interested just let me know!

Thanks :)


r/TheFarmerWasReplaced • • 7d ago

Dino bones thing

28 Upvotes

I never coded before and I saw this game so I thought it could be nice to learn but I think I’m kinda brute forcing it. I coded this for the dinosaur and I’m kinda proud about it. I’d really appreciate some advice and a bit of help since I can’t figure out how to make it a loop by swapping twice the hat and resetting the positions (I have multiple codes)


r/TheFarmerWasReplaced • • 7d ago

Code idea I know how to communication between drone

Thumbnail
youtu.be
8 Upvotes

So in this video, 4 purple hats drone place block representing a bit string eg. '110011" and 1 reader drone read it and print it out

red indicate 1 while green indicate 0

the bottom most column represent area reserve for flag

these are the flag

green -> not written yet -> reader can skip reading the bits

blue -> writting -> reader can skip reading the bits

red -> written -> reader has to read

Here is the code

def topos(x,y):

`cy = get_pos_y()`

`cx = get_pos_x()`

`while(cx != x):`

	`if(cx > x):`

		`move(West)`

	`else:`

		`move(East)`

	`cx = get_pos_x()`

`while(cy != y):`

	`if(cy > y):`

		`move(South)`

	`else:`

		`move(North)`

	`cy = get_pos_y()`

def writer_job(args):

`change_hat(Hats.Purple_Hat)`

`col = args[0]`

`nflip = args[1]`

`bit = args[2]`



`for i in range(0,nflip):`

	`do_a_flip()`



`topos(col,0)`



`place(Grounds.Block_Blue) # this tell reader that , the drone is writting`



`for j in range(0,len(bit)):` 

	`topos(col,2 + j) # writting field start at j = 2`

	`if(bit[j] == '1'):`

		`place(Grounds.Block_Red)`



`topos(col,0)`

`dig()`

`place(Grounds.Block_Red)`



`return`

def reader_job(args):

`change_hat(Hats.Green_Hat)`



`print("Hello, i am a reader drone")`



`num_writer_drone = args[0]`

`ex,ey = args[1]`

`bit_string_length = args[2]`



`bits = []`

`num_has_not_read = num_writer_drone`

`# bit prefill with 0`

`for d in range(num_writer_drone):`

	`tmp = []`

	`for b in range(bit_string_length):`

		`tmp.append(0)`

	`bits.append(tmp)`



`while(num_has_not_read != 0):`

	`for i in range(0,num_writer_drone):`

		`topos(i,0)`

		`if(get_ground_type() == Grounds.Block_Green):  # drone i is not writting yet`

continue

		`if(get_ground_type() == Grounds.Block_Blue): # Writting but not finished`

continue

		`if(get_ground_type() == Grounds.Block_Red): # finished writting -> read`

for j in range(0,bit_string_length):

topos(i,2 + j) # writting field start at j = 2

if(get_ground_type() == Grounds.Block_Red):

# read as 1

bits[i][j] = 1

#else 0 but we dont have to assign that cuz we prefil with 0 before hand

num_has_not_read = num_has_not_read - 1

topos(i,0)

dig()

`topos(ex,ey)`



`for d in range(num_writer_drone):`

	`bit_str = ''`

	`for b in range(bit_string_length):`

		`bit_str = bit_str + str(bits[d][b])`

	`message = "Drone " + str(d) + " wrote " + bit_str`

	`move(South)`

	`print(message)`

ws = 10

bit_string_length = 6

num_writer_drone = 4

set_world_size(10)

for i in range(0,num_writer_drone):

`topos(i,0)# reserve for flag`

`dig() # you need dlc for this`

`place(Grounds.Block_Green)`



`for j in range(2,2 + bit_string_length):` 

	`topos(i,j)# reserve for bit information`

	`dig() # you need dlc for this`

	`place(Grounds.Block_Green)`

bits = ["110011","101010","100010","001100"] # message for each writer drone to write

writer_drones = []

num_flips = [1,6,2,8]

topos(8,0)

reader_args = []

reader_args.append(num_writer_drone)

ex,ey = 6,6

reader_args.append((ex,ey)) # position where to print result

reader_args.append(bit_string_length)

reader_drone = spawn_drone(reader_job,reader_args)

topos(0,0)

do_a_flip()

do_a_flip()

for i in range(0,num_writer_drone):

`topos(i,0)`

`writer_args = []`

`writer_args.append(i) # assigning columns`

`writer_args.append(num_flips[i])`

`writer_args.append(bits[i])`



`writer_drones.append(spawn_drone(writer_job,writer_args))`

for w_drone in writer_drones:

`wait_for(w_drone)`

r/TheFarmerWasReplaced • • 7d ago

My farm Underground Treasure - The farmer was replaced

Thumbnail
youtube.com
5 Upvotes

The main bottleneck for this puzzle would be that the instruction trend to give you a lot of loops, luckily, I came up with a way to remove those loop while looping the instruction string

Here is the percentage of the distance the drone actually moved over the distance it would move if it followed the instruction string naively

Actual_path_length : 929 , Actual_move_length : 15

travese only : 1.61 %

=======================================

Actual_path_length : 555 , Actual_move_length : 43

travese only : 7.75 %

=======================================

Actual_path_length : 170 , Actual_move_length : 60

travese only : 35.29 %

=======================================

Actual_path_length : 1216 , Actual_move_length : 24

travese only : 1.97 %

=======================================

Actual_path_length : 358 , Actual_move_length : 62

travese only : 17.32 %

=======================================

Actual_path_length : 203 , Actual_move_length : 85

travese only : 41.87 %

=======================================

Actual_path_length : 385 , Actual_move_length : 43

travese only : 11.17 %

=======================================

Actual_path_length : 387 , Actual_move_length : 87

travese only : 22.48 %

=======================================


r/TheFarmerWasReplaced • • 8d ago

Heelllpppp Left works - Right doesn't. Is this a bug or am I misunderstanding something?

Post image
6 Upvotes

VERDICT: MISUNDERSTANDING!

The right-side clone is passing the result of the pump_scan(x) function - not the entire function. It's running the first time in order to determine the result (which is None) and sending that as the argument instead.


Just unlocked pumpkins and I wanted to experiment with the limits of passing arguments into defined functions.

Shouldn't both of these codes operate identically? Because they don't. A few more details:

On the right hand side, the passed function runs exactly once, during the first iteration of the loop. Clearly that means the function is passed successfully through the funct variable, yet it just ignores the passed function on every following iteration of the loop. Everything else in the loop runs perfectly fine - just not the passed function.

I also tested this with pre-defined functions and got the same result. Additionally, the related "Higher-Order Programming" achievement didn't trigger using this method.

On the left hand side, I changed the formatting to match the guide and suddenly the function parsed every iteration of the loop, without any issues (and triggering the achievement). What am I missing here? Is it just a bug?


r/TheFarmerWasReplaced • • 8d ago

My farm Finally

7 Upvotes

I can finally buy this drill that is locked behind 12M dynamite

farming dynamite was pain tho until I coded the near perfect solution


r/TheFarmerWasReplaced • • 8d ago

My farm dynamite sweeper 32 by 32 grid - The miner was replaced DLC

Thumbnail
youtube.com
8 Upvotes

I had to repost because the body isnt showing the YT link

This solution took me 2 whole days to be able to implement this because there were more practical challenges than I ever thought

The idea is to formulate a list of equations based on the grid and formulate a matrix to represent the problem, then transform the matrix system to the RREF (Reduced Row Echelon Form) to derive safe or unsafe tiles from it.

However, the algorithm cannot handle pattern where it is really 50/50 chance to be safe or boom but it can solve most of the cases

Here the github link

https://github.com/MarT1AZ/dynamite_sweeper_v4

If this help you, pls give it a start or upvote. This will compensate for my current state of sanity. I had to debug it for 2 whole day. Soemtimes, output just didnt print completely for some reason and I had to keep digging for dynamite which took around 20 seconds average.

I will come back and do some explaination later if this get popular

Note : I did make some explainations but when I selected this sub to post on, it reset my draft


r/TheFarmerWasReplaced • • 8d ago

Anyone else getting dirt in dynamite layers occasionally?

3 Upvotes

Is it a bug or am I somehow causing this?

No idea how this could happen in the first place

Also leaderboard runs complete, so I guess it doesn't happen then?


r/TheFarmerWasReplaced • • 8d ago

Optimization 2.3 million gold per minute!

Post image
32 Upvotes

maze size: 8

drones: 32

maze level: max

Previously when I did this I only got gold at 1.3m/min. Now I did it with high supply of power. The checkerboard positions will ensure every tile is possible in one step for each drones, and the speed of each drone contributes to the time it takes to move and harvest. Faster drone, fast harvest!

#edited each Treasure gives 2048 gold
drone-based rated output. 614400 gold, 16.26s Prints everytime a maze is spawned and the 300th treasure is harvested.

#here's my code

import main

set_world_size(8)
clear()

def toggleIt(pols):
# 	print("yeaaaaash")
	use_item(Items.Weird_Substance,pols)
	
def backNforth(fw,bw,pols):
	move(fw)
	toggleIt(pols)
	move(bw)
	
def toNfroTreasure2(pols):
	if get_entity_type()==Entities.Treasure:
		toggleIt(pols)
	elif get_entity_type(North)==Entities.Treasure:
		if can_move(North):
			backNforth(North,South,pols)
	elif get_entity_type(South)==Entities.Treasure:
		if can_move(South):
			backNforth(South,North,pols)
	elif get_entity_type(East)==Entities.Treasure:
		if can_move(East):
			backNforth(East,West,pols)
	elif get_entity_type(West)==Entities.Treasure:
		if can_move(West):
			backNforth(West,East,pols)
def ahoy(substances,j=(0,0)):
	main.goto(j[0],j[1])
	while True:
		toNfroTreasure2(substances)
# 			use_item(Items.Weird_Substance,substances)
# set_world_size(5)
def easyTreasure():
	size=get_world_size()
	substances = size*2**(num_unlocked(Unlocks.Mazes)-1)
	that_cargo = []
	for x in range(0,size):
		for y in range(0,size):
			if (x+y)%2==1:
				that_cargo.append(spawn_drone(ahoy,substances,(x,y)))
	main.goto(size-1,size-2)

	plant(Entities.Bush)
	use_item(Items.Weird_Substance,substances)
	while True:
		t1 = get_time()
		au1 = num_items(Items.Gold)
		while (get_time()-t1) < 0.3:
			toNfroTreasure2(substances)
		if (num_items(Items.Gold)-au1)==0:
			harvest()
			main.sleep(0.2)
			plant(Entities.Bush)
			use_item(Items.Weird_Substance,substances)
			
if __name__=="__main__":
	easyTreasure()

r/TheFarmerWasReplaced • • 9d ago

Heelllpppp I am once again stumped, but I feel so close.

Post image
7 Upvotes

The nefarious pumpkin farm. So, I am able to plant the whole world, do an initial pass checking for dead pumpkins and replanting.

Where I am having issues is trying to store the data for where there was a dead pumpkin. currently I'm doing that with:

x = get_pos_x()

y = get_pos_y()

MydeadPumpkins.append(x,y)

Then while my list is True or contains data, I'm trying to pop the list to generate inputs for my move_to function. The error I keep getting is that my move_to requires 2 arguments (x, y). I am not understanding how to pull that from my list.

Edit to say I would prefer hints over the straight answer. Trying to learn what I am doing wrong.


r/TheFarmerWasReplaced • • 9d ago

Recursive Spawn Drones

3 Upvotes

Is it worth it to do recursive spawn drones (spawned drones also spawn another drone) [1drone -> 2drones -> 4 drones -> 8drones etc.] in general cases?


r/TheFarmerWasReplaced • • 10d ago

My farm Multi drone coal code that I'm pretty proud of

43 Upvotes
worldSize = get_world_size()
Left = West
Right = East
Up = North
Down = South

def FarmCoal(threshold = -1):
  clear()
  # Change hat for the sake of differentiating the main drone from the others
  change_hat(Hats.Wizard_Hat)
  # For clear checking
  moveTo((worldSize // 2, worldSize // 2))
  endless = threshold == -1
  # Separate the field in 8 equal parts
  coalPlots = PartitionField(8)
  while num_items(Items.Coal) < threshold or endless:

    # Initial search for coal veins
    drones = []
    for plot in coalPlots:
      BL = plot[0]
      TR = plot[1]
      patchSize = TR[0] - BL[0] + 1
      middlePos = ((BL[0] + TR[0]) // 2, (BL[1] + TR[1]) // 2)
      if TR[1] + patchSize < worldSize and TR[0] + patchSize < worldSize:
        # Send a drone to the top right if boundary condition are respected
        # to cover more ground 
        drones.append(spawn_drone(MoveAndFindCoal, middlePos, 5, plot))
        drones.append(spawn_drone(MoveAndFindCoal, TR, 5, plot))
      else:
        drones.append(spawn_drone(MoveAndFindCoal, middlePos, 5, plot))

    coalToMine = []
    # Get the field parts where coal was found
    for drone in drones:
      result = wait_for(drone)
      if result[0]:
        coalPos = result[1]
        depthLeft = result[2]
        plotToMine = result[3]
        coalToMine.append((coalPos, depthLeft, plotToMine))

    # Special case where no coal is found at all
    if len(coalToMine) == 0:
      # This check happens for the main drone (wizard hat drone) which is why it is 
      # moved to the middle which reaches clay or rock faster than a corner 
      # due to cavein mechanics
      if get_ground_type() == Grounds.Clay or get_ground_type() == Grounds.Rock:
        clear()
        change_hat(Hats.Wizard_Hat)
        moveTo((worldSize // 2, worldSize // 2))
      # Restart the coal search if none was found
      continue

    # Mine the coal that was found
    drones = []
    for coalTarget in coalToMine:
      coalPos = coalTarget[0]
      depthLeft = coalTarget[1]
      plotToMine = coalTarget[2]
      drones.append(spawn_drone(MineCoal, coalPos, depthLeft, plotToMine))

    # If a drone has reached Clay or Rock after mining
    reachedClay = False
    for drone in drones:
      if wait_for(drone):
        reachedClay = True

    # Faster to reset than to dig through the entire rock layer for more coal
    if reachedClay:
      clear()
      change_hat(Hats.Wizard_Hat)
      moveTo((worldSize // 2, worldSize // 2))
  return

def MineCoal(coalPos, depthLeft, plotToMine):
  moveTo(coalPos)
  coalDepth = get_pos_z()

  # A naive search for the top right coal corner
  cornerFound = False
  while not cornerFound:
    dronePos = (get_pos_x(), get_pos_y())
#   if dronePos[0] + 1 <= plotToMine[1][0]:
    if dronePos[0] + 1 < worldSize:
      move(Right)
      DigToDepth(coalDepth)
      if get_ground_type() != Grounds.Coal:
        move(Left)
#   if dronePos[1] + 1 <= plotToMine[1][1]:
    if dronePos[1] + 1 < worldSize:
      move(Up)
      DigToDepth(coalDepth)
      if get_ground_type() != Grounds.Coal:
        move(Down)
    if (get_pos_x(), get_pos_y()) == dronePos:
      cornerFound = True
      TRCorner = dronePos
  moveTo(coalPos)

  # A naive search for the bottom left coal corner
  cornerFound = False
  while not cornerFound:
    dronePos = (get_pos_x(), get_pos_y())
    # We can either limit the drone to its field area's borders or just to the field 
    # borders, both have their ups and downs. More coal if we limit to the field but 
    # more risky than staying within our area
#   if dronePos[0] - 1 >= plotToMine[0][0]:
    if dronePos[0] - 1 >= 0:
      move(Left)
      DigToDepth(coalDepth)
      if get_ground_type() != Grounds.Coal:
        move(Right)
#   if dronePos[1] - 1 >= plotToMine[0][1]:
    if dronePos[1] - 1 >= 0:
      move(Down)
      DigToDepth(coalDepth)
      if get_ground_type() != Grounds.Coal:
        move(Up)
    if (get_pos_x(), get_pos_y()) == dronePos:
      cornerFound = True
      BLCorner = dronePos

  # Mine the coal between the two corners that were found
  dig()
  for col in range(BLCorner[0], TRCorner[0] + 1):
    for row in range(BLCorner[1], TRCorner[1]):
      move(Up)
      DigToDepth(coalDepth)
      if get_ground_type() == Grounds.Coal:
        dig()
    if col != TRCorner[0]:
      moveTo((col + 1, BLCorner[1]))
      DigToDepth(coalDepth)
      if get_ground_type() == Grounds.Coal:
        dig()
  moveTo(coalPos)

  # Mining the coal brings us one level deeper
  depthLeft -= 1
  # If we happen to find any coal while digging the rest of the way recursively call 
  # this function until there is nothing left to dig
  while depthLeft != 0:
    if get_ground_type() == Grounds.Coal:
      return MineCoal(coalPos, depthLeft, plotToMine)
    else:
      dig()
      depthLeft -= 1

  # Return the clear condition
  return get_ground_type() == Grounds.Clay or get_ground_type() == Grounds.Rock

def DigToDepth(depth):
  while get_pos_z() > depth:
    dig()
  return

def MoveAndFindCoal(pos, depth, coalPlot):
  moveTo(pos)
  returnedPlot = coalPlot
  # If the drone is one of the top right drones
  if pos == coalPlot[1]:
    # Define a small area for the top right drone to use as borders
    returnedPlot = ((pos[0] - 2, pos[1] - 2), (pos[0] + 2, pos[1] + 2))

  coalFound = False
  for i in range(depth):
    dig()
    coalFound = get_ground_type() == Grounds.Coal
    if coalFound:
      # We keep track of how much lower we were supposed to go if we hadn't found coal
      depthLeft = depth - i + 1
      # Return whether coal was found, the drone's position, the depth we have left to
      # mine and the corresponding area
      return True, (get_pos_x(), get_pos_y()), depthLeft, returnedPlot

  # depthLeft is set to 0 if we didn't find anything
  return False, (get_pos_x(), get_pos_y()), 0, returnedPlot

# Moves the drone to the specified position passed as a tuple (x, y)
# Will use the edges of the screen to get to the destination if
# it is closer to go that way
def moveTo(target):
  targetX = target[0]
  targetY = target[1]
  droneX = get_pos_x()
  droneY = get_pos_y()
  distX = droneX - targetX
  distY = droneY - targetY
  if distX < 0:
    xBestDirection = Right
  elif distX > 0:
    xBestDirection = Left
  if distY < 0:
    yBestDirection = Up
  elif distY > 0:
    yBestDirection = Down
  if abs(distX) > worldSize // 2 and distX != 0:
    if xBestDirection == Right:
      xBestDirection = Left
    else:
      xBestDirection = Right
  if abs(distY) > worldSize // 2 and distY != 0:
    if yBestDirection == Up:
      yBestDirection = Down
    else:
      yBestDirection = Up
  while droneX != targetX or droneY != targetY:
    if droneX != targetX:
      move(xBestDirection)
      droneX = get_pos_x()
    if droneY != targetY:
      move(yBestDirection)
      droneY = get_pos_y()
  return

# Separates the field in square areas according to the chosen patchSize
# Returns a list of tuples. One for each of the partitions.
# The tuples contain the coordinates of
# the bottom left and top right corner respectively of the partition they represent
def PartitionField(patchSize = 6):
  nbrPartitions = (worldSize // patchSize)**2
  nbrPerCol = worldSize // patchSize
  pos1X = 0
  pos2X = patchSize - 1
  partitionPos = [((pos1X, pos1X),(pos2X, pos2X))]

  for i in range(1, nbrPartitions):
    if len(partitionPos) % nbrPerCol == 0:
      pos1X += patchSize 
      pos2X += patchSize
    partitionPos.append(((pos1X, (i % nbrPerCol)*patchSize),(pos2X, ((i % nbrPerCol) + 1)*patchSize - 1)))
  return partitionPos

if __name__ == "__main__":
  threshold = -1
  FarmCoal(threshold)

This is designed to work for 32x32 farms and uses at most 17 drones at a time.

To summarize the way it works in a list of steps:

  1. Each drone digs down 5 layers except if they find coal in which case they stop and return the relevant information
  2. Repeat step 1 until at least one coal vein is found, clear() the field as needed when the clay/rock layer is reached
  3. For each coal vein found a drone is sent there to naively mine the coal from the bottom left corner to the top right corner of the vein (a few pieces will often be missed from this)
  4. The mining drone digs down the remaining depth that the drone from step 1 did not dig
  5. If coal is found during this process repeat step 3 and 4 until we have gone down 5 layers total
  6. If we have reached the clay/rock layer clear() the field
  7. Repeat from step 1 until threshold is met or forever if running in endless mode

This has gotten me at most around 800 coal/min so far, I'm sure there are ways to optimise this but this is quite satisfactory to me. Feel free to give any feedback, perhaps I've missed something to make this a lot better than it currently is.


r/TheFarmerWasReplaced • • 10d ago

Bug report/support Bug with Dynamite/Soot layers?

3 Upvotes

My drone seems to have uncovered a Dirt amongst the soot, should this be possible?


r/TheFarmerWasReplaced • • 11d ago

Heelllpppp Variable outside function to be used in function

2 Upvotes

Hi, Im trying to create a multi drone pumpkin farming setup

I currently have P as the variable for the number of pumpkins seen on the map and its outside of the defined function for goin gup a row counting then planting pumpkins, when i try to run it like this it says the variable isnt defined and needs to be defined before i can use it. how do i define the variable to be used by other functions.

at first i thought it was an import issue so i recreated everything in one file but it still didnt work