CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 25 of 25
  1. #16
    Join Date
    Sep 2010
    Posts
    16

    Re: Probability Function

    I forgot to put in the (-25) roll penalty for the StealChance, however you have a general idea of what I've accomplished.

  2. #17
    Join Date
    Jan 2010
    Posts
    1,133

    Re: Probability Function

    Quote Originally Posted by jmcewan View Post
    I was responding to dglienna's comment.

    I do understand what you are saying, I'm just not sure I want to randomize the numbers.[...]
    Isn't that just what you've tried to do with that code you posted?

    Quote Originally Posted by jmcewan View Post
    Hello again,

    Just and update. I've managed to create the function without any shortcomings. I did it as follows:

    StealChance = RandomClass.Next() % 96
    BallHandlingChance = RandomClass2.Next() % 98

    if( StealChance >= BallHandlingChance)
    {
    Console.WriteLine.("Great steal by " +defenderName);

    } else{

    Console.Write.(+ defenderName " gets called for the reaching foul");

    }

    What do you guys think?
    Now you've got it all randomized.
    The random class has a much more convenient method with the signature
    public virtual int Next(
    int maxValue
    );
    and another one
    public virtual int Next(
    int minValue, int maxValue
    );
    -- so you don't need to do what you've done with %.

    The convention is to write the names of the variables with a lowercase starting letter. I assume that RandomClass is an instance of the Random class? If so, it is an object, so the name you gave it is a bit misleading.
    Anyway, you don't need to, or should use two random objects in this case - one will do just fine; the only thing you need to do is to call the Next(...) method twice.

    The whole idea was to define an event such a "a steal has occurred", to define a way to calculate it's probability from the stats (in whatever way suits your needs), and to run a check against this probability, by generating a random integer number between 0 and 99 [including 99, which gives a total of 100 possibilities].
    Or you could alternatively divide the probability you had expressed in percentage by 100, and then call rnd.NextDouble(), which would give you a greater precision.

    P.S. And, when I say "to define" - I don't mean in code, but conceptually.
    Last edited by TheGreatCthulhu; September 12th, 2010 at 12:45 AM.

  3. #18
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    Re: Probability Function

    I assume the Steal and Handling probabilities have been calculated for players playing against exactly the same opposition, otherwise the %ages are pointless. I have 100% ball handling, having only picked a ball up once and got past one 12 year old. Does that mean I can get past a pro who has 68% steal?
    Rob
    -
    Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......

  4. #19
    Join Date
    Jan 2010
    Posts
    1,133

    Re: Probability Function

    Quote Originally Posted by rliq View Post
    I assume the Steal and Handling probabilities have been calculated for players playing against exactly the same opposition, otherwise the %ages are pointless. I have 100% ball handling, having only picked a ball up once and got past one 12 year old. Does that mean I can get past a pro who has 68% steal?
    I think the OP just tries to create a simulation/game like app, not some player performance analyzer. The stats are predetermined, possibly in a more or less arbitrary way.

  5. #20
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Re: Probability Function

    Quote Originally Posted by jmcewan View Post
    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.
    Hmm ... maybe:

    chanceOfSteal = (1 - ballHandlingRating) * stealRating

    0.0118 = (1 - 0.98) * 0.94
    My hobby projects:
    www.rclsoftware.org.uk

  6. #21
    Join Date
    Sep 2010
    Posts
    16

    Re: Probability Function

    Quote Originally Posted by Zaccheus View Post
    Hmm ... maybe:

    chanceOfSteal = (1 - ballHandlingRating) * stealRating

    0.0118 = (1 - 0.98) * 0.94
    How would you then use the result?

  7. #22
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Re: Probability Function

    That's up to you - what do you want to do with the 'chance of steal' ?
    My hobby projects:
    www.rclsoftware.org.uk

  8. #23
    Join Date
    Sep 2010
    Posts
    16

    Re: Probability Function

    Quote Originally Posted by Zaccheus View Post
    That's up to you - what do you want to do with the 'chance of steal' ?

    Perhaps credit the defender with +1 steal and change possession. Sounds like the perfect implementation of Finite State Machines.

    I'm looking into another possible way to achieve what I want. I would like to compare the two teams' stats then have it generate realistic statistical output.

  9. #24
    Join Date
    Dec 2010
    Posts
    19

    Re: Probability Function

    On the other forum i have posted you a new message. Hope it helps its more or less an complete way to simulate your game.

  10. #25
    Join Date
    Sep 2010
    Posts
    16

    Re: Probability Function

    Quote Originally Posted by FransBotes View Post
    On the other forum i have posted you a new message. Hope it helps its more or less an complete way to simulate your game.
    Saw it, it is great stuff. I think I will use this method to simulate the game engine.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured