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.
Answer
You can work your way backwards by creating a series of grids and calculating the stats for each grid.
Imagine for example 16 balls being bowled at a player (4 down the leg side, 4 down the off side and eight on target and the expected outcome for each one (ignoring dot balls where no runs are scored or wickets taken):
a) Batsman vs Poor Bowler
6 1 1 1 <-- Full Toss
1 2 1 1 <-- Overpitched
1 W 1 1 <-- Good Length
1 1 1 4 <-- Short of a length
total runs = 24 outs = 1 bowler's strike rate is 16 - batsman's average = 24 Run Rate=1.5
b) Batsman vs Medium Bowler
6 1 1 1
1 2 W 1
1 W 2 1
1 1 1 4
total runs 24 outs= 2 bowler's strike rate is 8 - batsman's average = 12 Run Rate=1.5
c) Batsman vs Good Bowler
W 1 2 1
1 2 W 1
1 W W 1
6 2 2 4
total runs = 24 outs = 4 bowler's strike rate 4 batsman's average = 6 Run Rate=1.5
So for a NxN grid
- The bowler's strike rate is
N * N/Number of Wickets in grid
(excluding stumpings) - The batting average is
Number of Runs in grid/ Number of Wickets in grid
- The run rate is
Number of runs in grid/ N * N
Now if all batsmen were of equal quality, you could choose between grid a) grid b) and grid c) based on the strike rate of the bowler, if the bowler has an average of 16 then always use grid a), if the bowler has an average 12 then half the time chose a) and half the time b) etc.
You can change the quality of the batsman in the same way, e.g. by reducing the number of runs within the grid:
d) Poor Batsman vs Poor Bowler
1 1 1 1
1 2 1 1
1 W 1 1
1 1 1 1
total runs = 16 outs= 1 bowler's strike rate 16 batsman's average = 16 Run Rate=1
e) Poor Batsman vs Medium Bowler
1 1 1 1
1 2 W 1
1 W 1 1
1 1 1 2
total runs = 16 outs = 2 bowler's strike rate 8 batsman's average = 8 Run Rate=1
f) Poor Batsman vs Good Bowler
2 1 1 1
1 W 1 1
1 W W 1
1 1 W 4
total runs = 16 outs= 4 bowler's strike rate 4 batsman's average = 4 Run Rate = 1
You could also increase aggression i.e. increase the run rate & strike rate simultaneously by reducing the number of dot balls per over.
No comments:
Post a Comment