Can all-or-nothing damage reach EV in the long run?
Moderator: Forum Moderators
Can all-or-nothing damage reach EV in the long run?
OK, actually I hope someone points out the one big logical flaw in my python script that attempts to simulate a stripped down version of BfW's battle logic since there simply must be one.
I've tried to simulate how damage is calculated in actions.cpp action:action(...) but whenever I use the all-or-nothing damage approach (in contrast to deterministic damage) the damage total goes way above the EV value, meaning both attacker and defender do too much damage in my simulation. However, if I switch back to deterministic damage the differences seem to be reduced to rounding errors.
PS: change the var "deterministicDmg" to either True or False to switch between both damage modes (False being the wesnoth way).
One could ask why I did not attach the debugging code to measure this directly in the original code. Well, for once I haven't figured out the actual control flow and when I tried to change the calculations there directly I ended up in an OOS hell anyway (outcommenting the OOS code isn't a good idea either I guess since they are there for a reason, no?). If I get some pointers on how to get on the right track there I would probably try again.
I've tried to simulate how damage is calculated in actions.cpp action:action(...) but whenever I use the all-or-nothing damage approach (in contrast to deterministic damage) the damage total goes way above the EV value, meaning both attacker and defender do too much damage in my simulation. However, if I switch back to deterministic damage the differences seem to be reduced to rounding errors.
PS: change the var "deterministicDmg" to either True or False to switch between both damage modes (False being the wesnoth way).
One could ask why I did not attach the debugging code to measure this directly in the original code. Well, for once I haven't figured out the actual control flow and when I tried to change the calculations there directly I ended up in an OOS hell anyway (outcommenting the OOS code isn't a good idea either I guess since they are there for a reason, no?). If I get some pointers on how to get on the right track there I would probably try again.
- Attachments
-
- random-attacks.zip
- zip file contains python script "random-attacks.py"
- (1.16 KiB) Downloaded 570 times
Re: Can all-or-nothing damage reach EV in the long run?
First some comments to your "deterministic" approach:
Your "deterministic" damage is not deterministic (i.e. depends on random), and doesn't depend on the terrain, other than your calculated EV.
This would have the same EV as 50% terrain, if you would be using a real round instead of floor - using math.floor(... + 0.5) shifts the damage more to the EV (I used [50] as the terrain list). (Or don't use rounding at all, even better.)
That it does work for you is caused since your terrain defense list is not symmetric to 50%.
Edit:
The real battle simulation seems to be right, and is only "over EV", since your EV calculation uses math.floor - use a real round (floor(...+0.5)), or don't round/cut at all (or only on output at the end), and it will be right.
Edit2:
A really deterministic battle would use
If you want something like "hit everytime, but have damage dependant on random", you'll need not a even distribution of damage (on average 50%), but something with EV dependent on the defense value (EV = def * damage).
So, maybe a variation of gaussian distribution, or simply multiply the damage in your above formula with 2*defDef.
Your "deterministic" damage is not deterministic (i.e. depends on random), and doesn't depend on the terrain, other than your calculated EV.
Code: Select all
if (deterministicDmg):
attDmgGiven += math.floor(attDmg * randomNumber / 100.0)
That it does work for you is caused since your terrain defense list is not symmetric to 50%.
Edit:
The real battle simulation seems to be right, and is only "over EV", since your EV calculation uses math.floor - use a real round (floor(...+0.5)), or don't round/cut at all (or only on output at the end), and it will be right.
Edit2:
A really deterministic battle would use
Code: Select all
if (deterministicDmg):
attDmgGiven += math.floor(attDmg * defDef / 100.0)
So, maybe a variation of gaussian distribution, or simply multiply the damage in your above formula with 2*defDef.
Re: Can all-or-nothing damage reach EV in the long run?
Found the issue: This universe lacks real randomness!