The Farmer Was Replaced

The Farmer Was Replaced

Pumpkin and Sunflower Code
Thought some might find it helpful. Not necessarily the most efficient ways to do this, but they work. Pumpkin routine basically waits until your entire farm is full of pumpkins for maximum return, then harvests. Sunflower plants the field full, finds the sunflower with the most petals, harvests and replants, and then rescans the field (thinking about how to do a map so I don't have to rescan every time, but don't see a convenient two dimensional array :P).

PUMPKINS
##Define Return Home Function def home(): for i in range(get_pos_x()): move(West) for i in range(get_pos_y()): move(South) ##Harvest anything left in the field and return to 0,0 for i in range (get_world_size()): for i in range (get_world_size()): if can_harvest(): harvest() move(North) move(East) home() ##Make sure fields are tilled / tiles are Ground type Soil for i in range (get_world_size()): for i in range (get_world_size()): if get_ground_type() == Grounds.Turf: till() move(North) move(East) home() #Farming loop, plant pumpkins until all are successfully grown #Then harvest when entire field is full while True: fullTiles = 0 for i in range (get_world_size()): for i in range (get_world_size()): if get_entity_type != Entities.Pumpkin: if can_harvest(): fullTiles = fullTiles +1 if num_items(Items.Pumpkin_Seed) < 1: trade(Items.Pumpkin_Seed) if num_items(Items.Pumpkin_Seed) == 0: break plant(Entities.Pumpkin) move(North) move(East) if fullTiles == get_world_size() * get_world_size(): harvest()


SUNFLOWERS (look 3 posts down for a better one)
def home(): for i in range(get_pos_x()): move(West) for i in range(get_pos_y()): move(South) for i in range (get_world_size()): for i in range (get_world_size()): if get_ground_type() == Grounds.Turf: till() move(North) move(East) home() if num_items(Items.Sunflower_Seed) <100: trade(Items.Sunflower_Seed, 100) if num_items(Items.Sunflower_Seed) <100: break for i in range (get_world_size()): for i in range (get_world_size()): plant(Entities.Sunflower) move(North) move(East) home() while True: petals = 0 targetx = 0 targety = 0 for i in range (get_world_size()): for i in range (get_world_size()): if measure() > petals: petals = measure() targetx = get_pos_x() targety = get_pos_y() quick_print("New Target:",targetx,",",targety,"=",petals) move(North) move(East) home() for i in range (targetx): move(East) for i in range (targety): move(North) harvest() trade(Items.Sunflower_Seed) trade(Items.Fertilizer) plant(Entities.Sunflower) use_item(Items.Fertilizer) home()
< >
Showing 1-9 of 9 comments
Here is my sunflow code that does the following:
  1. Plants everything and gets the power at the same time (Conveniently the power for the sunflower is shown prior to it being fully grown)
  2. Creates a list of the highest sunflowers
  3. Harvests just them
  4. Replants the spots it harvested and gets the power
  5. Repeats everything from 2 downwards.

It might be more efficient to wait for the sunflowers to fully grow prior to harvesting but in the grand scheme I don't think it matters

def plant_sunflowers(): if num_items(Items.Sunflower_Seed) < 1: trade(Items.Sunflower_Seed) if get_ground_type() != Grounds.Soil: till() if get_entity_type != Entities.Sunflower: plant(Entities.Sunflower) def sow_sunflowers(): sunflower_map = [] move_to_position(0,0) for i in range(get_world_size()): for i in range(get_world_size()): check_water(80) plant_sunflowers() x, y = get_pos_x(), get_pos_y() value = measure() sunflower_map.append((x, y, value)) move(North) move(East) return sunflower_map def check_sunflowers(sunflower_map, max_value): max_power_positions = [] count = 0 for item in sunflower_map: value = item[2] if value > max_value: max_value = value for item in sunflower_map: x, y, value = item if value == max_value: max_power_positions.append((x, y, value, count)) count += 1 for item in max_power_positions: checker = [] x, y, value, count = item move_to_position(x, y) harvest() for item in max_power_positions: x, y, value, count = item move_to_position(x, y) check_water(80) plant_sunflowers() x, y = get_pos_x(), get_pos_y() new_value = measure() sunflower_map.remove([x, y, value]) sunflower_map.insert(count, ([x, y, new_value])) def farm_sunflowers(n): move_to_start(True, True) sunflower_map = sow_sunflowers() while num_items(Items.Power) < n: max_value = 0 check_sunflowers(sunflower_map, max_value) farm_sunflowers(100000)
Nice! I didn't think to look for the highest X number of positions and harvest them
Here's my latest - similar idea to yours, but I figured out a way to correlate a list index to X,Y coordinates on a grid of an arbitrary size, which let me reference things a bit more directly. I've also got a few general purpose functions I made wrapped in here, which might also be helpful for people (tillPrep, for example):

clear() tillPrep(3) grid = fullSFScan() while True: matches = index(max(grid),grid) quick_print(grid) quick_print(matches) for i in range(len(matches)): dest = gridConvert(matches)
moveto(dest[0],dest[1])
harvest()
for i in range(len(matches)):
dest = gridConvert(matches)
moveto(dest[0],dest[1])
trade(Items.Sunflower_Seed)
plant(Entities.Sunflower)
grid[matches[i]] = measure()

def fullSFScan():
grid = []
home()
for i in range (get_world_size()):
for i in range (get_world_size()):
grid.append(measure())
move(North)
move(East)
return grid

def gridConvert(n):
gridsize = get_world_size()
yval = n % gridsize
xval = n // gridsize
return xval,yval

#Pass value 0 to plant nothing (empty soil), 1 = Carrots, 2 = Pumpkin, 3 = Sunflower, 4=Cactus
def tillPrep(n):
crop = [0,Entities.Carrots,Entities.Pumpkin,Entities.Sunflower,Entities.Cactus]
seed = [0,Items.Carrot_Seed,Items.Pumpkin_Seed,Items.Sunflower_Seed,Items.Cactus_Seed]
seedcount = num_items(seed[n])
##Harvest anything left in the field and return to 0,0
##Then till to soil, obtain seeds if needed, and plant
if n != 0:
if seedcount < (get_world_size())**2:
trade(seed[n], (get_world_size())**2)
for i in range (get_world_size()):
for i in range (get_world_size()):
harvest()
if get_ground_type() == Grounds.Turf:
till()
if n != 0:
plant(crop[n])
move(North)
move(East)
home()

def home():
for i in range(get_pos_x()):
move(West)
for i in range(get_pos_y()):
move(South)

def index(val,listname):
matches = []
for i in range (len(listname)):
if val == listname:
matches.append(i)
return matches
#[/code]
@fiordhraoi tried your sunflower code and cant get it to run for long, scans field and rescan before harvest that uses alot of power, also idk why but harvest yield isn't high running this, i tried a simply one as my first to just harvest is petals = 15 and on a 8x8 field i had 400 power in 3 seconds. your code seems to yield about 600 in 10 mins but then it goes down and if left running will only have 7 power before losing it to scan field to harvest one flower.

I'm in no way a coder or know a solution but having it harvest multiply could be tough but a better option, also would it be able to harvest, plant, then just measure the flower you just planted? meaning you dont have to rescan??
Originally posted by PR Deserthawk:
...

I'm in no way a coder or know a solution but having it harvest multiply could be tough but a better option, also would it be able to harvest, plant, then just measure the flower you just planted? meaning you dont have to rescan??

Check out the guide I wrote,

I talk about a few of the pitfalls that can happen as well as some strategies that can be employed to get better yields.

https://steamcommunity.com/sharedfiles/filedetails/?id=3267422323

Also this post
https://steamcommunity.com/app/2060160/discussions/0/4336483474864379263/

Has a good amount of information between myself and other being talked about.
Originally posted by PR Deserthawk:
@fiordhraoi tried your sunflower code and cant get it to run for long, scans field and rescan before harvest that uses alot of power, also idk why but harvest yield isn't high running this, i tried a simply one as my first to just harvest is petals = 15 and on a 8x8 field i had 400 power in 3 seconds. your code seems to yield about 600 in 10 mins but then it goes down and if left running will only have 7 power before losing it to scan field to harvest one flower.

I'm in no way a coder or know a solution but having it harvest multiply could be tough but a better option, also would it be able to harvest, plant, then just measure the flower you just planted? meaning you dont have to rescan??

I did notice in testing that my solution doesn't work well with smaller fields, and I was doing this on a 10x10, maybe that's why? I'll go back and look at my measurements, but from what I recall, I was making close to ~1k per minute.

I'm going to take a look at Owen's guide as well. I certainly didn't do a ton of optimization, so there are almost definitely more profitable ways. Mine was "it only takes me a couple minutes to get enough power for the speed upgrade." :)
In regards to the Sunflower method:

I would be interested in what your power/min average is. Because I used to do something similar until I wanted to optimize it. But if you re-read the document carefully you will notice that most of what you are doing is unnecessary if going for max power/s.

The most efficient method I found is pre-tilling and then planting a sunflower on every field and staying on the x0 y0 field and replanting with fertilizer until the sunflower has 15 petals and then harvest, then repeat because harvesting only the 15 petal sunflower wont reset the field.

With max upgrades and power I get an average of 9096/min using this method. I just did a test and got 45480 power over 5 minutes which equals to 9096/min or 151.6/s.

I've done a couple optimization passes on this code to reduce operation count:

Requirement: Fertilizer Unlocked
# Author: xC0DEB10C def farm_sunflower(): clear() pre_till() world_size_range = range(get_world_size()) for i in world_size_range: for j in world_size_range: if(num_items(Items.Sunflower_Seed) == 0): if(num_items(Items.Carrot) > 100 * 6): trade(Items.Sunflower_Seed, 100) else: print("Missing Carrots for Sunflower Seeds") plant(Entities.Sunflower) move(North) move(East) while(True): while(measure() != 15): till() till() if(num_items(Items.Sunflower_Seed) == 0): if(num_items(Items.Carrot) > 100 * 6): trade(Items.Sunflower_Seed, 100) else: print("Missing Carrots for Sunflower Seeds") plant(Entities.Sunflower) while(not can_harvest()): use_fertilizer() continue harvest()

And this is the use_fertilizer() function:
# Author: xC0DEB10C def use_fertilizer(): if(num_items(Items.Fertilizer) == 0): if(num_items(Items.Pumpkin) > 100 * 10): trade(Items.Fertilizer, 100) else: print("Missing Pumpkins to buy Fertilizer") use_item(Items.Fertilizer)

(Tabs have been replaced with 4 spaces for compact readability)
I'll also add my Pumpkin Code which I just finished optimizing. I found, that making sure each field has a "successful" pumpkin on it by using fertilizer and double checking during the first pass is more efficient than going over it multiple times or any other attempt I've seen.

# Author: xC0DEB10C def farm_pumpkin(): clear() pre_till() world_size_range = range(get_world_size()) while True: for i in world_size_range: for j in world_size_range: while(not can_harvest()): if(get_entity_type() != Entities.Pumpkin): if(num_items(Items.Pumpkin_Seed) == 0): if(num_items(Items.Carrot) > 100 * 10): trade(Items.Pumpkin_Seed, 100) else: print("Missing Carrots for Pumpkin Seeds") plant(Entities.Pumpkin) use_fertilizer() move(North) move(East) harvest()
(Tabs have been replaced with 4 spaces for compact readability)
Fast and Efficient!
I love seeing the different ways people have approached the sunflower harvesting. I'll offer my method, along with it's helper-function "move_to". I believe my solution is quite efficient since it doesn't require scanning the entire field multiple times.

Some Notes:
  • you must have sufficient pumpkins and carrots to trade for fertilizer and sunflower seeds, as well as Multi_Trade unlocked.
  • You could modify this to avoid fertilizing if desired (just do a flip until can_harvest is true).

#create a list to store pedal count and location info for each flower pedals=[] move_to(0,0) initialize_field() #plants and measures full farm while True: #Find the max flower, go to it, harvest, replant and repeat harvest_max_pedal_flower() def move_to(destx, desty): startx = get_pos_x() starty = get_pos_y() ymove = desty - starty xmove = destx - startx if ymove > 0: for y in range(ymove): move(North) elif ymove < 0: for y in range(ymove*-1): move(South) if xmove > 0: for x in range(xmove): move(East) elif xmove < 0: for x in range(xmove*-1): move(West) def initialize_field(): #assuming you have multi-trade unlocked, get enough seed for the field trade(Items.Sunflower_Seed, max(0, get_world_size()**2-num_items(Items.Sunflower_Seed))) trade(Items.Fertilizer, max(0, get_world_size()**2 - num_items(Items.Fertilizer))) #loop through the field, tilling and watering if needed, plant, fertilize #record the pedal count, and x & y location in a 'list of lists' called pedals for y in range(get_world_size()): for x in range(get_world_size()): if get_entity_type() != Entities.Sunflower: harvest() if get_ground_type() != Grounds.Soil: till() while get_water() < 1 and num_items(Items.Water_Tank)>0: use_item(Items.Water_Tank) plant(Entities.Sunflower) use_item(Items.Fertilizer) pedals.append([measure(), get_pos_x(), get_pos_y()]) move(North) move(East) def harvest_max_pedal_flower(): #the max function will use the first value (pedal count) in the list of 'triples' maxpedal = max(pedals) #stores the size, x, and y of the winner move_to(maxpedal[1],maxpedal[2]) harvest() #remove the winner from the list after harvesting, then replant and measure pedals.remove(maxpedal) #restock fertilizer and sunflower seed trade(Items.Fertilizer) trade(Items.Sunflower_Seed) if get_ground_type() != Grounds.Soil: till() while get_water() < 1 and num_items(Items.Water_Tank)>0: use_item(Items.Water_Tank) plant(Entities.Sunflower) use_item(Items.Fertilizer) #record the info for the new flower, then repeat all this to go to the new winner pedals.append([measure(),get_pos_x(),get_pos_y()])
< >
Showing 1-9 of 9 comments
Per page: 1530 50

Date Posted: Jun 11, 2024 @ 9:43pm
Posts: 9