[Solved] How do I check multiple probabilities?

Get help using Construct 2

» Sun Mar 09, 2014 8:09 pm

Hello.

I use an 2D array to store probabilities.

Lets say the first Y row represents the chances a character has to die from several death causes.
X1 is the chance to die from hearth attacks. X2 is the chance to starve. X3 the chance from being hit by an asteroid.

I now have to check which of the probabilities do occur... or maybe non of them occur.

How can I now check by which cause the character dies (if he even dies)? I need to put these probabilities in If conditions depending on each other.

Lets assume X1=35% , X2=60%, X3=80%.
Do I have to sum each probabilities?

100%-35%=65%
100%-60%=40%
100%-80%=20%

175% / 125% chance to die.

Thanks in advance!

I hope you know what I mean. It is hard to describe.
Last edited by Alyra Games on Tue Mar 11, 2014 9:14 pm, edited 1 time in total.
B
10
S
2
Posts: 135
Reputation: 1,090

» Mon Mar 10, 2014 1:11 am

I know what you mean but this is maths, not C2 related.
B
53
S
21
G
94
Posts: 2,425
Reputation: 55,563

» Mon Mar 10, 2014 2:00 am

I recently had the same question, check it out: viewtopic.php?f=147&t=95335

@plinkie There's a lot of math involved with making games. If you don't want to help, then don't reply
B
87
S
22
G
15
Posts: 1,041
Reputation: 15,353

» Mon Mar 10, 2014 3:49 am

Actually.. I'd go as far as saying that the most of the how-do I questions seem to be related to math one way or another. Distances, speeds, enemy prediction, probabilities, Logic (or lack of), trigonometry, basic matrix math, 3d/isometric projections. Makes me wonder don't they teach math anymore?

@Alyra I need to think.. There was a time I knew things like this. it's been so many years I have forgotten..
Need help? Upload .capx file with your question.
B
16
S
4
G
2
Posts: 233
Reputation: 2,560

» Mon Mar 10, 2014 7:29 pm

Thank you all for your replies!

I have an idea but i don't know if I'm right:

if random <= X1 - chane 1 occurs

if random > X1 and <= X1+X2 - chance 2 occurs

if random > X1+X2 and <= X1+X2+X3 - chance 3 occurs

if random > X1+X2+X3 - nothing occurs

Is this right? Does this keep the right % chances?
B
10
S
2
Posts: 135
Reputation: 1,090

» Mon Mar 10, 2014 8:28 pm

Worth reading through the thread that 7Soul posted ...
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,912

» Mon Mar 10, 2014 9:20 pm

Okay I will read through it. I have not had the time for it yet.

Edit:

Okay I read through the topic. I already had this solution in mind but my case is a little bit different so it whould not work for me (I think).

I safe my probabilities in an array and each of this probabilities can be ranging from 0%-100%. So if there are for example 5 different probabilities their sum can be greater or smaller than 100%.

I will show you an example. I attached a picture of the array. Each of this values can range from 0-100, representing % chances. 50% is the base value at the start of the game. The values are dynamic. Each Y row is an action the AI can make and each X row is the % chance of the object he is using for this action.

Let's say the first action (Y 0) is "destroy". And let's say the AI has 6 things he is able to destroy. X1=window, X2=door, X3=car, X4=house, X5=smartphone, X6=TV.

First i randomly choose an Y value to determine which action the AI is doing. After that I have to randomly let the AI pick an X value to determine with which object it is interacting. And this should be dependent on the % chances. If X1 is 0% the AI whould never destroy a window if he wants to destroy something. If X3 and X5 are both 100% than it whould always destroy either a car or a smartphone if the AI decides to destroy something.

So i have to set those values in relation to each other, but have to keep their own % chances. My had is about to explode.

I hope my problem is now clearer. There might be an easier solution than my approach but It gives me hadache.^^

Thanks for reading
You do not have the required permissions to view the files attached to this post.
B
10
S
2
Posts: 135
Reputation: 1,090

» Tue Mar 11, 2014 2:09 am

Hi.. After some consideration of your original question. And assuming these negative events are independent on one another.

I'd say that the way to see survival likelihood is to multiply the survival rates together.
So the odds of survival = .65 * .40 * .20 = 0.052 .. is slightly over 5% ...
Need help? Upload .capx file with your question.
B
16
S
4
G
2
Posts: 233
Reputation: 2,560

» Tue Mar 11, 2014 11:09 am

The way I do this is

step through each probability from high to low ( the high to low bit is important)
on each step I set the return value appropriately.

lets take your first example -

80% 60% and 30%
so you would step through these in high to low order
and lets say our percentage to check is 50%

so it would pass the first two (< 80 and < 60 ) but fail the third.

If you have 3 or 10 possibilities it makes no real difference (providing they are all different)

In your latest version you would need to take your (5 ?) possible % and pass them (hight to low) to a function that just does the above. This function would be probably be easier to write if you had a fixed number of possibilities (5,8,10, whatever) even if some of these possibilities were just padding.
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,912

» Tue Mar 11, 2014 1:06 pm

Thank you Joannak for your afford. But I described my problem badly in the first post.

And RamPackWobble whank you, too. But what if the first probability is 100%? Than the others whould never occur.

I have to find another way around this. :/

Edit:

And what if I instead go from low to high? So it will pass all 0% chances (they whould anyways never occur). But if the last 2 are 100% there is the same problem.

I think I now have a solution:

roll=round(random(X1+X2+X3+X4+X5+X6...))

if roll <=X1 - case 1

if roll >X1 & roll <= X1+X2 - case 2 occurs

if roll >X1+X2 & roll <= X1+X2+X3 - case 3 occurs

if roll >X1+X2+X3 & roll <= X1+X2+X3+X4 - case 4 occurs

if roll X1+X2+X3+X4 & roll <= X1+X2+X3+X4+X5 - case 5 occurs

if roll X1+X2+X3+X4+X5 & roll <= X1+X2+X3+X4+X5+X6 - case 6 occurs

So this whould ensure, that the AI does check all probabilities, even if there are more at 0% or 100%. The other good thing about this whould be that there is always an X case choosen (except all cases have 0% chance).

The values itself are dynamic but the number of X cases are static. So I think I could use this. Whould this be correct on the maths side?
B
10
S
2
Posts: 135
Reputation: 1,090

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 9 guests