BatBrain -- a central nervous system for consult scripts

zarqon

Well-known member
Hey all, I've run into some issues which I suspect may stem from caching profit in advevents, preventing me from making the next release. I'm tracking that down at the moment -- once I've got it sorted, I'll have a delicious release of tastiness for you.

@xKiv: Ah, I get it. I'm talking average actions, and you're talking average results.

There has long been a plan for ranges to be a part of BB's calculations, but I was going to make them fall under the "pessimism" setting. When evaluating action formulas, those containing ranges would have those ranges not averaged, but placed at a point somewhere between MIN and MAX based on your setting. I believe when that day comes, your complaint, which I am going to take as a suggestion, would allow us to do one better.
 

Bale

Minion
Hey all, I've run into some issues which I suspect may stem from caching profit in advevents, preventing me from making the next release.

Oh thank goodness! I was seeing some inconsistent results that I was struggling to understand, but I couldn't figure out where the bug was coming from! That might be the problem I was being bothered by so I am really happy you found it.
 

Theraze

Active member
Not sure if this happens on all free/unique runaways or if it's just the clingy pirate that's special, but getting this:
Custom action: use 2956 (stun first with skill 11003)
Destroy with: Mighty Axing
Round 1: Theraze executes a macro!
Round 1: Theraze casts BROADSIDE!
Round 2: Theraze uses the cocktail napkin!
DestroyAllMonsters was unable to figure out a useful combat strategy
You're on your own, partner.
Basically, the fight is over but BatBrain is telling DAM that it's still going on. Do all of the unique run-aways need handling for BB to know that the fight is done?
 

Winterbay

Active member
It also enlightens another wonderful batbrain bug: Using Broadside before banishing the monster is ... pretty pointless.
 

Theraze

Active member
I think that was noted earlier as BatBrain not being aware that it will definitely end combat, and therefore that stuns are useless. I'm just happy that it does use Broadside now when I'd otherwise get hit. :)
 

zarqon

Well-known member
1.1 Squared (1.21) Update, on 4.14

This is basically a de-wonking update, as I encountered some wonkiness from the previous update.

First, caching profit for all advevents was not working, since it was also caching profit for things like the base round event, so instead I opted to continue to calculate each time in to_profit() -- however, that function also saves the result in the advevent's profit field, meaning that a scripter can choose whether or not to use the profit field or the more expensive to_profit() function.

For example, in the attack_action() sort, I sort opts like so:

PHP:
   sort opts by -to_profit(value);
   sort opts by kill_rounds(value.dmg)*-(min(value.profit,-1));

Since the result of to_profit() is stored in the profit field during the first pass, for the second sort I simply reference the cached value, thus speeding things up.

The other fixes have mostly all already been discussed in this thread, but here they are for completeness:

  • Use the same checks mafia does to determine combat completion.
  • Fix auto-funk, which was not quite correctly implemented last time.
  • Don't auto-funk when you have no need to make combat take fewer rounds (i.e. during stasis)
  • The last update's code optimization ended up removing formulas from any actions flagged with "regular" -- meaning that TT skills didn't include the added damage from butting, among others. Fixed that without reverting the optimization.

Didn't quite make it to implementing the pessimism thing this time (sorry Bale), although I think I did add the setting itself. I've come down with a nasty cold and decided to update now before sinking into my bed for a week.

Enjoy!
 

Bale

Minion
Thank you. I like the to_profit storing so that the function doesn't need to be called as frequently. I look forward to taking it for a spin so I can see how much better it works.
 

Theraze

Active member
Hope you heal up well!

Yes, there is a pessimism value set. Yes, the comments tell you what it will do. No, it's not used anywhere in the file besides where it's initially set.
 

Winterbay

Active member
It appears that the fix to "regular" formulas screwed something up for all other skills. WHAM uses the following to set up skills:
Code:
//Check for the skills included in calculations
skill[int] allMySkills()
{
	skill[int] allmyskills;

	foreach i,opt in opts
	{
		vprint("Currently checking " + opt.id + " which has a reported damage of " + dmg_dealt(opt.dmg) + ".", "purple", 10);
		vprint("Raw damage is estimated at " + opt.dmg[$element[cold]] + ", " + opt.dmg[$element[hot]] + ", " + opt.dmg[$element[stench]]+ ", " + opt.dmg[$element[spooky]] + ", " + opt.dmg[$element[sleaze]] + ", " + opt.dmg[$element[none]] + ".", "purple", 10);
		if (contains_text(opt.id,"skill ") && dmg_dealt(opt.dmg) > 0 && ok(opt))
				allmyskills[count(allmyskills)] = to_skill(to_int(excise(opt.id,"skill ","")));
	}
	sort allmyskills by -value.mp_cost();
	return allmyskills;
}

This has worked fine until very recently when it stopped working. I did a check at verbosity 10 and got the following output:
Code:
> WHAM: Evaluating the attack but not performing it took 0.031 seconds.
 > Running ZLib version: r35 (current)
 > 1 HP costs 6.667μ. ( 264 / 312 )
 > 1 MP costs 17μ. ( 41 / 67 )
 > Running BatBrain version: 1.21 (current)
 > Running SmartStasis version: 3.14 (current)
 > Running WHAM version: 1.9 (current)
 > WHAM: We currently think that the round number is: 0
 > WHAM: No need to do anything with this monster.
 > procrastination potion (30.0 @ +95.874825): 138μ * 58.762447% = 81.09218
 > procrastination potion (30.0 @ +95.874825): 138μ * 58.762447% = 81.09218
 > Parsed round number: 2
 > Building options...
 > Evaluating 'max(170.0,max(84.0,67.0))'...
 > Options built! (19 actions)
 > WHAM: We currently think that the round number is: 2
 > WHAM: You have no profitable MP restoratives.
 > WHAM: You have no profitable HP restoratives.
 > WHAM: You are fighting a Procrastination Giant. Mafia considers that this monster has an attack of 87 or 125 when given a monster name.
 > WHAM: Mafia further considers that this monster has a defense value of 75 or 113 when given a monster name.
 > WHAM: Mafia further further considers that this monster has a HP value of 150 or 150 when given a monster name.
 > WHAM: Your current ML-adjustment is: 0.
 > WHAM: Setting up variables via BatBrain
 > WHAM: Monster HP is 150.0.
 > if pastround 49; abort "Stopping fight because it has gone on for too long (set WHAM_maxround to a higher value if you think this was in error)"; endif; 
 > WHAM: We currently think that the round number is: 2
 > WHAM: SS did not finish the script off, continuing with script execution. 
 > WHAM: Starting evaluation and performing of attack
 > WHAM: We currently think that the round number is: 2
 > WHAM: You will kill the monster in 2 rounds with your basic attack.
 > WHAM: The monster will take 23 rounds to kill you.
 > rounds_to_kill: 2, round_limit: 10, maxround: 30, die_rounds(): 23, hitchance("attack"): 0.95454544
 > WHAM: Expected received damage per round: 11.503806, Rounds to kill: 2, Expected damage: 138.85773, Hit chance: 1.0
 > Currently checking use 1788 which has a reported damage of 0.0.
 > Raw damage is estimated at 0.0, 0.0, 0.0, 0.0, 0.0, 0.0.
 > Currently checking use 347 which has a reported damage of 0.0.
 > Raw damage is estimated at 0.0, 0.0, 0.0, 0.0, 0.0, 0.0.
 > Currently checking use 474 which has a reported damage of 0.0.
 > Raw damage is estimated at 0.0, 0.0, 0.0, 0.0, 0.0, 0.0.
 > Currently checking use 469 which has a reported damage of 0.0.
 > Raw damage is estimated at 0.0, 0.0, 0.0, 0.0, 0.0, 0.0.
 > Currently checking use 208 which has a reported damage of 0.0.
 > Raw damage is estimated at 0.0, 0.0, 0.0, 0.0, 0.0, 0.0.
 > Currently checking use 2966 which has a reported damage of 0.0.
 > Raw damage is estimated at 0.0, 0.0, 0.0, 0.0, 0.0, 0.0.
 > Currently checking use 3020 which has a reported damage of 0.0.
 > Raw damage is estimated at 0.0, 0.0, 0.0, 0.0, 0.0, 0.0.
 > Currently checking skill 11026 which has a reported damage of 0.0.
 > Raw damage is estimated at 0.0, 0.0, 0.0, 0.0, 0.0, 0.0.
 > Currently checking skill 11003 which has a reported damage of 0.0.
 > Raw damage is estimated at 0.0, 0.0, 0.0, 0.0, 0.0, 0.0.
 > Currently checking use 549 which has a reported damage of 0.0.
 > Raw damage is estimated at 0.0, 0.0, 0.0, 0.0, 0.0, 0.0.
 > Currently checking use 747 which has a reported damage of 3.0.
 > Raw damage is estimated at 0.0, 0.0, 0.0, 0.0, 0.0, 3.0.
 > Currently checking use 563 which has a reported damage of 6.0.
 > Raw damage is estimated at 0.0, 0.0, 0.0, 0.0, 0.0, 6.0.
 > Currently checking use 2493 which has a reported damage of 17.5.
 > Raw damage is estimated at 0.0, 0.0, 0.0, 0.0, 0.0, 17.5.
 > Currently checking use 1705 which has a reported damage of 19.800001.
 > Raw damage is estimated at 0.0, 6.6000004, 0.0, 0.0, 0.0, 13.200001.
 > Currently checking use 630 which has a reported damage of 40.0.
 > Raw damage is estimated at 0.0, 0.0, 0.0, 0.0, 0.0, 40.0.
 > Currently checking attack which has a reported damage of 138.85773.
 > Raw damage is estimated at 9.545454, 0.0, 0.0, 0.0, 0.0, 129.31227.
 > Currently checking skill 11000 which has a reported damage of 145.47.
 > Raw damage is estimated at 10.0, 0.0, 0.0, 0.0, 0.0, 135.47.
 > Currently checking skill 11001 which has a reported damage of 150.0.
 > Raw damage is estimated at 10.0, 0.0, 0.0, 0.0, 0.0, 337.82.
 > Currently checking use 5048 which has a reported damage of 150.0.
 > Raw damage is estimated at 170.0, 0.0, 0.0, 0.0, 0.0, 0.0.
 > WHAM: Debug printing the damage dealt by your skills.
 >  
 >  
 > WHAM: Evaluating the attack but not performing it took 0.016 seconds.

As you can see items seems to work fine (but are not used by WHAM yet, I'm working on that), and skills evaluated by "regular" seems to work fine as well (such as attack, mighty axing and cleave) while heroic belch returns 0 as does throw trusty (but that' snot in batbrain so that's not so surprising).

Any idea what is going on here?
 

Winterbay

Active member
Double posting with new information.
I used the magic of dropbox to revert back to version 1.2 and lo-and-behold the script now works as expected again. I then looked at the changes done and found that in the build_skillz()-function the following was removed in version 1.21:
Code:
      if (dmg_dealt(d) == 0) {          // formulaic damage calculation if it wasn't set in the special cases above
         d = to_spread(fields.dmg);
         if (isseal) foreach el,amt in d if (d[el] > 0) d[el] = min(1.0,amt);
      }

I am very much convinced that this is the reason that heroic belch didn't show up in 1.21 but does so in 1.2. Can anyone give a reasonable explanation as to why this was removed from there?
 
I use BatBrain as required by SmartStasis. The most recent update to BatBrain has changed the skill used for statising: before the update it was Lasagna Bandages, now it's Ravioli Shurikens. This ends combats much sooner: most end by round 5, whereas last week they'd usually go past 12. I'm farming with a mimic, so that makes a big difference. Is there a way I can tell BatBrain which skill to use if nothing better is available?
 

Theraze

Active member
Use the version of BatBrain on the WHAM topic, for now. Because of a bug with BatBrain 1.21, it believes all non-regular-damage skills do 0 damage, so ravioli is the same damage as spaghetti is the same damage as weapon. Winterbay's tweaked version does properly use (and not use) damaging skills again. Note that as soon as BatBrain 1.22 (or whatever version... 1.21.1 would work also) comes out, you should probably update to that. :)
 

Winterbay

Active member
Yeah, my version is definitely only an interim version until zarqon gets well enough that he manages to release an official fix.
 

zarqon

Well-known member
Ack. Was hoping 1.21 would last longer than that, but that's an important fix to make. I'd moved that bit to a new location, but it didn't work there and I removed it without replacing it in the old place. So I just put the important bit back in. Perhaps later I'll have time to optimize that for speed a little more, but for now that will work fine.

I think I also fixed the odd flyering issue Bale reported (and which I also encountered) where it would only flyer every other combat when automating. That was another repercussion of the server-hit-reducing change to SS.

Okay, hopefully this update will be stable for a while while I work on other stuff. The next update to SS will make use of the server hit reductions properly, in addition to paving the way for my pretty awesome new fight.ash.

Also, I somehow doubt you rolled back 19 versions. ;)
 

Fluxxdog

Active member
I came across an oddity. BatBrain rates VolcanoMeter Erupt... whatever! as being a 0 cost attack. Thus, even if you can one-hit kill a monster, it can still be the "cheaper" option. This is due to skill 55 not having an MP cost, but it does have a cost of volcanic ash. Now, simplest workaround would be to closet the ash, but I like to use it for boss fights and hate getting caught with my pants... ashless ^^ when I suddenly find out I can't use that skill. My own personal copy of BatBrain has to_profit() adjusted like this:
Code:
float to_profit(advevent haps) {          // determines the profit of an action in the current combat
   advevent a = oneround(haps);
   haps.profit = minmax(-a.pdmg[$element[none]],-my_stat("hp"),max(0,my_maxhp()-my_stat("hp")-0.9*numeric_modifier("_spec","HP Regen Min")))*meatperhp +  // hp
          minmax(a.mp,-my_stat("mp"),max(0,my_maxmp()-my_stat("mp")-0.9*numeric_modifier("_spec","MP Regen Min")))*meatpermp +    // mp
          (a.att == 0 ? 0 : (m_dpr(0,0) - m_dpr(a.att,0))*meatperhp) +  // delevel
          a.meat;                                                       // meat
		[COLOR="#FF0000"]if(haps.id=="skill 55") haps.profit-=historical_price($item[volcanic ash]);[/COLOR]
   return haps.profit;
}
I was wondering, is there a better fix or a reason ash wasn't included to begin with?
 

zarqon

Well-known member
Thanks for bringing that to my attention -- presently Volcanocumulostratostruthioaustralopithecanthophthalmoruption is the only skill that costs an item, not to mention a skill I lack and thus can't test, but it might be nice to be able to account for skill "material component" costs more easily in the future. There is a better fix, and I'll make it for the next release, which unfortunately looks like it ought to be sooner again rather than later. Fumbles were being inappropriately added to all melee attack skills, when actually you can only fumble on a regular "Attack with weapon". This wouldn't be a high-priority bugfix except it meant that attack_action() preferred attacking with weapon over Mighty Axing in Boriscore.

I'm also taking advantage of the new effect() function in modifier_eval() formulas to reduce some of the overhead when building skills (16 instances in batfactors can now eliminate about 10 fvars and even more checks), so we may as well throw that into the mix and call it another update. ETA: tomorrow evening.

EDIT: If anyone has any additional spading about Boris to point me to, now would be a good time. For example, I saw something about Song of Battle guaranteeing that your attacks hit?
 
Last edited:

Magus_Prime

Well-known member
I can't speak for Song of Battle but one thing I've noticed is that Batbrain seems to discount the effect of Song of Fortune. If Song of Fortune is active it gives your first attack a 100% critical chance. That means that you can one-hit most monsters in the game, even if you have lots of active +ML. I consistently see Batbrain, in conjunction with SmartStasis and WHAM printing messages in the CLI to the effect of "You can two-hit the monster" when it's actually a one-hit kill.
 

Winterbay

Active member
The problem there is also that Mighty Axing appears to have a bonus-damage part that is largely unspaded and seems dependent on your muscle vs.. the monsters defense.
 
Top