16

As I mentioned in my comment above, I recommend you profile this before overcomplicating your code. A quick for loop summing dice is a lot easier to understand and modify than complicated math formulae and table-building/searching. Always profile first to make sure you're solving the important problems. ;) That said, there are two main ways to sample ...


15

I see this question has a number of close votes for being too broad or opinion-based, but I think a reasonably sourced overview can be provided within the scope of a StackExchange answer - I'll take a stab at that here. Sid Meier talked about this problem in his 2010 GDC Talk "The Psychology of Game Design (Everything you know is wrong)" (this gave me an ...


9

You may wish to completely rethink what "critical hits" do in your system and why you're using them. "Well, other RPGs use them!" is not a valid reason. One warning sign of a skewed design is the need to apply more and more special rules. Any kind of random bonus takes away from direct, tactical player skill and adds to strategic planning (RPG item load-...


8

There are good points in DMGregory's answer. I especially like the one where a win/loss is split into multiple minor wins/losses, which is taken from slot machines - when in doubt copy slot machines, because they're the ultimate game where (almost) all players lose, yet so many continue to play. Let's add some more points: Use gamedesign to allow victories,...


6

Try accounting for larger enemies multiple times, then drawing one from them. For instance let's say you have 6 enemies, two of them are medium, one is large and the other 3 are small. Then you'd have a list similar to small A, small B, small C, medium A, medium A, medium B, medium B, large A, large A, large A If you pick one of these random, then you'll ...


5

Dota 2 uses PRD (pseudo random distribution) which doesn't significantly affect the expectation, but decreases the chances of a streak, e.g. bash streak. Have a look at this, explains everything in detail. http://www.youtube.com/watch?v=KdS-K_rosCI


4

What matters is not the total of all the numbers but the ratio of how many numbers in one set win/lose against ALL the numbers in the other set. To understand this you need to simplify your set to an extreme example: A=[96, 1, 1, 1, 1] vs B=[22, 21, 20, 19, 18] Both sets add to a total of 100. However it's easy to see how in A vs B, A will win only 1 ...


4

I'd go with something like this (pseudo-code): spawnProbability = 0.001 // Your original probability at fixed timestep spawnAtThisFrequency = 1/30 // The original fixed timestep dt dtAcc = 0 // An accumulator that will accumulate the variable dt update( dt ) { dtAcc += dt; // Accumulate while( dtAcc >= spawnAtThisFrequency ) ...


4

A good tool to simulate this is AnyDice.com. It is supposed to be used to simulate dice throws in tabletop games, but it can in many cases be easily adapted to do the same with random chances in video games. In your case, the damage roll is output 5d{0, 1, 2} ("take a three-sided die with the values 0, 1 and 2, throw it 5 times and add up the results") which ...


3

You might want to look into the concepts behind non-transitive dice. Briefly, it's a set of dice such that: P(A beats B) > 50% P(B beats C) > 50% P(C beats A) > 50% etc... As an example, consider these 3 dice: A = { 2, 2, 4, 4, 9, 9 } B = { 1, 1, 6, 6, 8, 8 } C = { 3, 3, 5, 5, 7, 7 } Then: 5/9 = P(A beats B) = P(B beats C) = P(C beats A) Not ...


3

A lot of great stuff covered in the other answers. Here's my take on (the perception of) win/loss probabilities. In the case of PvP, consider different ways to track & show win loss scores either directly or in some sort of cooked format (I.E. player rank). Specific examples: Puzzle Pirates ranks player performance relative to all of the other players ...


3

I think this is a case where trying to be too smart will lead to a spiral of tweaks and adjustments to the random number generator that will make it very complex. The answer might be in the question: if a player may get frustrated by too many critical hits in a row, well, directly reduce the odds of this happening. If the RNG draws a 4th critical in a row, ...


3

One fairly common approach you can use that should give the results you're after: rather than rolling a die every time, instead pick a card : suppose you have a 1/10 chance of 'critical failure', a 4/10 chance of failure, a 4/10 chance of success, and a 1/10 chance of 'critical success'. Then rather than rolling a (metaphorical) d10 and handling the result, ...


2

Normally what we do professionally (I work at a company that makes slot machines and their games) is we create something called a paytable which has a list of all the winning combinations we want to appear and how likely they are to appear that way you never have to dynamically decide where the reels stop, you just look it up in the table and spin to that ...


2

I'm going to assume this is for a game that doesn't cheat the player. Maybe for a tutorial where you want it to appear random, but need them to have a specific amount of money at the end. The probability of winning a slot machine depends on the number of slots and the possible combinations. I think you'll be able to figure that out once you have those ...


2

Let's say the size-values are as follows: small = 3; medium = 2; large = 1; In this situation, you could add all size-values of your enemies together to calculate a biased random. For Example: smallUnitsTotal = 4; // => 12 points total (4 * 3) mediumUnitsTotal = 2; // => 4 points total (2 * 2) largeUnitsTotal = 1; // => 1 points total (1 * ...


2

Unless cars are created or destroyed between the two ends of the road, your average arrival rate will be the same as your average creation rate. Therefore, all you need to do is adjust the parameters of your Poisson distribution to match your desired arrival rate. The other variables you mention, such as acceleration, etc, aren't going to change the ...


2

You can use "expected values" like Continuum Crowds does it. From the Treuille et al paper: Expected periodic field changes. A similar issue arises when the field deterministically changes over time. Consider an environ- ment with two exit doors rapidly opening and closing. An exiting crowd would continuously switch direction back and forth towards the ...


2

One approach is to use the Monte Carlo method. Monte Carlo methods are mainly used in three problem classes: optimization, numerical integration, and generating draws from a probability distribution. This problem falls into the intersection of the first & third class, so Monte Carlo seems like a reasonable thing to try. The basic idea behind the Monte ...


1

As mentioned in the comments, you can easily normalize a collection of relative weights in an arbitrary range to a set of probabilities summing to 1 as follows: (Assuming no negative or #NAN weights) float totalWeight foreach(var item in items) totalWeight += item.weight; foreach(var item in items) item.probability = item.weight / totalWeight; Or ...


1

This can be handled by a straight forward reverse weighting. Assign enemy size 'Y' as a numeric value (ex. 1-4). Choose a ceiling value 'Z' that is greater than the largest possible value of 'Y' (The greater the difference between 'Z' and the highest 'Y' value will result in the least difference in attack frequency) Provide each enemy with a weighting ...


1

I'd be tempted to handle it like a raffle. Every time an attack slot comes around, everyone gets a number of raffle tickets according to their attack frequency. Then you do a random draw from those tickets, and deduct tickets from the winner. Everyone else keeps their tickets for the next draw, so someone who hasn't been picked in a while will gradually ...


1

How about this? NodeRate = NodesLeftToPut / TimeLeft; ChanceToSpawnNode = TimeStep * NodeRate if (Random.Range(0f, 1f) < ChanceToSpawnNode) { Spawn(); } The NodeRate is the number of nodes per second that you expect to occur, which changes as the timer drops and also when new nodes spawn. The chance to spawn during a time step is based on the NodeRate ...


1

You need to set each archer with a random target. You could set it to any of the enemies but it would probably work better if they can only see a number of them. For the sake of simplicity, I'm going to use 10, not 100. Archers: 0123456789 0123456789 Enemies: Now, let's say each archer can only reach the enemy in front of him and two either side for ...


1

Here's one simple method: rarity = 1 - Pow(random(), 1 + difficultyRating * maxBias) Here maxBias is a positive value that lets you control how skewed you want your probabilities to get. The higher difficultyRating gets, the more of the probability space gets devoted to the top end of the rarity scale.


1

While this is not a perfect solution, you can say something like: if (random.NextDouble() / x < dt) { // Create particle... } How this works: For now, let's assume that you want an average of 1/second (so / x does nothing). If it's been one second since the last frame, you want an average of one particle to appear. random.NextDouble() always ...


1

Here is my gaussian distrib. in 0..1 in c# With reference Note: r is the Random class istance. private double nextGaussian(double mean,double variance ) { // http://stackoverflow.com/questions/218060/random-gaussian-variables //with mean = 0.5 and variance = 0.5 we get uniform distribution over [0..1] double u1 = r.NextDouble(); ...


1

Another possible algorithm. This is easily expandable as well and does not have to use % of 100: //assuming rand() returns integers #define numberOfPlatformTypes 3 int platform[numberOfPlatformTypes]; platform[0] = 10; platform[1] = 30; platform[2] = 70; int total = 0; for(int i = 0; i < numberOfPlatformTypes; ++i) total += platform[i]; int r = rand()%...


1

I think there are already some nice answers given above but would suggest a different approach. When the player makes a critical hit you are giving him a small reward to entice further play. Sort of like how a gambling addict will stay at the poker table for 'just a little longer' after winning a hand. When the enemy gets hit by a critical it might not be ...


1

Bayesian Inference deals with situation quite a bit. You start with a probability distribution for an event occurring, then once it does, you update this probability to a new one. These are the prior and posterior probabilities respectively. It's often most useful to view this in tree form (grabbed this off the internet). In the tree, the branches ...


Only top voted, non community-wiki answers of a minimum length are eligible