The Farmer Was Replaced

The Farmer Was Replaced

Help me pls
Help me pls
Im new to python in general and i cant figure out why my code isnt working ive unlocked all the necessary components to make this work so idk anymore

def main():
if can_harvest():
harvest()

if get_ground_type() != Grounds.Turf:
till()

if get_ground_type() == Grounds.Soil:
plant(Entities.Carrots)
use_item(Items.Water_Tank)
trade(Items.Carrot_Seed, 10)

if num_items(Items.Water_Tank) <= 50:
trade(Items.Empty_Tank, 100)



for y in range(4):
if y % 2 == 0: # Even rows: Move east (left to right)
for x in range(3): # Move right across the row
main()
move(East)
main()
if y != 3: # Move down if not on the last row
move(South)
else: # Odd rows: Move west (right to left)
for x in range(3): # Move left across the row
main()
move(West)
main()
if y != 3: # Move down if not on the last row
move(South)

main()

#FUCXXXING WORK YOU PiECE OF ♥♥♥♥ WHY ♥♥♥♥♥♥♥ ♥♥♥♥ YOU
< >
Showing 1-15 of 17 comments
umop-apisdn Nov 4, 2024 @ 2:39am 
The first thing I can see is that your code isn't indented at all. That's going to cause issues.

Wrap your code in [code][/code] tags, so we can follow the logic flow.

Example:
def main(): if can_harvest(): harvest()

Edited for clarification:

Whitespace is important in python for controlling program flow. If we can't see where the loops and conditionals end, we don't know which (if either) of these code blocks you intend:

def main(): if can_harvest(): harvest() if get_ground_type() != Grounds.Turf: till() if get_ground_type() == Grounds.Soil: plant(Entities.Carrots) use_item(Items.Water_Tank) trade(Items.Carrot_Seed, 10) if num_items(Items.Water_Tank) <= 50: trade(Items.Empty_Tank, 100)

def main(): if can_harvest(): harvest() if get_ground_type() != Grounds.Turf: till() if get_ground_type() == Grounds.Soil: plant(Entities.Carrots) use_item(Items.Water_Tank) trade(Items.Carrot_Seed, 10) if num_items(Items.Water_Tank) <= 50: trade(Items.Empty_Tank, 100)

... and as odd as it may seem, the results from those two code blocks will be quite different from one another.

Help us to help you by showing us the code you see in the game, rather than making us try to guess what you may have written.
Last edited by umop-apisdn; Nov 4, 2024 @ 2:56am
Bobby Rooster Nov 4, 2024 @ 11:16am 
idk how to upload sc onto steam discussions i dont really use this
Bobby Rooster Nov 4, 2024 @ 11:19am 
def main(): if can_harvest(): harvest() if get_ground_type() != Grounds.Turf: till() if get_ground_type() == Grounds.Soil: plant(Entities.Carrots) use_item(Items.Water_Tank) trade(Items.Carrot_Seed, 10) if num_items(Items.Water_Tank) <= 50: trade(Items.Empty_Tank, 100) for y in range(4): if y % 2 == 0: # Even rows: Move east (left to right) for x in range(3): # Move right across the row main() move(East) main() if y != 3: # Move down if not on the last row move(South) else: # Odd rows: Move west (right to left) for x in range(3): # Move left across the row main() move(West) main() if y != 3: # Move down if not on the last row move(South)
Bobby Rooster Nov 4, 2024 @ 11:19am 
i guess maybe ur right i have to just indent everything more ill try it and let yall know
umop-apisdn Nov 4, 2024 @ 7:45pm 
Great job showing us the indentation in your code! Now we can see how it flows, and thus determine what it's doing.

Now... what is it that the code is doing that you don't want it to, or not doing that you do want it to?
Bobby Rooster Nov 5, 2024 @ 4:34pm 
watertankcap = 100 carrotcap = 1000 haycap = 1000 woodcap = 1000 sunflowercap = 100 x = get_pos_x() y = get_pos_y() def main(): if get_ground_type() == Grounds.Soil: till() # Tilling the soil before planting if can_harvest(): harvest() Watering() Planting() def movement(): # Loop through all 16 positions in the 4x4 grid for i in range(16): row = i // 4 # Row increases from 0 to 3 col = i % 4 # Column increases from 0 to 3 as we move East main() # Move East unless we're at the last column of the row if col < 3: move(East) # After completing a row, move North unless it's the last row if col == 3 and row < 3: move(North) while True: movement()

def Planting(): # hay if num_items(Items.Hay) < haycap: if get_ground_type() == Grounds.Soil: till() plant(Entities.grass) # trees and bushes elif num_items(Items.Wood) < woodcap: if (x % 2 == 0 and y % 2 == 1) or (x % 2 == 1 and y % 2 == 0): plant(Entities.Tree) else: if get_ground_type() == Grounds.Soil: till() plant(Entities.Bush) # carrots elif num_items(Items.Carrot) < carrotcap: carrot_count = num_items(Items.Carrot) # Store result to avoid redundant calls if carrot_count == 0: trade(Items.Carrot_Seed, 5) if get_ground_type() == Grounds.Soil: till() plant(Entities.Carrots) # sunflowers elif num_items(Items.Sunflower) < sunflowercap: sunflower_count = num_items(Items.Sunflower) # Store result to avoid redundant calls if sunflower_count == 0: trade(Items.Sunflower_Seed, 5) if get_ground_type() == Grounds.Soil: till() plant(Entities.Sunflower)

def Watering(): #thirsty if num_items(Items.Water_Tank) < watertankcap: trade(Items.Empty_Tank, 5) if get_water() < 0.75: use_item (Items.Water_Tank)

after hours of research and thinking this is the code i have come up with to attempt to suit my needs however it still does not work properly for some reason.

ground never gets tilled and items never get traded for maybei i shoul create a sep function for trades and maybe the get_harvest() has some weird priority and i should llower it but thats all i can think of for now
Last edited by Bobby Rooster; Nov 5, 2024 @ 4:35pm
umop-apisdn Nov 5, 2024 @ 7:50pm 
I do see several issues. Try not to get mad, this part is probably going to hurt a little. This is where I tear apart the code you have presented and explain why it's broken... and there's a lot that's broken, here. Set your emotional response aside for a moment, if you can, because I'm also going to explain how to fix most of it.

till() turns turf into soil, or soil into turf. get_ground_type() returns the type of ground at that spot; it will be either Grounds.Soil or Grounds.Turf, but you're only ever checking to see if it's Soil, and tilling all the soil into Turf. This means you will never have soil, which is why carrots and sunflowers are never being planted. It looks like you either don't understand conditional statements, or don't understand what get_ground_type() is doing... either way, you're only ever turning soil into turf in your code.

In main(), you're immediately tilling every piece of soil into turf. This will destroy anything that was planted on soil (if you ever had any soil in the first place). You then check if you can harvest, but the only things left will be hay, bushes, and trees.

Watering() looks okay. If you don't have enough water tanks, you buy more; then you use one of them if the water level on the current square is too low. Perfectly cromulent.

In Planting()...

Hay doesn't need planting, it "just grows" if the ground type is turf... but you're trying to plant grass. I'm betting that's gonna cause problems, although it won't cause the grass to not grow, so at least there's that.

Now, for the trees...

The modulus operator (%) gives back the remainder after division.
examples:
  • 1 % 2 = 1
  • 2 % 2 = 0
  • 25 % 2 = 1
  • 26 % 2 = 0
To summarize, you can use "if (number % 2) == 1" to see if a number is odd.

Trees don't like other trees right next to them. You seem to have figured that out, but you're checking an awful lot of things to figure out where to plant trees, probably because you didn't realize that "x + y" will be even if both numbers are even, even if both numbers are odd, or odd if only one number is even and the other is odd.
What this all comes down to is that you can simplify your "can I plant a tree?" math to:
if (x + y) % 2 == 1: plant(Entities.Tree) else: plant(Entities.Bush)
... but that doesn't matter, because x and y are always going to be whatever they were when you pressed "play", because they're only set once (at the top of your script, outside of any functions or loops). I would get x and y inside of either main(), or movement(). In short, it looks like you don't understand loops, either.

You can't plant(Entities.Carrots) because you've got turf instead of soil. You've tilled all your soil into turf, because you don't understand how get_ground_type() works.

I don't know what your sunflowers section is doing, other than I can see that it isn't going to do anything except perhaps buying seeds, because there's no such thing as Items.Sunflower... Entities.Sunflower, yes, but you can't use num_items() on entities... and all of this is moot, because you try to till() your soil into turf again, after which you fail to plant sunflowers because it's the wrong ground type.

My perception and review:
As far as I can tell, this code doesn't do anything except move around, and maybe harvest the occasional bush, tree, or hay. It feels an awful lot like you have gotten "help" to get to this point in the game, without understanding what the code you've copied is doing... or why. Copying other people's freely-given work is perfectly fine, once you understand what the code does... but you will never learn to program by using other people's code without understanding what that code does.

This game builds your programming knowledge piece by piece, expanding on what you've already learned with the next piece. I think you've tried to skip the "learning" part... but "button mashing" isn't going to help you in this game.

Now, as to what I would do about all of this:

I would recommend starting a new save.
Don't panic! This is not a failure, it's just part of the learning process.
Programming is hard. Like, really hard. It makes your brain do stuff in ways it's not used to; in ways it doesn't want to. It's like learning to juggle, in a sense. One ball is easy. Two balls is a little harder, but still doable. But you have to learn to juggle three balls before you can do five balls and really look cool.
I believe you have too many balls in the air, and nearly zero understanding of what any of those balls do when you throw them... and that's pretty much never going to work.

So: Start a new save.
Go slow.
Unlock one thing at a time, making sure you understand what the new thing you unlocked does (and how it works) before you move on to the next thing.
Read all of the information provided when you unlock things, and try to figure out the ramifications of the new action or item you've unlocked before you run off to the next thing. You will need to understand how what you're doing will affect the things you do afterward.

I'm not being mean when I say this:
Don't bother bringing this current mess with you; it's obviously not your own code... and it doesn't work anyway. Take a few days to wrap your head around "program flow". Once you learn and understand both "programming principles" and how the functions we are given in this scenario work, you will beat the game. Once you have done so, take a look at this old code and realize just how much you didn't "get" at the time.

We've all been there, and I won't lie and tell you that it's easy. Learning hard things is hard... but it can be fun, and it will definitely be incredibly rewarding... once you've finally bashed your head into the wall (figuratively speaking) enough times for it to sink in.
Last edited by umop-apisdn; Nov 5, 2024 @ 8:22pm
Bobby Rooster Nov 5, 2024 @ 10:07pm 
why would u think id be mad lmao im trash at coding i started like 2 months ago i dont have an ego about this unless you enjoy just ♥♥♥♥♥♥♥♥ on ppl, but i thank you for the advice. i will fully dissect this tom and post updates when i can
Bobby Rooster Nov 5, 2024 @ 10:11pm 
oh yeah i def took some liberties with chat gpt lmao, i learned loops last week i barely understand it, but the only way to learn is to bang my head against a wall and fail.
umop-apisdn Nov 7, 2024 @ 2:58am 
Originally posted by Ivins:
change your movement to something like

for i in range(get_world_size()):
##-all your farming needs go here-##

------move(North) ##Moves north 1 tile before repeating the loop##
move(East)

move east will be the last thing ever executed EVER in the entire thing.

A couple quick things:
  • You didn't wrap your code in a [code] block, so you had to write some silly stuff to try to make it format properly... which makes it not copy/paste directly, either. Considering this was the first thing discussed in this thread, it shows you didn't actually pay attention to the discussion... which automatically discounts any value you might have added to the discussion.

  • It doesn't take very long before it becomes apparent that a custom movement function that moves the drone to a specific position is desirable, so calling move(East) and move(North) directly isn't actually useful for very long. It's totally okay to be a newbie... but try not to give information in a manner that suggests you are an authority on the subject when you haven't actually learned or progressed very much yourself, yet.

    To be fair, that previous paragraph may apply to me, too. That being said, I've been slinging code for nearly 40 years, so please do forgive any mild arrogance I may display.

    As an example of move() being less useful as you progress in the game, I will share my movement function; it takes in an x and y coordinate, moves the drone to that position after deciding whether stepping off the edge of the map is faster than moving across the field, then performs a "scan" to get some information about what's in the position it just moved to.

Here's the relevant code (pulled from various source files, but hopefully complete):
(Tagged as a spoiler for obvious reasons, hover to see it)

(Note: This doesn't include any planting/harvesting code, because it's more fun to find those on your own)
# view of the whole "world" world_size = 0 grid_size = 0 grid = [] # fake enum list to make scanning easier ENTITY = 0 IS_GROWN = 1 FLOWER_POWER = 2 WATER = 3 # main loop while True: # adjust worldview if necessary if get_world_size() != world_size: world_size = get_world_size() grid_size = world_size * world_size generate_grid() scan_grid() # move and plant best resource for x in range(world_size): for y in range(world_size): move_to(x, y) # selects what to do next, and does it # (this function is not included in this excerpt, # you'll have to make your own!) make_best_resource() # resets grid to an empty structure # only called when world_size changes # (at the beginning, or when "expand" is unlocked) def generate_grid(): # clear existing data while len(grid) > 0: grid.pop() # generate data structure for column in range(world_size): if column < world_size: grid.append([]) for row in range(world_size): grid[column].append([None,False,None,0]) # ENTITY, IS_GROWN, FLOWER_POWER, WATER # move to new position def move_to(target_x, target_y): if is_moving_forward(target_x, get_pos_x()): direction = East else: direction = West while get_pos_x() != target_x: move(direction) if is_moving_forward(target_y, get_pos_y()): direction = North else: direction = South while get_pos_y() != target_y: move(direction) scan() # is current direction the shortest route to target? def is_moving_forward(target, current): boundary = get_world_size() / 2 if target > current: if abs(target - current) > boundary: return False else: return True else: if abs(target - current) > boundary: return True else: return False # get info about plot at current position def scan(): _x = get_pos_x() _y = get_pos_y() grid[_x][_y][ENTITY] = get_entity_type() grid[_x][_y][IS_GROWN] = can_harvest() grid[_x][_y][FLOWER_POWER] = measure() # grid[_x][_y][WATER] = get_water_level() # removed the above line because now that I have fertilizer, # I'm no longer watering; the water level will always be zero. # left it in for when I start from scratch for some reason # (eg, testing "unlocking" order) # moves through entire field to get current state # - called at the beginning of the script, # when the world size changes, # and after clearing pumpkins, maze, or cactus def scan_grid(): for _x in range(world_size): for _y in range(world_size): move_to(_x, _y)


Further Note: For those in a hurry, the relevant function itself is "move_to(target_x, target_y)". The rest of this wall of text is the supporting code that either calls that function, or makes it work (such as "is_moving_forward()", which checks that moving in one direction will result in a shorter "distance to target" than moving in the opposite direction).

Note 2: "scan()"ing every square I move to probably isn't the best way to do things, and rereading this code while I was grabbing the various pieces has shown me some refactoring targets... but my goal was "perfect vision" and "efficient movement". To be completely honest, I'm almost certain that doing it this way actively slows specific algorithms I've seen described in some "Let's Play" videos ("sunflowers by array" springs immediately to mind)... but it means I never have to think about what might or might not be underneath the drone when it arrives at a given square, because that information has already been gathered. Feel free to remove the "scan()" at the end of move_to(), and go on your merry way. Do be sure to grab is_moving_forward() on your way by, since move_to() in its current form doesn't work without it.

Note 3: I also always call scan() after changing the contents of a plot; ie, if I till, plant, harvest, water, or swap (although I stopped watering when I unlocked fertilizer). Yes, it costs a few ops to do so, but it keeps everything up-to-date; I feel the accuracy is more important at this phase in my journey toward "beating the game".

Note 4: This is probably an overly-large chunk of code to explain my point... but I wanted to show how it was used, as well as what it was doing. Sorry for the resulting wall of text.
Last edited by umop-apisdn; Nov 7, 2024 @ 4:01am
Bobby Rooster Nov 7, 2024 @ 11:15am 
Originally posted by Ivins:
change your movement to something like

for i in range(get_world_size()):
##-all your farming needs go here-##

------move(North) ##Moves north 1 tile before repeating the loop##
move(East)

move east will be the last thing ever executed EVER in the entire thing.



my movement is fine im quite happy with it, it does what i needs to do, what i am unhappy with is why my conditionals arent working
Bobby Rooster Nov 7, 2024 @ 11:21am 
Originally posted by umop-apisdn:
Originally posted by Ivins:
change your movement to something like

for i in range(get_world_size()):
##-all your farming needs go here-##

------move(North) ##Moves north 1 tile before repeating the loop##
move(East)

move east will be the last thing ever executed EVER in the entire thing.

A couple quick things:
  • You didn't wrap your code in a [code] block, so you had to write some silly stuff to try to make it format properly... which makes it not copy/paste directly, either. Considering this was the first thing discussed in this thread, it shows you didn't actually pay attention to the discussion... which automatically discounts any value you might have added to the discussion.

  • It doesn't take very long before it becomes apparent that a custom movement function that moves the drone to a specific position is desirable, so calling move(East) and move(North) directly isn't actually useful for very long. It's totally okay to be a newbie... but try not to give information in a manner that suggests you are an authority on the subject when you haven't actually learned or progressed very much yourself, yet.

    To be fair, that previous paragraph may apply to me, too. That being said, I've been slinging code for nearly 40 years, so please do forgive any mild arrogance I may display.

    As an example of move() being less useful as you progress in the game, I will share my movement function; it takes in an x and y coordinate, moves the drone to that position after deciding whether stepping off the edge of the map is faster than moving across the field, then performs a "scan" to get some information about what's in the position it just moved to.

Here's the relevant code (pulled from various source files, but hopefully complete):
(Tagged as a spoiler for obvious reasons, hover to see it)

(Note: This doesn't include any planting/harvesting code, because it's more fun to find those on your own)
# view of the whole "world" world_size = 0 grid_size = 0 grid = [] # fake enum list to make scanning easier ENTITY = 0 IS_GROWN = 1 FLOWER_POWER = 2 WATER = 3 # main loop while True: # adjust worldview if necessary if get_world_size() != world_size: world_size = get_world_size() grid_size = world_size * world_size generate_grid() scan_grid() # move and plant best resource for x in range(world_size): for y in range(world_size): move_to(x, y) # selects what to do next, and does it # (this function is not included in this excerpt, # you'll have to make your own!) make_best_resource() # resets grid to an empty structure # only called when world_size changes # (at the beginning, or when "expand" is unlocked) def generate_grid(): # clear existing data while len(grid) > 0: grid.pop() # generate data structure for column in range(world_size): if column < world_size: grid.append([]) for row in range(world_size): grid[column].append([None,False,None,0]) # ENTITY, IS_GROWN, FLOWER_POWER, WATER # move to new position def move_to(target_x, target_y): if is_moving_forward(target_x, get_pos_x()): direction = East else: direction = West while get_pos_x() != target_x: move(direction) if is_moving_forward(target_y, get_pos_y()): direction = North else: direction = South while get_pos_y() != target_y: move(direction) scan() # is current direction the shortest route to target? def is_moving_forward(target, current): boundary = get_world_size() / 2 if target > current: if abs(target - current) > boundary: return False else: return True else: if abs(target - current) > boundary: return True else: return False # get info about plot at current position def scan(): _x = get_pos_x() _y = get_pos_y() grid[_x][_y][ENTITY] = get_entity_type() grid[_x][_y][IS_GROWN] = can_harvest() grid[_x][_y][FLOWER_POWER] = measure() # grid[_x][_y][WATER] = get_water_level() # removed the above line because now that I have fertilizer, # I'm no longer watering; the water level will always be zero. # left it in for when I start from scratch for some reason # (eg, testing "unlocking" order) # moves through entire field to get current state # - called at the beginning of the script, # when the world size changes, # and after clearing pumpkins, maze, or cactus def scan_grid(): for _x in range(world_size): for _y in range(world_size): move_to(_x, _y)


Further Note: For those in a hurry, the relevant function itself is "move_to(target_x, target_y)". The rest of this wall of text is the supporting code that either calls that function, or makes it work (such as "is_moving_forward()", which checks that moving in one direction will result in a shorter "distance to target" than moving in the opposite direction).

Note 2: "scan()"ing every square I move to probably isn't the best way to do things, and rereading this code while I was grabbing the various pieces has shown me some refactoring targets... but my goal was "perfect vision" and "efficient movement". To be completely honest, I'm almost certain that doing it this way actively slows specific algorithms I've seen described in some "Let's Play" videos ("sunflowers by array" springs immediately to mind)... but it means I never have to think about what might or might not be underneath the drone when it arrives at a given square, because that information has already been gathered. Feel free to remove the "scan()" at the end of move_to(), and go on your merry way. Do be sure to grab is_moving_forward() on your way by, since move_to() in its current form doesn't work without it.

Note 3: I also always call scan() after changing the contents of a plot; ie, if I till, plant, harvest, water, or swap (although I stopped watering when I unlocked fertilizer). Yes, it costs a few ops to do so, but it keeps everything up-to-date; I feel the accuracy is more important at this phase in my journey toward "beating the game".

Note 4: This is probably an overly-large chunk of code to explain my point... but I wanted to show how it was used, as well as what it was doing. Sorry for the resulting wall of text.
+


this is solid code but i have to unlock lists to make this function this will serve as a great refrence point for the future ty.
Ivins Nov 7, 2024 @ 7:21pm 
Originally posted by umop-apisdn:
Originally posted by Ivins:
change your movement to something like

for i in range(get_world_size()):
##-all your farming needs go here-##

------move(North) ##Moves north 1 tile before repeating the loop##
move(East)

move east will be the last thing ever executed EVER in the entire thing.

A couple quick things:
  • You didn't wrap your code in a [code] block, so you had to write some silly stuff to try to make it format properly... which makes it not copy/paste directly, either. Considering this was the first thing discussed in this thread, it shows you didn't actually pay attention to the discussion... which automatically discounts any value you might have added to the discussion.

  • It doesn't take very long before it becomes apparent that a custom movement function that moves the drone to a specific position is desirable, so calling move(East) and move(North) directly isn't actually useful for very long. It's totally okay to be a newbie... but try not to give information in a manner that suggests you are an authority on the subject when you haven't actually learned or progressed very much yourself, yet.

    To be fair, that previous paragraph may apply to me, too. That being said, I've been slinging code for nearly 40 years, so please do forgive any mild arrogance I may display.

    As an example of move() being less useful as you progress in the game, I will share my movement function; it takes in an x and y coordinate, moves the drone to that position after deciding whether stepping off the edge of the map is faster than moving across the field, then performs a "scan" to get some information about what's in the position it just moved to.

Here's the relevant code (pulled from various source files, but hopefully complete):
(Tagged as a spoiler for obvious reasons, hover to see it)

(Note: This doesn't include any planting/harvesting code, because it's more fun to find those on your own)
# view of the whole "world" world_size = 0 grid_size = 0 grid = [] # fake enum list to make scanning easier ENTITY = 0 IS_GROWN = 1 FLOWER_POWER = 2 WATER = 3 # main loop while True: # adjust worldview if necessary if get_world_size() != world_size: world_size = get_world_size() grid_size = world_size * world_size generate_grid() scan_grid() # move and plant best resource for x in range(world_size): for y in range(world_size): move_to(x, y) # selects what to do next, and does it # (this function is not included in this excerpt, # you'll have to make your own!) make_best_resource() # resets grid to an empty structure # only called when world_size changes # (at the beginning, or when "expand" is unlocked) def generate_grid(): # clear existing data while len(grid) > 0: grid.pop() # generate data structure for column in range(world_size): if column < world_size: grid.append([]) for row in range(world_size): grid[column].append([None,False,None,0]) # ENTITY, IS_GROWN, FLOWER_POWER, WATER # move to new position def move_to(target_x, target_y): if is_moving_forward(target_x, get_pos_x()): direction = East else: direction = West while get_pos_x() != target_x: move(direction) if is_moving_forward(target_y, get_pos_y()): direction = North else: direction = South while get_pos_y() != target_y: move(direction) scan() # is current direction the shortest route to target? def is_moving_forward(target, current): boundary = get_world_size() / 2 if target > current: if abs(target - current) > boundary: return False else: return True else: if abs(target - current) > boundary: return True else: return False # get info about plot at current position def scan(): _x = get_pos_x() _y = get_pos_y() grid[_x][_y][ENTITY] = get_entity_type() grid[_x][_y][IS_GROWN] = can_harvest() grid[_x][_y][FLOWER_POWER] = measure() # grid[_x][_y][WATER] = get_water_level() # removed the above line because now that I have fertilizer, # I'm no longer watering; the water level will always be zero. # left it in for when I start from scratch for some reason # (eg, testing "unlocking" order) # moves through entire field to get current state # - called at the beginning of the script, # when the world size changes, # and after clearing pumpkins, maze, or cactus def scan_grid(): for _x in range(world_size): for _y in range(world_size): move_to(_x, _y)


Further Note: For those in a hurry, the relevant function itself is "move_to(target_x, target_y)". The rest of this wall of text is the supporting code that either calls that function, or makes it work (such as "is_moving_forward()", which checks that moving in one direction will result in a shorter "distance to target" than moving in the opposite direction).

Note 2: "scan()"ing every square I move to probably isn't the best way to do things, and rereading this code while I was grabbing the various pieces has shown me some refactoring targets... but my goal was "perfect vision" and "efficient movement". To be completely honest, I'm almost certain that doing it this way actively slows specific algorithms I've seen described in some "Let's Play" videos ("sunflowers by array" springs immediately to mind)... but it means I never have to think about what might or might not be underneath the drone when it arrives at a given square, because that information has already been gathered. Feel free to remove the "scan()" at the end of move_to(), and go on your merry way. Do be sure to grab is_moving_forward() on your way by, since move_to() in its current form doesn't work without it.

Note 3: I also always call scan() after changing the contents of a plot; ie, if I till, plant, harvest, water, or swap (although I stopped watering when I unlocked fertilizer). Yes, it costs a few ops to do so, but it keeps everything up-to-date; I feel the accuracy is more important at this phase in my journey toward "beating the game".

Note 4: This is probably an overly-large chunk of code to explain my point... but I wanted to show how it was used, as well as what it was doing. Sorry for the resulting wall of text.


discord mod ahhh reply, writing so much extra ♥♥♥♥ to get the same results
Last edited by Ivins; Nov 7, 2024 @ 7:26pm
umop-apisdn Nov 7, 2024 @ 8:46pm 
Originally posted by Ivins:
discord mod ahhh reply, writing so much extra ♥♥♥♥ to get the same results

How well does the movement code you shared handle sunflowers?

Care to race? We plant a full 10x10 grid of sunflowers; first one to clear the field by harvesting the flowers in the correct order wins... no fair saying you cleared the field because the first sunflower you harvested destroyed them all.

For that matter, how are you handling the Maze levels at all if you're only moving North and East?

Now that I think about it, I suppose my entire comment boils down to "tell us you haven't figured out how to beat the game without saying you haven't beaten the game"... or maybe "Try again when you get past pumpkins."
Last edited by umop-apisdn; Nov 7, 2024 @ 8:49pm
Ivins Nov 7, 2024 @ 9:33pm 
Originally posted by umop-apisdn:
Originally posted by Ivins:
discord mod ahhh reply, writing so much extra ♥♥♥♥ to get the same results

How well does the movement code you shared handle sunflowers?

Care to race? We plant a full 10x10 grid of sunflowers; first one to clear the field by harvesting the flowers in the correct order wins... no fair saying you cleared the field because the first sunflower you harvested destroyed them all.

For that matter, how are you handling the Maze levels at all if you're only moving North and East?

Now that I think about it, I suppose my entire comment boils down to "tell us you haven't figured out how to beat the game without saying you haven't beaten the game"... or maybe "Try again when you get past pumpkins."

nowhere did I say i only move north and east, I offered the newbie a solution he can understand very easily. Just going to block your snarky discord mod ahhh elitist attitude.
< >
Showing 1-15 of 17 comments
Per page: 1530 50