KoLMafia Scripting Contest: Repair the Elves' Shield Generator

stannius

Member
Does "break", you know, break out of a loop? E.g. would this (pseudocode so as not to spoil others' contest entries) work (by which I mean, adventure until one runs out of adventures, or hits Big-Time, whichever comes first)?
Code:
while(my_adventures() > 0)
{
     string visitResult = AdventureOnHamburglaris();

     if (visitResult .contains_text("Combat"))
     {
          run_combat();		
     }
     else if (visitResult .contains_text("Big-Time Generator"))
     {
          PlayPorko();
          break;
     }
}

Also, is it possible to lose the generator game, if you make the right (best) choice? It's a little tough to figure out because you can only win once per ascension...
 

Bale

Minion
Yes. Break will do that. It's a little inelegant though. I'd usually do it like this:

PHP:
boolean done;

while(my_adventures() > 0 && !done)
{
     string visitResult = AdventureOnHamburglaris();

     if (visitResult .contains_text("Combat"))
     {
          run_combat();		
     }
     else if (visitResult .contains_text("Big-Time Generator"))
     {
          PlayPorko();
          done = true;
     }
}

There is always a successful game.
 
OK, I am having a very real problem with the Big-Time Generator and I absolutely cannot figure out why.

So, first, Big-Time Generator is a choice adv (#538) that has one choice, so I set_property("choiceAdventure#538","1") in the global declarations part of my script. So, now, when mafia hits Big-Time Generator, it should go directly to the Porko Board, where I load up the function that figures out which slot to play to win, and then create the visit_url with that index as the option=. Mafia consistently aborts with "encountered choice adventure with no choices". WTF am I doing wrong?

Code:
set_property( "choiceAdventure538", "1" );
int pickme;

int best_play() {
    string payouts =  get_property("lastPorkoExpected");
    string [int] payoutmap = split_string(payouts,":");
    pickme = 0;
    int max = to_float(payoutmap[pickme]);
    for index from 0 to 8 {
        float cur = to_float(payoutmap[index]);
        if ( cur > max ) {
            pickme = index;
            max = cur;
        }
    }
    pickme += 1;  // convert index of array to a slot number
    return pickme;
}

boolean repair_generator() {
    if (item_amount($item[e.m.u. unit]) > 0) equip($item[e.m.u. unit]);
    else return false;
    adventure(1,$location[Hamburglaris]);
    pickme = best_play();
    text = visit_url("choice.php?whichchoice=540&pwd&option="+pickme.to_string());
    if (contains_text(text,"you fall through one of those glowy-circle transporter things"))
        return true;
}

I think it's acting like best_play() isn't returning anything, but like i said, my porko script has exactly the same function and I don't have any problem with it there.

ETA: OK, so I went back over all the examples that are available and I think I might be an idiot.
Someone is gonna have to explain to me the reason for this extra (it seems extra)
Code:
 text = visit_url("choice.php")
before pickme = best_play()
 
Last edited:

stannius

Member
My ultimate goal is to be the go-to spaaace script. How long do I have to wait before I incorporate the good ideas from others' scripts, without invalidating my own entry? By copyright law, I think I can incorporate their ideas as long as I don't use their code. By patent law, their ideas are protected as well. :)
 
Last edited:

lostcalpolydude

Developer
Staff member
My ultimate goal is to be the go-to spaaace script. How long do I have to wait before I incorporate the good ideas from others' scripts, without invalidating my own entry? By copyright law, I think I can incorporate their ideas as long as I don't use their code. By patent law, their ideas are protected as well. :)

Contestants have until July the 31st to submit a script.
Probably then.
 

ralan

New member
I'm trying my hand at this, but I've never written anything in ASH before. Fortunately I've learned Java, but I'm generally pretty new to this stuff.

Does ash work similarly to java? What I mean is this:

PHP:
void function_01() {
  <command #2>;
}

void function_02() {
  <command #3>;
}
void main() {
  command #1
  function_01();
  function_02();
  command #4
}
Will this execute the commands in the order I've written? Just want to make sure I'm not making a massive assumption here..

Also, why do people put main() at the bottom? Is that just convention?

:) thanks. Hope that wasn't a stupid question.
 
Last edited:

slyz

Developer
My ultimate goal is to be the go-to spaaace script.
Hey, my ultimate goal is to be the go-to spaaace script, the contest is just a front so I can steal everyone's ideas!

But yes, please wait until the end of the contest to release anything that incorporates other people's ideas/code.
 

slyz

Developer
The commands are going to be executed in the order you numbered them. The only thing I can add is that any command at the top level will be executed before the main(), so you can have this:
PHP:
<command #1>;

void function_01() {
  <command #3>;
}

void function_02() {
  <command #4>;
}

void main() {
  command #2
  function_01();
  function_02();
  command #5
}

Also, why do people put main() at the bottom? Is that just convention?
In ASH, main() has to be at the bottom, since it will call other functions, presumably, and those functions have to be defined before the Mafia ASH parser reaches main().

If you call a function before defining it, you will get this kind of message:
Code:
[COLOR="#ff0000"]Function 'function_02()' undefined. This script may require a more recent version of KoLmafia and/or its supporting scripts. (test.ash, line 3)[/COLOR]

That reminded me to add a link to the KoLMafia Wiki ASH Errors page.
 

ralan

New member
Thanks! Now one more thing... is there any easy way to test my script, or do I just have to get feedback from others?
 

stannius

Member
In ASH, main() has to be at the bottom, since it will call other functions, presumably, and those functions have to be defined before the Mafia ASH parser reaches main().

It's similar to javascript, in that functions objects (?) are created as the parser encounters them as it traverses linearly through the file. (Though unlike javascript, AFAIK it doesn't do hoisting or anything.)
 

eegee

Member
Thanks! Now one more thing... is there any easy way to test my script, or do I just have to get feedback from others?
I have a similar question. I would really like to have a stab at making a script for this competition. Unfortunately, I have already completed the quest and there is no (easy) way for me attempt the quest again.

I have only one character and no multi's. I have never ascended and I have no intention of ascending any time soon. So my real question is: do you think Jick would ban me if I create a whole bunch of new accounts, send meat from my account to each of the new accounts, and test and complete the space quest with each of them?

If there is another simpler/better way to participate in this competition, I'm open to suggestions.
 

Winterbay

Active member
You could ascend and do it again :)
Or you could ask for volunteers, I'll be breaking the prism again in 1 or 2 days and could test the script for you then if you want to.
 

slyz

Developer
As long as the multis don't benefit your main, I think it's ok. That's how spading multis work, and no one seems to frown on those.

Of course, I may be wrong ^^
 

eegee

Member
Thanks Winterbay for the offer. I would take you up on the offer but I'll probably only start on the script next weekend.

slyz, I guess the multi's will be benefiting from my account since I plan to send them everything needed to do the quests. I've made an account on the KoL forums and I'm waiting for activation. I'll post a question there to see if what I want to do would be allowed.
 

lostcalpolydude

Developer
Staff member
If you want a more meaningful answer than slyz's post, send a kmail to Multi Czar. That is the only useful answer that comes out of those threads.
 
First, my rant in post 23... not completely without merit. After some more testing, I have determined that
Code:
adventure(1,$location[Hamburglaris])
isn't working. What does work is
Code:
visit_url("adventure.php?snarfblat=267")

Now, correct me if I'm wrong here, but shouldn't those two statements be functionally equivalent?
 

lostcalpolydude

Developer
Staff member
Code:
> ash adventure(1,$location[Hamburglaris])

Visit to Spaaace: Hamburglaris Shield Generator in progress...
[color=red]You can't hit anything there.[/color]

After removing some +ML...

Code:
> ash adventure(1,$location[Hamburglaris])

Visit to Spaaace: Hamburglaris Shield Generator in progress...

I lost the fight due to this being some random character, but there was no problem with adventuring there. Is Hamburglaris in your list of locations in the Adventure window?
 
Yeah, it is (in my list of locations in the Adventure Window). I don't know what the issue is, but it's the Big-Time Generator choiceadv that doesn't seem to fire if I get there from adventure() rather than visit_url().

So I should be more clear. For many versions the code in post 23, didn't work.
Code:
set_property( "choiceAdventure538", "1" );
adventure(1,$location[Hamburglaris]);
visit_url("choice.php?pwd&whichchoice=538&option=1"); 
text = visit_url("choice.php");

But when I change the adventure() to visit_url() as noted... the script runs perfectly thru the rest of its commands.
 
Last edited:

Veracity

Developer
Staff member
Yeah, it is (in my list of locations in the Adventure Window). I don't know what the issue is, but it's the Big-Time Generator choiceadv that doesn't seem to fire if I get there from adventure() rather than visit_url().
That is because ...

Big-Time Generator is a choice adv (#538) that has one choice, so I set_property("choiceAdventure#538","1") in the global declarations part of my script. So, now, when mafia hits Big-Time Generator, it should go directly to the Porko Board, where I load up the function that figures out which slot to play to win, and then create the visit_url with that index as the option=. Mafia consistently aborts with "encountered choice adventure with no choices"
... there is apparently something funky about how they made that button work such that it didn't look like the normal choice.php pages.

I'd have to see the HTML of the page with the single choice in order to figure out what the issue is.
 
Top