Is there a function that calculates the probability (in percentage) of an argument? I understand that this comment maybe a little vague, however I've only recently began programming so I'm having some issues expressing what I truly want.
Yes. Perhaps I can explain myself better with an example:
Imagine a basketball game where players move/act based on stats. A defender may have his STEAL rating at 94, and the offensive player has a BALL HANDLING rating of 98. I would like to know if a function exist that calculates the probability of the defender taking the ball from the offensive player. Like if (based on the stats) the defender has a 31% chance of making the steal.
I do understand what you are saying, I'm just not sure I want to randomize the numbers. That would mean I would randomize (using the above example) the players Steal attribute anywhere between 92 to 96 and the the offensive player's ball handling 96 - 100.
I suppose if that is the only way then I definitely give it a try.
jmcewan, you can't just have some numbers and a magic function that will calculate the probability of whether an event will happen, not without first defining some rules - what are all the possible events, what approach should be used in calculation? If I you wanted to find out the chance that it'll rain tomorrow, you wouldn't just throw a die, would you? You would have to consider how the actual weather conditions affect the outcome (and maybe develop a simplified model, because factoring all the stuff in would be impractical).
And once you have the probability, what will you do with it? It will not make anything happen on it's own, no if statement will make it work. You need something to actually happen with the same chance. So go back and re-read BigEd781's post.
And try to answer it - even post what you think is the right answer here, why not? If you didn't get the hint, no shame there - at least you'll know where to go next from the feedback.
Also, in your basketball game scenario - you already have the probabilities in the form of stats (or these can be derived from the stats), so you don't need to really calculate them.
You just need make things happen, or not - and a random number generator is a good tool for that.
Last edited by TheGreatCthulhu; September 4th, 2010 at 02:19 PM.
I really haven't been programming long so I'm not sure what I am suppose to be seeing. I must admit, I do feel a little foolish right now for not being able to come up with an answer.
You are right....the answer was right there. I understand now. The problem I was having is thinking that a percentage value should be the answer whereas it should help to form the solution.
BTW, in relation with what you said about the stats, if you were having trouble understanding how to correlate the STEAL & BALL HANDLING ratings, with the setup you described in your earlier post:
Originally Posted by jmcewan
Imagine a basketball game where players move/act based on stats. A defender may have his STEAL rating at 94, and the offensive player has a BALL HANDLING rating of 98. I would like to know if a function exist that calculates the probability of the defender taking the ball from the offensive player. Like if (based on the stats) the defender has a 31% chance of making the steal.
There's no universal approach, that is totally up to you. As a guide, you could use a method similar to those a lot of pen & paper FRP games use. In essence, they have the rulebook, which defines how to handle this - some numbers are added or subtracted or whatever, and a new number is derived from that, and this number is matched against a dice roll.
So, similarly, you would define your own rules.
For example:
(1) CHANCE = STEAL - BALL_HANDLING/2,
or
(2)
// this is not actual code
// it is assumed that a stat value can range from 0 to 100
if STEAL == BALL_HANDLING == 0 then
CHANCE = 0
else if min(STEAL, BALL_HANDLING) == STEAL then
CHANCE = 100 * STEAL / BALL_HANDLING
else
CHANCE = 100 * (1 - BALL_HANDLING/STEAL)
or
(3) Run a check for BALL_HANDLING first, diminished by a bad luck factor (that affects every stat; let's say it's 25). Then if the test fails, do the same for STEAL. If the test succeeds, the defense player has taken the ball. If not, the offensive player got really lucky.
or
(4) something else...
Now, these all give different probabilities, and model the behavior of the system/simulation/game in a slightly different way.
Once you have decided what suits your needs best, and once you have the CHANCE calculated, you can "throw a 100-sided die" - a FRP analogy once again - and here, the equivalent is the random number generator.
Bookmarks