Jump to content

  • Log In with Google      Sign In   
  • Create Account


Deterministic Critical / Dodge Chance


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
21 replies to this topic

#1 n00b0dy   Members   -  Reputation: 103

Like
0Likes
Like

Posted 12 July 2012 - 12:41 AM

I want a propability distribution / pseudonumber generator / or simple algorithm to simulate deterministic critical chance in an rpg with the following attributes:

Lets say i have 10% critical chance.

1) [Requirement] Every 10 hits, at least one of them must be critical. I dont care which let it be random.
i.e Between those 10 hits, player will crit at least once.
2) [Requirement] Between those 10 hits, player wont be able to crit twice.
From 1) 2) we conclude we want player to crit exactly once.
3) [optional] P(X=x) = 10% for x = {1,2,3,... 10} Chance of an attack between those 10 hits to be a critical =10%. So that it's not exploitable e.g player hitting a minion first and then attacking enemy champion and getting 100% critical chance.

Ok so you math experts what is the solution to my problem, there must be a propability distribution to solve my problem.

To Conculde:
I want between [ 1 / crit_chance ] hits, player to crit exactly one time.
[optional] chance the crit to be at Xth attempt is equal for x = {1,2,3,... 10}.

thank you,

Sponsor:

#2 Hodgman   Moderators   -  Reputation: 27668

Like
1Likes
Like

Posted 12 July 2012 - 01:13 AM

You could use a deck of cards instead of a dice.
Randomly shuffle 9 'hit' cards with 1 'crit' card. Every time the player attacks, draw a card. When the pile is empty, re-shuffle it randomly.

[edit]
I remember reading an article on approaches like this, and he suggested decks over dice in a lot of situations to give more stability to the designer.
If you use dice (e.g. rand), then it's still possible for a player to get 100 crits in a row, or to never ever get a single crit. If enough people play your game, these possibilities become certainties -- there's going to be one player out there who is unlucky enough to fail every "roll to hit" test that the game throws at him...

Edited by Hodgman, 12 July 2012 - 01:18 AM.


#3 l0calh05t   Members   -  Reputation: 644

Like
1Likes
Like

Posted 12 July 2012 - 02:00 AM

I remember reading an article on approaches like this, and he suggested decks over dice in a lot of situations to give more stability to the designer.


This would be the article you are thinking of: http://archive.gamedev.net/archive/reference/design/features/randomness/default.html (more specifically: http://archive.gamedev.net/archive/reference/design/features/randomness/page3.html )

#4 d07RiV   Members   -  Reputation: 115

Like
0Likes
Like

Posted 12 July 2012 - 02:33 AM

3) [

optional

] P(X=x) = 10% for x = {1,2,3,... 10} Chance of an attack between those 10 hits to be a critical =10%. So that it's not exploitable e.g player hitting a minion first and then attacking enemy champion and getting 100% critical chance.


If the player attacked 9 times and neither of those crit, wouldn't he know for sure that the next attack will crit?



For simplicity, after every 10 attacks you could roll a number 1-10, which would determine which of the next 10 attacks should crit. You could achieve determinism by using a fixed random seed.



#5 Brother Bob   Moderators   -  Reputation: 7781

Like
0Likes
Like

Posted 12 July 2012 - 02:45 AM

For simplicity, after every 10 attacks you could roll a number 1-10, which would determine which of the next 10 attacks should crit. You could achieve determinism by using a fixed random seed.

That is almost what Hodgman suggested to use a deck instead of a die but less flexible and not much easier. It really doesn't extend well to more than one crit to keep track of all outcomes while with the deck you can shape any distribution with no extra work.

#6 saejox   Members   -  Reputation: 714

Like
0Likes
Like

Posted 12 July 2012 - 03:01 AM

you know what's fun: double crits, even better triple crit.

nothing more satisfying than being on a crit streak.

#7 n00b0dy   Members   -  Reputation: 103

Like
0Likes
Like

Posted 12 July 2012 - 03:17 AM

If the player attacked 9 times and neither of those crit, wouldn't he know for sure that the next attack will crit?

Thats true, it would be a huge exploit, e.g in the laning phase imagine every 10 attacks the enemy carry to get a free guaranteed crit.

How about the 10th predictable card, being a "non activated critical" that instead increases the damage of next 9 attacks by 11.1% ?

Still we would know that the 9th predictable card has 50% chance of being a critical. [still an exploit].
And the 8th has a 25% chance to be a critical. And so on ...
So that would defeat the whole point of placing the "exploit prevention".

you know what's fun: double crits, even better triple crit.

nothing more satisfying than being on a crit streak.

And what if this happens to YOU, instead of the enemy, you instantly lose the fight in 3 sec instead 10.


Here is how i will implement the "card" algorithm.
int currentAttack = 1;
int criticalCardPosition = random(1, 10);
isCritical( )
{
	f (currentAttack == criticalCardPosition)
	{
		return true;
	}
	return false;
}
onAttack()
{
   currentAttack++;
   if (currentAttack == 11)
   {
	  criticalCardPosition = random(1, 10);
	  currentAttack = 1;
   }
}

Edited by n00b0dy, 12 July 2012 - 03:30 AM.


#8 Inferiarum   Members   -  Reputation: 723

Like
0Likes
Like

Posted 12 July 2012 - 03:28 AM

If the player attacked 9 times and neither of those crit, wouldn't he know for sure that the next attack will crit?

Thats true, it would be a huge exploit, e.g in the laning phase imagine every 10 attacks the enemy carry to get a free guaranteed crit.

How about the 10th predictable card, being a "non activated critical" that instead increases the damage of next 9 attacks by 11.1% ?

Still we would know that the 9th predictable card has 50% chance of being a critical. [still an exploit].
And the 8th has a 25% chance to be a critical. And so on ...

you know what's fun: double crits, even better triple crit.

nothing more satisfying than being on a crit streak.

And what if this happens to YOU, instead of the enemy, you instantly lose the fight in 3 sec instead 10.


You could only predict the crit if you knew you were at the last card of the deck. But the player does not really know that. And also the prediction is only possible if the last card is the crit, which should not happen too often with lower crit chances. (with high crit chances it is not that important anyway)

On a related note :)
http://en.wikipedia.org/wiki/Unexpected_hanging_paradox

#9 n00b0dy   Members   -  Reputation: 103

Like
0Likes
Like

Posted 12 July 2012 - 03:43 AM

You could only predict the crit if you knew you were at the last card of the deck

A) Player knows critical chance from tooltip. He infers that deck size is 10.
B) Player performs 9 autoattacks on simple minions, he is lucky none of them critted (10% chance).
Chance for crit to be last card of the deck = 10%.
Now he goes and attacks enemy champion getting a free guaranteed hit.

Also here is one other thing that i noticed with my algorithm. Player can get double crit in a quick succession.

Imagine the following example :
deck 1 : crit 10.
deck 2 : crit 1.
That means that the player will be able to get a double crit if he is lucky, 1% chance.

#10 n00b0dy   Members   -  Reputation: 103

Like
0Likes
Like

Posted 12 July 2012 - 04:11 AM

Maybe we should relax the initial requirements to see if we can make it less predictable.

Suppose : player has 10% critical chance.

Deck(1, 10) = deck with 1 critical card out of 10 cards.
Bug: Player can predict last card if he knows all the previous
Why:
a) he knows deck size in this case 10.
b) he knows current attack position (he counts his autoattacks).

We cannot change b) but we can modify a) so that player doesn't know the deck size.

Deck(2, 20) = deck with 2 critical cards out of 10 cards.
Deck(X, X*10);

how about a random size of deck is chosen when the deck ends, that way he cannot predict when he can critical.
Because he doesn't know the deck size.

What restriction does the new algorithm place:
1) It allows attacks to critical several times in a row if they get "lucky" depending on deck size.

Edited by n00b0dy, 12 July 2012 - 04:13 AM.


#11 Hodgman   Moderators   -  Reputation: 27668

Like
0Likes
Like

Posted 12 July 2012 - 04:42 AM

A) Player knows critical chance from tooltip. He infers that deck size is 10.
B) Player performs 9 autoattacks on simple minions, he is lucky none of them critted (10% chance).
Chance for crit to be last card of the deck = 10%.
Now he goes and attacks enemy champion getting a free guaranteed hit.

Only on the first 10 attacks -- say crit position is 3 in the first shuffle and 9 in the next shuffle, then there's more than 10 swings between crits (same way that you can get 2 crits in a row).

#12 jefferytitan   Members   -  Reputation: 1672

Like
0Likes
Like

Posted 12 July 2012 - 04:43 AM

Hmm, if you want fairness but not necessarily predictability of crits, maybe something like the following:
1. Draw 10 out of a deck of 11 (or more generally 10 + x).
2. Put any crits not drawn into the next deck.

Alternately go the probability way instead of a deck. Adjust the probability for each crit pick based upon the expected vs actual number of crits for a sliding window.

Edit: I know it doesn't exactly fulfil the criteria, but the criteria themselves look like the problem for creating predictability.

Edited by jefferytitan, 12 July 2012 - 04:47 AM.


#13 apatriarca   Crossbones+   -  Reputation: 1604

Like
0Likes
Like

Posted 12 July 2012 - 05:02 AM

If you want to prevent double crits, you can simply use the deck system and just prevent the first card to be a critical if the last card was a critical (you can for example choose the first card from the previous cards but the last). But I think double crits are generally ok and the deck system already prevent triple or more crits.

Your rules themselves make it possible to predict some cards, for example the card after a crit and the tenth attack every ten attacks. If you want a less predictable system you should drop some rules.

#14 RedBaron5   Members   -  Reputation: 573

Like
0Likes
Like

Posted 12 July 2012 - 07:08 AM

One thing to be aware of: The card system removes a little bit of the crit chance flexibility. You will only be able to move critical percent up or down by 10%. This is quite a big jump as most games have skills that only increase crit by 1-2%.

#15 Inferiarum   Members   -  Reputation: 723

Like
0Likes
Like

Posted 12 July 2012 - 07:29 AM

One thing to be aware of: The card system removes a little bit of the crit chance flexibility. You will only be able to move critical percent up or down by 10%. This is quite a big jump as most games have skills that only increase crit by 1-2%.


If you do the implementation right it should be possible to get arbitrary crit chances.


E.g. if 1 out of 4.5 hits is a crit you alternate between decks with 4 and 5 cards.

That is, use integer numbers for the deck sizes and accumulate the decimal amounts until they account for an additional card

#16 JTippetts   Moderators   -  Reputation: 8159

Like
0Likes
Like

Posted 12 July 2012 - 07:34 AM

You can also use a bigger deck. 10% would mean 10 crit cards in a 100 card deck. The more cards you use, the less able a player will be to "count cards", so to speak, and try to line up guaranteed crits. At least without third-party tools to do the job for him. With in-place shuffling, you can mitigate the overhead of shuffling so that the larger decks do not become a performance problem. Set your deck size to correspond to the smallest increment of crit chance.

#17 RedBaron5   Members   -  Reputation: 573

Like
0Likes
Like

Posted 12 July 2012 - 08:21 AM

You can also use a bigger deck. 10% would mean 10 crit cards in a 100 card deck. The more cards you use, the less able a player will be to "count cards", so to speak, and try to line up guaranteed crits. At least without third-party tools to do the job for him. With in-place shuffling, you can mitigate the overhead of shuffling so that the larger decks do not become a performance problem. Set your deck size to correspond to the smallest increment of crit chance.


You wouldn't be able to guarantee one crit in 10 though. You could only guarantee one crit in 91 attacks.

#18 arkane7   Members   -  Reputation: 213

Like
0Likes
Like

Posted 12 July 2012 - 11:26 AM

One way to solve your problem of double-crit and predictability is to give every attack a 10% crit chance, and check the previous 2 or 3 attacks to see if there were any criticals to prevent chaining.

This will prevent your guaranteed 1 crit out of 10 attacks unfortunately, and may give up to 2-3 crits in 10 or worse player "never" gets a critical. However, that is still very unlikely with each only having 10% and now the player cannot "count cards" to know when they will get a critical, and prevents getting a critical twice in a row, or every other turn.

Just thought I'd give my two cents on how to prevent exploitation, though it will mess up some of your other requirements.
Always improve, never quit.

#19 Inferiarum   Members   -  Reputation: 723

Like
0Likes
Like

Posted 12 July 2012 - 12:01 PM

One way to solve your problem of double-crit and predictability is to give every attack a 10% crit chance, and check the previous 2 or 3 attacks to see if there were any criticals to prevent chaining.

This will prevent your guaranteed 1 crit out of 10 attacks unfortunately, and may give up to 2-3 crits in 10 or worse player "never" gets a critical. However, that is still very unlikely with each only having 10% and now the player cannot "count cards" to know when they will get a critical, and prevents getting a critical twice in a row, or every other turn.

Just thought I'd give my two cents on how to prevent exploitation, though it will mess up some of your other requirements.


I do not think predicting crits is an issue with the deck system. The crits are still random. You cannot count from the last crit, but you have to keep counting throughout the whole game. And still you can only predict a crit if it is in the last card of the deck. And you have to know how the algorithm deals with changes in crit chance. And also for numbers of cards which are not natural numbers it is totally hopeless.

#20 n00b0dy   Members   -  Reputation: 103

Like
0Likes
Like

Posted 13 July 2012 - 02:31 AM


You can also use a bigger deck. 10% would mean 10 crit cards in a 100 card deck. The more cards you use, the less able a player will be to "count cards", so to speak, and try to line up guaranteed crits. At least without third-party tools to do the job for him. With in-place shuffling, you can mitigate the overhead of shuffling so that the larger decks do not become a performance problem. Set your deck size to correspond to the smallest increment of crit chance.


You wouldn't be able to guarantee one crit in 10 though. You could only guarantee one crit in 91 attacks.


Lets say player has 4% crit chance. We can implement arbitrary critical chances the following way:

Plain logic:
1) Create a deck size of 100 cards.
2) Mini deck size = 100 / 4 = 25
2) place 1 critical card at each minideck[0,25].
b) [optional prevent doublecrits] with the restriction that the distance between 2 critical cards is at least A.
if (critical Chance <= 10%) A = 5;
else if (critical Chance <= 20%) A = 2;
else if (critical Chance <= 30%) A = 1;
else A = 0;


Code: performance = O( mini-decks ).
int A  ;
for each minideck
{
	int randomPos = random( minideck.min, minideck.max);
	if ( A + randomPos > minideck.max)
   {
		 getNextMinideck().min = (  randomPos + A );
   }
}

Lets see what points this algorithm covers:
1) arbitrary critical chance;
2) prevents too frequent crits if critical chance < 30%.
3) [predictable].If player knows critical chance, he knows A, he knows the source code (assume open source game),
he knows minideck size.

Can we remove point c? predictability ? what if we make minidecks variable size ?
instead size=25, make it size = random[20, 30].


There is one big problem that makes it complicated / impossible to implement in rpgs.
What if critical chance changes ? e.g a player uses an ability with +20% critical chance ?
Then it will have to reconstruct all decks from the beginning, losing the previous result = flawed critical chance calculation.

Edited by n00b0dy, 13 July 2012 - 02:52 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS