zarqon
Well-known member
BatBrain
BatBrain (Battle Brain) -- part of my ongoing BatMan project -- is a function library for script authors who want to write a consult script. Years of work and lots of collaborative effort (from scripters, devs, Wiki scrapers, and lots of users) have gone into this and it is pretty much the awesomest ASH library script to come down the pike since ASH was a twinkle in Hola's eye.
For Users
Like ZLib (which BatBrain also requires), BatBrain is a function library for use by other scripts. Running this script will do basically nothing; don't even bother. However, without this script sitting somewhere in your mafia directory, other scripts which want to use these functions won't work. So that's all you have to do -- download it. You're done.
For Scripters
This script is designed to provide you a comprehensive picture of the combat environment, then give you easy-to-use tools to decide what to do with your available options. Using this library, your script will approach omniscience regarding your current battle. You can then predictively build your combat, finally submitting the entire thing as a macro when you're done.
Server-friendly consult scripts with capabilities far exceeding both a normal CCS and a BALLS macro are now within even a mediocre ASH scripter's grasp.
Any consult script that uses BatBrain must call act(pg) before doing anything else, or your combat environment will not be built correctly. Like so:
Actually, I recommend importing SmartStasis instead -- then you'll have the power of both scripts at your disposal!
If you'd like an example of how to use BatBrain in a consult script, I have included a very simple sample script called, appropriately, SimpleSmack. This is the script I use for exactly everything, in order to run BatBrain through its paces. It takes advantage of BatBrain's queueing ability to attempt to build and then submit a full combat as a macro, with just a few custom actions and safeguards in place to preserve automation. Something much more involved, like WHAM, is also possible if you want further ideas.
I've also included a consult script for handling Pokefam battles -- SimplePoke -- which is basically BatBrain for Pokefam fights.
BatBrain documentation: click here or type "ashwiki batbrain" in your CLI.
batfactors documentation: click here or type "ashwiki batfactors" in your CLI.
Installation
Type this in your CLI:
Changelog
Changes beyond this point are listed on BatBrain's SourceForge changelog; however, I will continue to post more in-depth update notes in this thread.
BatBrain (Battle Brain) -- part of my ongoing BatMan project -- is a function library for script authors who want to write a consult script. Years of work and lots of collaborative effort (from scripters, devs, Wiki scrapers, and lots of users) have gone into this and it is pretty much the awesomest ASH library script to come down the pike since ASH was a twinkle in Hola's eye.
For Users
Like ZLib (which BatBrain also requires), BatBrain is a function library for use by other scripts. Running this script will do basically nothing; don't even bother. However, without this script sitting somewhere in your mafia directory, other scripts which want to use these functions won't work. So that's all you have to do -- download it. You're done.
For Scripters
This script is designed to provide you a comprehensive picture of the combat environment, then give you easy-to-use tools to decide what to do with your available options. Using this library, your script will approach omniscience regarding your current battle. You can then predictively build your combat, finally submitting the entire thing as a macro when you're done.
Server-friendly consult scripts with capabilities far exceeding both a normal CCS and a BALLS macro are now within even a mediocre ASH scripter's grasp.
Any consult script that uses BatBrain must call act(pg) before doing anything else, or your combat environment will not be built correctly. Like so:
PHP:
import <BatBrain.ash>
void main(int initround, monster foe, string pg) {
act(pg);
// now you can smack down the monster with BatBrain-powered gusto!
}
Actually, I recommend importing SmartStasis instead -- then you'll have the power of both scripts at your disposal!
If you'd like an example of how to use BatBrain in a consult script, I have included a very simple sample script called, appropriately, SimpleSmack. This is the script I use for exactly everything, in order to run BatBrain through its paces. It takes advantage of BatBrain's queueing ability to attempt to build and then submit a full combat as a macro, with just a few custom actions and safeguards in place to preserve automation. Something much more involved, like WHAM, is also possible if you want further ideas.
I've also included a consult script for handling Pokefam battles -- SimplePoke -- which is basically BatBrain for Pokefam fights.
BatBrain documentation: click here or type "ashwiki batbrain" in your CLI.
batfactors documentation: click here or type "ashwiki batfactors" in your CLI.
Installation
Type this in your CLI:
Code:
svn checkout https://svn.code.sf.net/p/batbrain/code
Changelog
Code:
5.01.11 - Mayday! Mayday! BatBrain version 1.0 posted. Now that it's predictive in combat I figured it's finally ready for release.
6.02.11 - 1.1 changes: lots. Some highlights (because I don't remember them all): slightly reformatted advevents to include the number of rounds an event takes (and made some progress on integrating stats more), cleaned up some output, new functions kill_rounds() and die_rounds(), and automatic acquisition of stat-appropriate Juju Gazes.
6.03.11 - 1.2 changes: reworked monster stuff a bit -- there's now a function [tt]m_event()[/tt] which returns the entire monster event, including damage, self-heals, beaten up, and special moves. Still needs some fleshing out but it's a marked improvement. BatBrain now uses this in its predictions. NSN and quiet healer never deal damage. Some functions were altering opts[] -- change those to work on copies. Predictive adjustment now works for multi-round events -- it factors in the base round and monster attack for each round.
6.04.11 - 1.3 changes: consolidate round-building code in one place. Don't include monster value in meat if the action wins the combat -- that's the job of an importing script. Fix copying advevents -- use new (blank) advevents rather than the variable being initialized.
6.14.11 - 1.4 changes: fix divide by zero error. Consolidate success chance code for all actions into hitchance(), and factor all actions by their success chance when adding to opts[]. Use proper critical hit chance (with modifiers) to calculate both hitchance and damage. Use 11 rather than 10.5 for hit chance based on info on KoLspading. Change low-HP aborts in macros to be recalculated each round, and skip if the monster is stunned -- and allow autoAbortThreshold to determine the abort cutoff if it's set higher than the monster's damage.
6.14.11 - 1.5 changes: hard on the heels of 1.4, more stuff revamped thanks to this attentive community and me actually having a few free hours at work. Rework the way rounds are added to events -- an advevent now takes 0 rounds unless the round number is specified. This fixes the issue where Bander augmentation made an action take 2 rounds, and allows me to remove a lot of [tt]rounds = 0[/tt] statements. Fix the way fumbles and crits are used in hitchance. Include blocking for skills/attack. Black Cat means pickpocket should never consider items at 100%. Allow enqueueing (yes, definitely sexy) up to maxround.
6.19.11 - 1.6 changes: hitchance for more skills, fumbles only apply to attacks, one more little fix to hitchance formula. Hardcode damage for Clobber. Remove stat == ML checks for determining unknown stats. Account for Spiciness; it doesn't count for non-sauce skills. Fix resistance for booty crab. Account for Clockwork Apparatus transforming fumbles into awesome. Bee thoven is multistun-immune. [I]n[/I] Bottles of Beer on a Golem blocks spells.
6.21.11 - Happy summer to those of you in the Northern Hemisphere! 1.7 changes: don't factor skill cost by hitchance. Don't name the fumble event since it interferes with the attack event.
7.02.11 - Happy in between Canada Day and American Independence Day! 1.8 changes: fix a bounds issue in hitchance. Fix a bounds issue in Harpoon! formula. Expand [tt]my_stat()[/tt] to include all stats, sensitive to speculation using "whatif". Using the previous feature, only remove dangerous poisons. Tracking for once-per-combat issues is now saved in an external map, to give BatBrain-powered relay scripts accurate information. During enqueueing, precede deleveling skills with Mistletoe if you haven't used that yet this combat. More efficient parsing of events using a matcher rather than a bunch of stringslinging. Added the critical event to regular attacks. Items granting special results for a critical hit mostly added to batfactors.
7.08.11 - 1.9 changes: Include deleveling in [tt]to_profit()[/tt]. When selecting stasis action, consider all actions that will never kill the monster equal in terms of damage. Ranged smacks are impossible. Mistletoe precedes only appropriate skills, and only if you have MP enough (predictively) for both. Automatically add "hascombatitem" and "hasskill" conditions to all repeat-enqueued actions. Buzzerker is multistun-immune. [tt]eval()[/tt] substats rather than [tt]to_int()[/tt]ing them.
9.06.11 - 1.10 changes: it's been a while, so it's hard to say what all was changed. Fixed stasis item selection sort. Allow pipe-delimited lists of monsters in "monster" and "notmonster" tags. Support for Fist skills, including Master's passive augmentation of unarmed attack. Filter all melee skills when wielding a ranged weapon. Where appropriate, consider your effective familiar in the event you're using a Doppelshifter or costume wardrobe. Miscellaneous other improvements.
9.22.11 - 1.11 changes: Use mafia's Unarmed modifier for Fist detection, also check fistSkillsKnown rather than my_path(). Don't keep considering skills if you acquire Amnesia mid-combat.
11.30.11 - 1.12 changes: Improvements galore! Revert erroneous unarmed checks -- instead, add a simple little [tt]unarmed()[/tt] function. Add a "once" keyword to batfactors -- any action flagged with "once" will only be available -- you guessed it -- once. Rework happenings -- now all actions that are enqueued officially "happen" and use canonical action names. Enqueueing also triggers an options rebuild, since some actions may be unavailable or different after the first use. Fix hitchance for moxman. Resistance for nemesis demons appears to be 40% across the board. Fancypants Scarecrow support. Naughty shuriken support. Chilled Monkey Brain support. Feed support. New [tt]attack_action()[/tt] function which returns a decent option for killing the monster. Quiet healer does have an attack. Stickler for Promptness support. Monster meat drops are capped at 12 in Fistcore, before bonuses. All items are worth no less than 50 meat, to avoid thinking nontradeables such as paperclip sproingers are free. In [tt]kill_rounds()[/tt], but not [tt]monster_stat()[/tt], assume the pessimistic side of monsters' 5% HP variance, capped at +5. Convert [tt]page[/tt] into a global variable containing the most recent page load -- removed as a parameter for most functions.
12.2.11 - 1.14 changes: Fix for detecting unknown bang potions/spheres. Fix for Knee hitchance.
12.6.11 - 1.15 changes: Fix round detection on multi-round pages. Complete the happenings revamp -- BB now records [I]all[/I] actions and the number of times they have happened this fight. Resetting the queue will wipe enqueued happenings which have not yet happened. Add deleveling doubling for Mistletoe. Now that dangerpoisons uses the rather expensive [tt]attack_action()[/tt], significantly speed things up by building the list of dangerous poisons only once at the beginning of combat.
1.15.12 - 1.16 changes: Reformatted BB -- you can now initialize BB to a specific monster using the [tt]set_monster()[/tt] command, thus making BB useful speculatively outside of combat. If you don't initialize BB it will initialize to [tt]last_monster()[/tt] automatically in [tt]act()[/tt]. Safer, better attack action selection. Don't erroneously factor monster special moves by monster hit chance. Speed: cache base round and monster events per round. Detect combat completion in [tt]act()[/tt] and don't continue with options rebuild and responses.
3.12.12 - 1.17 changes: New format for batfactors, allowing for greater accuracy in spreads. HP is now handled as player damage and is a spread. Better support for some Boris skills (still doesn't know about hitchance though).
3.14.12 - 1.18 changes: Fixed player damage having a minimum of 1, even for 0-pdmg actions. Improved Boris support for Cleave and Song of Fortune's auto-crit. Normalize "perfect" damage type.
3.31.12 - 1.19 changes: Added Black Cat and O.A.F. item/skill blocking/replacement. Rework [tt]enqueue()[/tt] and [tt]macro()[/tt] commands to keep macro information out of the queue. Implement auto-funk when enqueueing two consecutive item throws! Support for Sick Pythons, Bifurcating Blow, clumsiness bark, and orange agent. Speed: cache profit of advevents to make [tt]to_profit()[/tt] much less expensive, and refactor detections/responses in both [tt]act()[/tt] and [tt]batround()[/tt] to use a faster and more accurate switch statement. Track base pairs thrown at Cyrus using BB's happenings detection rather than the previous error-prone method in SS. Only return 50 for items with no accessible value. Fix combat completion detection for monsters with no Adventure Again link. Significantly improve the sort in [tt]attack_action()[/tt]. Holy crap this was a big update.
4.01.12 - 1.20 changes: Fix a devious little bug which allowed empty macros to be submitted.
4.14.12 - 1.21 changes: Refine the refinement to [tt]attack_action()[/tt]. Continue to cache profit in the profit field of advevents, but always recalculate in [tt]to_profit()[/tt]. Fix damage calculations for "regular" attacks. Fix auto-funk, and avoid performing it when you don't need the combat to be faster.
4.19.12 - 1.22 changes: Add an important line back in which was unintentionally removed previously. When detecting happenings on the final page of combat, [tt]my_turncount()[/tt] has already advanced, so set the occurrence to turncount - 1.
4.29.12 - 1.23 changes: Fix inconsistencies in happenings tracking for relay play vs. automated play. Fix [tt]kill_rounds()[/tt] erroneously having a minimum of 2. Don't add fumbles to melee attack skills. Don't allow enqueueing of more items than you have. Song of Battle grants 100% hitchance. Cache action type functions in global variables smack, plink, and buytime. Considerably improve the [tt]stun_action()[/tt] sort. Use recent [tt]effect()[/tt] function in formulas to eliminate several fvars and checks. Include material component cost for skills. Be completely pessimistic about monster HP variance throughout. Speed improvement: only consider m.poison, not all possible poison effects. Despite appearing in the menu, Mighty Axing is not available with Trusty unequipped.
7.12.12 - 1.24 changes: Hopefully final combat completion detection method -- not fooled by CAB or Bugged Bugbear. Improved support for: Boshing Smack Slap, OPS, enchanted fire extinguisher, PADL phones, communications windchimes, double-ice shards, Mighty Axing, Cleave. Record compound happenings individually. Properly account for MP/HP regen for both gain and loss. Hold back possibly needed tower items in all known locations. Ignore deleveling profit when your attack will one-shot the monster. Improve DB action detection for Mistletoe insertion. Don't include empty batrounds in the macro.
8.10.12 - 1.25 changes: Don't use a reserved word for a variable name. Don't throw goal items.
11.05.12 - 1.26 changes: Two MP updates for Zombiecore: 1) ignore all MP loss other than skill costs, and 2) ignore all MP gain not from infecting zombies (only 2.5 skills can do this). Add ongoing infection damage to base event for Infectious Bite. QWOPped Up grants Clumsy. Skeletal scabbard doubles damage from swords. Support for Bear Hug, Grizzly Scene, Ravenous Pounce, Howl of the Alpha thanks to Winterbay. Misses are now glancing blows. Also, don't factor fumbles and crits by hitchance. Move declarations outside foreach loop for greater efficiency.
11.23.12 - 1.27 changes: Mafia monster name changes. In Zombiecore [tt]my_maxmp()[/tt] may be 0, so don't divide by that. Fix Pop and Lock It matcher. Restore BatBrain's knowledge of equipment and effects to its former glory.
12.01.12 - 1.28 changes: Support for Jalapeño and Jabañero Saucespheres, new physically resistant monsters, and Raging Animal. Differentiate monster attack/defense elements for determining monster attack/resistances.
1.03.12 - 1.29 changes: If player has Manuel, use his supplied stats without any adjustments for unknown_ml or HP variance. When simulating a round, cap gains to HP/MP from player actions [I]before[/I] applying the monster event. Moxious Maneuver uses moxie for damage.
1.18.13 - 1.30 changes: Unknown monster stats are now -1. Properly remove items for Mother Slime and Chester. Properly filter skills based on page text. Ignore mafia's "Found in this fight" message when parsing items. SC Nemesis fixes: Track seal pup wailing with happened("sealwail"). Smacks work with the Sledgehammer. Remove all non-weapon sources of damage from options when facing mother hellseals.
1.27.13 - 1.31 changes: Add special attacks for elemental hobos and frustrating knight. Don't ignore elemental damage in [tt]die_rounds()[/tt].
1.31.13 - 1.31.1 changes: Complete monster attack as a spread fix and the final death of the longstanding Salve/Bandages bug. Only include double-ice cap retaliation event if it hasn't happened.
4.1.13 - /\/\^v^/\/\ changes: multifarious! Described [URL="http://kolmafia.us/showthread.php?6445-BatBrain-a-central-nervous-system-for-consult-scripts&p=89624&viewfull=1#post89624"]here[/URL].
5.1.13 - ~(^._.^) changes: Fix elemental form bug, more [tt]to_event()[/tt] refactoring. Integrate [tt]endscombat[/tt] in several more places.
5.8.13 - 1.35 changes: Names of phyla have changed. Reset spell damage before compensating for Spiciness. Allow enqueueing up to 3 rounds beyond end of combat.
5.29.13 - 1.36 changes: [URL="http://kolmafia.us/index.php?posts/91958/"]Multifarious again![/URL]
6.02.13 - 1.37 changes: BRICKO reactors only do huge damage to BRICKO monsters. Faster, better skills filtering regardless of browser-added quotation marks. More yellow-ray delay tweaking.
6.07.13 - 1.38 changes: Don't count Master of the Surprising Fist twice. Add fvar wpnpower support for Silent skills. Fix endless loop with Juju mask equipped.
6.19.13 - 1.39 changes: BatBrain is on SourceForge! Read about the changes to this version at the link below.
Changes beyond this point are listed on BatBrain's SourceForge changelog; however, I will continue to post more in-depth update notes in this thread.
Last edited: