Topic: New soldiers fights program
Posted at: 2017-08-23, 00:50
My last thoughts were around soldiers problem: my fight simulation was doing great job, but it wasn't exact. My target was to create complete and exact simulation of fights. It isn't an easy job. So I was thinking about this for a long time and finished with (another) program .
You can see the code here:
The old one is checked many times and should not contain any bug. The new one is rather "new" and I don't know if there is any problem. Hope not!
Comparison between tables:
(taken from: https://wl.widelands.org/forum/post/19573/)
How I calculated all the stuff?
I have splitted calculations into three parts:
So for example if we have soldier A and B, A is an attacker (attacks first).
To calculate that probabilities I was trying to calculate convolution (https://en.wikipedia.org/wiki/Convolution) of continuous uniform distribution (https://en.wikipedia.org/wiki/Uniform_distribution_(continuous)) and then calculate cumulative distribution function (https://en.wikipedia.org/wiki/Cumulative_distribution_function) for each result to get probabilities p(N_aX) & p(N_bX). But I failed. I've noticed that for N hits you can just draw N-dimensional cube and cut N-dimensional pyramid based on one apex of this cube. The probability is a ration between two volumes. OK, not exactly, but after a few modifications you will get it!
After that we have to calculate how possible is to kill B with N_a hits while he can kill A with N_b hits. That contained some steps inside:
Possibility of killing B: we know exactly how many are miss-tries and a possibility of that, also how many are hit-tries and a possibility of that. The only missing factor is how many times we can "pick" those tries between all tries. That is binomial coefficient (https://en.wikipedia.org/wiki/Binomial_coefficient).
Possibility of not-killing A: we have to calculate all the possibilities of correct miss-hit correct combination. After that we sum all them and get the result. With binomial coefficient in use we can simplify that a bit and make it faster for the computer.
Last part is to make the calculations working. Because we have infinite sum of all possibilities of 5-tries fights, 6-tries fights, 7, 8, ... and so on fights (with N_a and N_b kill-wins), we have to pick a border. Let it be 0.000...1 (10^-10) of "best" probability. So approximately after 15 cases, the calculations stopped and you can sum all the possibilities.
After all those problems solved I've spotted another one: computer calculations aren't exact (about 15-digits exact for standard floating point numbers). So I've researched a bit and found that Python has rational numbers and calculations on them are exact (you can't lose information with infinite numerator and denominator precision).
In short version that is whole my engine and hope it has no mistakes. Probably in a few weeks I will provide a pdf with all the equations I've used, but I am not sure if anybody is interested on that .
If you have any questions, please write them! Maybe I've made terrible mistake or you proved something else - check that!
Posted at: 2017-08-23, 14:15
Thanks for the tool
My probability calculus is a bit meh, so I can't help with checking.
Busy indexing nil valuesTop Quote