CanAdv -- check whether you can adventure at a given location

Winterbay

Active member
I use a few functions to do things pretty similar to what you pointed out earlier in this thread.

PHP:
// arg = "stepNx" will return N * 10 + <letters a-i transmogrified into digits 1-9>
int numerify(string arg)
{
    int max_steps = 12;
    matcher m_step = create_matcher("^step(\\d+)([a-i]?)$", arg);
    switch {
    case arg == "unstarted": return -1;
    case arg == "started": return 0;
    case arg == "finished": return max_steps * 10 + 10;
    case arg == "step0": break;
    case find(m_step): //for i from 0 to 2 print("group " + i + " = \"" + group(m_step, i) + "\"");
        string d = group(m_step, 1);
        string s = group(m_step, 2);
        // if d <= max_steps && there's no extra "0"s return maths
        if (length(d) <= (d.to_int() > max_steps ? 0 : (d.to_int() > 9 ? 2 : 1))) return d.to_int() * 10 + (s == "" ? 0 : index_of("_abcdefghi", s));
    }
    nb_abort("\"" + arg + "\" doesn't make any sense at all.");
    return -11;
}

boolean is_at_least(string a_string, string b_string)
{
    if (numerify(a_string) >= numerify(b_string)) return true;
    else return false;
}

boolean is_past(string a_string, string b_string)
{
    if (numerify(a_string) > numerify(b_string)) return true;
    else return false;
}

boolean is_not_yet(string a_string, string b_string)
{
    if (numerify(a_string) < numerify(b_string)) return true;
    else return false;
}

The numerify() function is more elaborate than it really needs to be because my quest scripts also use pseudo steps like "step4d". But doing things like:
Code:
 if (get_property("questL04Bats").is_at_least("step3")) print("yay!")
is kind of handy.

Interesting. Mind if I modify that for use in bumcheekascend when I get some time over?
 

Theraze

Active member
Sounds good... I'll probably end up using the numerify functions instead of Bale's switches from earlier, but plan on having that into 0.82 today. Some slight tweaks to shorten the lines:
Code:
boolean is_exactly(string a_string, string b_string)
{
    return (numerify(a_string) == numerify(b_string));
}

boolean is_at_least(string a_string, string b_string)
{
    return (numerify(a_string) >= numerify(b_string));
}

boolean is_past(string a_string, string b_string)
{
    return (numerify(a_string) > numerify(b_string));
}

boolean is_not_yet(string a_string, string b_string)
{
    return (numerify(a_string) < numerify(b_string));
}
Also had to add an "is_exactly" for the Boss Bat fight, since it's only available at step3.
 

nworbetan

Member
Both of you feel free to use it wherever, and I'll be glad I could help.

It's funny, I finally noticed how redundant those "if"s (and parenthesis) were after I posted it too. :)
 

Theraze

Active member
New canadv released, with the various changes noted above. Oh yeah... also changed it so that prep requires validation rather then always believing it's opened up. :)
 

nworbetan

Member
Since I can probably count the number of people who are going to actually use those crazy pseudo quest step things on one finger, here's a substantially less convoluted version of numerify():
PHP:
int numerify(string arg)
{
    int max_steps = 12;
    matcher m_step = create_matcher("^step([1-9][0-9]*)$", arg);
    switch {
    case arg == "unstarted": return -1;
    case arg == "started": return 0;
    case arg == "finished": return max_steps + 1;
    case find(m_step):
        int i = group(m_step, 1).to_int();
        if (i <= max_steps) return i;
    }
    abort("\"" + arg + "\" doesn't make any sense at all.");
    return -11;
 }
 
Last edited:

Theraze

Active member
Took out the letter detection and ended up with this, that works... benefits/drawbacks between this and your version in 225?
Code:
int numerify(string arg)
{
    int max_steps = 12;
    matcher m_step = create_matcher("^step(\\d+)*$", arg);
    switch {
    case arg == "unstarted": return -1;
    case arg == "started": return 0;
    case arg == "finished": return max_steps + 1;
    case find(m_step):
        string d = group(m_step, 1);
        if (length(d) <= (d.to_int() > max_steps ? 0 : (d.to_int() > 9 ? 2 : 1))) return d.to_int();
    }
    vprint("\"" + arg + "\" doesn't make any sense at all.", -3);
    return -11;
}
Looks like you convert the string a bit earlier and I'm not completely sure if your matcher actually works properly in the Wossname... I think step 10 would fail and be detected as step 1.

Edit: Changed the find section to this, based on your code:
Code:
    case find(m_step):
        int d = group(m_step, 1).to_int();
        if (d <= max_steps) return d;
Should work with any number given.

Edit2: Got it... your matcher skips step01-type checking explicitly and is a 2-digit number matcher. Eh, may as well leave it easier. :)
 
Last edited:

nworbetan

Member
The regex in #225 just checks to see that the "stepN" is well formed, and it'll accept any N as long as it doesn't start with a 0. It's so much easier and more straighforward that way, instead of creating roundabout exceptions to let "step0<a-i>" pass and then exceptions to those exceptions to block "step0". >_<
 

nworbetan

Member
Yeah, "step0<anything>" being illegal is kind of exactly why I set the function up to stop and complain if it sees it. You know, accept what it can use, reject what it can't. ;)
 

Donavin69

Member
it appears that the new peak has broken CanAdvs ability to see it is available. I turned the verbosity all the way to 10 hoping to get more output from my little script:

Code:
import <canadv.ash>

void main() {
	if(can_adv($location[Icy Peak],false))
		print("Can adv");
	else
		print("Can't adv");
}

but I simply get:
PHP:
Running The CanAdv Project version: 0.82 (current)
Can't adv
 

Theraze

Active member
It's because the entry is not the Tr4pz0r anymore, but the Trapper. Spelling kills, kids. And punctuation saves them. :)
 

Theraze

Active member
Anyways, realized today that the reason why Ninja Snowmen hasn't been seen as a bounty location is because the gif name changed from leftmiddle.gif to lair.gif, so... New CanAdv, now with goatlet/extreme/snowmen unlocking. Again.
 

Crowther

Active member
The script requests I report unknown locations here. . .

Code:
Unknown location: Anemone Mine (Mining)
Please report this missing location here: http://kolmafia.us/showthread.php?t=2027
Checking resistance to stench...
You can already resist stench.
Unknown location: The Knob Shaft (Mining)
Please report this missing location here: http://kolmafia.us/showthread.php?t=2027
Unknown location: Mist-Shrouded Peak
Please report this missing location here: http://kolmafia.us/showthread.php?t=2027
Unknown location: Itznotyerzitz Mine (in Disguise)
Please report this missing location here: http://kolmafia.us/showthread.php?t=2027
 

Theraze

Active member
Believe those were added a while back. Anyways, new Level 8 and Level 9 quest zones should be added now.
 

fewyn

Administrator
Staff member
I just noticed this script doesn't take into account if the player has a skeletal skiff instead of a dinghy.
 

heeheehee

Developer
Staff member
Dec 31 announcement said:
Also, stat requirements on zones are now recommendations, rather than requirements. Zones want to be free!

Just change primecheck(int) to always return true, methinks?
 

Winterbay

Active member
Except that mafia still disallows adventuring in the areas.

Not really. If you go somewhere where you are too low levelled KoL shows you a page which says "Are you sure you want to go here, you are a bit under levelled. It is recommended you get X mainstat first" (or similar), with a tic-box to allow you to not show that again. And if autoadventuring Mafia will loop around saying "adventure 1 of n, You gain X substats" which probably should get reported as a bug.
 

Theraze

Active member
True. If, at some point, mafia actually tracks if people have selected to have KoL no longer limit their adventuring, at that point we can make stat requirements no longer matter. Until that point when it's tracked...
 
Top