<< Back to Warzone Classic Forum   Search

Posts 41 - 52 of 52   <<Prev   1  2  3  
What are your most improbable failed attacks?: 2013-06-24 14:53:09


Krzysztof 
Level 67
Report
Sorry for resurrection dead thread, but anyway (maybe it will help anyone :P)

Within the calculation I depend on the nCr function, which simply grows very rapidly (exponentially in fact); with 16379 or more attackers to simulate it overflows even the Extended floating point type. I'd have to look into a reasonable approximation for bigger numbers; the current "Sorry, that's not supported" is not acceptable


Well, the fact is nCr value is not needed here. The whole formula for chance is:
nCr * probability^r * (1 - probability)^(n-r)
and it sure the result is between 0 and 1. So all we have to do is to change operations order to keep numbers low. It should looks like this:
double Chance(int n, int r, double probability)
{
	double result = 1;
	int power1counter = 0;
	int power2counter = 0;
	for (var i = 0; i <= r; i++)
	{
		if (i > 0) 
			result = result * (n + 1 - i) / i;
		
		while (result > 1 && power1counter < r) //reducing if needed
		{
			result = result * probability;
			power1counter++;
		}
		while (result > 1 && power2counter < n-r) //reducing if needed 
		{
			result = result * (1 - probability); 
			power2counter++;
		}
	}
	
	while (power1counter < r)
	{
		result = result * probability;
		power1counter++;
	}
	while (power2counter < n - r)
	{
		result = result * (1 - probability);
		power2counter++;
	}
	return result;
}


Ofc. it will be slower, but it allow calculations for any number without using special types for big numbers.
What are your most improbable failed attacks?: 2013-07-17 18:40:38

RvW 
Level 54
Report
(Sorry for the late reply, I wasn't actively checking up on this thread any more.)

This does not readily extends to doing a lot of nCr calculations... In practice that'd turn a linear running time into a quadratic running time. Pity, but I think acceptable. When I find time to work on this again I'll consider your approach (and test how fast / slow it really is (and carefully test it is indeed correct; it looks good, but you never know where corner cases might lurk!)).

Also, one minor change I'd suggest:
You only need that "if ( i > 0 )" once, to "hide" the division by i on the very first iteration (when i is zero). But... the value of "result" is one at that moment, which means the two while loops won't be executed either; you don't need that iteration at all. If you change the for loop to count from one to r, you can ditch the "if ( i > 0 )".



One thing about your proposal I find funny is how it is elegant and ugly at the same time. :p Doing the exponents one-by-one whenever result gets bigger than an (actually rather arbitrary) value is ugly, but keeping the (intermediate) result in a "nice" range for as long as possible is actually a rather elegant way to prevent an overflow. :)
What are your most improbable failed attacks?: 2013-07-17 22:21:39


Krzysztof 
Level 67
Report
Well, those calculation above is generally correct, but don't do what they where created for, because division by i in line:
result = result * (n + 1 - i) / i;


should also be used to keep intermediate results in acceptable range.



This does not readily extends to doing a lot of nCr calculations... In practice that'd turn a linear running time into a quadratic running time


yup, i've noticed that when i used this code in practice, but few mathematical transformation can do the trick and solve this problem.
I was implementing 'reversed analyzer' (inspired by Widzisz's idea described here: http://warlight.uservoice.com/forums/77051-warlight-features/suggestions/3732209-reversed-analyze-graph) but gave up cause all those graphic stuff and UI is not what i like and can :P
Still, calucaltion itself are pretty fast and looks good (weighted-random only) You can check it at http://plemiona.hostingasp.pl/warlight and i can send you code if you are planning to do anything with it
What are your most improbable failed attacks?: 2013-07-17 23:50:56


Min34 
Level 63
Report
You guys remember the good times when this thread was still about your most improbable failed attacks.
What are your most improbable failed attacks?: 2013-07-18 00:31:45

RvW 
Level 54
Report
> Well, those calculation above is generally correct, but don't do what
> they where created for, because division by i in line:
>
> result = result * (n + 1 - i) / i;
>
> should also be used to keep intermediate results in acceptable range.

I'm sorry, but I do not understand what you mean... Are you saying your code is not correct!?
What are your most improbable failed attacks?: 2013-07-18 08:10:34


Krzysztof 
Level 67
Report
@RvW - Yes and no

The goal was to write a code which can caluclate formula:

nCr * probability^r * (1 - probability)^(n-r)

and avoid overflow for bigger numbers - this isn't achieved (it needs modification described earlier) so in this terms it's incorrent

But if we stay away from bigger numbers and avoid overflows results will be fine.
What are your most improbable failed attacks?: 2013-07-18 13:00:41


{rp} Julius Caesar 
Level 46
Report
Those numbers are so… mind blowing i have no clue what they mean i just know to simply attack with double whats defending and i usually win
What are your most improbable failed attacks?: 2013-07-18 13:08:03


told you i could change your name
Level 28
Report
^+1 :P
What are your most improbable failed attacks?: 2013-07-18 14:06:22


Min34 
Level 63
Report
I use the analyse-option :D So I don't have to do all this work :p
What are your most improbable failed attacks?: 2013-07-18 18:56:33

RvW 
Level 54
Report
Min,
The built-in analyser works by performing the attack a hundred (thousand?) times and seeing how often it succeeds; it is not a mathematical analysis, it is a simulator. It is possible for the analyser to say "this attack has approximately 100% chance of succeeding", but when you actually perform the attack it still fails. The "approximately" is not in there because of rounding, it is there because the method used is simply not exact.
For comparison, the analyser I wrote makes a distinction between "100.00%" (that's a rounded result; you should read it as "99.995% or more") and "guaranteed" (it will always work).

The point of this exercise is to build a better analyser: one which performs the calculation, instead of the simulation. So, if me and kszyhoo succeed in working it out, you will benefit as well. :)
What are your most improbable failed attacks?: 2013-07-20 12:22:39


told you i could change your name
Level 28
Report
http://warlight.net/MultiPlayer?GameID=4557542

a 5v2 failed and then a 3v1 failed, so 0.06*0.06=0.036

gave me -33 armies on turn 4, yet i still won :D
What are your most improbable failed attacks?: 2013-08-25 22:24:30

Seahawks 
Level 54
Report
http://warlight.net/MultiPlayer?GameID=4737921, 3v2, 3v2, 2v2 and my opponent failed a 3v2, just on turn 2, what are odds of this?
Posts 41 - 52 of 52   <<Prev   1  2  3