New ASH function request! retrieve_item_cheapskate()

dj_d

Member
First things first: Kolmafia has breathed new life in to my playing (dormant since 2005). Holatuwol, you're a miracle worker. Wow!

I'm joking about the function name, but I'd love a way in ASH to duplicate the functionality of acquire/retrieve() but with a maximum cost. Here's how I imagine it'd work.

int retrieve_item(int quantity, item it, int budget);

This function would calculate the total cost to retrieve the number of items specified by standard mechanisms: mall, chez snootee, Hangks if available, etc. If the cost is less than budget, it would execute the retrieves. If the cost is more than budget, it would return the price difference. If the items are unavailable, it returns zero.

A sister function would be budget_item. It would do the same thing, except not buy.

Perhaps one more thing: retrieve would be extended to return what it actually paid for the item, in case you're shopping on a limited budget and want to keep track of how much you spend.

This would be a HUGE boon to a whole class of scripts. Want to have twinkly wads at breakfast, but worried the price will spike sometime and kolmafia will auto-bankrupt you? No problem. Acquire only if the total price is less than 4500 meat, otherwise, throw an error so you know you need to change breakfasts.

Or think about scripts like maximize.ash. You could write a script that would maximize your +HP, given everything you own plus a budget of 100,000 meat. It could recommend or purchase specific purchases and even execute them for you.

Or wossname.ash could let you specify a budget for meat vortices and related handy items... there's tons of uses!

The one problem I can anticipate is that mall prices can change fast. Say you're looking for 2 hell ramens for 5,000. And say there appear to be 1 for 2,450 and 1 for 2,550. It purchases the first one, and the second disappears, so it's not able to complete on budget. Suck. Perhaps it has more robust error cases for "got some but not all"?

Anyway, I can imagine this enabling a whole new class of scripting awesomeness. It's top on my wishlist for kolmafia.

Keep up the great work, H!
 

Sandiman

Member
I don't think any of those ideas need to be implemented in ASH itself. I'm fairly certain ASH programmers/I would be able to make things like "retrieve_item(int quantity, item it, int budget)" as wrappers to existing functions. If you're interested, I'd be happy to offer out my services for hire (PM me with an offer). Otherwise, this should probably be reworded as a script request/reward as opposed to an ASH modification.
 

dj_d

Member
I'll defer to the maintainers of the scripting language, but it does seem like something of an oversight that among all the wonderful and useful things you can find out about your character, environment, etc, there's no provisions for finding out mall prices.

Still, if I'm the only one who thinks it'd be handy, then by all means (powers-that-be) do ignore my suggestion! It's not worth it to please just me.
 

dj_d

Member
By the way, I did read the current ASH function list and didn't see the two key things I'd need to implement what I'm talking about myself
- get mall price for an item
- buy an item if it doesn't exceed mall price
(note: not the same as checking the price, then buying the item, since you need the transaction to be atomic)

If I'm missing the above, then my bad!
 

zarqon

Well-known member
For your budget idea, pretty sure this will mostly do what you want:

Code:
boolean retrieve_item(int quantity, item it, int budget) {
  int reserve = my_meat()-budget;
  if (reserve > 0)
   cli_execute("closet put "+reserve+" meat");
  boolean itworked = retrieve_item(quantity, it);
  if (reserve > 0)
   cli_execute("closet take "+reserve+" meat");
  return itworked;
}

You can also keep track of how much you spend by comparing my_meat() before and after you call retrieve_item().

Similarly, the only way to get mall prices is to buy the items. Which is as it should be. I agree with the powers that be that the power to easily write evil mallbots is too dangerous a power to set loose in this world.
 

Paragon

Member
I agree that the mall bots are not good news... i mean, i would like one... but so would everyone else and i agree that not everyone should be able to easily have a mall bot... by the same token, i also agree that having a better method for buying items out of the mall would be a great idea.
How about we made the function to attempt to buy the item using X meat but only return either pass or fail. Either you bought the item for that amount or less, or you didn't. This would make it so that it couldn't really be used for a mall bot any easier then i currently can (You'd have to buy the item to find the price just like you do now.) Granted you would be able to tell if an item was more expensive then a particular value, but as the post above just pointed out you could already do that (or you could put any amount of "Safe" meat into a trade, gift, kmail.. etc.)
The proposed new function would simply reduce the number of server hits on kol.
 

dj_d

Member
Perhaps KOLMafia could implement a pricecheck feature that returns the *second* cheapest mall price (or the cheapest if more than one person is offering it at the same price). I can't think offhand of how to use that for malicious mallbotting - anyone?

Zarqon, that's very clever. Thanks! I'm going to use that approach in my goodnight script, and it's a huge headache saver.

And by the way, OCW is one of my favorite scripts!
 

dj_d

Member
Interesting problem with your script, Z, that I think might be a mafia bug. If you timeout before running it, then the "closet put" command will cause mafia to reconnect, but the command won't actually work. You don't put the meat in, so you wind up with 2x as much meat in your inventory (because the "closet take" does work). Do you know of a command to "refresh" the connection? Right now, I'm putting and taking 1 meat from the closet each time I do anything, but that's not really optimal. :)
 

zarqon

Well-known member
Interesting idea. I'd like an ASH function that would return the average price from the top 5 stores. Or top 10, if that's safer. I don't believe such a function would make the mall exploitable, and it would give people a fair idea of what price they could expect to pay for something.
 

zarqon

Well-known member
I use that very method for my StashBot script, but it's not very reliable. Many items lack sufficient data to get an accurate value consistently. I occasionally get clan members complaining that their items were misvalued. You can try it using this little scriptlet. If it's accurate enough for you, you can probably figure out a way to make it work for you. Until something better comes along, this is my way around the item value issue.
 

Attachments

  • value.ash
    509 bytes · Views: 34

zarqon

Well-known member
Eureka! An ASH function that returns the lowest mall price for an item once per item per day. It's true that users could find where that data is stored, clear the value and recall the function, but that's more trouble than just manually reloading the mall store.

What do you think, mafia developers? Safe enough?
 

dj_d

Member
Hm... I just spent a bunch of time with value.ash, and it's started running funny. After working reasonably well for a few tests, I pulled the value of every food and drink item to create a spreadsheet of them (want to figure out some idea consumption strategies given current mall prices) and it returned either 100 or 0. Did I break it? :)
 

zarqon

Well-known member
That's what I mean about not every item on the wiki having sufficient data. It is also dependent on two other servers being operational and all of them having the necessary ports open. Some days it seems to work great, other times it seems to behave as you described. Which is why a mall_value(item) ASH function (once per day per item) would be terrific.

I put a lot of time and effort into writing this very complicated workaround (hitting a server that hits a server) but I would be happy to throw all that out, and no doubt so would the two hosts in question, if mafia could provide values internally.
 

dj_d

Member
OK. I've been noodling on a script that keeps a text file of the "last known good" price of items. It would update any time your function retrieved a value that looked nonbogus (trying once a day). When it tried to buy something, it'd use the retrieve_item_cheapskate approach discussed above. When it succeeded, the purchase price would be the new canonical price. My thought is it would also probably average the last 3 known good prices.

What's annoying is I only really want this for stuff whose price doesn't change much day by day. I just want to know if I should be buying hell ramen or chow mein etc.
 

zarqon

Well-known member
Yeah, as I wrote your new scriptlet's thread, I didn't know about that other site. Looks great! Less info to work with, but more thorough. I'm still hoping for a response from someone with ASH-editing power about a time-limited internal value() function.
 
Top