# [Solved] How do I check multiple probabilities?

Get help using Construct 2

### » Tue Mar 11, 2014 2:30 pm

by going hi to low with
100%(returning 1)
90 %(returning 2)
80%(returning 3)
70%(returning 4)
60%(returning 5)
as probabilities with the "found" being 75%

then first time 100 would set the return to be "1" but this would then be over written by the 90 setting the return to be "2" which would then be overwritten by the 80 setting the return to be "3" the 70 would not alter the return value nor would the 60 so the return ("3") would indicate it fell into the 80% range...
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 2:47 pm

But if 2 or more values are the same than the first ones whould never occur:

100%(returning 1, but will never occur)
100%(will always overwrite 1 to 2)
80%(returning 3)
70%(returning 4, but will never occur)
70%(will always overwrite 4 to 5)

I will try out if I can use my solution and if the % chances keep correct. I will loop through the code 10,000 times like you did in the other thread.
B
10
S
2
Posts: 135
Reputation: 1,090

### » Tue Mar 11, 2014 3:02 pm

True - so you could also include a check for that and then pick one at random ? But, what is the chance of there being 2 or more with the same chance and would it matter if it picks the lower one in the list ?
This is the method I've used in the past and it worked for me - maybe you can take the idea and alter it to your needs or maybe you need another approach.
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 3:06 pm

Yes it needs to be possible for each case to occur. Because in my example the AI whould never destroy the window if he wants to destroy something.. even though he has a 100% chance to want to destroy a window.

I'm currently setting up the 10,000 loop and I then will post the .capx.
B
10
S
2
Posts: 135
Reputation: 1,090

### » Tue Mar 11, 2014 4:52 pm

I'm stuck in the complicated percentage calculation.

It's actually not "per cent" (/100) it's "per total amount of all values of the X array row)

I am trying to figure out how I have to set up the equation.

Rolls is the total number of rolls and X0 is the total amount of the occurring X0 cases. I want to figure out at how many % X0 occurs:

Set Text:
round(rolls/x0*(array.At(0,0)+array.At(1,0)+array.At(2,0)+array.At(3,0)+array.At(4,0)+array.At(5,0)+array.At(6,0)+array.At(7,0)+array.At(8,0)+array.At(9,0))) & "% dynamic chance"

Edit:

Awesome! I figured it out. I had to swap "rolls/x0" to "x0/rolls". I will soon upload the .capx so everyone who will need this can look at it.^^

Edit 2:

Here is the .capx. On the top left you can see all rolls. On the left the static % chances given in the array. On the right side the dynamic case occurences.

Edit 3:

I updated the .capx so everyone, who needs this solution, can easily comprehend how it works.
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 10:18 pm

Ah. That Capx explains a lot. So in the each round there will allways happen one event of the ten possible?
B
16
S
4
G
2
Posts: 233
Reputation: 2,560

### » Tue Mar 11, 2014 10:27 pm

Yeah it was a bit hard to explain, what I wanted the code to do.

Yes there will always happen one of the events, except they all have 0% chance. Than the AI will choose another action to do (this part I still have to implement).

I currently try to use a function so I don't have to copy this code for each of the actions.
B
10
S
2
Posts: 135
Reputation: 1,090

### » Wed Mar 12, 2014 5:56 am

@Alyra Games What you are trying to determine is a Bayes decision tree, assuming that your probabilities are independent, Joannak is right, you should multiple them. You can't have a probability over 100% at anytime, because that would happen all the time. (So, no probabilities like 125%)

Instead of checking for each probability, build a decision tree that gives you the path for each case. With that, you will be able to determine the probability for each scenario.

Note that the sum of all the probabilities should be equal to 1 (or 100%).

A quick google search for Bayes Decision tree should help you to understand the probabilities behind of what you are doing, look for an example with numbers... Once you get the idea of it, you should be able to implement it with a function that generates a result if your probability is between certain values.

Edit: I didn't notice that the solution was already there. Yes a function will help you avoid that. Anyways, a decision tree always help in this scenario (I like graphics).
B
8
S
3
G
1
Posts: 135
Reputation: 2,209

### » Wed Mar 12, 2014 7:08 am

@Joannak Sorry I now understand what you tried to tell me.

@gfigueroa The way I'm handling it right now is working for me, but the Bayes decision tree looks interesting and powerful. I only have to understand it as it looks really complicated. The formulas especially. oO

If you take a quick look at my .capx, do you think the Bayes decision tree whould give me advantages over the way I'm doing it?
B
10
S
2
Posts: 135
Reputation: 1,090

Previous