Install Steam
login
|
language
简体中文 (Simplified Chinese)
繁體中文 (Traditional Chinese)
日本語 (Japanese)
한국어 (Korean)
ไทย (Thai)
Български (Bulgarian)
Čeština (Czech)
Dansk (Danish)
Deutsch (German)
Español - España (Spanish - Spain)
Español - Latinoamérica (Spanish - Latin America)
Ελληνικά (Greek)
Français (French)
Italiano (Italian)
Bahasa Indonesia (Indonesian)
Magyar (Hungarian)
Nederlands (Dutch)
Norsk (Norwegian)
Polski (Polish)
Português (Portuguese - Portugal)
Português - Brasil (Portuguese - Brazil)
Română (Romanian)
Русский (Russian)
Suomi (Finnish)
Svenska (Swedish)
Türkçe (Turkish)
Tiếng Việt (Vietnamese)
Українська (Ukrainian)
Report a translation problem
Visit the entire list in sequence. If nothing there, plant; if growing pumpkin, skip; if fully grown pumpkin, remove coords from list.
When list empty, harvest()
Note:
sz = world size
grid.mv() moves the drone to (x,y) tuple using shortest path
>> x & y span 1 to world size, not 0 to world size -1; personal preference.
settings.wthr = 0.75 (watering threshold)
Probably room for improvement, but it gets the job done and plugs quite nicely into my main script.
Looks like you have redundancies in your code, not really needed but otherwise looks good.
Also, why do you have a conditional check in your smart_harvest which doesn't update each loop but is passed in? Should look more like
As python goes left to right when checking conditionals. if you pass in false to the smart_harvest it will never attempt to even check the second condition and skipping straight to the harvest part, while also removing a not updating conditional from the looping structure.
Here is my take on this issue with me using your code to build on.
Some more stuff going on but it is basically the same.
Improvments:
1. Initial state check as it might fail inside while attempting to gather pumpkins so we do this so we can resume.
2. Used a list of the positions as True/False to indicate if that position needs attention still and then only went to those positions
3. Added default values and renamed variables to improve readability
4. Changed the movement of the drone to scan back and forth to optimize the movement around the board
5. Implemented a move function which does the shortest route to the wanted move
There are still improvements to be done on this code, was just keyboard banging it out so it had some new ***FEATURES***!
I do quite like your version. It works perfectly and seems quite a bit faster than babysitting each individual square, even if the latter is using fertiliser. I might have a crack at the plant, scan, fix, repeat approach at some point,
Definitely an oversight on my part, but as the smart harvest is basically just a glorified fertilizer it should be adjusted as such.
Harvesting should just be the generic game harvest as there is not really any use case for doing otherwise. So just refactor to this and away one can go! The only time one would really want to dynamically change crops and thus remove one is if there was a need for a different crop to support a current operation, and generally it is better to just wait for the already planted crop to finish so no special culling logic is needed thus still back to square one of using the basic harvest function.
Also, now that is just a fertilize function it can be added to the loop logic! Though I doubt it will really speed up the planting process that much. The reasoning behind this is that there are 100 spaces that must grow and by the time you get down to that last 3-5 unless you get VERY, VERY, VERY lucky they tend not to be local to one another. Therefore, your bot will have to travel a certain number of spaces just to check so it will barely eek out and time savings as you have to "waste" time moving from one location to another.
Notes:
Also, if you watched the script run a few times it should be apparent that the check that is done initially should only be done when starting up as after it starts running the initial state of the board is always going to be empty. So it is easy to make it faster by removing this redundancy, (Again, just bashed this together quick as a demo)
There are other things but it is always a fun challenge to see if one can improve on someone else's code as this requires rationalizing what they were thinking and how they solved that problem. Then to go above that to optimize the code or improve the chain of logic. (Generally why most programmers would rather rewrite the ENTIRE thing than do so as it is not easy to get into another's head.)
I also implore you to try a similar approach to mine as well. As it will be very helpful to rationalize how another thinks. I use a number of tricks on how python works to get it to implicitly do the thing that I want, though for a seasoned python person it is explicit.
The coolest bit is this
As the whole board is stored as a 1-D array/list as True/False values you can check the value of the first one for it's truthiness. Using that with an and against the length of the set of values in the list, this bit is VERY cool, you can get it down to a set with 1 OR 2 length, where 1 means ALL are False or ALL are True.
Thus, if the first bit is True then if also the length of the set is 1 then ALL entries MUST be True so you can harvest it at that point!
If that didn't make any sense, then look up the documentation for the set function in python. (If you want to do a deep dive google group theory and/or set theory!)
That's exactly what it's for. It's part of a larger script that switches regularly between crops to keep them all ticking up at more or less the same rate. If the drone switches from polyculture to pumpkins, it can harvest the previous crop as it plants and not waste all those x5 bonuses and without having to do separate passes for harvesting and planting. Not to mention, I'm more often than not going to check to make sure there's a mature crop before harvesting, so it's nice to have it as a function. It's not just for my pumpkin script, it's a general use function I use on almost everything.
I definitely will. In fact, I have to thank you for your help here. Seems counter-intuitive (at least to my barely competent anus), but the planting the whole thing and rechecking for holes is a lot quicker than just babysitting each square. I'm definitely inspired to have a crack at writing my own version.
Ha, glad it's not just me. Honestly, I had to spend about 15 minutes reading over your version until it made sense, and the only reason it didn't take longer is because I finally had the genius idea to just test it. Probably should've been step one, but what can you do?
I have to be honest, that went way over my head. It seems a good approach for cacti (I think did something similar in the last version of the game), but for pumpkins, I feel like just using a list of coordinates would be quicker. Remove a coordinate when you find a mature pumpkin, then harvest when the list is empty. Save you needing to translate list position into coordinates.
It all depends on what your requirements are.
Either you spend CPU cycles or RAM(memory), cost vs. benefits. Also, you have to remember that using memory has the cost of accessing that memory and such.
In my case I just use the inherent conversion of a 1-D array to (x,y) from the formula of x + y * width to keep the coords of the board with the pertinent information stored in the value. Which means that I have a contiguous section (potentially) of 100 bits (True/False) values which store not only the (x,y) value of the specific data but the data I need as well. Compare this to using a 2-D array/list or a dict where for this use case I would have to store the data and the coord that it is associated with.
Thus I minimized the memory footprint from python and used CPU cycles instead to calculate it on the fly as it is basically free as the size of the board is only 100 and even the crappiest of google books has a 1.3 ghz processor so that is not even a drop in the bucket on CPU time. Same could be said for the memory footprint as well. If scaled though to let say a world size of 1,000 the memory footprint would still be just 1,000,000 bit vs using a 2-D array or dict where who even knows! (Can calculate but won't) Mind you as python's list can store any type we are not getting real savings from doing this minus the fact we are not storing additional data.
Example of data growth between implicit storage of (x,y) vs explicit.
As a note, using numy bit arrays would make the data far less but no reason to as the scope is this game.
The beauty of how I am doing it with set conversion is that python is, for python, REALLY REALLY fast at turning a list into a set! (Hash table magic)
Also I remove any potential bugs from the removal and insertion of data into a data structure by doing it this way which is great! Which is why I would recommend just keeping it in memory, UNLESS you are doing BIG data stuff where that would be impossible.
Less bugs means a happier programmer!
Fair enough, that makes a great deal of sense. I guess I'll have to bear that in mind if I ever do any coding outside of a programming game.