r/TheFarmerWasReplaced

I was inspired

So this is my code I managed to make it from scratch using this reddit post as inspiration for it
https://www.reddit.com/r/TheFarmerWasReplaced/comments/1vpcgh4/fullyauto_sunflower_farm/?q=I+know+I%27m+late+to+the+party+but+I+got+inspired+by+the+way+you+did+yours.+But+I+had+to+modify+it.&type=comments&cId=b9f2c222-3201-4da1-9fdc-f908ddc78ff6&iId=8cf58a10-b8e7-4eca-9661-24d8e6546d8a
I didn't use the code in the original post at all, I just used the way i saw the drones move as inspiration. 3.5 hours it took me. I am so happy
Edit: Sorry It's quiet I have my master volume on 5% my ears are sensitive.

megapumpkin measuring not working, please help me to understand./ what is the purpose of nested "for 'variable' in range()" statements?

Hi. Me again.

  1. My megapumpkin measuring check is not working like I intended. Strangely it works when I stop it after I create a megapumpkin then start it again. Please critique and explain; I am entirely new to Python.

  2. What is the reason for nesting "for 'variable' in range()" statements? As in:

"for i in range(get_world_size())
>for j in range(get_world_size())"

I have seen it before but the explanation in the game doesn't make sense to me that I can remember.

Thank you!

u/InsideOutlander — 2 days ago

Help with making maze solver code more concise

I am trying to make this left hand rule maze solver function as concise as possible, even if it becomes more unreadable. I think the idea is called code golf.

I can't seem to make it less than 9 lines. Any help or suggestions appreciated. Code below.

Solver function ("maze"):

def runner(index = 0, dirs = {North:West, East:North, South:East, West:South}):

`plant(Entities.Bush)`

`use_item(Items.Weird_Substance,get_world_size()*32)`

`while get_entity_type() != Entities.Treasure:`

	`if not move(list(dirs)[index]) and not can_move(dirs[list(dirs)[index]]):`

		`index = (index + 1) % 4`

	`elif can_move(dirs[list(dirs)[index]]):`

		`index = (index - 1) % 4`

`harvest()`

Main file:

import maze

set_world_size(6)

while not maze.runner():

`pass`
u/Remarkable_Crab5892 — 3 days ago

Drone is moving up through a row twice after harvesting and planting.

What it says on the tin. I cannot figure out why this is happening. I am relatively new to the game and entirely inexperienced with Python outside of the simplified version that is in this game (I am using this game as an introduction). I would appreciate some help troubleshooting in a way that helps me understand what I am missing. Thank you!

Here is the section code that keeps producing the extra passes over the rows it plants trees every first square with the second and third squares being carrots.

for j in range(get_world_size()):

		if can\_harvest():

harvest()

		plant(Entities.Tree)

		get\_water()

		if get\_water() == 0:

use_item(Items.Water)

		move(North)

		if can\_harvest():

harvest()

		plant(Entities.Carrot)

		if get\_water() == 0:

use_item(Items.Water)

		move(North)

		if can\_harvest():

harvest()

		plant(Entities.Carrot)

		if get\_water() == 0:

use_item(Items.Water)

		move(North)

Full Code, JIC:

while True:

if num\_items(Items.Hay) <= 10000000:

	for j in range(get\_world\_size()):

		if can\_harvest():

harvest()

		plant(Entities.Grass)

		get\_water()

		if get\_water() == 0:

use_item(Items.Water)

		move(North)

	move(East)

elif num\_items(Items.Hay) <= 15000000:

	for j in range(get\_world\_size()):

		if can\_harvest():

harvest()

		plant(Entities.Tree)

		get\_water()

		if get\_water() == 0:

use_item(Items.Water)

		move(North)

		if can\_harvest():

harvest()

		plant(Entities.Carrot)

		if get\_water() == 0:

use_item(Items.Water)

		move(North)

		if can\_harvest():

harvest()

		plant(Entities.Carrot)

		if get\_water() == 0:

use_item(Items.Water)

		move(North)

	move(East)

	for j in range(get\_world\_size()):

		if can\_harvest():

harvest()

		plant(Entities.Carrot)

		get\_water()

		if get\_water() == 0:

use_item(Items.Water)

		move(North)

	move(East)
reddit.com
u/InsideOutlander — 5 days ago

Cactus Trouble

I am succesfully planting all cacti using multi drones (i only have the one extra). I am looking for help getting my sort_coloumn() function to work. i have tried a lot of diffrent things, to make it work myself and it just dont work. i really want it to be so close to my code as possible and it does not have to be efficient. sorry for my bad english rn im tired af

def sort_coloumn():

swapped = True

while swapped:

	swapped = False

	if measure() > measure(North):

		move(North)

		swapped = True

	move(North)

def sort_all_coloumn():

move\_to\_x\_pos(0)

for i in range(grid\_size):

	move\_to\_x\_pos(i)

	drone = spawn\_drone(sort\_coloumn)

	move(East)

	wait\_for(drone)
reddit.com
u/Lyxse17 — 7 days ago

Expertly optimized and highly sophisticated maze solving.

Everyone does left hand rule. Whoever finds the treasure first gets to restart the maze. There is no exit condition.

u/otacksamme_roger — 13 days ago

Would this game be boring or too easy for a junior dev?

I see this game reccomended a lot for beginners.
Does that mean it would maybe be too easy/boring for someone that did graduate not too long time ago?

reddit.com
u/NTMAnon — 13 days ago

Trying to use operator on a function, not its return... but it's got parentheses?

Piece of the code it's getting hung up on: if get_pos_x() > x: while get_pos_x() != x: move(West)

Situation:

Trying to make a script, that does the following:

Plants bush on entire farm Creates max_Drones() coords, then deploys drones to go to these coordinates, and standby to execute maze solving code All drones solve maze

The problem happens specifically between steps 2 and 3. The drones go to their spot, until the maze spawns and they're blocked from moving. It actually happens while using that function to pathfind.

Instead of being stuck in a loop of trying to move where they can't (which is what I was trying to solve before the code broke), the game throws that error.

Notably, the code USED to work. Then I tried to implement can_move() logic and it permanently broke, even after reverting the changes. Says I'm trying to call the operator on the function instead of its return, suggesting to use ()... which is already there.

Thoughts?

NOTE: this code is imported from a utility file to the main maze solver file. The "error on missing ()" is also toggled off in settings.

reddit.com
u/Killerhurtz — 13 days ago

On the fence, got a few questions.

This game is currently on sale and I am on the fence, I want to buy it to get into coding but currently have 0 experience. I also believe the language is very similar to Python.

1.) Do I need to learn to code before hoping into this game?

2.) Can this game actually help me become good at coding considering I have never coded but really want to?

3.) Do I need to learn material outside of the game to finish it?

First time in this sub, not sure if these types of posts are allowed.

reddit.com
u/DuckFromEternia — 14 days ago