Coding, Terrain Advantage, Damage

Share and discuss strategies for playing the game, and get help and tips from other players.

Moderators: Forum Moderators, Developers

User avatar
Richter
Posts: 8
Joined: September 20th, 2016, 9:25 pm

Coding, Terrain Advantage, Damage

Post by Richter » September 24th, 2016, 5:07 pm

I'm working on my own combat calculator in basic C++, I have something to assist in determining the averages of damage you get which will take into account many different things. Whilst I'm doing it, and while I am still relatively new to Wesnoth, I observe something about defence that trumps offence, under specific circumstances.

If an attacker must pick less defence in his attack than the defender, and the defender holds, defender should win a lot more games on average, this is just assuming that I could place damage directly into a gold value (1 damage = 2-3 gold for example). But alas, a computer makes less mistakes than I do. Here's some code snippets for a small amount of work I did today.

Code: Select all

    double damage(0);
    double resistance(0);
    double strike(0);
    double defence(0);
    double def(0);
    double TODay(0);
    double charge(0);
    if (input == 1) {
    cout << "You will first need to specify the amount of damage, " << endl;
    cout << "and how much opponent's resistances are." << endl;
    cout << "Damage: " << endl;

    cin >> damage;
    cout << "Damage is: " << damage << endl;
    cout << "Type resistance as a minus or positive number: " << endl;

    cin >> resistance;
    cout << "Resistance is: " << resistance << endl;
    cout << "How many attacks will happen? " << endl;
    cout << "Amount of attacks: " << endl;

    cin >> strike;
    cout << strike << " Attacks will occur." << endl;
    cout << endl;
    cout << "-25, 0 Or 25 For time of day bonus? " << endl;

    cin >> TODay;
    cout << "Type 0 If unit does not charge, 2 if it does: " << endl;

    cin >> charge;
    cout << "Finally, what is the defence of the opponent? " << endl;

    cin >> defence;
    cout << "Opponent defence is " << defence << "." << endl;
    cout << endl;

    TODay = 1+(TODay/100);
    def = (defence/100);
    resistance = 1+(resistance/100);
    cout << "Total possible damage is: "                       << damage*charge*strike*TODay*resistance << endl;
    cout << "The probability of this happening is: "                          << (pow((1-def), strike)) << endl;
    cout << "The probability of at least one hit is: "                          << 1-(pow(def, strike)) << endl;
    cout << "Average damage expected is: "                 << damage*charge*strike*TODay*resistance*def << endl;


    cout << "Would you like to do another calculation? " << endl;
    cin >> Exit;
Example picture:
Image

Basically, this answers a question to a person in an old thread, regarding horseman damage. It also assumes that the average damage you will do will tend to regress toward the mean, which, if you are paying attention to the majority of your round's conflicts, may be of some utility. I will go ahead and make the controversial statement, that if someone were to double hit an elvish archer in one turn, that is less likely that someone will then hit twice on another unit with 70% defence, rather, the expected values will err towards missing, or will average out over time.

Eventually I want to evolve this thing to look nicer, do more stuff, determine if one hit kills are available, and once the bones are down (possible) turn it into a mouse-over calculator for in-game moves, where a hover-on box will appear displaying various values depending on unit selected. The game has it's own calculator, but I like doing things the way I like, you know.

Because Wesnoth deals in yes or no deals, there is no average damage, but rather the average expected value based on how many attacks land, so I'll have to think of a quick improvement.

Average damage does work, though, if you factor in the damage done in multiple turns.

Note, if you were to program something to record the rolls you do over multiple rounds, it would be accurate at predicting the average damage of a unit type, but more importantly, you'd be keeping track of the lifetime, of the amount of times that you tried to OHKO an elvish archer for example.

And, after a certain point, it becomes accurate at predicting when you are expected to win your lottery.

For example, while it is only a 0.09% Chance to OHKO an archer the first time you roll, consecutive attempts will increase the likeliness by the exact same logic that we assume we will hit the archer at least once within a number of turns. So when is this likely? Well, on the fifth one-shot attempt, there is a 45% Chance to kill that archer on a forest with your horseman in one turn, as 1-0.09*5 = 55%, 55% Chance to miss = 45% To hit.

After the fifth fails, your sixth attempt will be a lovely 54%, as 1-0.09*6 = 0.46

The implication of this means that if someone is counting their hits each game, or even their dodges, they can determine the likelihood of their future games being of "phenomenal" luck, or bad luck, based on the principle of a regression towards a mean. This becomes rather accurate over time, as the normal distribution appears after you do enough rolls. Tricky stuff, huh? With a computer you can test it. (And I will). This is also why casinos tend to have no windows.

This should work: on the principle, that a chance of something to happen 50% of the time, will err toward the mean of 50% over the course of 100, and 1,000 games/runs.

If that does not happen, the odds were not 50%. (Or you will need more time). After 100 runs, normal distribution usually always emerges, the times that it does not are considered unusual.

Tad_Carlucci
Developer
Posts: 418
Joined: April 24th, 2016, 4:18 pm

Re: Coding, Terrain Advantage, Damage

Post by Tad_Carlucci » September 24th, 2016, 6:31 pm

**sigh**

**eye-roll**

No.

No.

And, no.

https://en.wikipedia.org/wiki/Gambler%27s_fallacy covers the errors in this thinking far better than I care to.
I forked real life and now I'm getting merge conflicts.

User avatar
Richter
Posts: 8
Joined: September 20th, 2016, 9:25 pm

Re: Coding, Terrain Advantage, Damage

Post by Richter » September 24th, 2016, 7:58 pm

This isn't gambler's fallacy. You can confirm it with simulating all of the rolls. Which shouldn't be too hard to do.

It'd basically mean, I make a counter box that includes hits after successive failures, run around 1,000 and then draw the results up in a tally. Can't beat hard math.

In fact, someone already did this, and it has references to the normal distribution chart here:
http://www.mathsisfun.com/data/quincunx.html

Adjust left probability to say, 0.09, give it a greater number of rows to max. You can speed it up if you like.

https://gyazo.com/7141dd4b4efc883338d2a376f1f4b6f2

You should notice that on pegs 5-7 Down, that the probability of it turning left begins to converge closer to 40-60%, because as demonstrated with the equation 1-0.09*5, and *6, that is when it indeed reaches the ranges of 45-54%

If you are taking consecutive chances at something, the chance to roll the same thing in a row, is not the same as it is to only roll for one single occasion. The issue is that there is no such thing as a disconnected, isolated event, in the universe. That would require you to have an alternative.

Additionally, it's been observed before; with the boy/girl paradox.
One scientific study showed that when identical information was conveyed, but with different partially ambiguous wordings that emphasized different points, that the percentage of MBA students who answered 1/2 changed from 85% to 39%.
61% Of MBA students know what's up. But only on the condition it was like flipping two coins (0.50^2=0.25).

And then there is also the martingale; https://en.wikipedia.org/wiki/Martingal ... _system%29

Which states that you double up after a loss until you inevitably win back your cash, and actually works, but only if you have a lot of money. This issue has been that for every great lottery you win, you also lose a lottery, but you can actually do a coin flip on that 6th chance, would you like to be able to flip for a 50% Chance to oneshot that elf? I know I would.

https://i.gyazo.com/2aa3981bf755ff0997f ... 012579.png

I did another 503 and just adjusted the pegs to be around 7, now for 6.

https://i.gyazo.com/6d2915f8cc43b423ab4 ... 0c2380.png

288 Is 58% (rounded), meaning, that our guess that there would be at least 45% on the other side of it by that point fell staggeringly close to what was predicted. Even more beautiful, is that the place we assume that most will end up at (one left) accounts for a whopping 33% of our predictions.

Getting 33% of our supposed 0.09% dice rolls correct, or even 10%, is incredible.

In the 7 Peg example, it becomes even more accurate, with only 49% of our one shots going past the seventh peg, and 38% Of them landing on the sixth, at which point it is again approaching a 50% chance.

For the large, 19 Peg simulation, we expect at least 3 turns to the left to occur, thus, we expect most of our pellets to end up at box 16, 17, and 18 respectively. The majority did. Though this is not about your chance to pull miracles, mainly, my idea was to find the average and see if defending (gaining % defence adjustments) overall, was the best way to win, as if damage is = gold, then, opponent will deal 40% damage, and be giving you a 20% gold advantage overall, if you simply get a good spot, and camp. Especially so if you gain one village and keep it. As you will just snowball out of control almost every time.

Tad_Carlucci
Developer
Posts: 418
Joined: April 24th, 2016, 4:18 pm

Re: Coding, Terrain Advantage, Damage

Post by Tad_Carlucci » September 24th, 2016, 9:17 pm

Which it the bigger shame?

That you don't have a clue and publish this tripe?

Or that someone will read what you wrote and actually believe it?
I forked real life and now I'm getting merge conflicts.

User avatar
zookeeper
WML Wizard
Posts: 9740
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Coding, Terrain Advantage, Damage

Post by zookeeper » September 24th, 2016, 9:32 pm

Maybe you'd like to summarize what it is you're saying and what this thread is about in one plain english paragraph. Because it's really not particularly clear.

User avatar
Richter
Posts: 8
Joined: September 20th, 2016, 9:25 pm

Re: Coding, Terrain Advantage, Damage

Post by Richter » September 24th, 2016, 9:48 pm

After consecutive failures the odds of a success increase as the odds of failure decrease, to account for normal distribution of odds and a regression to the mean.

It's why you can usually count on a horse hitting an elf in a forest once. And why in the threads shown earlier, the strategy tended to work well for people who were struggling to break the lines of the elves.
Tad_Carlucci wrote:Which it the bigger shame?

That you don't have a clue and publish this tripe?

Or that someone will read what you wrote and actually believe it?
I find it shameful that you appeal to emotions before using any reasoning. That's one of cockiness or laziness, but I daren't say stupidity.

Velensk
Multiplayer Contributor
Posts: 3984
Joined: January 24th, 2007, 12:56 am

Re: Coding, Terrain Advantage, Damage

Post by Velensk » September 24th, 2016, 9:55 pm

That first sentence is the exact essence of the Gamblers Fallacy.

The odds of success do not increase after a streak of failure.

Now the odds of a continuous streak of failure of significant length are low but once you've had one the odds of the next result being in your favor are exactly the same as they were before. This is most easily seen with a series of coin flips. The odds of getting TTTT is significantly lower than getting 2 heads and 2 tails or even 1 heads and 3 tails however once you have already rolled TTT, your odds of the streak becoming TTTT vs TTTH are exactly the same because the original odds of TTTT and TTTH were exactly the same, it's just that there are more possible combinations that result in 2 heads and 2 tails that define the average.
"There are two kinds of old men in the world. The kind who didn't go to war and who say that they should have lived fast died young and left a handsome corpse and the old men who did go to war and who say that there is no such thing as a handsome corpse."

Tad_Carlucci
Developer
Posts: 418
Joined: April 24th, 2016, 4:18 pm

Re: Coding, Terrain Advantage, Damage

Post by Tad_Carlucci » September 24th, 2016, 10:33 pm

Laziness, yes.

I'm too old and too tired to deal with another student who skipped class. Take you work to your professor Monday during office hours. I'm sure they'll know of some undergrad who gets it to be your tutor and help you correct your work.
I forked real life and now I'm getting merge conflicts.

User avatar
Richter
Posts: 8
Joined: September 20th, 2016, 9:25 pm

Re: Coding, Terrain Advantage, Damage

Post by Richter » September 24th, 2016, 10:38 pm

Velensk wrote: it's just that there are more possible combinations that result in 2 heads and 2 tails that define the average.
I am already familiar with the concept, and it's been shown in some of the pictures earlier.

The link basically just simulates flips and adjusts probability based on your input. You would see a normal distribution appear for 50-50, which means that peculiar events, overall, happen less in large numbers. TTTT Can be defined as a peculiar event. And they're easy to keep track of, you ever had one of those games where you whiff every attack despite getting hit, or having a large advantage at your disposal? Your natural inclination is to then assume, "I'm not going to win the lottery the next turn".

And in general, you don't. If it happened consistently you wouldn't be playing with the odds at 60% to your advantage, it would be seen as a rare event.

Image

For example, we see that 0.50^7 = 0.0078125, as a fraction, it is 1/128.
We expect that, after 7 Bounces, we will have around 128 Heads and tails combined in boxes 2 and 7, we have 117, slightly short, but still 91% accurate.


And overall we still consider that the times it goes over that are extremely small compared to the big picture, the more something deviates from the average, the more likely it is from that example to then regress towards the average.

Now if you remove all the other variables from a game and let our history of attacks with that horseman be the coin, we will tend to be flipping coins for if we one hit KO an elf after a certain point.
Which is at the sixth attempt, where we have 0.91^6=0.567~, or 43%, rounded, afterwards, we're looking at even better odds that we will hit, as our average needs to be met and is expected.

Had you kept track of all variables in a game, you could flip coins for what should otherwise be unlikely events.

User avatar
Ravana
Forum Moderator
Posts: 2206
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Coding, Terrain Advantage, Damage

Post by Ravana » September 24th, 2016, 10:48 pm

Had you kept track of all variables in a game, you could flip coins for what should otherwise be unlikely events.
Only they are still just as unlikely as before.

I have thought of having addon that artificially creates these conditions you want, but decided that it would have too many cases to observe.

User avatar
Richter
Posts: 8
Joined: September 20th, 2016, 9:25 pm

Re: Coding, Terrain Advantage, Damage

Post by Richter » September 24th, 2016, 11:04 pm

Then, quick question. Is the chance of flipping heads twice in two coin flips 50%, or 25%?
I already know the answer.

User avatar
zookeeper
WML Wizard
Posts: 9740
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Coding, Terrain Advantage, Damage

Post by zookeeper » September 24th, 2016, 11:04 pm

Richter wrote:After consecutive failures the odds of a success increase as the odds of failure decrease, to account for normal distribution of odds and a regression to the mean.
So you're saying that if we're flipping coins and I've landed 5 tails in a row, there won't be a 50-50 chance of heads or tails on the next flip?

I suggest you apply this knowledge to gambling and become a millionaire in a few weeks.

User avatar
Gyra_Solune
Posts: 263
Joined: July 29th, 2015, 5:23 am

Re: Coding, Terrain Advantage, Damage

Post by Gyra_Solune » September 24th, 2016, 11:06 pm

Tad_Carlucci wrote:Which it the bigger shame?

That you don't have a clue and publish this tripe?

Or that someone will read what you wrote and actually believe it?
This kind of talk is rather rude and unproductive, please refrain from it.

Welcome to the forums, Richter. Probability is one of those hotly contested things that has gotten a lot of flak over the years, and that's probably because people aren't that great at probability intuitively!

Basically the way I prefer to think of it is simply 'i can expect to be doing about 30% of my total damage against an elf archer in the woods'. This isn't exactly 100% true - more realistically you would say 'i can expect to hit this elf maybe once with a spearman, and it's about a coin flip if I hit it with this orcish grunt', which is why higher-strike units like the Elvish Fighter and the Fencer fare just a little bit better against dodgy units even if their total damage isn't as great. But in general I just look at the total damage of my unit and multiply it by the chance to hit for what should see as the expected outcome - as though indeed, I am calculating a defense subtraction instead of an evasion mechanic. If I hit more than that, it's basically a critical hit, if I hit less than that, it's basically a critical miss, and I shouldn't count on that.

I almost always hear talk of luck coming into play with the Horseman and indeed in this sense, it's a very critical-centric unit...but to be honest? I don't really use Horsemen much. They're very much meant to be situational. I keep one around just on the off chance an enemy just happens to get in the exact right kind of position where they're vulnerable (and, in that sense, to deter enemies from getting into positions where they'd be prone to getting blown away, because i might need that position) but I rarely ever rely on them. Despite everything I am firmly of the opinion that they'd be MORE powerful if their attack was 18-1 instead of 9-2, simply because it could outright OHKO a wide range of units before they even get the chance to retaliate.

In general regression towards a mean is a broader, analytical thing. Probabilities do that in the long run, but for an instance in the sequence of events, probabilities won't actually increase or decrease just because they must regress to the mean - it's still going to have the exact same probability. If you flip a coin, it's still going to be a coin flip, even if it's come up tails the past 30 times in a row, and it's not going to be any safer to bet on heads just because of that. So if you're on a streak of bad rolls, it actually is a bad idea to look at previous events and think 'okay I haven't actually managed to hit this unit on a hill once even though it's surrounded by mages, but that means this Horseman will hit both times' - because the unit on a hill still has a 50% defense rate and so you only have a 25% of hitting it both times, even if you were struck by astronomically low probability in missing fifteen 70% chances to hit. For operating on a greater strategic perspective, the RNG shouldn't play into your movements at all. The RNG may make for surprising variance and unexpected reversals at times, but you should rely on good strategy and operations targeted at the ultimate goal of the game - to defeat the enemy leader - over worrying too much about the probability calculator and expecting dice to roll your way.

Tad_Carlucci
Developer
Posts: 418
Joined: April 24th, 2016, 4:18 pm

Re: Coding, Terrain Advantage, Damage

Post by Tad_Carlucci » September 25th, 2016, 12:01 am

The problem, and it's something I see a lot of places, not just here, is that people insist they understand randomness and probability theory when most do not. It's not that they cannot do the math, it's that they're using the wrong math to begin with.

Take the question posed above, "What are the odds of two fair coin tosses both being heads?" The answer, of course is 1-in-4.

But that's solving the wrong problem!

The correct question is, "What are the odds of the next fair coin toss showing heads?" And that is always going to be 1-in-2.

In my defense, I point out that I did start out by sending the OP to the page about the Gambler's Fallacy. And the response was claim it wasn't that error by using the definition of the mistake as proof it was not.
I forked real life and now I'm getting merge conflicts.

User avatar
Richter
Posts: 8
Joined: September 20th, 2016, 9:25 pm

Re: Coding, Terrain Advantage, Damage

Post by Richter » September 25th, 2016, 12:59 am

Tad_Carlucci wrote:The problem, and it's something I see a lot of places, not just here, is that people insist they understand randomness and probability theory when most do not. It's not that they cannot do the math, it's that they're using the wrong math to begin with.

Take the question posed above, "What are the odds of two fair coin tosses both being heads?" The answer, of course is 1-in-4.

But that's solving the wrong problem!

The correct question is, "What are the odds of the next fair coin toss showing heads?" And that is always going to be 1-in-2.

In my defense, I point out that I did start out by sending the OP to the page about the Gambler's Fallacy. And the response was claim it wasn't that error by using the definition of the mistake as proof it was not.
The point is that the previous attempts do not suddenly go out of existence due to the next one, it assumes that the past is non-extant. Yes, had the universe at that present moment suddenly decided to start, you would be at your first coin flip, but we are not at such a place. We are at our second coin flip, and the odds of us being correct since we placed our bets at the start have not changed.

I wouldn't go into a game saying "I think all my hits are going to miss this game", and for that to happen would require for me to witness an event that may well only happen once every month, or more. So it is safe to say, that on average, you will land your hits when you expect, and this something that you can rely upon.

I usually use 0.50 as an example of my reasoning because it is easy to find out the values of the exponent, and everyone's pretty familiar with 1/2 and 1/4.

But where you gain some luck in one area you lose it somewhere else, this always tends to be true for the averages, either lots of 1/4 flips to make up for one of those 1/32s, or a pair of 1/16. But by the very method that this chance is 'made up for' is in itself admitting that in some other areas we're expecting it to become true. How do we avoid that logic?

Post Reply