How do I apply different probability factors in an algorithm for a cricket simulation game?

Posted by Komal Sharma on Game Development See other posts from Game Development or by Komal Sharma
Published on 2013-07-21T19:29:47Z Indexed on 2013/10/20 16:12 UTC
Read the original article Hit count: 395

Filed under:
|
|

I am trying to write the algorithm for a cricket simulation game which generates runs on each ball between 0 to 6. The run rate or runs generated changes when these factors come into play like skill of the batsman, skill of the bowler, target to be chased. Wickets left.

If the batsman is skilled more runs will be generated. There will be a mode of play of the batsman aggressive, normal, defensive. If he plays aggressive chances of getting out will be more. If the chasing target is more the run rate should be more. If the overs are final the run rate should be more.

I am using java random number function for this. The code so far I've written is

    public class Cricket {

public static void main(String args[])
{
    int totalRuns=0;
  //i is the balls bowled   
     for (int i = 1; i <= 60 ; i++)
       {
        int RunsPerBall = (int)(Math.random()*6);
        //System.out.println(Random);
        totalRuns=totalRuns+RunsPerBall;
       }
    System.out.println(totalRuns);
}

    }

Can somebody help me how to apply the factors in the code. I believe probability will be used with this. I am not clear how to apply the probability of the factors stated above in the code.

© Game Development or respective owner

Related posts about java

Related posts about algorithm