Sunflowers are my BEST Python-Automated Crop
Vložit
- čas přidán 11. 09. 2024
- Program and optimize a drone to automate a farm and watch it do the work for you. Collect resources to unlock better technology and become the most efficient farmer in the world. Improve your problem solving and coding skills.
Check out The Farmer was Replaced here:
-- store.steampow...
Check out my Python tutorials:
• VARIABLES, TYPES, AND ...
#games #olexa #strategy #farming #automation #programming
Thanks for watching!
-- Extra Olexa Content - / @olexa2
-- Discord: / discord
-- Twitch: / olexastream
-- Twitter: / olexayt
-- Reddit: / olexa
-- My Nexus Gamestore: www.nexus.gg/o...
-- CZcams: / olexayt
-- Business Email: olexakid@gmail.com
-- Join this channel to get access to perks:
/ @olexayt
Music I Use:
-- www.bensound.c...
-- Spring by Ikson
-- Harris Heller Streambeats Lofi Spring by Ikson | ikson.com/tell...
Music promoted by www.free-stock...
What up with the goto function at 12:50 - 14:21 ? Seems like it wasn't needed
Oh oops. Editing error on my part. Left over from the previous video. Sorry about this everyone!
@@OlexaYTI forgive you Tyler don’t worry
Fun fact: you can measure the sunflower's petals before it's fully grown. That means you can generate the petals list immediately on the planting loop, without needing to scan through a second one.
Also, when you harvest the biggest sunflower, you can immediately replant, measure it, add it into your data, and run the program for hundreds of iterations at once, each time getting the maximum power from one flower harvest. If it runs long enough, eventually all sunflowers have 7 petals except possibly for the one you replant, so that's a potential use case for fertilizer to spam farm a single tile (probably overkill for power at that point though).
It's interesting to see the strategy you used for the internal data, because it's completely different to mine - I make a 3D array, storing flower coordinates indexed by their measured petal count. As the data is built up, it is structured in a way that naturally orders the flowers by their petals, so I don't need to use the max() function at all; I just go to harvest one from the last category. When I replant, I insert the new flower in the structure where it fits, and carry on.
Here's my code, for anyone interested. As utility functions, buy() is my custom trade up to a desired threshold, cut() is my custom lossless harvest, irrigate() is my custom watering up to a desired threshold.
def Sunflowers(REPEATS):
size = get_world_size()
buy(Items.Sunflower_Seed, size ** 2 + REPEATS)
# generate 3D data structure, of positions indexed by petal count
Data = []
for i in range(size):
for i in range(size):
if get_ground_type() == Grounds.Turf:
till()
if get_entity_type() != Entities.Sunflower:
cut()
plant(Entities.Sunflower)
irrigate(1)
petals = measure()
while len(Data) 0:
biggest = len(Data) - 1
goto(Data[biggest][0][0], Data[biggest][0][1])
Data[biggest].pop(0)
cut()
plant(Entities.Sunflower)
irrigate(1)
petals = measure()
while len(Data)
Well, sitting in one place and growing sunflower with fertilizer is the fastest way to collect power, but it eats too much fertilizer. Second best for me was stupid scanning field. It makes more power in 1 min that smarter finding way to the biggest petal. My code is:
need_power(num_items(Items.Power)+50000)
def need_power(power):
while num_items(Items.Power)0: # collecting part
for x_coord in range(get_world_size()):
for y_coord in range(get_world_size()):
i = (get_world_size() * x_coord + y_coord)
if y_coord == 0: # check for skipping line
this_line_pedals = []
for t in range(get_world_size()):
this_line_pedals.append(pedals[i+t])
if max(pedals) > max(this_line_pedals):
move(East) # there is no max petals, skipping line
break
elif max(this_line_pedals) == 0:
move(East) # there is no sunflowers at all
break
if pedals[i] == max(pedals):
harvest()
pedals.pop(i)
pedals.insert(i, 0) # not messing pedals index
if y_coord == (get_world_size()-1):
move(East)
move(North)
else:
move(North)
could you explain what a lossless harvest is? im assuming time but im not 100% on it.
and how exactly is your list working? as far as i can tell its storing multiple X,Y data on one number like a key in a dict? but it storing all positions of that number of petal in one entry isnt something ive seen before
this might be worded horribly, sorry, but im only intermediate (at best) at programming and this game is interesting enough to give a push, so id appreciate any explaination youre willing to give
@@SlyStorm-kj9wh
1. The base function harvest() will just destroy the crop underneath if it isn't fully grown, wasting all the time spent growing up to that point, so my custom function waits over the crop until it's grown, before harvesting. I first need to make it check that something exists to wait for, otherwise it could get stuck waiting on an empty square. This custom function can be safely called in any board situation, and so I use it in every farming program:
def cut():
if get_entity_type() != None:
while True:
if can_harvest():
harvest()
break
2. For the data storage: it's a list of lists of lists. I.e., it's 3-dimensional. You can have lists being individual elements in other lists. List inception. :P
Think of it like a cabinet with shelves, and folders in the shelves, with each folder containing 2 sheets of paper for a coordinate pair. The base list named Data is the entire cabinet. Each shelf, Data[a], has an index 'a' on the cabinet (for petal count). Each shelf is its own list. Each folder Data[a][b] has an index 'b' in the shelf's list (for the chronological order of being placed inside). It is also a list itself, containing 2 elements (the x & y values, Data[a][b][c] for c = 0 or 1, respectively). So, the y value of the 3rd oldest flower added with 7 petals is at Data[7][2][1] , 7 for the 8th shelf, 2 for the 3rd folder from the front, and [1] for its y coordinate.
The cabinet starts as an empty list, with no shelves. Upon measuring a flower to add into it, the very first thing that needs to be done is to add empty shelves to the cabinet, from the bottom up, to have a correct shelf to put the folder into. Each time a flower has more petals than the cabinet has shelves, the cabinet needs to be expanded upwards.
Then, a folder needs to be placed into the petals shelf. This folder is a newly created list, containing as its elements the present x value and the present y value.
After all flowers have been added, the total number of shelves is the length of the list Data. The ones with the most petals are simply the ones in the top shelf of Data[biggest]. I pull out the oldest one, Data[biggest][0] ; since append() adds to the end of a list, the 0 index of that list is always the oldest. Harvest, replant, add new flower's data, expand cabinet if needed as previously.
If the harvested flower was the last one in its shelf, and its replanted replacement has fewer petals, the top shelf is now empty. So a new check for the biggest flower would fail. In this case, we need to shrink the cabinet by trimming empty shelves from the top until we find one that isn't empty (which we are guaranteed to, because we just planted one somewhere).
Then this process can be repeated as many times as you like, with a continuously morphing cabinet. Eventually, after hundreds of iterations, the shelf Data[7] becomes very full, because 7 is the fewest petals a flower can spawn with, and those are left alone until the very end. The shelves of Data[0] through Data[6] are all empty, always. If I wanted to save a couple calculations in the beginning, I could have initialized Data to start with 8 empty shelves instead, as
Data = [[], [], [], [], [], [], [], []]
That is a full step by step explanation of what my code is doing.
@@SlyStorm-kj9wh A worked example should help illustrate, actually:
Suppose we have a 2x2 grid. The flowers on this grid have 7, 10, 8, and 7 petals. The drone is told to only repeat for one loop.
1. Drone starts at (0,0) and measures 7.
Data = [ [], [], [], [], [], [], [], [ [0, 0] ] ]
2. Drone goes to (0, 1) and measures 10.
Data = [ [], [], [], [], [], [], [], [ [0, 0] ], [], [], [ [0, 1] ] ]
3. Drone goes to (1, 0) and measures 8.
Data = [ [], [], [], [], [], [], [], [ [0, 0] ], [ [1, 0] ], [], [ [0, 1] ] ]
4. Drone goes to (1, 1) and measures 7.
Data = [ [], [], [], [], [], [], [], [ [0, 0], [1, 1] ], [ [1, 0] ], [], [ [0, 1] ] ]
5. Data has a length of 11, so drone goes to entry Data[10][0] to harvest, whose coordinates are [0, 1].
Data = [ [], [], [], [], [], [], [], [ [0, 0], [1, 1] ], [ [1, 0] ], [], [] ]
It replants and measures 7.
Data = [ [], [], [], [], [], [], [], [ [0, 0], [1, 1], [0, 1] ], [ [1, 0] ] ]
Data now has a length of 9, trimmed since the 10 index was made empty, and the 9 index never had anything in it.
6. Drone is done, and resets its position to (0, 0).
@@apophys1110 i think i get it now, or at least understand enough to try and replicate it and understand it more, thank you for such a detailed explaination :)
This whole game has been super satisfying, but watching you perfect the sunflowers was ESPECIALLY satisfying!
These videos got me to buy the game and start learning coding
Just want to start with saying that I have really been enjoying this series and you're doing a great job at it. I don't know if this is still the case, but you used to be able to call measure() on a freshly planted sunflower before it is fully grown, so on your first loop over the farm you can already be populating the list of petals. This would save a full traverse reading all of the measures. This also would let you replant and measure the new sunflower as soon as you harvest one, again saving a trip around the farm.
Oh interesting. Yeah that would save one passthrough
with the large size of the entire field (and the correspondingly large time to finish the pass), you probably don't need to water tiles most of the time. that saves doing the extra checks, the watering, and in the beginning also the growing of lots of wood for buying lots of empty buckets.
in the next video you might be doing the fertilizer, which would be helpfull to quickly grow those few plants that were recently (re)planted and didn't fully grow yet until you want to harvest them. even with water it might take a short time, especially when always replanting sunflowers that then might be the only one with the largest number of petals.
when doing a full pass for replanting, i always saw some sunflowers with a low number of petals being leftover and those tiles not being replanted. harvesting them too or deleting them (eg by planting and harvesting "wrong sunflowers") might be beneficial to be able to replant those tiles and get flowers with more petals on those tiles too.
in my current game, i think that immediately replanting each harvested flower, measuring it and storing it in a sorted array of petalnumbers, and going directly to the next harvestable flower from that array (instead of doing lots of full passes) is more effective to always get the max number of power.
@@Anson_AKB The tiles that have 'low petal count' are essentially just fodder for the high petal counts. you gain no more or no less power for having low petal counts, as all that matters is the total count of the flowers themselves not the combined petal count of the flowers.
@@Anson_AKB The tutorial seems to say that the number of petals doesn't matter for the yield. That would mean leaving the small flowers is an increase in efficiency.
@@Kraus- to make it more easily visible, let's assume that you have almost only 7-petal flowers (flowers have 7-15 petals) and only very few (a handfull of) flowers have more petals. then harvesting one of these many-petal flowers and replanting it will almost certainly get you another multi-petal flower or rarely another 7-petal flower. then for any of these few flowers (that may be scattered all over the field) that you harvest and replant you get a new one with most probably more than 7 petals. now the only few flowers that you may harvest are those newly planted flowers which in turn forces you to move a lot back and forth between them (costing time and using power) and also most often wait for those specific flowers to do their entire growth (can be shortened by fertilizing but that then costs pumpkins [and in turn replanting the entire field for carrots and pumpkins, and also a full planting pass for sunflowers afterwards] and fertilizer) before harvesting them.
overall, having lots of the 15-, 14-, 13-, etc-petal flowers would allow to harvest and replant more in a single pass over almost the entire field, and quite often not needing watering or fertilizing them to get back to a fully grown flower for harvesting and replanting. thus i have implemented some "cutoff" limit for the number of petals and when there are no more flowers above that limit, i clean the field, do an entire planting pass for all tiles (using for x and for y, instead of many slower goto), and start over.
the worst probably were those medium cases with lots of 7,8,9,etc petals and none of 15,14,13,etc petals (low total power when doing passes over the entire field without replanting immediately, and lots of waiting for a specific flower to grow when doing "harvest and replant" for each one).
Didn’t see anyone mention it yet, but lists of tuples are sorted by each tuple’s items, in order. So if you store a list of (petals, coords) and then ask for the max of it you will get back something like (15, (2, 5)). This avoids keeping track of things separately.
I can't wait for Olexa to get to Mazes. I love maze algorithms and I want to see how he does it
You are NOT going to be happy lmao
@@OlexaYT he might not be happy, but I will :)
Yeah I wasn't expecting to have to code one when I started lol. Fortunately I just spent like 10 minutes throwing up a basic wall hugging traversal and that was good enough for idling it. At some point I'd like to create a real mapping + backtracking one so I can actually do the mazes with loops. Will be interesting to see what Olexa tries first.
@@myclamish Yeah I'd love to see somebody do that since my coding skills and experience leave me with little to no idea how to do that other than assuming it'd involve making a map with arrays, how it would handle the map changing and a random wall being removed i'm not sure, unless it just blindly follows the original map even after walls are removed, which might not be the most efficient, though it would at least eliminate taking wrong paths perhaps. The only thing I can think of is having it recheck every wall it remembers being there every time it moves, though if it does find an opening it'd have to record it and recalculate it's path. I can see it getting rather complicated. Frankly, I just found it orders of magnitude simpler to not bother and just stick with the basic code being run at extremely fast speed, since re-using the maze only increases the payout by 1 times each time, and you still need to solve the maze only it's doing it virtually instead of live. At max speed it can solve each maze in seconds.
@MindCaged yeah I was also thinking if you just do a basic traversal algorithm and just map the whole maze in memory before solving it once, it would be faster to just keep using what's stored than trying to work out any new paths especially since the bot doesn't know where the goal is
I did a List of Tuples that store the pedal count, x, and y and insertion sort them into the list while planting. Then you just remove the top item from the list, move to and harvest it, and repeat until the list is empty.
Alternatively, when harvesting, you could replant and immediately measure and insert back into the list.
I've been diggin' this mini series. I've been wanting to get into code for Network Automation and this has been really fun and helpful!
I think you can check num petals while planting, also you could replant just the sunflowers you harvested instead of scanning the whole grid
and I'm not sure if the way the list is constructed is actually the most efficient. (probably efficient enough, but shortest path to next isn't always the shortest overall path between multiple points.)
You can measure directly after.
Small tip: at 25:46 instead of moving the lines back one by one, you can mark them and press shift + tab
Doesn't work for me, triggers the steam overlay and deletes the lines :( was disappointed when I tried it
Damn didnt think about that, i hope ctrl z worked xD
@@DatBoiWitDaz06 I disabled Steam ovelay for this game for that reason
@@DatBoiWitDaz06 yea same you have to go into the steam settings and change the key command for the overlay
I am loving this series! I ended up picking up the game for myself and am having a blasting remembering the good old times at uni.
It's funny how everyone finds a different way of solving things.
For sunflowers, I think you can measure them just after you plant them, before they grow, so you can do one less pass
Probably not the most efficient idea, but came up with an interesting strat for sunflowers. Plant the whole field, then eliminate the all the flowers that have more petals than the absolute minimum allowed (you'd have to find this) then plant again. Eventually, you will have a field where all flowers have the minimum possible petals. Then, you can just spam grow and immediately harvest on the same square without needing to check anything.
Sadly if you harvest anything but the max petal sunflower, it destroys all the sunflowers on the farm, so this strategy wouldn't work.
@@SanjamKumar it would work, since no matter how many petals the flower is, because all others are at the minimum, it is either greater than or equal to and can be harvested without destroying them.
And you can get them all to be the minimum by not destroying the ones that are at the minimum until they are all there.
If we have a 4x4 grid where the numbers represent the petals, (and 1 is the min)
1,2,3,4,
5,6,7,8
9,10,11,12
13,14,15,16
We destroy 16 then 15 then 14... until just 1 remains. We replant and get
1, 1, 1, 1
1, 1, 1, 1
2, 3, 4, 5,
6, 7, 8, 9
(obviously some luck to speed up the process)
and repeat until
1,1,1,1
1,1,1,1
1,1,1,1
1,1,1,[anything here]
Then we can harvest the bottom right and replant, it will never be lower than the maximum petals
Hmm, sounds like it could work, though you generally don't /need/ tons of power, you only use it to boost the drone's speed and in my experience it lasts a good long while, so after I got over like 100K it'd probably last for like an hour or more, haven't done any math, it just depletes very slowly if your code is efficient.
@EvanLarson it does work, I’ve done it before. The minimum amount of petals in 7 so you plant everything to have 7 petals and spam harvest
i went for that, as i play the game as an idler (Starting a crop and then doing other things, coming back after some time to thousands/millions of resources). I started sunflowers comparing and harvesting the biggest the whole time. I replanted the harvested sunflower right away, so never reset the field during a sunflower run. My first try was pretty basic, always scanning the whole field for every harvest, updating a coordinate variable every time a bigger sunflower was found than before. Because of that i noticed the obvious effect, that after a long time i was left with only minimum sized sunflowers in the field and only the first flower was ever harvested. Which brought me to my current code.
With fertilizer and water i grow and harvest each square until the petals measure 7 (least amount of petals). I plant my field like this and when it is done i plant-fertilize-harvest the same square as long as i want.
But like i said, only really makes sense when playing the game as an idler, as planting the whole field with 7-petal-flowers already takes some time depending on the RNG-Gods.
Really want to find the time to get back into the game, rewrite everything with the goal being efficiency with an eye towards the reset-leaderboard.
This series is maturing very well, keep up the good work! - your function is awesome to watch... and, hear me out....
If you have sunflowers, and you already know all the values of petals of all the flowers, then you would only need to compare one new one.
- so harvest (1), water(1), plant (1), wait (or recheck all petals, if you suspect they'll change), measure petals of ONLY the new one , do math, repeat from harvest. -
so you'll continually only need to replant the one you harvested - so coming into the function: plant them all, measure them all. then head to the second part of the function which is basically maintaining the garden - efficiently.
but, straight mathematics on side note:
I am convinced your method of harvesting all those with highest value is higher return over time (at cost of more energy usage too)
I would love to see you do a completely automated 4x4 farm (that farms everything efficiently at the same time.)
My go to for energy is:
Plant a sunflower
Measure its petals
If it doesnt have 7 petals (the minimum it can get) till the ground twice to get rid of it
repeat till you have the full square
fertilize and harvest the same plant over and over
This is the most efficient method after you get it set up, while setting up you can even harvest instead of tilling to reduce waste as all previous sunflowers will have 7 petals
@@Benthorpy harvesting the wrong sunflower kills all sunflowers.
Olexa - I am no math major but I know an ai that is and according to my favorite AI I have some things to think through for you! You do not have to go back (obviously) to change how many you harvest, but in a 7x7 grid you have a few options for efficient breakpoints of carrots -> power:
The most power per carrot will always be 'Harvest one flower, replant it'.
The most time efficient (assuming that it takes about half the time to replant that it does to harvest) will be to harvest as many as you want before replanting.
There is a weird breakpoint, where in a 7x7 grid the optimal is about 10 harvested. From 1->5 is a BIG jump in speed (once again assuming twice the time to harvest as plant) for a relatively low return in power per carrot, but from 5-> 10 is ANOTHER really big jump in speed with another relatively low return in power per carrot. However, the jump from 10->15 is MINUTE in comparison of jumps in terms of speed, where you are now getting basically no increase in speed in exchange for a much bigger loss in power per carrot.
All of this is something to consider, as well as considering that fact that you could always replant and measure as soon as you harvest a sunflower meaning the code would read something like:
plant all --> scan all --> go to biggest --> harvest and replant --> add new flower to list --> go to biggest --> harvest and replant --> etc etc. which, in terms of speed and power per carrot would be the best of both worlds because you are not going over the entire grid attempting to replant instead you are just planting exactly what you've removed.
I actually did this and it kind of works
My Code breaks After two minutest or so
Also as soon as you plant them you can measure and dont have to wait for them to grow
So i am constantly replanting and harvesting the sunflowers
And if the recently planted sunflower is by Chance the one with the Max petals i spam it With fertilizer so it grows instantly and i can Farm it directly
as one of the many people watching this that doesnt do any actual coding, i still feel like im learning just from watching
im understanding what does what and how it reacts with other stuff and its really cool
this might get me into coding just because it makes you feel smart
For the maze, since the drone has to go to a place to explore something and the BFS algorithm has a lot of backtracking, the drone ends up having to move much more than in a DFS algorithm and that makes BFS slower than DFS in this case.
That's why for my solution I explore the whole maze first, run BFS on a simulated maze, and then use the path BFS came up with for actually moving.
of course, you probably wouldn't care about the efficiency part of this all this time later, but the most efficient sunflower farm has all flowers except for 1 (or maybe 2) that have the minimum number of possible petals. Then you harvest the 1 flower which is guaranteed to be the best flower to pick, every single time. You can run a code designed to determine the minimum number of petals a flower can have, plant a flower, if it has more than the minimum, harvest it, and repeat until it has minimum, then move to next space. This proposed idea would take a while, and I know you could optimize it, but a nice jumping off point if you only ever wanted to plant sunflowers for an extended period of time. this method is sub-optimal when swapping between other plants as the setup requires a bit of time
what fun!
in a theoretical endgame farm that's large enough for it, it could be worth designating an area for sunflowers permanently and filling all but one square with min-petal sunflowers, allowing a quick "power topup" function where you pop over to the remaining square and harvest->plant a sunflower without having to care how many petals it has and without needing to water the rest of the flowers. i guess you'd need to reset it whenever the farm expanded tho
This actually does look really satisfying, nice job.
He he, I like my own comment.
@Olexa I believe you can scan as soon as you plant the sunflower. It doesnt need to be fully grown to "measure" how many petals there are. This should remove an entire movement cycle from the loop. Hope this helps!
I bought this then proceeded to spend 10 hours playing it. So damn fun!
I setup the sunflowers to leave any 7’s until they were all 7’s. Then just park it at 0,0 and spam plant>water>fertilize until out of seeds or fertilizer. Absolutely slams once it hits high gear!
if we want to ignore replant the flowers as they are harvested, i would say the best number for num_maxes would be (world_size^2 - (world_size - 1)^2), assuming power gained rounds down to the whole number. for the 7x7 grid you get 7 energy on the first flower when you have 49 flowers, then 6 energy for each flower after that until you are below 36.
Jesus Christ. 5 minutes is the earliest I think I'll ever be without notifications
Looks like the Sunflowers will immediately register their pedal count when planted. For more efficiency, I would harvest, plant, check petal count, then move to next highest petal count. that way you're always harvesting sqrt(count) power, and minimizing the movement required between harvests since you already have the farm state
You can plant, water and measure each cell till the farm is planted, then harvest the one with most petals, do the pop’s, replant it, measure it and keep going.
It will take more time to fully plant the farm, but, once it gets going you aren’t gonna be dang fast!
Immediatly after you plant you can measure and remove the extra scan.
Also you can almost always hatvest then plant. Then you can keep the grid replacing as you harvest
When you plant or scan you start each column from the top. You could do top bottom top bottom. Saves one move each column.
Unless im missing something once you get fertilizer could you harvest and replant all the sunflowers that have more than the minimum number of petals until the whole farm is minimum petals then keep the drone still and loop harvest, plant, fertilize? Probably only pays off if you want power in bulk but sounds satisfying. Thank you for keeping up the series
Honestly yup. That sounds brilliant haha
If you do that, remember to always start harvesting from the max, because if you harvest a sunflower smaller than the max all of them get destroyed
I was actually really proud of my solution for sunflowers, i stored the petals in a list like you did but instead of rescanning after every harvest. I keep an accurate database of the flowers by replanting, and fertilizing the flower after the harvest. Then popping the old measure and inserting the new measurement in place. By keeping the list in order i can also use the index of the measurement to derive the coordinates for the next flower, so i only need 1 list. (Found this because i couldn't get my goto function to read tuples and didn't feel like making too many new variables)
You don't even need to fertilize, measure works for sunflowers that haven't grown yet
Sick video, been watching slowly as I progress my own game, my approach to the flowers were a little different. I had similar start but I have it keep track of the highest petal flower on the board and fertilize harvest and replants the flower until its petal count is less than the previous highest. So the longer it runs the more efficient it gets until there are only 7 count flowers on the board and I can spam on tile at a time with fertilizer and planting another flower because it will never have less petals than anything on the board
After the harvest, do a plant immediately. Also, figure out how many check-harvest-plants it takes to fully grow and only recheck the replants after that time or longer.
I'm making a script that fills the field with flowers with the lowest possible amounts of peddals so that you can then have the drone plant, scan, harvest, and replant on a few specific tiles knowing that they will always have more or equal to the amount of paddals on the rest of the field.
I know its probably not more effective but I like the idea.
What I did with mine was set it to automatically buy empty tanks whenever I have less than 5 full tanks so it just automatically expands.
I also have it growing hay, trees, and carrots all at once. I have a line of hay along the bottom, the checker board of trees, and then carrots in between. That way I don't have to devote the whole farm to hay which is kinda wasteful because of how fast it grows even unwatered, and I don't have to put up with the less efficient bushes.
25:50 You can actually mark the entire section of code and Tab it or Shift-Tab it
Y'know, I really wouldn't like this game too much because my brain doesn't do that well with coding--but watching you play this game (besides the pumpkin video) was a delight to see
It's interesting to see how different people do stuff differently...
Sunflowers I just plant all, then go a full sweep and harvest all 15, then 14,13,12,11, then harvest any so I can just replant...
Pumpkins I plant them all, then do another pass and plant if empty, and on the third pass I look for empty and keep replanting till it's done... that makes it so that after that run I can just harvest the field... with a 10x10, on average, second replant will be about 20, and 3rd would be 4 that i can just manually recheck...
Hey Tyler, it is not clear in the game, but you can actually measure the petals right after planting a sunflower, so you don't have to scan the entire grid again, making the process just a bit faster
You have such an interesting way of solving these. I am loving the series and it's interesting to see how everyone solves it differently.
def moveTo(x,y):
goX = x - get_pos_x()
goY = y - get_pos_y()
while goX != 0:
if goX > 0:
move(East)
else:
move(West)
goX = x - get_pos_x()
while goY != 0:
if goY > 0:
move(North)
else:
move(South)
goY = y - get_pos_y()
def Sunflowers():
bestFlower = False
bestPetalCount = -9999
bestX = 0
bestY = 0
currentPetalCount = 0
grown = 0
for x in range(get_world_size()):
for y in range(get_world_size()):
if num_items(Items.Sunflower_Seed) = bestPetalCount:
bestX = get_pos_x()
bestY = get_pos_y()
bestPetalCount = currentPetalCount
move(East)
move(South)
if grown == get_world_size()*get_world_size():
moveTo(bestX,bestY)
harvest()
Does Measure(direction) check if something is grown on not?
Either way it's a interesting way to check if your pumpkin is dead and you could check 3 rows at a time making your pumpkin farm even faster.
If the absolute distance of the next go to is less than 2 you could basically use the direction command to scam it just needs to do some math to get it's direction.
Current coordinate - new coordinate
If it's a - on x it's south, if it's a - on y it's west, x= + it's north …y=+ it's east
If you reset position after harvesting max_petals, then eventually all the low tier sunflowers will end up on the right half of the field and your drone will need to "fly less"
Love this series! Never learned programming and I’m seriously able to follow you even when you say you’re getting lost lol
Im not sure if anyone have said this yet but if you want to "un-tabbify" aka move marked rows to the left instead of the right, you simply mark the rows, hold shift and then press tab. :-P You are welcome.
Thanks for video)
You can call mesure() immediately after plant() sunflower and append to array coords and petals, it's faster x2 (don't need fly 2 times)
I think, You can plant more carrots for seeds (example: need plant 100 pumpkins and 100 sunflowers => need 200 carrots + 100 for storage) need calculate it =)
Sorry, my English is not very good, but i'm trying
Finally I got done doing my own sunflowers so I can watch this :D
You have Inspired me to learn python as my first real program language. Real meaning, VB in school not really counting because I am 40 something now.
Love the series it's great seeing your thinking process, you're tricking me into learning
Damn this code was super clean and worked like a charm!
Very nice episode, really enjoyed it!
Loving the game
I have nothing to add, just commenting for the algorithm. I love this series
I think the optimal way to do the sunflowers, without getting into travelling salesmen problems is to harvest the sunflower, replant it, and keep harvesting until that first one has grown, then check the newly planted ones and add them to the list.
While there is some steps missing in my code below, this is my main intelligence for the sunflowers.
After about 100 harvests the drone just stands in place, harvests → plants → fertilizes → and harvests again. Doesn't really get more efficient than that.
def checkPower(tp): #tp is an empty list at the start and fills after checking each flower using this function
spot=0
for c in tp: #for every coordinate (including measure) in the list
if measure() >= c[1]: #if the current flowers measure is bigger or equal on the current spot (index) leave the loop
break
spot += 1 #increment spot and recheck the list if not empty
tp.insert(spot,[me(),measure()]) #insert the current cordinate {me() as [x,y]} and measure() into lowest possible index in the list, as long as the power is high
↑ ↑ ↑ Pretty much creates a list sorted with biggest power on lowest index, including spots coordinates ↑ ↑ ↑
############## Some mumbo Jumbo in between ##############
while True: #After the first flower has been cut we land here
while not can_harvest(): #Checks if the current flower is harvestable
sunflowerDone() #Plants Sunflower if necessary (and returns true if harvestable)
checkPower(top) #Use Function mentioned above
smartMove2(top[0][0]) #Shortest Route to the first index of the list (highest Power) using the coordinate on [0]
harvest()
top.pop(0) #Remove the first index for the list, 2nd highest flower is now in front → Repeat the while True loop
Great job on them sunflowers! If you wanted to harvest all the sunflowers, may I suggest that final “while” loop be “while list_petals”. I think the reason why it’s only harvesting roughly half now, is because the “num_maxes” variable is equal to “len(list_petals)” due to the length of that array reducing with every iteration of the while loop
You don't want to harvest all of the sunflowers. The yield is equal to the square root of the number of flowers. Depending on how it's rounded, all the harvests while 43 to 49 flowers exist give maximum yield on the 7x7 farm.
Ideally you would harvest a single flower, immediately replant, add it to the list, then go to harvest the next largest.
Harvesting the entire field is a huge waste.
@@Kraus- oh I must’ve misunderstood that part 😅
So there are a few improvements you could make. First you can already measure directly after planting so you don't have to scan the entire field again. Secondly you could make the list sorted by the amount of petals while inserting so you can just iterate over them while farming. And the third thing would be to optimize the farming path reducing the walkways instead of randomly farming the first flower with the highest amount of petals.
Your goto also looks quite wild and you are essentially defining every possible situation instead of generalizing it. My approach was that there are always 2 ways to get to another point on each axis, either by taking the "simple" way of just going b-a or by using the "advanced" way utilizing the border overflow. I then just calculated both ways and took the shorter one by comparing the absolute length of the 2 values. For example given a world size of 10, current x of 1 and destination x of 9 you can either go 8 or -2 steps. -2 is the shorter absolute path so I would go 2 times West.
That’s probably intelligent lol
If you do write a breadth first algorithm I'd love to see it, though it might be overkill, and not sure if it could easily work since you can't see where the walls are, you can only try to travel a direction and see if it succeeds or fails. My algorithm is actually quite simple and is rather short after I simplified it, it's basically the hug the wall method. If you wanted to do the advanced maze feature where you re-use the maze and it moves the treasure chest and tells you where it'll move to so you actually have an idea where the chest is, so you can try to move towards it, though that gets /much/ more complicated and I'm not brave or experienced enough to try it, especially since I don't know how much greater the yield you'd get.would be for all the extra work. With all the speed upgrades it only takes a very short time to solve the maze even with a simple algorithm, so I feel for me it's easier to just solve the maze once and restart, rather than trying to level up the maze. Maybe I'm missing something. I suppose maybe if you kept a map of the maze you could calculate the shortest path to a given coordinate without having to move, but from what I understand leveling up also randomly removes a wall, so you might end up keeping following the original map because there's no way to tell if a wall has been removed without trying to travel through it, and also the hug the wall method only works if there are no loops, while removing a wall might also open up a loop.
I did the sunflowers using an array, just stored the number of petals of each sunflower and used their index within the list to find their coordinates. But this works just fine.
Nice vid!
with the sunflowers I instantly plant after harvesting, and check the number of petals of the new one. My code is more seed effective, but i certainly don't think is faster.
Hi light + Shift + Tab I believe is the un tabification
Yes this is true
It also brings up the steam overlay, so I hope you turned it off! :D
nice nice! I havent made it to sunflowers yet, I can only take so much coding at a time lol. I wonder if you could harvest all the largest sunflowers until the entire grid is the minimum number of petals and then harvest the entire grid.
Probably
Anyone who said sunflowers are hardest havent got to mazes and companion crops lol. having a fully dynamic and expandable script for companion crops is a toughie.
and if you can get your maze algorithm up to the 300 iteration cap, you have my respect as a programmer
For the sunflowers, you don’t need to scan the entire grid. You can remember the petalAmount of the sunflowers you didn’t just plant
Or you could measure it after planting at least that's what I've seen
"untabbify": shift + tab
Steam overlay might pop up, so you may have to change Steam's shortcut to open the overlay if you haven't already
A common IDE feature is CTRL + / to comment a line. Maybe it works here too (e.g. for commenting out multiple lines: highlight those lines and press CTRL + /)
Yeah unfortunately doesn’t. That’s what I tried
Thank you for making a another vid
You might be able to press Shift-Tab to de-Tabify everything after highlighting it, at least that is how all my progams have worked.
My first time through I used a dictionary(yea yea I did treasure before sunflowers) for my sunflowers, storing location and measurement at the same time of planting. Then I worked through that dictionary while it had items(big loop). First identifying what the max petals was(1st small loop), then once I had that iterate through the dictionary moved to where the flower was, harvest and remove from dictionary(2nd small loop). to then go back to the big loop. Basically harvesting all of the flowers from max to min. I seemed to generate energy quickly that way.
I've read that if you just replant (I would have to assume rescan also) the max ones it will self optimize to only harvesting like 1 or 2 flowers. Considering a full scan each time(since I don't know what the new max is and the other flowers lost a petal or more)(aka numbers get wonky with old results and new measurements) I don't think that is energy/movement efficient. I might be overthinking this too :) and whatever measurements are there they will still be higher then the others. /shrug
Anyways I restarted a new save (cause practice), and I might try it with just lists that way I can just use a max to identify maxes. Seems a bit more efficient in some regards at the very worst it is just approaching a problem differently. So win/win.
Peace
Im really Stuck on the mazes looking forward to seeing your Solution to them
You kinda want it to get the whole grid full of bad sunflowers and then just harvest a single one that is the best and replant that, cause then you end up where you can just keep replanting and harvesting the same single tile over and over again and keep getting the most power, its going to be faster and alot cheaper on the seeds, but this also works fine 🤗
Love your vids was looking forward to this one the whole day
With at 7x7 grid size you have 49 spots, so for sunflowers alone you can collect like 20 or even 30 and you would still net 5-6 energy per sunflower. As you get 6 energy from 36-48 (if it does not round up) and 5 energy from 25-35 per harvested sunflower.
So 24 would be a decent number for 49 plants. 4 energy might be worth it too, didnt do the math on that one there
Yeah but doesn't y=√x where X is the number of petals return a diminishing return? Wouldn't the ideal play be to cultivate a single square of.sunflower?
@@owenatkin3148 have to take into account that the growth is not instant (unless you want to use fertilizer)
@@owenatkin3148 You get power equal to the square root of the number of sunflowers; the number of petals on the sunflower doesn't factor in at all. If the grid is full of flowers, you earn power equal to the side length of the grid (in this case 7).
If you harvest a maximum-petal sunflower, all the other flowers stay, otherwise they disappear. The actual number on the petals is irrelevant.
It saves resources, and actions that would drain power, to maintain a planted field between iterations.
@@owenatkin3148 well kinda in that manner, as it returns the squre root from the total number of planted sunflowers.
Asuming it does not round that means that you only get 7 power from 49 so the first plant, then you get 6 power until you harvest the 36th plant (14 harvested in total, for 85 energy ), then 5 until you harvested the 25th (25 harvested in total for 140 energy), then 4 until you harvest the 16th ( 34 in total for 176 energy).
So I would make the break either after 85 or 140 energy, as then you gain less
Not sure if it’s still a thing but I heard there is a competitive mode. You should look into that once you unlock everything so you can try and really min/max the code
Not too much to say on this one, except you that you can plant and measure right after without looping the grid for it, it also let you harvest plant measure then goto the next with the most, just make sure you check for can_harvest if you do that because the new flower could be the next you want to harvest...
Shift+TAB untabs
(also you can select a bunch of lines to remove or add tabs)
That just opens up the steam overlay for me.
@@Pirochiro got my steam overlay set to CTRL+SHIFT+Z or else it kept messing with some of my games. (you can change it in the options)
Wouldn’t it be more effective to have him replant each individual location immediately after harvesting? Then the number of sunflowers would always equal 49.
Gotta be careful about that though bc you need to make sure that new flower’s petals aren’t the max
Ah.... Ya... I was one of those that assumed sunflowers would be more difficult..... It was for me though because I made it difficult!
I was not happy with the list functions, so I made several helper functions, like IndexOf(Item), RemoveAt(Item, Index), and Replace(Item, Index). It didn't occur to me to use Max. lol I ended up storing a list of [coords, pedals] and finding the first, largest sunflower, harvesting it and replacing it in the stored list.
Pluses, you always get max power each harvest, because the grid is always full.
Cons, I suck at coding and should have just used Max! XD
Mazes will be fun. I am still don't really understand how to BFS or DFS, but I think a simple "Follow the left wall" should do the trick.
Amazes me how easy you found the sunflowers
I think and I might be wrong, but your code was more efficient before the last change? So "harvesting a sunflower yields power equal to the square root of the number of sunflowers on the farm" So the in theory most efficient is always harvest 1 sunflower as it will provide the highest power per seed, so I do think that doing a few per loop was pretty efficient, then once you harvest way more per go, you lose significant seed/energy efficiency.
Your initial implementation was good, as number of sunflowers matters for power, not petals
Feed me more tasty pumpkins Olexa
Olexa, I think that you can put the reset drone and harvest grid functions at the start of the main loop instead of using one per function
Very efficient and fun to watch.
Hey olexa iam no coding genius but cant you plant the sun flowers as you harvest and scan at the end and go forever?
Great episode! One question though (non coder); won't your drone get stuck if all the sunflowers have the same number of petals? That might happen if you afk for a good bit.
They would all be the maximum at that point so i think it’d just choose a random one and harvest it
Lets do some basic maths
World size 7
√49 = 7 energy the first
√48 to √36 are all decimels of 6.x
So if rounding is to nearest
√48:√43 < 6.5
√42: √36 > 6.5
So youve effectively gotten 7^2 energy from the first 7 harvests.
So it really depends on how many actions its taking in your goto function for the counter. You have 49 tiles to traverse too so you want at least 4 energy per harvest just so you have the energy at least to cover scanning and planting (49*2 = 98, 4 energy is 120 actions.
So as long as √Sunflowers > (tiles in field*2) youre net positive on energy.
Do inverse operation
4^2 is 16
49-16 = 33
So you can harvest 33 sunflowers before youd see diminished returns.
I dont quite know how you'd make the function but ill do my best to express the maths.
Num Tiles - ((RoundUp((Num Tiles *2)/30))^2) = MaxHarvests
This should make it scale with the size of the farm so that you never harvest unless youre net positive.
Im not sure how or where the rounding occurs so you may have to just find how you can apply this logic to the code.
I mean the actual most optimal way numerically is to only harvest 1 sunflower a time.
You always get the maximum energy you're only replacing the one seed and planting the one seed.
1 seed equals world size energy
7 x 7 is 49
√49 is 7
So just doing one means you'll constantly just get world size energy and it takes the least amount of actions as it's only doing a small amount of actions in-between. Harvest trade seed plant seed and water and then go to again
But I admit the drone looks super happy using instant transmission all over the place.
Olexa, i need more, i need it in my veins
Olexa flexing his coding skills will never not be entertaining
Keep going. This is fun.
This series is addictive ❤️
I don't know about the code, but the outcome is what I'd want for optimal bot activity.
Elegant af.
But why not just plant right after harvesting? That way every sunflower harvested gives maximum power.
Also, loving the series!
If you have fertiliser could you plant, fertilise and then measure it immediately? That would remove the need for passing over the whole grid each time.
Hey not a coder, but I was thinking instead of calling the trade function when you need more seeds, why not call it at the beginning, like require 50 pumpkins first plants 50 carrots buys 50 pumpkin seeds and the plant 50 pumpkins
I've got to know, why do you have "REQUIREMENTS += 1000 " in your infinite loop?
Isn't REQUIREMENTS a constant that is never modified anywhere else. So adding to it is just slowing down how often you swap between different types of plants over time.
Loop 1 every 4200
Loop 2 every 5200
Loop 3 every 6200
It's like a memory leak
Unless of course one of the earlier plants decrease requirements by 1000 because you want less of the others and you're just counteracting this change. Instead of passing the parameter of that plant as "REQUIREMENTS + 1000"
It’s just a way for me to run that function infinitely idley to collect resources before each episode so we don’t have to wait for it to buy things during an episode
Found this channel like, 3 hours ago. Ima be real, im only here for the farming game. 10/10
It’s almost like all of my content is good!
I plan to watch more, you are fr underrated.
@@OlexaYTbtw, only water the ones you cut for the sunflowers, you used 300 barrels.
Wouldnt you be able to plant and harvest one sunflower at a time. That way you get max power for each plant because all other plots are filled? I hope this makes sense?
Highlight Code and hit Shift + Tab to untab multiple lines of code
I love how you "easily untabbified" multiple times in this video, but when it mattered (25:52), you forgot how to do that :D
I think the order of your crops in the general farming function is incorrect.
I feel that you should have pumpkins before carrots.
Otherwise, you farm the carrots, and then you farm the pumpkins using up those carrots. It makes more sense to me to do it the other way around so you end up with the requirements satisfied at the end of the loop.
Also, look at my comment on the previous video for a much simpler goto function.