New OOTS products from CafePress
New OOTS t-shirts, ornaments, mugs, bags, and more
Results 1 to 18 of 18
  1. - Top - End - #1
    Pixie in the Playground
     
    Mastocles's Avatar

    Join Date
    Jul 2014
    Location
    New Zealand
    Gender
    Male

    Lightbulb D&D Battle simulator

    I have written a python 3.4 script (here) to simulate D&D 5e battles.
    The aim is determine the victory probability given a lineup of creatures in two or more teams.

    The model
    Repeating a battle thousands of times gives statistical error of a percentage point and takes a second.
    It does not know about space —it assumes everyone is contiguous to everyone, but ignores close combat range disadvantage.
    It does not know all of the rules or most of the spells, but it is fairly robust.
    The various creatures play munchkinishly by targetting the opponent with the lower AC —it can be switched to random, but I don't think that reflects the game.
    The tactics are fixed —a sprawling mess TBH and I would be tempted to make it Bayesian, but it is not really worth it. The tactics are simple: heal/buff if needed, dodge if being targeted and having the edge on turn economy, net if available and turn economy —added for a hypothesis of mine—, otherwise attack. No helping tanks, no grappling barbarians to deactivate their rage or similar.
    Some class features are present… that is because I am using my current party as a template.
    I can simulate a single battle and get a narration… it sounds pretty much like a normal encounter: a few fumbles, bard gets squashed etc.
    It would need a herculean amount of work to make it complete and I am pleased as it is, so I'd probably only do minor tweaks.
    The major issue is that casters get pwoned first, which is a big problem. To determine PC merit I did a 'commoner assist test' (assist 3 commoners against 4 giant rats —calibrated for 80% loss if a rubbish adventure comes (hp 8, +2 strength, AC 14)—), which is fairly good.

    Conclusions
    It has confirmed a few things:
    • A small edge dramatically switches defeat to victory: the contributing factors in order are damage dice, AC and then hp.
    • Everyone knows that the DMG encounter maths are weak. A hard encounter is a 50% win if the players don't use their class extras. If they do it's 90% win. Double the corrected XP of the encounter makes it nearly 50% and that assumes the DM is playing munchkinishly.
    • A 2d6 is the same as a d12+d2–1, d7+d5, 2d8 –2, 3d3+1, 4d2+1 or 7. The extra 0.5 mean advantage of a 2d6 over a 1d12, never gives more than a 4.5% points extra on victory probability when two equal duellist spar (lvl 1–20, AC 14–18). Albeit obvious, this keeps getting debated over the table.
    • 13 commoners is the tipping point to take down a hill giant.
    • Victory probability of a commoner vs. a giant rat is 7% —hence the well known story of the rat killing quest.


    Regarding the first and last point: a pretty picture showing how a small change has a big effect.


    So, if anyone has any cool hypotheses that they would like tested, please feel free to ask or use the script!

  2. - Top - End - #2
    Halfling in the Playground
    Join Date
    Apr 2015

    Default Re: D&D Battle simulator

    This is awesome! I've been thinking about how to tackle this problem analytically since the PMFs for any given action are pretty well specified. However, this script saves me so much work that I had to stop lurking just to remark.

    Any rate, one way you could avoid the "casters get creamed" problem with your target picking algorithm is to make a directed graph of who is putting damage where. Each character would be a node on the graph and the connectivity would represent where their attacks were headed each turn. This could simulate a "front rank" and "back rank" by requiring that nodes be adjacent to attack each other with melee attacks. Similarly, the model could incorporate shoving, attacks of opportunity and other attempts to block bodies by updating the graph connectivity based on some actions that individual actors pick. For instance, casting misty step could let you skip past a rank and become adjacent to ranged attackers.

    I'll play around with this and see if I can codify the graph thing.

  3. - Top - End - #3
    Pixie in the Playground
     
    Mastocles's Avatar

    Join Date
    Jul 2014
    Location
    New Zealand
    Gender
    Male

    Default Re: D&D Battle simulator

    Thanks!
    I really like that implementation as it avoids having a map (with cover and features etc.)

    Although, I am not sure about the tactics (when is it best to simply swing the weapon, to dodge, to help, to disengage, to switch targets triggering an AoO, to defenestrate an opponent).
    I mentioned above that the "AI", which is the Encounter battle() method, is a mess of conditional statements for case specific actions. So it might need a fix to be allow more tactical decisions.
    I was adding more features as I went and I wasn't expecting this much stuff. I am half considering making a list of available actions (method references like cast_barkskin, but better) and a respective list of assessment methods that would return a value rating the move, so that the top ranked action could be called. The factors affecting the rating could be tweaked random allowing a random walk towards the best strategy. Anyway, that is just crazy talk.

    I forgot to write that some data mentioned in my first post is present here: report 1 and report 2.

  4. - Top - End - #4
    Dwarf in the Playground
     
    DruidGuy

    Join Date
    Dec 2014

    Default Re: D&D Battle simulator

    The simulator can take into accounts thing like positioning, spell selection, and general tactics(although attacking weakest to strongest is a really smart way to simulate that, very smart), but something I think your simulator would be good for is quantifying hit points over AC.

    an example would be, given the option, "is +1 to AC better that an extra 5 hp? 10hp? 20hp?" Also looking at something like survivability vs damage output. An example could be "Is there a correlation between damage output and survivability?" and "Do tanker builds put out more damage because they would stay up longer in a fight?"

    One last thing, we used to record stats for a few of our games. We did it from levels 2-5 about 7 session and the one thing that really popped out was that there was a steady 3 to 1 damage taken vs damage dealt all the way through.

    Anyways, this is awesome and keep up the good work. I can't wait till I get a little bit of free time to play around with your code. it's been a long time since I used python. It will be fun to see how much I remember too!
    Last edited by Sullivan; 2015-04-10 at 12:22 AM.

  5. - Top - End - #5
    Titan in the Playground
     
    Flumph

    Join Date
    Nov 2010

    Default Re: D&D Battle simulator

    Good work!

    And here I was patting myself on the back for writing amateur (literally halfway through my first course in the R language), unfinished code to simulate how many attack rolls it takes to kill a single combination of hit points and AC. The saddest part of this is that I already did the "hard" work, and now I'm stuck trying to get averages and plots from my probability table (i.e. Number of Attacks Needed vs. Probability. That's the "atkprobtable" near the bottom). I think the table might be interpreting its contents as a string rather than integers/floats. Or something like that. Once I can get this table working, it won't take long to start simulating 1v1 slugfests, adding more features (pretty graphs, more than 2 combatants, vulnerability/resistance, chance to win a slugfest, etc), and applying data analytics to it.

    EDIT: Whoops. Turned out I just needed to mapply() the as.double function to the table. I feel really dumb right now.

    Spoiler: R Code
    Show
    #Skill Roll
    #d20roll
    p.d6 <- rep(1/6,6)
    d6 <- 1:6

    dieroll<-function(x,n){

    sample(d6, size=1, prob=p.d6, replace=T)
    }
    mean(result)
    sd(result)
    ###
    #Try to make a die-roll function

    dieroll<-function(x,n){
    p.die <- rep(1/x,x)
    die <- 1:x
    return(sample(die, size=n, prob=p.die, replace=T))
    }
    ###Modified d20
    d20<-function(x=0){
    return(dieroll(20,1)+x)
    }
    ###d12, d10, d8, d6, d4, d2
    d12<-function(x=0){
    return(dieroll(12,1)+x)
    }
    d10<-function(x=0){
    return(dieroll(10,1)+x)
    }
    d8<-function(x=0){
    return(dieroll(8,1)+x)
    }
    d6<-function(x=0){
    return(dieroll(6,1)+x)
    }
    d4<-function(x=0){
    return(dieroll(4,1)+x)
    }
    ###



    simatks<-function(Atk_bonus, AC, Max_HP){

    hitdmg<-function(X){
    return(d8(0))
    }
    critdmg<-function(x){
    return(d8(0)+d8(0))

    }

    crit_counter=0
    hit_counter=0
    miss_counter=0
    atk_counter=0
    dmgcnt=0

    HP = Max_HP
    while(HP>0){
    Atk_roll= d20(Atk_bonus)
    hitdmg1=hitdmg(0)
    critdmg1=critdmg(0)
    Hitstring="Error"

    if (Atk_roll-Atk_bonus==20){
    HP = HP - critdmg1
    dmgcnt = dmgcnt + critdmg1
    crit_counter=crit_counter+1
    atk_counter=atk_counter+1
    Hitstring="Crit"
    }
    else if (Atk_roll >= AC){

    HP = HP - hitdmg1
    hit_counter=hit_counter+1
    atk_counter=atk_counter+1
    dmgcnt = dmgcnt + hitdmg1
    Hitstring="Hit"
    }
    else if (Atk_roll < AC){
    miss_counter=miss_counter+1
    atk_counter=atk_counter+1
    Hitstring="Missed"
    }
    #print(cat("attack #",atk_counter, Hitstring, "and", HP, " hit points remain||"))
    }
    return(atk_counter)
    }

    countatks=mapply(simatks, rep(0,1000), MoreArgs=list(AC=10, Max_HP=20))

    counttable<-table(countatks)
    atkprobtable=data.frame(counttable/sum(counttable))
    names(atkprobtable)=c("Atks", "Prob")
    atkprobtable=mapply(as.double,atkprobtable)

    plot(atkprobtable, type="b")


    It's inspiring to see someone like OP actually managing to get work done. Keep it up.
    Last edited by Slipperychicken; 2015-04-10 at 02:20 AM.

  6. - Top - End - #6
    Halfling in the Playground
    Join Date
    Apr 2015

    Default Re: D&D Battle simulator

    Quote Originally Posted by Mastocles View Post
    I really like that implementation as it avoids having a map (with cover and features etc.)
    I think you can also include terrain effects as nodes on the graph that break up adjaecency -- null nodes that launch no attacks. I need to think about it more, but the idea is that adding null nodes (that may or may not be traversable) to the graph structure can restrict the ability to move adjaecent. Modeling spirit guardians and slows is also tricky: I guess it increases the action cost to adjust your connections on the graph I guess.

    Although, I am not sure about the tactics (when is it best to simply swing the weapon, to dodge, to help, to disengage, to switch targets triggering an AoO, to defenestrate an opponent).
    I mentioned above that the "AI", which is the Encounter battle() method, is a mess of conditional statements for case specific actions. So it might need a fix to be allow more tactical decisions.
    I was adding more features as I went and I wasn't expecting this much stuff. I am half considering making a list of available actions (method references like cast_barkskin, but better) and a respective list of assessment methods that would return a value rating the move, so that the top ranked action could be called. The factors affecting the rating could be tweaked random allowing a random walk towards the best strategy. Anyway, that is just crazy talk.
    My incomplete ruminations are as follows: The simplest picture of this is to imagine your team as a giant pile of hit points and the enemy team as a giant pile of hit points. You guys are gong to swap damage, cc, adjacency adjustment and healing until you drop. The total damage each round serves as a counter on the combat as it ticks towards the enemies total HP. In this light, healing only makes sense if it heals more than the action cost to cast it: if healing word nullifies one round of an enemy's damage, then it's a good call because it didn't cost a damaging action. Similarly, CC only makes sense if it makes your ticker go faster than the enemy ticker -- if it denies more than the action cost to cast it.

    Your resource expenditure should be optimized such that you run out of resources at the end of the last encounter before you restock. You can imagine multiple encounters as a bigger pile of hit points you have to whittle down, with the opportunity to refresh some resources in between. Optimization should be carried out over all available resources: HP, spells, short rest renewables and consumables (presumably prioritizing consumable expenditure way down).

  7. - Top - End - #7
    Pixie in the Playground
     
    Mastocles's Avatar

    Join Date
    Jul 2014
    Location
    New Zealand
    Gender
    Male

    Default Re: D&D Battle simulator

    Due to an upcoming funding round, I find myself bogged down with work, so I cannot upgrade the code anytime soon.
    The simulation is decent enough to see whether certain homebrew weapons are broken or not, which was actually my original intent —I started doing an analysis and I needed some tests, although I never did finish my analysis fully: link to draft.
    Ideally I would like to change the decision-making part, but making it adaptive (multidimensional-MCMC), would require a lot of effort despite its appeal.
    If spacial decision enter the fray, I think such a training walk would be required as I cannot say when certain tactics are better —melee attack, grapple, disengage or cause an AoO? Normally, it depends on the player's personality!*
    But for the foreseeable future I probably will restructure how spells and such are handled to make it more flexible and add class features based on what test is required.

    *) Last week my party encountered a hag: I netted her and another player pushed her prone, but then a third player instead of going along with the lockdown decided to attack and fumbled, which the DM ruled as cutting the net. There is no way that the simulator would do any of that.

  8. - Top - End - #8
    Ettin in the Playground
     
    MindFlayer

    Join Date
    Mar 2015
    Gender
    Male

    Default Re: D&D Battle simulator

    I am not sure MCMC would be the best way to go. If I understand correctly I think you could run into some problems as resources get drained through the fight and future performance is negatively correlated with past performance for anyone expending resources.

    I haven't had a look at your code but does it handle advantage and are you happy with how it handles that? I tried to do something similar a while ago but getting the decision on shove actions and whether they were worthwhile was something I found difficult. I never really got round to trying spells so the combat abilities like that were very important - this meant that the most important factor in a lot of combats was initiative. For short combats initiative being high was important. For longer combats initiative being the same in the party was important.

    Following the logical path of actions was difficult. If player 1 shoves then there is a probability of a prone target which diminishes the value of player 2 shoving. Player 3 may be a rogue who gets a big benefit from attacking a prone target but they may be incapacitated before they can. If player 1 or 2 makes an enemy prone then the enemy should focus on stopping the rogue attacking and so on...

    The complexity of the paths means backwards induction is useless and programming in all of the rules etc. was far, far beyond me.

    If you have the resources and some pre-existing code you might be better off just collecting all visible characteristics about your party and trying to use a GA to eliminate rubbish tactics. I don't have a lot of experience of GAs myself but some of my colleagues seem to be able to do some pretty awesome things with them.

  9. - Top - End - #9
    Pixie in the Playground
     
    Mastocles's Avatar

    Join Date
    Jul 2014
    Location
    New Zealand
    Gender
    Male

    Default Re: D&D Battle simulator

    I hadn't considered a genetic algorithm, which is probably a better idea. When I get time, I'll look into it.

    I was thinking that an assessment function for each possible action which does a weighted sum of a few factors, such as ratio baddies to PCs (turn economy), number of weenies, number of fatties, personal death probability and so forth, where the weight is determined through a multidimentional walk (a hill climbing function probably).

    The weird thing is that if it did, it might be better than actual players! In a campaign, I made a mistake of having a kill tally and it brought out the worst in the players and the tactics were really poor.

    Currently, the stats get reset after each of the thousands of iterations of battle simulations, the casters are targetted first and only heals and buffs are present, so spell depletion might not be an issue any time soon.

    Yes, it handles crits, fumbles, advantage and disadvantage —albeit very inelegantly as conditions are a poorly done patch-over.

  10. - Top - End - #10
    Ettin in the Playground
     
    MindFlayer

    Join Date
    Mar 2015
    Gender
    Male

    Default Re: D&D Battle simulator

    If you are looking at weighted input functions are you talking about pre-calculated input functions or using a machine learning technique to calculate the inputs. If it is a weighted average for each input doesn't this just become a neural network (please forgive my ignorance - machine learning is only on the periphery of what I know)?

    Other approaches might be a classification algorithm (VSM style) of actions into two categories - optimal and not optimal - but as each action would only be optimal or not optimal within the context of what everyone else would do the calculations would quickly become pretty damn big.

    One of the other things that is problematic with a machine learning approach is that it is difficult to represent RP aspects of combat. Is a caster conservative with their resources? Are they afraid of something else after this encounter? Are they smart/cryptic and unwilling to commit their full range of abilities until they can surprise an opponent particularly susceptible to them and so on. Still, just using it as a benchmark it is pretty useful.

  11. - Top - End - #11
    Titan in the Playground
    Join Date
    May 2007
    Location
    The Land of Cleves
    Gender
    Male

    Default Re: D&D Battle simulator

    On a much simpler level, not all win are equal. A battle where the last man standing is one of the PCs is technically a win, but I think that most players would regard that as a very bad outcome. You might want to break it up into four outcomes, instead of two: Side A wins intact, side A wins with casualties, side B wins with casualties, side B wins intact (maybe roll those last two together, if side A is assumed to be the PCs, because taking some down with you is small consolation for a TPK).
    Time travels in divers paces with divers persons.
    As You Like It, III:ii:328

    Chronos's Unalliterative Skillmonkey Guide
    Current Homebrew: 5th edition psionics

  12. - Top - End - #12
    Pixie in the Playground
     
    Mastocles's Avatar

    Join Date
    Jul 2014
    Location
    New Zealand
    Gender
    Male

    Default Re: D&D Battle simulator

    Machine learning
    MrStabby, you're most likely right, machine learning isn't my area of expertise either.
    Most likely I'd be using the Python scipy.solver if I were to, as that would make life easier.
    Although, from my party it is clear that a top priority is I should make a user interface and compile it as a .exe file for my Windows friends.
    A possible direction
    For now, the script works well at predicting the true difficulty of an encounter for a experienced party, which is what I need.*
    The current encounter builder, page 56 of the Basic rules or somewhere in the DMG, is for newbies. That makes me think: I could recalculate the values on the table and of common monsters —it'd be a good use for the script, although I'd have to write a calculator in JavaScript, which is yucky.
    *) It predicts who may win at a PvP battle, but my friends dispute the particulars of the results and come up with more reasons why there is a flaw.

    Degrees of victory
    Chronos, that is a good point. There is a Perfect win (9 hp loss), a normal win and a "near TPK" (one character drops). The near TPKs are arguably why a truly hard encounter is fun. Average number of turns is a nice metric too.

  13. - Top - End - #13
    Bugbear in the Playground
     
    jkat718's Avatar

    Join Date
    Aug 2014

    Default Re: D&D Battle simulator

    Quote Originally Posted by Mastocles View Post
    The current encounter builder, page 56 of the Basic rules or somewhere in the DMG, is for newbies. That makes me think: I could recalculate the values on the table and of common monsters —it'd be a good use for the script, although I'd have to write a calculator in JavaScript, which is yucky.
    What's the problem with the encounter building guidelines? I mean, they're obviously (very) loose estimates, but do they really give results that are that inaccurate?
    Spoiler: Current Games
    Show
    Current Live Game: Defenders of Stormfast, "A Brave New World of Adventure" Obsidian Portal
    Current PbP Game: 5th Edition low-level game IC OOC Tracker Map
    Current PbP Game: I6 - Ravenloft IC OOC

    Full Signature
    I often post from mobile, so feel free to correct any typos.

  14. - Top - End - #14
    Pixie in the Playground
     
    Mastocles's Avatar

    Join Date
    Jul 2014
    Location
    New Zealand
    Gender
    Male

    Default Re: D&D Battle simulator

    Quote Originally Posted by jkat718 View Post
    What's the problem with the encounter building guidelines?
    I really like the guidelines as they are better than 3.5 or PF's because the a better calculation of party strength is better and there is a multiplier (for action economy). 3.5/PF Leadership feat or PF Summoner class (turn economy) were clear examples of how important action economy is.
    Nevertheless, from my experience, the maths is extremely conservative for a balanced party played by veteran players —understandable, but frustrating.
    Additionally, it doesn't tell you approximately what is the TPK probability of Hard encounter. According to the simulations it is 0–10%, which isn't that dangerous, especially as its an underestimate.
    I might be scarred from Warhammer 40K: Dark Heresy, but I would say a Hard encounter is 20–50% TPK chance —a save by DM fiat is more fun than a last minute extra minion summoning to correct for the ease of the battle.
    Having said that, I am unsure how it much could be improved apart from a few tweaks.

  15. - Top - End - #15
    Pixie in the Playground
     
    Mastocles's Avatar

    Join Date
    Jul 2014
    Location
    New Zealand
    Gender
    Male

    Default Re: D&D Battle simulator

    Also, anyone know of a spreadsheet (or JSON) with some Monsters that have most of their stats? I can only find CR and type and one or two details, none with the whole set (hp, ac, abilities stats, damage parameters, etc.)

  16. - Top - End - #16
    Bugbear in the Playground
     
    jkat718's Avatar

    Join Date
    Aug 2014

    Default Re: D&D Battle simulator

    Quote Originally Posted by Mastocles View Post
    I might be scarred from Warhammer 40K: Dark Heresy, but I would say a Hard encounter is 20–50% TPK chance —a save by DM fiat is more fun than a last minute extra minion summoning to correct for the ease of the battle.
    The DMG defines Hard and Deadly as follows:
    Quote Originally Posted by DMG, p. 82
    Hard. A hard encounter could go badly for the adventurers. Weaker characters might get taken out of the fight, and there's a slim chance that one or more characters might die.
    Deadly. A deadly encounter could be lethal for one or more player characters. Survival often requires good tactics and quick thinking, and the party risks defeat.
    20-50% chance of TPK sounds more like Deadly to me. A Hard encounter might have 20-50% chance of a hireling dying, not an adventurer. I think that, for experienced players, you should just bump everything down a difficulty level. Not sure how you'd calculate what the next threshold would be, but there's probably some way to figure it out.

    Quote Originally Posted by Mastocles View Post
    Also, anyone know of a spreadsheet (or JSON) with some Monsters that have most of their stats? I can only find CR and type and one or two details, none with the whole set (hp, ac, abilities stats, damage parameters, etc.)
    It probably doesn't exist (especially not with creatures from the MM, as that would just be C&D bait), but I could throw together something using the Basic DMG, if you'd like.
    Spoiler: Current Games
    Show
    Current Live Game: Defenders of Stormfast, "A Brave New World of Adventure" Obsidian Portal
    Current PbP Game: 5th Edition low-level game IC OOC Tracker Map
    Current PbP Game: I6 - Ravenloft IC OOC

    Full Signature
    I often post from mobile, so feel free to correct any typos.

  17. - Top - End - #17
    Pixie in the Playground
     
    Mastocles's Avatar

    Join Date
    Jul 2014
    Location
    New Zealand
    Gender
    Male

    Default Re: D&D Battle simulator


  18. - Top - End - #18
    Halfling in the Playground
     
    NecromancerGuy

    Join Date
    Jul 2015

    Default Re: D&D Battle simulator

    The button to clear lineup doesn't work entirely. It does clean the interface, but doesn't clean the variable containing the list of combattants.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •