Require help in writing the algorithm for my cricket simulation game

1k Views Asked by At

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 me 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. The question might seem a little abstract, will really appreciate any help or direction which u could provide

1

There are 1 best solutions below

0
On

This is not a problem of coding (yet), it is a problem of defining what you want the code to do.

"If a batsman is more skilled, more runs will be generated." What do you mean by this? Do you want the skill of a batsman to be 0 or 1, and if 0 then the runs will be 0..3 all equally likely, and if 1 then the runs will be 4..6 equally likely? Perhaps you want batsman skill to be on a continuum not just 0 or 1. Do you want a skilled batsman to always score one more run than an unskilled one? Perhaps you want a skilled batsman to score 5% more runs than an unskilled one. Do you want a skilled batsman to roll twice and keep the higher roll? All of these are easy to program, and give substantially different results. You need to decide how much of an effect skill has, and what sort of effect. The same for the other criteria.

I advise you to think through just what you want, with specific numbers. After you're done, if you're having trouble putting it all together, post that more detailed question or revise this one.