I've got a spreadsheet with equations similar to that in your second post, but it takes a few more things into account.
=(((E6)*(20-C6-F6))+(((20-F6)/20)*(E6)*C6*D6)+((F6/20)*(E6)*(C6)))/20
Breaking it down, E6 is average weapon damage, C6 is crit chance/5 (so a 20 would be a 1), D6 is the crit multiplier, and F6 is the chance to miss the attack. The spreadsheet has an A and B column, which are devoted to the Attack Bonus and Defender's AC, respectively. The F column is B-A, but has an enforced minimum of 1 to account for automatic misses on a 1. I think it takes into account ties going to the player, but I'd need to really look through the math to make sure.
The first part [((E6)*(20-C6-F6))] is average weapon damage not including critical damage. Notice that it subtracts both the miss chance and the crit chance.
The second part [(20-F6)/20)*(E6)*C6*D6)] is the chance of being a successful critical.
The third part [((F6/20)*(E6)*(C6))] is the chance to have a failed crit and instead deal normal weapon damage.
All of those add together, and then it's divided by 20 to get the average weapon damage factoring in crits and misses. For instance, if it was a weapon that did an average of 5 damage and had 20/x2 crit, and only missed on a 1, its average damage would be 4.9875.
I need to port it from Excel over to Google Docs one of these days... I also need to update it to have a column with bonus to confirming crits.
I don't remember the poster's name, but I saw some calculations posted and immediately put them into Excel, then after tweaking the equation (and getting help with making sure it was correct) went to town on calculating various effects, mostly Power Attack and the like. Part of what lead me to do that was wanting to figure out the math for
Arcane Duelists.
Once I can get my crap organized I'll post a full thread on AD math, as well as for Power Attack and other things.
You might get something out of these topics:
http://www.minmaxboards.com/index.php?topic=6429.msg96496#msg96496http://www.minmaxboards.com/index.php?topic=6417.msg96196#msg96196