The Farmer Was Replaced

The Farmer Was Replaced

gravia Dec 10, 2024 @ 5:21am
My attempt at this game
So technically I'm a software engineer, so it's always fun to try a new approach to various languages within games. Like python in this game. Given that python is not my strongest language I figured I'd toss in here what I've got so far, and see if people are willing to share optimizations and other tweaks I could add.
I'm always willing to learn, and I am definitely not great at seeing everything, which means that I too make mistakes and I'm happy to see insights of other people here!

For instance, one issue I'm experiencing is that the bot doesn't wait for all 4 pumpkins (in this instance) to be fully grown and allow it to become a mega pumpkin before harvesting.


I've updated the code
So here's my main:
# define global variables axis_size = get_world_size() # Clear everything and start over clear() # main loop while True: # loop over x-axis for x in range(axis_size): # loop over y-axis for y in range(axis_size): if x <= 2 and y <= 2: block(Entities.Grass, False) if x <= 2 and y > 2: block(Entities.Tree, True) if x > 2 and y <= 2: block(Entities.Carrots) if x > 2 and y > 2: block(Entities.Pumpkin, True) move(North) move(East)

here's my various definitions:

general_definitions
# manual move to location def move_to(xpos, ypos): while get_pos_x() != xpos: move(East) while get_pos_y() != ypox: move(North) def harvest_block(allow_till = False): if can_harvest(): harvest() if allow_till and get_ground_type() == Grounds.Turf: till() if not allow_till and get_ground_type() == Grounds.Soil: till() def purchase(item): if num_items(item) == 0: trade(item, 1) def block(type, allow_harvest = False): if type == Entities.Grass: harvest_block() return if type == Entities.Carrots: prep(type) harvest_block(True) purchase(Items.Carrot_Seed) plant(Entities.Carrots) return if type == Entities.Pumpkin: prep(type) if get_entity_type() == Entities.Pumpkin: if can_harvest() and not allow_harvest: do_a_flip() if can_harvest() and allow_harvest: harvest_block(True) purchase(Items.Pumpkin_Seed) plant(Entities.Pumpkin) if get_entity_type() == None: purchase(Items.Pumpkin_Seed) plant(Entities.Pumpkin) return if type == Entities.Tree: prep(type) if (get_pos_x() % 2 != 0 and get_pos_y() % 2 == 0) or (get_pos_x() % 2 == 0 and get_pos_y() % 2 != 0): harvest_block(True) plant(Entities.Tree) else: harvest_block(False) return def prep(type): if get_entity_type() != type: harvest_block(True)
Last edited by gravia; Dec 10, 2024 @ 8:40am
< >
Showing 1-3 of 3 comments
gravia Dec 10, 2024 @ 5:52am 
Originally posted by umop-apisdn:
Your clear_all() could just be the built-in clear(); it makes the field all grass on turf, and moves the drone to the bottom-left corner.
Oh, I didn't notice this one, that might actually be a very good update!

Originally posted by umop-apisdn:
You might want to give your move_to_base() some arguments, so you can move_to(x_coord, y_coord). You can do some default value trickery to get it to accept a coordinate tuple as well as separate x/y coords, but that's really more work than it's worth unless you're storing your coordinates as (x,y) everywhere else, too.
This might be a fun exercise, I'll give it a shot. But like you said, it might be more work than it's worth hehe.

Originally posted by umop-apisdn:
Your tilling function is built into your harvest function, but you're tilling separately. Pick one method or the other, and use it that way consistently in the rest of the project.
This is probably already updated, I think I saw this too just after I posted this message. But I'll have a look just to be sure. I'll see if I can edit with new code after I process all of this hehe

Originally posted by umop-apisdn:
Your purchase function effectively changes "trade(item)" to "purchase(item)". Why?
Just to make sure that it only trade(item) when the "num_items(item) == 0" (or less than 1) it's an extra step, but I don't like repeating myself every time I have to do this (for now only pumpkin and carrots but later prolly others too)

Originally posted by umop-apisdn:
Look in your main loop at how you're counting pumpkins to figure out why you're harvesting too soon... and you may need the little tidbit of info that when they reach the point where they should acquire maximum growth, pumpkins have a chance to fail and despawn (this is by design). Perhaps look more closely at the plot you're over, and/or don't count your pumpkins before they hatch.
Hrm, this seems like something I should probably have looked at and might have forgotten hehe. Thanks, I'll have a deeper look into this.

Originally posted by umop-apisdn:
Final thoughts on your current situation:
- It seems to take a tick for a pumpkin to recognize that it should form a mega-pumpkin with its neighbors.
- Doing a flip takes exactly 1 second.
[/quote]
<3 I might actually flip first then hehe. Backflip before harvest seems like a great idea!
drax14 Dec 16, 2024 @ 12:03am 
I do it this way
plant a field of pumpkins
second round
don't harvest the pumpkins plant them wait for them to grow
you can count the number of pumpkins that have already grown and therefore won't dry out and end the cycle
harvest
Leo Dec 17, 2024 @ 2:53pm 
interesting i got this:

if (get_pos_x() % 2 != 0 and get_pos_y() % 2 == 0) or (get_pos_x() % 2 == 0 and get_pos_y() % 2 != 0)

as

if (get_pos_x() + and get_pos_y()) % 2 == 0:
Last edited by Leo; Dec 17, 2024 @ 2:53pm
< >
Showing 1-3 of 3 comments
Per page: 1530 50