Miner.ash - Automated ore farming

Miner 2.5 - Automated ore farming

Requires Zlib.

I made this script mostly for help in acquiring the ore necessary for the Dwarvish War Uniform, but also as a quick way to get the ore for the trapper.

Here is an alias to get the ore that the trapper is asking for:
alias tore => ash import <miner.ash> get_tore=true; mine_stuff();

And here is one to utilize the free mining that you get from Unaccompanied Miner:
alias fmine => ashq import <miner.ash> free_mine();

User Preferences

boolean get_tore
If true the script will just get the ore the Trapper is asking for.

boolean mine_all
If true will mine all walls in cavern instead of just the top 3 rows. By default the script only mines the top 3 rows of evey cavern because almost all ore is found in the top 3 rows.
WARNING: Mining all walls consumes 36 adv. per cavern as opposed to 21 for just the top 3 rows.

boolean open_mine2
If true and you've selected to mine ore that can only be mined in the Knob Shaft this will gain access to The Knob Shaft. It opens Cobb's Knob Laboratory if it's not already open.

boolean asked
Set this to true if you plan on mining in the anemone mine and have already asked grandpa about it.

int asbestos, chrome, linoleum, diamond, bubblewrap, cardboard, styrofoam, teflon, velcro, vinyl, aquamarine, stonepower, meatstack
These set the amount of the specified item to mine for. These numbers take into account items already in inventory. (i.e. If you set int chrome = 3; and you already have 3 or more chunks of chrome ore in inventory the script won't farm for more chrome ore.) You can set as many of these as you want.

For instance:
Code:
int chrome = 3;
int diamond = 3;
int bubblewrap = 10;
The script will mine the Itznotyerzitz Mine until you have 3 chunks of chrome ore and 3 lumps of diamond in inventory and will then mine the Knob Shaft until you have 10 chunks of bubblewrap ore in inventory.

Notable Functions:

boolean free_mine()
This uses the 5 free mine attempts granted by the skill Unaccompanied Miner. It will try to get the trapper ore if you still need it and can access Itznotyerzitz Mine. Then it will try to mine for the most profitable ore based on mine access and mall prices (or autosell value if in Ronin/HC).

boolean mine(int amount, item ore)
This tries to retrieve amount ore and if it is unsuccessful it mines for the remaining amount needed.

boolean mine(int[item] ore)
This repeatedly tries to retrieve 3 of the ore you need the most of in the map until you can't retrieve anymore and then mines for the remaining amounts needed.

The following code for example:
Code:
import <miner.ash>
int[item] to_mine;
to_mine[$item[chrome ore]] = 16;
to_mine[$item[asbestos ore]] = 11;
to_mine[$item[linoleum ore]] = 12;
mine(to_mine);
The script will try to retrieve 3 chrome ore and if successful
will try to retrieve 3 more chrome ore and if successful
will try to retrieve 3 linoleum ore and if successful
will try to retrieve 3 asbestos ore and so forth until an unsuccessful retrieval attempt.

This ensures that you have the lowest amount of each ore if you end up having to mine. Witch means fewer caverns to mine through and a lot of saved turns.


Thanks goes to Zarqon, Jason Harper, mredge73, & Bale for helping me fix my n00bish scripting errors.

If you find this script useful donations in the form of in-game ninja paraphernalia are always appreciated! Thanks and enjoy the script!

Change log:
11.05.09 - Added mine() function. Changed counter_change() to switch.
09.24.10 - Added support for Anemone mine. Re-factored code. Overloaded the mine function to take a map. Converted prints to vprints and aborts to exits. Now restores your outfit to whatever it was before mining.
09.29.10 - Added the free_mine() function to utilize the Unaccompanied Miner skill.
09.30.10 - Fixed mine one access detection bug.
10.01.10 - Re-factored code to reduce some server hits.
10.04.10 - Last update to reduce server hits caused an infinite loop when finding a new cavern. Fixed that bug.
02.20.11 - Changed Harem location name.
05.29.11 - Fixed sea/mine3 detection error.
 

Attachments

  • miner.ash
    18.4 KB · Views: 1,417
Last edited:

zarqon

Well-known member
Nice! I love the handy aliases you include with your scripts, since I spend most of my time playing KoL in the CLI.

I think you should consider adding some functionality similar to obtain() where I could just tell it to mine for X of a given ore. A single function that does that would be a useful thing -- I think I would basically always use this to get X of a given ore, rather than to clear the top rows of the mine.

You may also want to consider using switch instead of if-else blocks. In some cases it would make your code a lot easier to read, for example your counter_change() function:

Code:
void counter_change(){
    switch (counter) {
       case 54:
       case 46:
       case 38: if (mineall) counter = counter - 3;
                 else counter = counter - 8; break;
       case 25:
       case 17: counter = counter - 3; break;
       case 9: visit_url("mining.php?mine="+mine.to_string()+"&reset=1&pwd");
                 counter = 54; break;
       default: counter = counter - 1;
    }
}

Thanks for sharing this.
 
I think you should consider adding some functionality similar to obtain() where I could just tell it to mine for X of a given ore. A single function that does that would be a useful thing -- I think I would basically always use this to get X of a given ore, rather than to clear the top rows of the mine.

By "functionality similar to obtain()" do you mean that it should try to retrieve the the items before it tries to mine? Would you be using this in a script? I'm not sure I understand what you're asking. :confused:

As far as using switch I tried implementing this several different ways when I first started writing this script awhile back and ended up running into some problems. I'll give it another go though. I can't even remember why I changed it to else if statements. :eek:

Thanks for the feedback. It is much appreciated. :)
 
I love this script!

Very helpful!
Glad you like it! I'm sure you'll enjoy this update as well.

Update v2.2

  • Added support for Anemone mine.
  • Re-factored code.
  • Enhanced retrieval logic - significant number of turns saved when mining.
  • Overloaded the mine function to take a map of items.
  • Converted prints to vprints and aborts to exits.
  • Now restores your outfit to whatever it was before mining.
 

th3y

Member
Feedback/suggestion: I would love it if there were a script (or addition to this script) that would optimally "use" my free turns of Unaccompanied Miner. In other words:
- while "free" minings remain:
- if L8 mine is accessible and do not have ores requested by trapper, hunt them
- else, among all accessible mines (Itznotyerzitz, Mine shaft, etc.) hunt most "profitable" encounters
- in HC/ronin, value = autosell; in aftercore, value = mallsell

As a token of appreciation, I'll offer a Mr. A PLUS a red balloon for anyone who substantially implements something like that ; ) [Must be in a way that does not interfere with maintainability of this script Miner.ash. In other words, imports Miner.ash and uses functions from it, not a modified "fork" of Miner.ash]
 
Last edited:
That's the next thing (and currently the only) on the implementation list. So the next update will be just for a free mine function.
 

natnit

Member
Feedback/suggestion: I would love it if there were a script (or addition to this script) that would optimally "use" my free turns of Unaccompanied Miner. In other words:
- while "free" minings remain:
- if L8 mine is accessible and do not have ores requested by trapper, hunt them
- else, among all accessible mines (Itznotyerzitz, Mine shaft, etc.) hunt most "profitable" encounters
- in HC/ronin, value = autosell; in aftercore, value = mallsell

As a token of appreciation, I'll offer a Mr. A PLUS a red balloon for anyone who substantially implements something like that ; ) [Must be in a way that does not interfere with maintainability of this script Miner.ash. In other words, imports Miner.ash and uses functions from it, not a modified "fork" of Miner.ash]

I'm pretty much done with this, but I've realized the only person that could fulfill your requests is FN Ninja!

A fork or rewrite of miner.ash is essentially required because somethings are hardcoded:
1) Mining only ends when you are out of turns or you have obtained as many ores as you have set out to. For this to work, there would need to be a function to mine X times. I could write such a function, but given the way the code currently is, it would require rewriting most of miner.ash.
2) Requirements of underwater breathing apparatus to free mine underwater. I have not found a convenient way of bypassing this.

Other than that, I just wanted to commend FN Ninja on this script; it's pretty darn clever in a bunch of places! :)

FN: If you want to discuss possible mining optimizations (and maybe even setting the counter dynamically via regular expressions on page visit) let me know!

th3y: If there were a function to spend one mining turn, I could wrap up the code in less than an hour. Advise further.

And just a fun fact. Based on the mining algorithm that miner.ash uses, here are expected returns per mining turn:
Autosell: Itz (43.20), Shaft (18.75), Anemone (48.4)
Mallsell: Itz (359.3), Shaft (77.41), Anemone (584.3)

Interesting that at current prices, in aftercore, Unaccompanied Miner pays for itself in ~38 days! :)
 
As a token of appreciation, I'll offer a Mr. A PLUS a red balloon for anyone who substantially implements something like that ; ) [Must be in a way that does not interfere with maintainability of this script Miner.ash. In other words, imports Miner.ash and uses functions from it, not a modified "fork" of Miner.ash]
Offer a Mr. A and ye shall receive. I stayed up after school scripting this, but was too tired to post it last night. I had a solid 9 hours of class time yesterday! Brutal Tuesdays.

Update 2.3

Added the free_mine() function. It uses the 5 free mine attempts granted by the skill Unaccompanied Miner. It will try to get the trapper ore if you still need it and can access Itznotyerzitz Mine. Then it will try to mine for the most profitable ore based on mine access and mall prices (or autosell value if in Ronin/HC).

Here is an alias to utilize the free mining that you get from Unaccompanied Miner:
alias fmine => ashq import <miner.ash> free_mine();

or you can import miner.ash and use the function in your daily routine.

I haven't tested free_mine() with the trapper quest. Let me know how it goes.


I just wanted to commend FN Ninja on this script; it's pretty darn clever in a bunch of places! :)
Thank you.

FN: If you want to discuss possible mining optimizations (and maybe even setting the counter dynamically via regular expressions on page visit) let me know!
Yes, I am interested.
 

th3y

Member
Thanks very much! It will take me 2-3 days before I can access needed resources, but I will then award:
- That FN Ninja: Mr. A + red balloon
- nitnat: Candy Cornucopia + red balloon
- oly0015: ninja pirate zombie robot head (he made an early attempt at this http://kolmafia.us/showthread.php?4748-Freemine.ash)

One question: just skimming the code, I see in free_mine():
Code:
			reset_mining_values();			
			set_amount(item_amount(best) + 5, best);
			mine_stuff();

Would free_mine() then necessarily mine 5 times, even if there were fewer than 5 free turns available when it is invoked? I'm thinking of a situation where, for example, you mine 3 free times from the relay browser, then later call free_mine(). Is there protection to ensure that the script wouldn't end up spending 3 adventures (2 remaining free mine plus 3 additional attempts)?

Also, does the "_freeMinesDepleted" property come from mafia itself? (In other words, can I use that from another script to detect whether I should call this one?)


EDIT: OK, skimming further, it looks like there is a flag (do_free) that prevents mine_stuff() from spending adventures during a "free" attempt...



-Th3y thank you
 
Last edited:

slyz

Developer
I just tested this in aftercore - I only needed to visit the old man to avoid having Mafia throw an error when getting a blank page from seafloor.php, but it's just a one time thing.

Thank you for sharing this wonderful functionality!

Also, does the "_freeMinesDepleted" property come from mafia itself? (In other words, can I use that from another script to detect whether I should call this one?)
Nope, mine.ash creates _freeMinesDepleted. And thank you for giving incentive to That FN Ninja to share this =)
 

natnit

Member
Thank you very much for your generosity, th3y. To uphold my side of the deal, I'll post what I had. It is obviously non-working (and in an unpolished state: don't make fun :)), but I think there might be some fixes (i.e. the definition of m1open, iirc) and useful functions that FN ninja can incorporate. Haven't checked his code yet (will do it in a moment), but I'm interested to see his algorithm for determining which mine is more profitable!
 

Attachments

  • natnit_freemine.ash
    4.8 KB · Views: 62

th3y

Member
Possible bug... yesterday, free_mine() went for chrome ore as expected, but today, it went for bubblewrap:
Code:
Calculating the best ore to mine...
Searching for "bubblewrap ore"...
Searching for "cardboard ore"...
Searching for "styrofoam ore"...
Current mall prices indicate that the best ore to mine would be...
the bubblewrap ore, which is selling for: 200 meat.

I am in aftercore, so do have mall access. Skimming the code, I think that when free_mine() is called directly as in the alias you suggested, m1open is never set. Thus the "mine 1" ores are not considered as possibilities in best_ore().

EDIT: aha. I manually put on the Dwarvish outfit before calling free_mine() today. In that case, the source of mclargehuge.php contains
Code:
<img src="http://images.kingdomofloathing.com/otherimages/mclargehuge/bottomright_outfit.gif"
so your test for m1open, which looks for "bottomright.gif" will fail.
 
Last edited:

slyz

Developer
m1open is set when the script is imported. The problem is that the script looks for ""bottomright.gif"" in mclargehuge.php, but when you have a mining outfit on, the name of the image is "bottomright_outfit.gif" instead.

Simply change line 80
Code:
boolean m1open = contains_text(visit_url("mclargehuge.php"), "bottomright.gif");
to
Code:
boolean m1open = contains_text(visit_url("mclargehuge.php"), "bottomright");
 

natnit

Member
/me points to his post and attachment above, which noted a fix for m1open :)

Sorry for not making it more clear! :)
 
/me points to his post and attachment above, which noted a fix for m1open :)

Sorry for not making it more clear! :)

It was clear, it's just that the first time I got back online to see your post the other posts where already there as well. Anyways, so thanks again.

Update 2.31

Re-factored code to save server hits when dealing with caverns that are already partially mined.
 
Top