Jump to content

[SOLVED] Calulating missing chance in battle, based on 2 player's agility - online game


slyte33

Recommended Posts

Basically there is an attacker and a defender.

 

The Attacker has 1,000 agility, the Defender has 10,000 agility.

 

The attacker should have a 10% chance of not missing(1,000/10,000=0.1(10%))

 

I've been at this for hours and hours, but cannot find a solution..

 

At first I thought...there is nothing hard about dividing 1,000 into 10,000 and making a player miss 90% of the time, but then I figured i'd need a:

 

if ($? >= ?)

{

//miss

}

 

which gave me a problem

 

Feedback on this would be much appreciated, thank you ;)

Well, you'll need an element of randomness.

 

 

The first thing that comes to mind (because I've seen it before, not because I thought of it lol) is:

 

 

$chance = 100*$agil1/$agil2;

if(rand(1, 100) <= $chance) {

    //hit

}

Well, you'll need an element of randomness.

 

 

The first thing that comes to mind (because I've seen it before, not because I thought of it lol) is:

 

 

$chance = 100*$agil1/$agil2;

if(rand(1, 100) <= $chance) {

    //hit

}

 

Thank you so much! :D

Works perfectly :)

Not sure how true this is, but mt_rand() is supposed to be faster and more randomly generated than rand().

It used to be, but over the years it has gotten faster [than mt_rand()].

 

But it still is more random like you said.

The reason it is more random is that the algorithm behind it takes into account microsecond (mt -> microtime).  Thus, if you're only running it 1 time, the randomness is theoretically the same or at least almost the same.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.