# Event-rolling algorithm

0 favourites
• 4 posts
From the Asset Store
Finding the shortest path through the cells based on the A-star algorithm
• This is partly a plea for help to make a mathematical algorithm rather than only Construct 2 based help. I always think from the wrong perspective when doing algorithms and end up making some really crazy stuff.

What im doing right now is a sort of event-rolling algorithm that i want to be able to change the outcomes % by just changing numbers. I'll try to explain the problem as good as i can:

Lets say i have 5 different levels of stuff that can happen, ranging from A,B,C,D,E. A being most common and E being extremely rare. And then make a roll to see which it becomes.

Initially the roll has like a 7/10 to become A and 2/10 to become B, and a 1/10 to become C. But then i add a sort of luck+1 factor, and suddenly A is 6/10, B is 3/10 and C is 1/10. If i add another +1 luck factor, A becomes 5/10, B becomes 3/10 and C becomes 2/10. Another +1 makes A 4/10, B 3/10, C 2/10 and D 1/10. And the more luck factors are put in, the bigger chance for a better outcome.

I did this initially with rolling a random 10, and A was 0-8, B was 9+, C was 13+, D was 16+ and so forth and so on. But i quickly realized this was an extremely flawed system, since if the luck factor became too high, the chance of it becoming A vanished completely which was something i didnt want.

So basicly what im trying to figure out is how to calculate the chances in a good scaleable way, so as that when the higher level letters chance increases, the lower chances becomes smaller, but never dissapears completely.

Also having specific luck factors to skew the results is also something i would like to have, like B-luck +2, which increases the chance of the B result by quite a bit, while only taking away % from letters that are already inside the chance scale.

I havent played around much with weighting chance factors like this before, so im sorry if its either too easy or too hard for people to help me figure this out ^^;; The only things that come up in my head is some sort of system that takes the weights of all letters that have a variable of 1+ and then scale the % of each letter as a % of how many weights it has compared to all the weights on the scale. But im not sure how to implement that >_<

Any help or hints are appreciated!

/Mike

• Here is a topic with a way to do weighted random:

http://www.scirra.com/forum/weighted-probabilities_topic48421.html

With that instead of doing this:

a7 b2 c1 d0 e0

You could do this and end up with about the same probabilities but give d and e a slight chance of happening.

a700 b200 c100 d10 e1 total=1011

For leveling up just add to the weights.

You could do it linearly.

Like add 1 to a, 2 to b, 3 to c...

After 100 level ups the weights would be:

a800 b400 c400 d410 e501

You could also do it quadratically (x^2)

Add 1 to a, 4 to b, 9 to c, 16 to d...

After 100 level ups the weights would be:

a800 b600 c1000 d1610 e2501

• Thanks for the link and the information, i have been thinking a bit and together with what you said i think i know how to go from here, much appreciated! ^^

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• Sorry to brings this thread back from the dead but I'm kind of stuck with this.

I've implemented the weighted random and it works great. My problem is I don't know how to add to the weights.

The example uses a string of numbers. I tried deconstructing that string and reconstructing it but that didn't work. I tried using arrays but that didn't work either. How exactly do you add to the weights?

R0J0hound Thank you for providing a sample file in the other thread. I've been looking for that for ages

• 4 posts