Class MonsterMetrics

java.lang.Object
MonsterMetrics

public class MonsterMetrics extends Object
Application to measure monster power levels.
Since:
2016-02-10
  • Field Details

    • MAX_LEVEL

      final int MAX_LEVEL
      See Also:
    • MAX_ENEMIES

      final int MAX_ENEMIES
      See Also:
    • DEFAULT_FIGHTS_GENERAL

      final int DEFAULT_FIGHTS_GENERAL
      See Also:
    • DEFAULT_FIGHTS_SPOTLIGHT

      final int DEFAULT_FIGHTS_SPOTLIGHT
      See Also:
    • DEFAULT_MAGIC_PER_LEVEL_PCT

      final int DEFAULT_MAGIC_PER_LEVEL_PCT
      See Also:
    • DEFAULT_WIZARD_RATIO

      final int DEFAULT_WIZARD_RATIO
      See Also:
    • GRAPH_Y_INTERVAL

      final int GRAPH_Y_INTERVAL
      See Also:
    • DEFAULT_ARMOR

      final Armor.Type DEFAULT_ARMOR
    • MAX_OPP_LEVEL

      final int MAX_OPP_LEVEL
      See Also:
    • MAX_MON_NUMBER

      final int MAX_MON_NUMBER
      See Also:
    • DEFAULT_PARTY_SIZE

      final int DEFAULT_PARTY_SIZE
      See Also:
    • spotlightMonster

      Monster spotlightMonster
      Single monster option for measurement.
    • numberOfFights

      int numberOfFights
      Number of fights to run per search space point.
    • armorType

      Armor.Type armorType
      Armor type for battling fighters.
    • pctMagicPerLevel

      int pctMagicPerLevel
      Chance per level for magic sword.
    • wizardFrequency

      int wizardFrequency
      Fraction of party who are wizards.
    • commandPartyLevel

      int commandPartyLevel
      PC level for sample fight run.
    • expectedPartySize

      int expectedPartySize
      PC expected party size.
    • commandMonsterNumber

      int commandMonsterNumber
      Monster number for single matchup.
    • displayUnknownSpecials

      boolean displayUnknownSpecials
      Flag to display unknown special abilities.
    • displayOnlyRevisions

      boolean displayOnlyRevisions
      Flag to display only revised EHD values.
    • displayEquatedFighters

      boolean displayEquatedFighters
      Flag to display equated fighters per level.
    • displayEquatedFightersHD

      boolean displayEquatedFightersHD
      Flag to display equated fighters HD per level.
    • graphEquatedFightersHD

      boolean graphEquatedFightersHD
      Flag to graph equated fighters HD.
    • showParityWinRatios

      boolean showParityWinRatios
      Flag to show parity win ratios.
    • showQuickBattleStats

      boolean showQuickBattleStats
      Flag to show quick battle stats exclusively.
    • showBestLevelMatch

      boolean showBestLevelMatch
      Flag to show suggested best level match.
    • showBestNumberMatch

      boolean showBestNumberMatch
      Flag to show suggested best number matches.
    • printedSomeMonster

      boolean printedSomeMonster
      Did we print anything on this run?
    • doShowSampleFight

      boolean doShowSampleFight
      Show one sample fight at parity numbers.
    • doAssessSingleMatchup

      boolean doAssessSingleMatchup
      Assess matchup at specified party level & monster number.
    • makeBNMTable

      boolean makeBNMTable
      Flag to make a table of best-number-match values.
    • waitForKeypress

      boolean waitForKeypress
      Should we wait for a keypress to start (for profiler)?
    • doPrintStatBlocks

      boolean doPrintStatBlocks
      Should we only print stat blocks for monsters?
    • exitAfterArgs

      boolean exitAfterArgs
      Flag to escape after parsing arguments.
    • timeStart

      long timeStart
      Process start time.
    • timeStop

      long timeStop
      Process stop time.
  • Constructor Details

    • MonsterMetrics

      MonsterMetrics()
      Basic constructor.
  • Method Details

    • printBanner

      private void printBanner()
      Print program banner.
    • printUsage

      private void printUsage()
      Print usage.
    • processArgs

      private void processArgs(String[] args)
      Process arguments, including pre- and post-processing
    • parseArgs

      private void parseArgs(String[] args)
      Parse arguments.
    • getParamInt

      private int getParamInt(String s)
      Get integer following equals sign in command parameter.
    • getParamString

      private String getParamString(String s)
      Get string following equals sign in command parameter.
    • getArmorType

      private Armor.Type getArmorType(String s)
      Get armor type from command parameter.
    • parseSampleFightOption

      private void parseSampleFightOption(String s)
      Parse option for a sample fight.
    • parseSingleMatchupOption

      private void parseSingleMatchupOption(String s)
      Parse option for a single matchup.
    • reportMonsters

      private void reportMonsters()
      Report monster metrics as commanded.
    • reportAllMonsters

      private void reportAllMonsters()
      Report number of fighters at each level to match all monsters.
    • reportOneMonster

      private void reportOneMonster(Monster monster)
      Report equated fighters and estimated EHD for one monster.
    • anySpecialPrinting

      private boolean anySpecialPrinting()
      Any special printing done per monster?
    • isEHDClose

      private boolean isEHDClose(double oldEHD, double newEHD)
      Determine if EHDs are relatively close. Note the -r switch is used for regression testing of the whole Arena suite. (Gives visibility if a code modification has unexpected side effects.) There's natural variation in estimated EHD due to random sampling, and more at higher levels, which we don't want to spuriously flag revised values. So we implement an exponential error bar before triggering a report. Also, there are some low-level monsters with EHDs right around the halfway point between two integers that would trigger a report half the time, if we compared integer values, and had an error bar below 1. Therefore, we compare decimal values, and only trigger a report if there's at least a 2/3 unit difference. For the monsters in question, we made the manual choice in the database of leaning toward the actual HD. In some cases this may mask the fact that the true EHD is under the halfway point by a tiny fraction. E.g.: Zombie, Caveman, Gnoll, Bugbear, Ogre, Hill Giant.
    • getEquatedFighters

      private double[] getEquatedFighters(Monster monster)
      Get equated fighters per level for a monster.
    • getEquatedFightersHD

      private double[] getEquatedFightersHD(double[] equatedFighters)
      Get equated fighter hit dice for a monster.
    • toString

      private String toString(double[] array, int precision)
      Create string from a double array, to given precision.
    • roundDbl

      private double roundDbl(double val, int precision)
      Round a double to an indicated precision.
    • getDblArrayMax

      private double getDblArrayMax(double[] array)
      Get the maximum of a double array.
    • getDblArrayMin

      private double getDblArrayMin(double[] array)
      Get the minimum of a double array.
    • getDblArrayMean

      private double getDblArrayMean(double[] array)
      Get the mean of a double array.
    • getDblArrayHarmonicMean

      private double getDblArrayHarmonicMean(double[] array)
      Get the harmonic mean of a double array.
    • graphDblArray

      private void graphDblArray(double[] array)
      Print a graph of a double array.
    • matchMonsterToFighters

      private int matchMonsterToFighters(Monster monster, int fighterLevel)
      Match fighters of given level to monster of one type.
      Parameters:
      monster - Type of monster.
      fighterLevel - Level of fighter.
      Returns:
      If positive, one monster to many fighters; if negative, one fighter to many monsters.
    • matchFight

      private int matchFight(Function<Integer,Double> winRatioFunc)
      Search for a matched fight based on some parameter.
      Parameters:
      winRatioFunc - Must be increasing in parameter.
    • isCloserToHalf

      private boolean isCloserToHalf(double val1, double val2)
      Is the first number closer to one half than the second number?
      Returns:
      true if val1 is at least as close to 0.5 as val2
    • ratioMonstersBeatFighters

      private double ratioMonstersBeatFighters(Monster monsterType, int monsterNumber, int fighterLevel, int fighterNumber, boolean invert)
      Find the probability that these monsters beat these fighters.
      Parameters:
      invert - If true, returns chance of fighters beating monsters.
    • invertIfNeeded

      private double invertIfNeeded(double ratio, boolean invert)
      Invert a win ratio if needed.
    • testLopsidedMatch

      private boolean testLopsidedMatch(int fight, int wins)
      Test to shortcut a lopsided matchup. Tell if ratio over 0.5 at 2-sigma (97.7%) confidence See Weiss Introductory Statistics: Procedure 12.2, handicap enemy 10 fights.
    • makeFighterParty

      private Party makeFighterParty(int level, int number)
      Create a specified party of fighters.
    • newFighter

      private Character newFighter(int level)
      Create a new fighter of the indicated level. Equipment is kept to fixed baseline, with only magic swords to hit monsters as required. (So: Do not use standard Character equip or magic.)
    • newSword

      private Weapon newSword(int level)
      Create a sword for a new fighter.
    • newWizard

      private Character newWizard(int level)
      Create a new wizard of the indicated level. Equipment is kept to fixed baseline. (So: Do not use standard Character equip or magic.)
    • displayUnknownSpecials

      private void displayUnknownSpecials()
      Display unknown special abilities if desired.
    • getBattleStats

      private MonsterMetrics.BattleStats getBattleStats(Monster monster, int ftrLevel)
      Compute stats for monster vs. standard-sized party at a given level. Here we assume a linear matching function based on database EHD (similar to rough idea on Vol-3, p. 11)
    • getBalancedMonsterNumbers

      private int getBalancedMonsterNumbers(Monster monster, int ftrLevel, int partySize)
      Compute fair monster numbers by EHD. Assumes fixed party size and level.
      Returns:
      fair number of monsters (possibly 0)
    • printQuickBattleStats

      private void printQuickBattleStats()
      Print simple report of parity battle stats.
    • printQuickBattleStats

      private void printQuickBattleStats(Monster monster)
      Print simple parity battle stats for one monster.
    • getParityWinRatios

      private double[] getParityWinRatios(Monster monster)
      Compute an array of win ratios for monster at linear-EHD-parity vs. standard party at various levels.
    • ratioMonstersBeatFighters

      private double ratioMonstersBeatFighters(Monster monster, int ftrLevel)
      Get monster win ratio for same-size parties.
    • getBestLevelMatch

      private int getBestLevelMatch(Monster monster)
      Get the best level match for a given monster. Assumes monster numbers fixed at standard party size. Searches for level where they're a match for same-size party of PCs (i.e., closest to 50% chance to win against each other)
      Returns:
      level at which monsters & PCs are closest to 50% win ratio
    • ratioMonstersBeatFighters

      private double ratioMonstersBeatFighters(Monster monster, int monNumber, int ftrLevel)
      Get monster win ratio for variable number of monsters.
    • getBestNumberMatch

      private int getBestNumberMatch(Monster monster, int ftrLevel)
      Get the best number-appearing match for a given monster. Assumes opposing PC party levels and size are fixed. Searches for number where they're a match for same-size party of PCs (i.e., closest to 50% chance to win against each other)
      Returns:
      level at which monsters & PCs are closest to 50% win ratio
    • getBestNumberArray

      private int[] getBestNumberArray(Monster monster)
      Construct an array of best number matches per level.
    • printBNMTable

      private void printBNMTable()
      Print a table of BNM values.
    • printBNMRow

      private void printBNMRow(Monster monster)
      Print one monster in a BNM table.
    • showSampleFight

      private void showSampleFight()
      Run a sample fight. Assumes standard party size, PC level 1 to MAX_LEVEL, and monster numbers at parity total EHD.
    • assessSingleMatchup

      private void assessSingleMatchup()
      Assess a single specified matchup.
    • printStatBlocks

      private void printStatBlocks()
      Print stat blocks.
    • startClock

      private void startClock()
      Start the process timer.
    • stopClock

      private void stopClock()
      Stop the process timer & report.
    • main

      public static void main(String[] args)
      Main application method.