Harvest – A highly customisable farming script

eegee

Member
I've been away for a while and I'm glad to see that Harvest has been updated. I'm also glad that the curly brackets are now on the same lines as methods/etc. :p

I have some fixes for Harvest.ash::
  • line 202: have_foldable("doh") works now (also added to Harvest Combat.ash & relay_Harvest.ash)
  • line 1097: decision to consume munchies pill should use x3 VOA since one will get +3 advs from a fortune cookie
  • line 1362: get_foldable($item[rain-doh black box]) does nothing since Rain-Doh is not foldable
  • line 1640: fixed using Spooky Putty monster instead of sheet

I left out the "recommended VoA" feature because I'm not convinced that it actually gives the best VoA setting possible, and it's not what I had in mind when I wrote Harvest. I wanted to make a script that made it as easy as possible to implement a given farming strategy and that gave you useful statistics about that strategy, not a script that mindlessly (if cleverly) botted in the most optimal way possible. Not that recommending a VoA setting is mindless botting, but it's the sort of inch-mile/slippery slope thing I want to avoid. Make sense? Feel free to argue with me, I'm happy to change my mind if anyone can provide a well conceived argument :).
Agreed 'recommended'!='best' :). But no worries, I've written a wrapper for Harvest to calculate that VOA now. BTW if you'd like your "meat per adventure" to be more accurate for useful statistics, I'd recommend you should also include the cost of overdrinking similar to way the cost of consuming is included (I missed that one previously with the VOA mod by including it twice).
 

Attachments

  • Harvest r11511p501.zip
    27.4 KB · Views: 44

Banana Lord

Member
I'm also glad that the curly brackets are now on the same lines as methods/etc. :p
Haha! The first part of one of my courses (the C programming part) required us to learn good style. Funnily enough, the lecturer taking the second part (embedded systems) of the same course doesn't seem to have got that memo. Style's one of those never ending battles, I think :D

What's the deal with line 202? Your fix will only return true if the player has a black box or a box full of monster. have_foldable should return true if the player has any of the forms of a given foldable. I can't get access to mafia to test right now, but where does my code fall over? [EDIT: See below >_<]

I note that in situations like that on line 1097 you put brackets around the mathematical part of the statement. I was under the impression that the two statements below were identical. Is it a style thing, or a this-matters-sometimes-so-we-do-it-all-the-time thing?
PHP:
if(get_property("valueOfAdventure").to_int() * 3 > mall_price($item[munchies pill]))
if((get_property("valueOfAdventure").to_int() * 3) > mall_price($item[munchies pill]))

Line 1362. How did I never noticed that Rain-Doh isn't foldable? It says so right there on the wiki: "This is not a foldable". Well. That makes a lot more sense xD

Also, I am right in thinking that there should be a break; on line 201 aren't I? I'm working on four projects at the moment, each requiring a different language (Python, MATLAB, C and now ASH) and every so often I get mixed up.

I moved the call to over drink() up a few lines in finish_up(). That should do the trick, but it's been a long time since I ran through the logic of the script properly. Hopefully there's not some obscure reason for putting overdrink() where it was that I forgot to document. I'll upload the fixes in a minute.

EDIT: Where are my manners? Thanks for the fixes eegee! :)
EDIT2: Updated versions posted.
 
Last edited:

eegee

Member
As always, you're welcome. :)

I note that in situations like that on line 1097 you put brackets around the mathematical part of the statement. I was under the impression that the two statements below were identical. Is it a style thing, or a this-matters-sometimes-so-we-do-it-all-the-time thing?
They should be the same, but can you guarantee that the compiler/interpreter will evaluate * before > or instead evaluate left-to-right? I can't, so I always explicitly add parentheses to all my equations to clearly express my intent and avoid any logical errors. On a plus, I think it improves readability as well. As for the curly bracket on which line style, that has more to do with styles that pertain to programming languages. I do so love it being on the same line.

On the styles thing, let me add two more tidbits you might like to add to your programming_foo: 1) use spaces instead of tabs for indenting (you can search on google for various arguments about this), and if you use spaces use 2 instead of 4 since most people can read either and this allows for more compact code; 2) try explicitly add curly braces to all if/else/for/foreach control structures, this might help detect logic errors and it will allow for easier addition to control structures later. These two suggestions might or might not be considered good programming styles depending on who you ask, but I personally have found them useful on a daily basis.

Also, I am right in thinking that there should be a break; on line 201 aren't I? I'm working on four projects at the moment, each requiring a different language (Python, MATLAB, C and now ASH) and every so often I get mixed up.
You are quite right. I accidentally copypasta'd over that line. Without the break, "origami" would fall through to "doh" which isn't right.

I moved the call to over drink() up a few lines in finish_up(). That should do the trick, but it's been a long time since I ran through the logic of the script properly. Hopefully there's not some obscure reason for putting overdrink() where it was that I forgot to document.
That should be right as long as it's between "_har_endmeat" and "_har_endadventures" since overdrinking will increase the turn count.
 

Veracity

Developer
Staff member
Can you guarantee that the compiler/interpreter will evaluate * before >
Yes. It's called "operator precedence". ASH uses Java's operator precedence. For your convenience, the KoLmafia Wiki has a table that spells it out for you.

By the way - I think that having a curly brace on the same line as a function declaration is bad style. :p
 

Banana Lord

Member
Use spaces instead of tabs for indenting (you can search on google for various arguments about this), and if you use spaces use 2 instead of 4 since most people can read either and this allows for more compact code;
I've heard this before, and I agree with the reasoning, but I'm always too lazy to hit space four (or two) times when I can just hit tab once >_<

2) try explicitly add curly braces to all if/else/for/foreach control structures, this might help detect logic errors and it will allow for easier addition to control structures later.
Yep, that's one I've already started doing, though I haven't modified any instances in Harvest yet.

That should be right as long as it's between "_har_endmeat" and "_har_endadventures" since overdrinking will increase the turn count.
It is now! xD

EDIT: Funnily enough I think that the reason I started coding with curly braces below the function declarations was because way back when I started teaching myself ASH (which was the first programming I'd ever done) the examples I pulled apart were written by Veracity ;-) In the style guidelines I was given it states that curly braces are acceptable either on the same line as the function declaration or on the line below (at that point you have to wonder what the point of a standard is if it comes with options, but whatever), but that they should always be on the same line for conditionals etc. Although I'm going off memory here and it was a long document.
 
Last edited:

eegee

Member
Yes. It's called "operator precedence". ASH uses Java's operator precedence. For your convenience, the KoLmafia Wiki has a table that spells it out for
Sorry, I missed that page. I was making a general point not targeting language specifications. But once again, even though we have operator precedence, the duty still falls on the compiler/interpreter to enforce that and luckily KoLmafia does it the Java way.
By the way - I think that having a curly brace on the same line as a function declaration is bad style. :p
..and talking about the Java way. They also like what I like. :p
 

eegee

Member
I've heard this before, and I agree with the reasoning, but I'm always too lazy to hit space four (or two) times when I can just hit tab once >_<
I also use the tab button. Fortunately most IDEs and proper text editors (like Notepad++) allow customization of this button, and I've set mine to replace tabs with 2 spaces.

(at that point you have to wonder what the point of a standard is if it comes with options, but whatever)
Yes, there are different standard/styles/opinions. But no matter which you settle with (or are forced to use), the crucial thing is to be consistent across code.
 

eegee

Member
I’ve gone and added some “fax farming”. It is not integrated with bounty hunting and still needs some improvement.

Currently, fax farming assumes that one has a monster in their fax machine and will not work otherwise. If one has a copier, there will be an option to further farm with copying.
 

Attachments

  • Harvest r11511p508.zip
    30.3 KB · Views: 46

Catch-22

Active member
..and talking about the Java way. They also like what I like. :p

I prefer writing that way too, but when I submit patches to KoLmafia I try to follow the KoLmafia coding conventions :) As a result, my ASH scripts and my patches are a completely different style, which is also a completely different style to what I do at work (mostly because I usually work in another language at work).
 

Veracity

Developer
Staff member
When I submit patches to KoLmafia I try to follow the KoLmafia coding conventions :)
If you don't do that, either somebody will spend a lot of their own time reformatting what you submit, or they will simply ignore your work. In either case, your reputation as a KoLmafia contributor goes down.

I am amused that you (egee) quote the standards that Oracle (or Sun) use internally as if it is some sort of "official" coding standard for Java. I used C and C++ for, oh, 15 years before Java was invented - and NO coding standard for those languages puts the bracket on the same line as a function definition. None of them. Not one. You do that with Java and I need to look at it and you are SLOWING ME DOWN in my attempt to understand what you have written. Fortunately, I will never ever have to try to maintain your code. So, do whatever you want! But, try to claim that you have the one-true Java (or ASH) coding style? I call bullshit, and you have lost a lot of credibility with me.

With me, I say. I don't claim to have the "one true" coding style, either. But I am very clear on what makes it easier and what makes it harder for me, when I am looking at code.

Whether you care what I think about you is completely up to you. Perhaps YOU don't give a damn if I think you write hard to understand code. It's completely up to you. Do what sinks your own boat. ;)

Look at the Linux coding style to see what _I_ prefer. Which is not, as it turns out, the KoLmafia coding style that hola introduced. But when writing for KoLmafia, I use(d) hola's style.
 
Last edited:

slyz

Developer
I think I started out by copying Bale's more compact coding style. Then I spend some time looking at the Mafia source trying to figure things out, and I realized that having so much space made the code really clearer and simpler to read.

Brackets on the same line and two space indents aside, simply writing this:
PHP:
$item[ seal tooth ]
instead of this
PHP:
$item[seal tooth]
adds a bit of work typing spaces, but is worth it in my opinion.
 

Catch-22

Active member
If you don't do that, either somebody will spend a lot of their own time reformatting what you submit, or they will simply ignore your work. In either case, your reputation as a KoLmafia contributor goes down.

There's no clear documentation stating what the coding conventions are (that I found) so it's mostly guess work by looking at what is there already. Early on it took me a while to remember to space out parenthesized parameters ( such as ( this ) ). Another thing that is not obvious to the naked eye is indentation of lexical scopes, in KoLmafia blank lines aren't indented, whereas my personal coding style tends to keep indentation even on blank lines (by default, Eclipse, Netbeans and Notepad++ will indent blank lines, Visual Studio will not). I've seen a few places where devs have committed indented blank lines. I'm still not quite sure how many characters should be in a comment line before making it a multi-line comment, so I tend to just go with whatever makes sense at the time.

If anyone ever felt like writing out some style guidelines and sticking them in devdoc, I'd happily read and attempt to adhere to them :)
 

Veracity

Developer
Staff member
in KoLmafia blank lines aren't indented, whereas my personal coding style tends to keep indentation even on blank lines (by default, Eclipse, Netbeans and Notepad++ will indent blank lines, Visual Studio will not). I've seen a few places where devs have committed indented blank lines.
As you point out, indentation on blank lines is an artifact of the text editor, not a "style" thing.
 

roippi

Developer
The formatting enforced by format.xml (found in the /util package) is as close to an official coding guideline that we have. It's an Eclipse thing and otherwise not terribly human-readable, but yeah.
 

Veracity

Developer
Staff member
If anyone ever felt like writing out some style guidelines and sticking them in devdoc, I'd happily read and attempt to adhere to them :)
Heh. I submitted exactly one file to devdoc - ExampleCoinMaster.txt. That was the one that I felt needed the most explanation. We've had a couple of Coinmasters submitted by people other than me since I published that, so, I guess it was adequate.

In my view, I have four more files:

ExampleCoinMasterRequest.java
ExampleRequest.txt
ExampleRequest.java
CodingStandards.java

They are all empty. Maybe someday I will write them and submit them. :)
 

Cone_of_Cold

New member
I'm totally new to KoLMafia and I think I'm doin' it wrong.

I run "Harvest.ash" from the drop-down Scripts menu and I get

> call scripts/Harvest.ash

Script setup complete. You can now configure the script's options with the relay script
Remember to click the Save button (bottom left) when you're done

in the CLI. Then I run relay_Harvest.ash and instead of the preferences window shown in the image on the first thread of the file I get this in the CLI:

> call scripts/relay_Harvest.ash

Script setup complete. You can now configure the script's options with the relay script
Remember to click the Save button (bottom left) when you're done

And now I see that this thread hasn't been commented on in several months and I just realized that I might be doing it so wrong that it might even be outdated or something. :/
 

Banana Lord

Member
A glance at my KoL profile will tell you that I haven't been on in a while, but as far as I know Harvest still works fine. I've just logged in and given it a run, and it seems to be doing fine. When you run "Harvest" from the drop down scripts menu in the relay browser (the tab that opens in a browser window when you click on the map icon at the top of Mafia's main interface) you're actually running relay_Harvest.ash, which is a support script to make using the main script easier. When you run "Harvest.ash" from the Scripts menu in Mafia you're running the main script (you could achieve the same result by typing "call scripts/Harvest.ash", "Harvest.ash", or "Harvest" in the CLI). To set Harvest up, either run Harvest.ash from the Scripts menu in Mafia or run relay_Harvest.ash from the drop down in the aforementioned relay browser. That will result in the "Script setup complete" dialog in the CLI (so you should be all good up to this point). Now all you have to do is run relay_Harvest.ash by selecting "Harvest" from the drop down in the relay browser and the interface should drop down into the main KoL pane. That's assuming you've got all the necessary support scripts installed properly, as listed in the first post. If you're still having trouble report back and I'll try to help :)

EDIT: It seems to me that you may be trying to run relay_Harvest.ash from the CLI, is that right? If so, that's not how you're meant to do it :) The idea is to run the relay script from the relay browser, just as I described above.
 
Last edited:

Cone_of_Cold

New member
EDIT: It seems to me that you may be trying to run relay_Harvest.ash from the CLI, is that right? If so, that's not how you're meant to do it :) The idea is to run the relay script from the relay browser, just as I described above.

I'm glad to hear Harvest is still working even though it hasn't been updated in some time. Like many others before me I'm sure, the main reason I started using KoLMafia in the first place was to automate farming the castle (sea, etc.).

This was where I was screwing up. I was doing this all in the CLI and I kept getting the "Script setup complete" message. Like I said, I'm relatively new to KoL mafia, and while I was familiar with the map button that opens up browser window, I had no idea it was called the "relay browser" nor did I know certain scripts needed to be executed from the relay browser.

Thanks for your help and your quick reply! I was worried that since no one had responded to this thread in a while that my inquiry would go unanswered.

A few things, though:
1. When the farming was all finished, the script nightcapped with a pink pony instead of the bucket of wine I have in my inventory (I have Clip Art as as skill, too, so it's not like I'm buying the wine). I suspect this has less to do with your script as much as it does with EatDrink.ash?
2. Is it generally advantageous to specify more exact "adventure value" or a more conservative one? Like let's say my meat per adventure is 1000, but the currently-programmed "adventure value" is the default 500. Would I change the 500 to 950 or something to let the script auto-buy more expensive/potent items or leave it at 500 so it spends more conservatively?

Thanks in advance.
 

Banana Lord

Member
1) Yep, that's down to EatDrink.

2) In the end the best advice I can give you is to try it and see. You'll have to fine tune that setting over a number of months to get it exactly where you want it. In general, you want to set your adventure value to something similar to your MPA. I certainly wouldn't exceed it without a good reason. Take all that with a grain of salt, it's been a while :)
 

lostcalpolydude

Developer
Staff member
I have Clip Art as as skill, too, so it's not like I'm buying the wine

Irrelevant, since you could sell the bucket of wine instead of consuming it, or possibly some other more valuable clip art item instead. Looking at the current prices for pink pony and bucket of wine, if you tell the script that an adventure is worth 500 meat then it shouldn't spend an extra 7200 meat for 11.5 adventures (626 mpa spent).
 
Top