BatBrain -- a central nervous system for consult scripts

So I found a bug in BatBrain when you have an elemental form (like coldform).

the current code gives an error about editing a map's contents within foreach.

So I made the following change, which basically uses a couple of temporary variables to get around this mafia limitation.

It no longer breaks and appears to be working correctly with coldform.

(FYI this is the whole function, since I didn't have the original for a diff. The changes occur after the comment:
// if you have an elemental form, all damage to the monster is of that element)

Code:
advevent to_event(string id, spread dmg, spread pdmg, string special, int howmanyrounds) {
   int aoe = 1;
   advevent res;
   res.id = id;
   res.rounds = howmanyrounds;
   matcher bittles = create_matcher("([a-z!]+?) (.+?)(?:$|, )",special);
   while (bittles.find()) switch (bittles.group(1)) {
      case "att": res.att = aoe*eval(bittles.group(2),fvars); break;
      case "def": res.def = aoe*eval(bittles.group(2),fvars); break;
      case "stun": res.stun = eval(bittles.group(2),fvars); break;
      case "mp": if (my_class() == $class[zombie master]) continue;
         res.mp = eval(bittles.group(2),fvars); break;
      case "meat": res.meat = eval(bittles.group(2),fvars); break;
      case "item": string[int] its = split_string(bittles.group(2),"; "); float v;
         foreach n,it in its {
            if (contains_text(id,"enthroned") && $ints[3450,4469,1445,1446,1447,1448] contains to_int(to_item(it)) && stolen contains to_item(it)) { v=0; break; }
            v += item_val(to_item(it));
         } res.meat += v/count(its); break;
      case "aoe": aoe = min(howmanyfoes,to_int(bittles.group(2))); break;
      case "monster": boolean[monster] mlist; foreach n,mst in split_string(bittles.group(2),"\\|")
             mlist[to_monster(mst)] = true; if (!(mlist contains m)) return new advevent; break;
      case "notmonster": boolean[monster] mlist2; foreach n,mst in split_string(bittles.group(2),"\\|")
         mlist2[to_monster(mst)] = true; if (mlist2 contains m) return new advevent; break;
      case "phylum": if (m.phylum != to_phylum(bittles.group(2))) return new advevent; break;
      case "stats": string[int] sts = split_string(bittles.group(2),"\\|");
         foreach n,st in sts res.stats[to_class((n+1)*2).primestat] = eval(st,fvars); break;
      case "!!": res.note = bittles.group(2); break;
   }
   res.endscombat = special.contains_text("endscombat");
   res.dmg = factor(dmg,aoe);

   if (eform != $element[none]) {       // if you have an elemental form, all damage to the monster is of that element

      float tmp = res.dmg[eForm];
      element[int] toEmpty;
      foreach el,dm in res.dmg {
         if (el == eform) continue;
         toEmpty[count(toEmpty)] = el;
         tmp += dm;
      }
      res.dmg[eForm] = tmp;
      foreach eKey in toEmpty {
         res.dmg[toEmpty[eKey]] = 0;
      }
          if (res.dmg[$element[none]] > 0) { res.dmg[eform] += res.dmg[$element[none]]; res.dmg[$element[none]] = 0; }
   }
   res.pdmg = factor(pdmg,1.0);
   return res;
}

You'll find that I posted a similar fix 2 pages or so back I think :)
 
@zarqon: I think I found a couple of bugs in the blacklist code that should be fixed in the upcoming "cute mouse" version.

The first is:
if (blacklist contains ("use"+it) && blacklist["use "+it] == 0) continue;
should be:
if (blacklist contains ("use "+it) && blacklist["use "+it] == 0) continue;
Note the missing space.

The second is two lines later:
happenings["use "+it].queued >= max(0,item_amount(to_item(it)) - blacklist["use "+it])))) continue;
I think max should be min.

In temp_blacklist_inc() I think that blacklist[id] += amt;
should actually be blacklist[id] = max(blacklist[id], amt);

Also, this:
if (get_property("sideDefeated") == "neither" && item_amount($item[flaregun]) > 0) temp_blacklist_inc("use 1705",1);
Should be followed by this:
if (my_path() == "Bugbear Invasion") blacklist["use 1705"] += 1;
Unfortunately mafia does not have any tracking for the Bugbear Mothership, so we'll just have to leave that flaregun on permanent reserve.
 
Last edited:
Guys, I'm pretty sure it's a polar bear. Cats have ears like Asian emoticon eyes: =^..^=

@Bale: Space missing! Important fix! Thanks for catching that.

The max should be max. Unless that was your way of saying BatBrain should ignore all items?

Changing temp_blacklist_inc as you suggest would make it temp_blacklist_assign_sometimes instead. It would sometimes reserve the extra items, but not if you were already reserving an equal or greater number for something else. It's intended as a simple increment function which skips incrementing 0 (infinity as far as the blacklist is concerned).

Aha! People need a flaregun to save instances of Loathing from Bugbears! Will add that (using temp_blacklist_inc() -- simply incrementing the blacklist would override people who had blacklisted all flareguns, and go from reserving all of them to reserving just one).

I'm working on cute mouse right now, may edit this post with an update in a few hours!
 
I'm also glad I caught that space since it was causing the blacklist to fail for all items. I investigated it because of a bug report in the WHAM thread about WHAM not saving CSA obedience grenades.

Thanx for correcting my other corrections. I hadn't dug into BatBrain since I stopped developing DAM and the lack of practice shows. Decoding your scripts is a fine art.
 
Checking for updates (running BatBrain ver. /\/\^v^/\/\)...
The string "/\/\^v^/\/\" is not an integer; returning 0 (zlib.ash, line 181)
The string "(^" is not an integer; returning 0 (zlib.ash, line 181)
The string "/\/\^v^/\/\" is not an integer; returning 0 (zlib.ash, line 182)
The string "(^" is not an integer; returning 0 (zlib.ash, line 182)
New Version of BatBrain Available: (^._.^)~

Sorry guys! (cackles wickedly, no trace of apology in his eyes)

Why, oh why must you endure this putridity in your CLI? Has version (^._.^)~ brought you anything other than heartache?

Yes. Cute Mouse has brought you a refinement of the angular ASCII scrawlings from version /\/\^v^/\/\. It has brought you a cute face with an elegantly squiggly tail. But it doesn't stop there; further refinements include:

  • A fix for elemental forms.
  • A refactoring of to_event() for greater accuracy with not only elemental forms but also any formula which uses the "dmg" keyword (starfish- and mosquito-types, for starters). It should be a bit faster, as well, which adds up considering how many times this function is called.
  • A fix for hookspear wielders.
  • At least one more bulleted list.
Cute Mouse also takes the barest suggestion of direction present in Scrawled Bat and runs with it. We now have further integration of the "endscombat" flag:

  • When building an event in to_event(), BatBrain now automatically sets endscombat to true for events that deal enough damage to kill the monster (not including damage from other sources).
  • After enqueueing an action with endscombat == true, it considers the combat finished and no further actions can be enqueued.
  • BatBrain can check endscombat rather than dmg_dealt(blah) > monster_stat(hp) in other places, which is a speed improvement.
  • SmartStasis is going to take advantage of this flag and skip stuns before actions which are known to end combat. It's a useful flag, don't know why I didn't add it ages ago. Thank you, Cute Mouse!
If you, too, appreciate these fixes and updates, please express your gratitude to Cute Mouse himself. Since Cute Mouse is extremely refined, please avoid any coarse language, indefensible misspellings, or angular scrawlings.

@Bale: Not all items, only items which were set to total blacklist. But still an important fix.
 
Last edited:
Code:
The string "(^\" is not an integer; returning 0 (zlib.ash, line 181)
The string "(^" is not an integer; returning 0 (zlib.ash, line 181)
The string "(^\" is not an integer; returning 0 (zlib.ash, line 182)
The string "(^" is not an integer; returning 0 (zlib.ash, line 182)
The string "_\" is not an integer; returning 0 (zlib.ash, line 181)
The string "_" is not an integer; returning 0 (zlib.ash, line 181)
The string "_\" is not an integer; returning 0 (zlib.ash, line 182)
The string "_" is not an integer; returning 0 (zlib.ash, line 182)
The string "^)~" is not an integer; returning 0 (zlib.ash, line 181)
The string "^)~" is not an integer; returning 0 (zlib.ash, line 181)
The string "^)~" is not an integer; returning 0 (zlib.ash, line 182)
The string "^)~" is not an integer; returning 0 (zlib.ash, line 182)
New Version of BatBrain Available: (^._.^)~
Upgrade from (^\._\.^)~ to (^._.^)~ here!
It seems to be saying you're too clever for your own good ;) Changing it to "(^\._\.^)~" has it working properly.
 
Last edited by a moderator:
(^._.^)~ - "SQUEAK!"

Translation: "Right you are, good sir. I believe you will find that Master Zarqon uploaded a version of BatBrain which contained a horribly morbid image of me (all cut up, as it were), but I have taken the liberty of correcting his inexplicably heinous error and rejoining my various bits. My thanks are yours for having pointed this out."
 
I'm getting a error:

Division by zero (BatBrain.ash, line 835)

That area of the code looks like it's to do with BatMan RE, but after that I get rather lost...

SQUEAK
 
Cute Mouse in conjunction with Wham and SmartStasis wants to use a facsimile dictionary which then fails to enqueue and causes combat to revert to manual. Problem went away by putting dictionaty in closet.

Cute Mouse aborted with a divide by zero error at 835.

Disco Bandit in Bad Moon doing 100% Black Cat run which might both explain the first point and be a good reason not to address it.

Same character in HITS for the second.

I regret that I have placed Cute Mouse in exile to protect him/her from the Black Cat.
 
Well, based on fronobulax's report, I guess I'm just changing ASCII1 in the version check to ASCII2. At least until ASCII3 comes out. At which point ASCII1 might become ASCII3, or it might just get replaced. We'll see.
 
I think Cute Mouse is sulking because no thanks were directed his way. Fortunately, it's the cute kind of sulking.

Awww, there there Cute Mouse. Maybe if I revert the tiny change causing the divide by zero error people will show you some love.

*reverts line 832 without changing version number because to change the version number would be to change Cute Mouse himself*
 
Cute Mouse in conjunction with Wham and SmartStasis wants to use a facsimile dictionary which then fails to enqueue and causes combat to revert to manual. Problem went away by putting dictionaty in closet.

Cute Mouse aborted with a divide by zero error at 835.

Disco Bandit in Bad Moon doing 100% Black Cat run which might both explain the first point and be a good reason not to address it.

Same character in HITS for the second.

I regret that I have placed Cute Mouse in exile to protect him/her from the Black Cat.

I don't think it's related to the cat. I just had Cute Mouse/Wham/SmartStasis use a (non-facsimile) dictionary on a lobsterfrogman in a Jarlsberg run. It seems to think the dictionary will deal damage outside the Valley.

I've reverted to ASCII Bat, which is fine because it means I see a large red Cute Mouse in my CLI every time I automate a fight.
 
It turns out Cute Mouse was facing the wrong direction this whole time. I've sorted that out, so now the script ought to work fine again, including facsimile dictionaries.

~(^._.^) - "SQUEAK!"

Translation: -- Embarrassment needs no translation.
 
I've upgraded to the version in the first post but it's failing the version check:

New Version of BatBrain Available: (^._.^)~
Upgrade from ~(^._.^) to (^._.^)~ here!

The version currently posted has the tilde on the right side while the first post has the tilde on the left.

Does this mean that you'll have to make a version upgrade to fix the issue with the version upgrade?
 
Last edited:
Magnus, that's because the version checker cannot identify that a version with the tail on the left is better than a version with the tail on the right.

I would guess that you originally upgraded to the right-tail version and when you did, zversions identified that as the most recent version. Then you updated to the left-tail version, but zversions will not forget about the wonderfulness of right-tails until tomorrow.

To fix this, go to your /data directory and open zversions.txt in an unformatted text editor. Delete the line that starts with batbrain and save the modified file.
 
Back
Top