ZLib -- Zarqon's useful function library

zarqon

Well-known member
Woohoo!! I ADORE the new path, it is a thing of beauty and excitement, especially as it promises two more paths of equivalent allure. Oddly enough, in my pen/paper gaming group, one of our party members has just learned how to cast a spell which changes the target into an avatar of one of the two dead gods. He's planning on trying this new spell next session (tonight). I will be sure to share this information with him -- it is a very clear sign if you ask me.

I also adore the slew of multifarious updates to KoLmafia in the last couple months. I feel like the whole dev team/support minions have been attacking the feature/bug forum with a vengeance since 2012 rolled around, reducing the number of outstanding threads by a huge number. Veracity in particular has been on an improvement rampage! It's wonderful. Thank you, spendid, splendid devs.

Also thanks Bale for the lovely code.

First post updated, which also includes Theraze's "autostop" suggestion for obtain(). The best order is probably the order of frequency/likelihood, so I sorted them that way.
 

ereinion

Member
I think there might be a slight error with the version checking of your latest version. When calling a script that uses zlib, I get:
Code:
The string r34 is not an integer; returning 34 (zlib.ash, line 191)
The string r33 is not an integer; returning 33 (zlib.ash, line 191)
The string r34 is not an integer; returning 34 (zlib.ash, line 192)
The string r33 is not an integer; returning 33 (zlib.ash, line 192)
I'm using r10508 of mafia, in case it's a change of the mafia code that causing this, and not zlib itself.
 
Last edited:

Theraze

Active member
Hehe. Nope, that's a 'feature' of zarqon's love of putting 'r' on his version numbers. Open zversions and remove the zlib from the end, and it'll stop complaining.

For more info, read posts 840-842. :)
 

Bale

Minion
Earlier in this thread, zarqon suggested that was a "feature" since it would encourage script writers to use a proper versioning format. Heh.
 

zarqon

Well-known member
r35 Updates!

Since this update will save you time, I figured that justified taking your time by posting another update for you to download.

The big timesaver is that all forms of ZLib's has_goal() have been sped up considerably. Previously, has_goal(item) iterated over all items to see if the item being considered was an ingredient of any goals. Calling has_goal(monster) was slower still, because it calls has_goal(item) for each item the monster might drop. Finally, has_goal(location) dragged along, since it calls has_goal(monster) for each monster you might encounter. I have a macro called "goalinfo" which calls has_goal() on all items, monsters, and locations to tell me which items are/contain goals, which monsters drop goals at what rate, and which locations yield goals -- and until recently it took about a minute to run, due to all that "iterating over all items over and over" business. It was ugly and inefficient, but there was no better way.

Now, there is a better way. Hola has made goals accessible to ASH in new and exciting ways. For starters, has_goal(item) can check ASH's new goal_exists("item") right off the bat to see if there even are any item goals, and return 0 if not, without even getting into its calculations. Secondly, rather than iterate over all items to identify goals, we can now iterate over ASH's new get_goals(), which is so much smaller than the current number of items that the performance increase is massive, despite the fact that we have to run a matcher on each goal and then convert it to an item.

These new functions add up to has_goal() being significantly less expensive, and just as accurate. It's particularly noticeable using my (unedited) macro, which now finishes in about a second. SmartStasis contains 7 has_goal() calls in various places, so that will speed up a bit too. Exciting!

The second noteworthy change is a combination feature and bugfix, in reference to a discussion that occurred here back in December.

All functions which may benefit from using speculative values now include an optional usespec parameter. If omitted, it is assumed to be false and speculative values are not used at all. If true, speculative values are used. When using speculative modifiers, if you do not first speculate something, all modifiers will be 0 (_spec is empty). ZLib will help you avoid bizarre results by speculating nothing ("whatif quiet") if it detects that _spec is empty.

The following functions are now spec-optional, about the following modifiers:

int my_defstat( [boolean usespec] ) -- speculates about Buffed Muscle/Moxie
float has_goal(monster m, [boolean usespec] ) -- speculates about Item Drop and Pickpocket Chance
float has_goal(location l, [boolean usespec] ) -- speculates about Combat Rate

Any additional functions which may be added later will use this same format.

Any questions? Yes, you in the back.

Q: Does this update make my script more awesome?
A: If your script calls any form of has_goal(), it will be faster, which is awesome. If your script speculated and then used has_goal() assuming non-speculative results, your script will be fixed, which is awesome. So basically yes.

Q: Does this change break my script?
A: If your script previously speculated, and then relied on the speculative results given by has_goal(), you will need to change those calls to include the optional usespec parameter (true) -- otherwise non-speculative values will be used. So probably no, but possibly yes.
 
Last edited:

Donavin69

Member
I already updated to the new version, and was shocked how much faster SmartStasis and DestroyAllMonsters processed my fights. Thanks Zarqon!
 

zarqon

Well-known member
Thanks friends!

While I was playing around with the new functions, I discovered something. It seems when encounter rates are conditional or otherwise not well known for a zone, mafia lists the noncombat rate at -1. This breaks has_goal(location) for any of those zones which contain monsters -- for instance with a goal of gunpowder, has_goal(sonofa beach) returns 1.01, or 101%. This has been broken since has_goal(location) existed, in fact. Evidently not many people care much about the specific results of has_goal() other than that it's > 0!

So what I've done is upload a fix for that, completely ignoring noncombat rate for those zones -- which means Combat Rate modifiers will not affect the predicted outcome for those zones at all, even if it does in reality. Best we can do, I think. We'll call it an early-leaked feature of the next update, since it's evidently an unimportant fix.

Mafia lists the base noncombat chance at -1 for the following monster-containing zones:

  • Daily Dungeon
  • Burnbarrel Blvd.
  • Exposure Esplanade
  • The Heap
  • The Ancient Hobo Burial Ground
  • The Purple Light District
  • The Skate Park
  • Anemone Mine
  • Tavern Cellar
  • Cobb's Knob Barracks
  • Cobb's Knob Treasury
  • Belilafs Comedy Club
  • Hey Deze Arena
  • Post-War Sonofa Beach
  • Mt. Molehill
  • Barrel full of Barrels
  • The Barracks
  • The Primordial Soup
  • The Jungles of Ancient Loathing
  • Seaside Megalopolis
  • Hamburglaris Shield Generator
  • Small-O-Fier
  • Huge-A-Ma-tron
  • Kegger in the Woods
  • St. Sneaky Pete's Day Stupor
  • Elf Alley
  • CRIMBCO cubicles
  • Icy Peak of the Past
  • The Haunted Sorority House

Seems like perhaps there are known numbers which we could put in for some of them. On the other hand, if these are all conditional, that would probably be a feature request, to make appearance_rates() actually check those conditions where possible. On the other other hand, that might be too big an undertaking to be worth adding to mafia. Anyone know more than me about this? (Many hands go up.) Okay, better question: anyone care to share any constructive knowledge about this?
 

fewyn

Administrator
Staff member
The string "r35" is not an integer; returning 35 (zlib.ash, line 191)
The string "r34" is not an integer; returning 34 (zlib.ash, line 191)
The string "r35" is not an integer; returning 35 (zlib.ash, line 192)
The string "r34" is not an integer; returning 34 (zlib.ash, line 192)

Getting this like crazy.
 

linguinelad

Member
help

For some reason the libramburn script stopped summoning my dice while autoadventuring. These are my current variables in zlib.

zlib automcd = true
zlib defaultoutfit = current
zlib is_100_run = none
zlib libramburn_minmp = 75
zlib libramburn_summonbrickos = false
zlib libramburn_summondice = true
zlib libramburn_summonfavors = false
zlib libramburn_summonhearts = false
zlib libramburn_summoninhc = false
zlib libramburn_summonresolutions = false
zlib libramburn_summonsongs = false
zlib threshold = 3
zlib unknown_ml = 170
zlib vamp_do_isabellas = false
zlib vamp_do_masq = true
zlib vamp_do_vlads = false
zlib vamp_isabellas_goal = main
zlib vamp_masq_goal = heart
zlib vamp_masq_stat = main
zlib vamp_vlads_goal = spell damage
zlib verbosity = 3


I also want to add that I'm using daily build r10826. Strangely enough, I'm using libramburn on a multi which works fine, the difference is I'm using daily build r10797.
 
Last edited:

Theraze

Active member
Wouldn't it make sense to put this on the libramburn script thread instead of the zlib thread?

Also, any chance you're in HC currently? Since that's obviously turned off...
 

linguinelad

Member
Lol

Wouldn't it make sense to put this on the libramburn script thread instead of the zlib thread?

Also, any chance you're in HC currently? Since that's obviously turned off...

LOL. I just noticed that I posted it in the wrong thread. I was checking out this thread to see what some zlib vars did like the threshold var. Then I forgot to go to the libram burn thread to post it.

And no I'm not in HC.
 
Last edited:

Sines

New member
Trying to run a slime tube script. Except all it's ever done is send a k-mail telling I'm using it. This is the first script I've ever tried to use, so I have no idea what is going on. I saw someone suggest solving an issue by altering the zversions document, and while that did seem to have some kind of effect, the script still doesn't run, and I am still only half-slime-organed. Truly, this is tragedy.

Any idea what to do?
 

lostcalpolydude

Developer
Staff member
Trying to run a slime tube script. Except all it's ever done is send a k-mail telling I'm using it. This is the first script I've ever tried to use, so I have no idea what is going on. I saw someone suggest solving an issue by altering the zversions document, and while that did seem to have some kind of effect, the script still doesn't run, and I am still only half-slime-organed. Truly, this is tragedy.

Any idea what to do?

You might want to post in the thread for that script rather than in the zlib thread. Any help will depend on people knowing what script you are using.
 

atlasica

New member
I've downloaded networth.ash and tatoomatic.ash (along with ZLib), but whenever I try to run either of them, I receive a

Function 'goal_exists( string )' undefined. This script may require a more recent version of KoLmafia and/or its supporting scripts. (zlib.ash, line 336)

error...

Would this be a problem with networth/tatoomatic? Or something else?
 
Top