HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Weighted Random - Should I bother?

08-22-2008, 07:12 PM#1
Ammorth
Just putting the finishing touches on my DamageDetect/DamagePrevent/EvasionAndMiss systems when I remembered about how Blizzard coded weighting randoms into critical strikes and evasions so that long chains of successes wouldn't happen. Should I bother with this? The chances of it happening would be slim.

If I were to do include it though, what would be the best way?

Currently I have a struct for each evading unit which I store the chance to evade. Then if struct.chance >= GetRandomReal(0., 1.) then it evades.
08-22-2008, 09:05 PM#2
Themerion
Since Blizzard implemented units' damage to use dice, why not do the same?

Split the total chance in X intervals.
Get the sum of GetRandomReal(0,total_chance/X)
08-22-2008, 11:37 PM#3
Ammorth
I totally didn't understand a thing about your method...
08-23-2008, 06:16 AM#4
TheDamien
Quote:
Originally Posted by Ammorth
... Blizzard coded weighting randoms into critical strikes and evasions so that long chains of successes wouldn't happen.

They did? =\
08-23-2008, 06:42 AM#5
Gorman
Its probably best just to do the same as blizzard, otherwise people can be like: "why isn't it exactly the same as bliz when i test under bla bla circumstances?"

Besides, it would be a pretty cool feature to have!
08-23-2008, 09:09 AM#6
Themerion
Hm.. I'll try to be a bit clearer.

Total sum of chances should always be 1 anyway...

Collapse JASS:
// Weighted random through dice

// How many dice?
// The more dice, the more weighted towards the middle (50%).
integer die_count=2

// The maximum outcome for 1 die.
real die_range=1/die_count

real result=0
integer i=0

// Throw all the dice!
loop
    exitwhen i>=die_count

    // count the sum of all throws.
    set result=result+GetRandomReal(0,die_range)

    set i=i+1
endloop

// Now do your check...
if struct.chance >= result then
08-23-2008, 12:31 PM#7
Strilanc
Errr... there are a couple things wrong here.

1: Blizzard didn't weight their probability distribution. They (apparently) generated a bunch of random sequences, picked the ones that people would perceive as 'random but fair', and now randomly pick between those sequences. That is to say, they reduced the variance. There are various reasons for doing this, the main one being that people tend to think random distributions are non-random. For example, it's unlikely for there to be 10 crit strikes in a row, but it's not unlikely for it to happen once in an entire day of games on bnet. Many people who saw that (remember, once per day) might end up whining on the forums that blademasters were overpowered, totally ignoring the rarity of the event.

2: You're generating a true/false value, and this dice stuff won't have the effect you're expecting. You're going to change "10%" to "actually way less than 10%", instead of reducing the variance. If you want to reduce the variance without pre-generating sequences, you need to store some kind of state. For example, you could remember the last couple true/false values and make the common one less likely. You could also store a weighted average exponentially favoring the latest values.
08-23-2008, 02:41 PM#8
Ammorth
I figured it out last night and it works nicely.

http://www.wc3campaigns.net/pastebin...4bf709373ab810

Not only does it keep the actual percentage as close to the given percentage, but it prevents long strings of the same out-come.