Bowlingprogrambowlers Bprgbjava
Bowlingprogrambowlers Bprgbjava
ahmed;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
*/
private String name;
private int runscoredperballandoutcomeperballinaOver;
private int overbowlingnumberofballs;//6 balls per over
/*
name[0]="Kirat Boli";
name[1]="N.S. Nodhi";
name[2]="R Rumrah";
name[3]="Shashi Henra";
*/
if (batsmanflag==1) {
[Link]("bowler "+ option +"bowling. A ball is bowled.
Batsman 1 is batting");
[Link]("The Score is - "+[Link] +"runs
and "+ [Link] + " wickets");
} else if (batsmanflag==2) {
[Link]("bowler "+ option +"bowling. A ball is bowled.
Batsman 2 is batting");
[Link]("The Score is - "+[Link] +"runs
and "+ [Link] + " wickets");
}
if (([Link]>=40) && ([Link]<3) &&
([Link]<=36)) {
[Link]("Lengaburu
wins!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
[Link]=1;
} else if (([Link]==40) && ([Link]<=3) &&
([Link]<=36)) {
[Link]("ITS A
TIE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
[Link]=0;
} else if (([Link]<40) && ([Link]>=3) &&
([Link]<=36)) {
[Link]("Enchai
Wins!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
[Link]=2;
}
}
String Commentary="";
int runsscored=0;
int equationmatchscorerunsscoredwicketstakenwicketsremaining[]=new
int[2];
int matchscore=0;
int wickets=0;
int wicketstakenflag=0;
int equationmatchscorerunsscored=40; // read from properties file
int equationwicketstakenwicketsremaining=3;
int i=0;
int j=0;
int overnumber[]=new int[4];
int scoreandwicketsforover[]=new int[12]; //do read from properties
file
int option;
option=bowler;
/*for(i=0;i<4;i++) {
overnumber[i]=[Link][i];
}*/
if (matchesplayed>0) {
scoreandwicketsforover=
readbowlersequence(overorderforeverybowler, bowleroutcome, matchesplayed); //Async
-to read from generated file
} else {
scoreandwicketsforover= bowleroutcome;//Sync
}
int jcntr;
jcntr=0;
j=matchesplayed*6;
int jcntrlength;
jcntrlength=0;
jcntrlength=j+6;
int batsmanflag;
batsmanflag=1;
for (jcntr=j;jcntr<jcntrlength;jcntr++) {
if (scoreandwicketsforover[jcntr]==0) {
runsscored=runsscored+0;
[Link]=[Link]+0;
batsmanflag=1;
equationmatchscorerunsscored=equationmatchscorerunsscored-0;
printScore(option,runsscored,wickets,batsmanflag);
}
else if(scoreandwicketsforover[jcntr]==1) {
runsscored=runsscored+1;
[Link]=[Link]+1;
batsmanflag=2;
equationmatchscorerunsscored=equationmatchscorerunsscored-1;
printScore(option,runsscored,wickets,batsmanflag);
}
else if(scoreandwicketsforover[jcntr]==2) {
runsscored=runsscored+2;
[Link]=[Link]+2;
batsmanflag=1;
equationmatchscorerunsscored=equationmatchscorerunsscored-2;
printScore(option,runsscored,wickets,batsmanflag);
}
else if(scoreandwicketsforover[jcntr]==3) {
runsscored=runsscored+3;
[Link]=[Link]+3;
batsmanflag=2;
equationmatchscorerunsscored=equationmatchscorerunsscored-3;
printScore(option,runsscored,wickets,batsmanflag);
}
else if(scoreandwicketsforover[jcntr]==4) {
runsscored=runsscored+4;
[Link]=[Link]+4;
batsmanflag=1;
equationmatchscorerunsscored=equationmatchscorerunsscored-4;
printScore(option,runsscored,wickets,batsmanflag);
}
else if(scoreandwicketsforover[jcntr]==5) {
runsscored=runsscored+5;
[Link]=[Link]+5;
batsmanflag=2;
equationmatchscorerunsscored=equationmatchscorerunsscored-5;
printScore(option,runsscored,wickets,batsmanflag);
}
else if(scoreandwicketsforover[jcntr]==6) {
runsscored=runsscored+6;
[Link]=[Link]+6;
batsmanflag=1;
equationmatchscorerunsscored=equationmatchscorerunsscored-6;
printScore(option,runsscored,wickets,batsmanflag);
}
else if(scoreandwicketsforover[jcntr]==-1) {
wickets=wickets+1;
[Link]=[Link]+1;
batsmanflag=2;
equationwicketstakenwicketsremaining=equationwicketstakenwicketsremaining-1;
wicketstakenflag=1;
printScore(option,runsscored,wickets,batsmanflag);
}
[Link]=[Link]+1;
} //for 1 over
equationmatchscorerunsscoredwicketstakenwicketsremaining[1]=[Link]+eq
uationmatchscorerunsscoredwicketstakenwicketsremaining[1];
} else if ([Link]<40){
equationmatchscorerunsscoredwicketstakenwicketsremaining[0]=[Link]+equa
tionmatchscorerunsscoredwicketstakenwicketsremaining[0];
}
int result;
result=0;
int runs;
runs=[Link];
int wickets;
wickets=[Link];
[Link]("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!ITS A TIE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
result=0;
} else if (([Link]>=40) && ([Link]<3) &&
(icntr<=4) && ([Link]>=36)) {
[Link]("Lengaburu
Wins!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
result=1;
} else if (([Link]<40) && ([Link]>=3) &&
(icntr<=4) && ([Link]>=36)) {
[Link]("Enchai
Wins!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
result=2;
} else if (([Link]<40) && ([Link]<=3) &&
(icntr<=4) && ([Link]>=36)) {
[Link]("Enchai
Wins!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
result=2;
}
return result;
//orderofrunscoredperballandoutcomeperballinaOver=[Link]()*0.8*100;
int bowlingcntr;
bowlingcntr=1;
double randombowlingoutcome;
int seed;
seed=8;
int countersofbowler1[]={5,30,25,10,15,1,9,5};
int countersofbowler2[]={10,40,20,5,10,1,4,10};
int countersofbowler3[]={20,30,15,5,5,1,4,20};
int countersofbowler4[]={30, 25,5,0,5,1,4,30};
int passrunningover;
passrunningover=over;
/*
* int bowler1cntr[]={0,45,270,225,90,135,9,81,45}; int
* bowler2cntr[]={0,90,360,180,45,90,9,36,90}; int
* bowler3cntr[]={0,180,270,135,45,45,9,36,180}; int
* bowler4cntr[]={0,270,225,45,0,45,9,36,270};
*/
int i;
i=1;
[Link]("bowler -"+bowler);
int bowlercntr;
bowlercntr=1;
int cntr;
cntr=0;
// bowler 1 sequence
//static int cntr1, cntr2,cntr3, cntr4, cntr5, cntr6, cntr7, cntr8;
String score;
score="";
score="<score>"+"<bowler>"+bowler+"</bowler>";
String source;
source=[Link];
int wickets;
wickets=0;
int matchscore;
matchscore=0;
int oversbowled;
oversbowled=0;
oversbowled=over;
score=score+"<over>";
if (matchesplayed>0) {
bowlercoutcome = readbowlersequence(bowlercntr, bowlercoutcome,
matchesplayed);
}
int batsmanflag;
batsmanflag=1;
if (matchesplayed==0) {
bowlingcntr = [Link]();//TO
GENERATE RANDOM ORDER OF SCORE
}
if ((bowlercntr>=6) && ((bowlercntr%6)==0)){//increment overs by
1
oversbowled=oversbowled+1;
score=score+oversbowled+"</over>";
score=score+"<rorwoutcomeresult>"+0+"</rorwoutcomeresult>";
//runorwicketoutcomeresult
[Link]=[Link]+0;
printScore(bowler,[Link],[Link],batsmanflag);
} else if (bowlingcntr>=12.5 && bowlingcntr<25)
{
cntr=bowlerselected[2];
//cntr=cntr-1;
if (cntr>0){
outcome[bowlercntr]=1;//1 run
cntr=cntr-1;
bowlerselected[2]=bowlerselected[2]-1;
}
//matchscore=matchscore+1;
score=score+"<ball>"+bowlercntr+"</ball>";
score=score+"<rorwoutcomeresult>"+1+"</rorwoutcomeresult>";
[Link]=[Link]+1;
batsmanflag=2;
printScore(bowler,[Link],[Link],batsmanflag);
} else if (bowlingcntr>=25 && bowlingcntr<37.5)
{
cntr=bowlerselected[3];
//cntr=cntr-1;
if (cntr>0){
outcome[bowlercntr]=2;//2 run
cntr=cntr-1;
bowlerselected[3]=bowlerselected[3]-1;
}
//matchscore=matchscore+2;
score=score+"<ball>"+bowlercntr+"</ball>";
score=score+"<rorwoutcomeresult>"+2+"</rorwoutcomeresult>";
[Link]=[Link]+2;
printScore(bowler,[Link],[Link],batsmanflag);
} else if (bowlingcntr>=37.5 && bowlingcntr<50)
{
cntr=bowlerselected[4];
//cntr=cntr-1;
if (cntr>0){
outcome[bowlercntr]=3;//3 run
cntr=cntr-1;
bowlerselected[4]=bowlerselected[4]-1;
}
//matchscore=matchscore+3;
score=score+"<ball>"+bowlercntr+"</ball>";
score=score+"<rorwoutcomeresult>"+3+"</rorwoutcomeresult>";
[Link]=[Link]+3;
batsmanflag=1;
printScore(bowler,[Link],[Link],batsmanflag);
} else if (bowlingcntr>=50 && bowlingcntr<62.5)
{
cntr=bowlerselected[5];
//cntr=cntr-1;
if (cntr>0){
outcome[bowlercntr]=4;//4 run
cntr=cntr-1;
bowlerselected[5]=bowlerselected[5]-1;
}
//matchscore=matchscore+4;
score=score+"<ball>"+bowlercntr+"</ball>";
score=score+"<rorwoutcomeresult>"+4+"</rorwoutcomeresult>";
[Link]=[Link]+4;
printScore(bowler,[Link],[Link],batsmanflag);
} else if (bowlingcntr>=62.5 && bowlingcntr<75)
{
cntr=bowlerselected[6];
//cntr=cntr-1;
if (cntr>0){
outcome[bowlercntr]=5;//5 run
cntr=cntr-1;
bowlerselected[6]=bowlerselected[6]-1;
}
//matchscore=matchscore+5;
score=score+"<ball>"+bowlercntr+"</ball>";
score=score+"<rorwoutcomeresult>"+5+"</rorwoutcomeresult>";
[Link]=[Link]+5;
batsmanflag=2;
printScore(bowler,[Link],[Link],batsmanflag);
} else if (bowlingcntr>=75 && bowlingcntr<87.5)
{
cntr=bowlerselected[7];
//cntr=cntr-1;
if (cntr>0){
outcome[bowlercntr]=6;//6 run
cntr=cntr-1;
bowlerselected[7]=bowlerselected[7]-1;
}
//matchscore=matchscore+6;
score=score+"<ball>"+bowlercntr+"</ball>";
score=score+"<rorwoutcomeresult>"+6+"</rorwoutcomeresult>";
[Link]=[Link]+6;
printScore(bowler,[Link],[Link],batsmanflag);
} else if (bowlingcntr>=87.5 &&
bowlingcntr<100) {
cntr=bowlerselected[8];
//cntr=cntr-1;
if (cntr>0){
outcome[bowlercntr]=-1;//1 wicket
cntr=cntr-1;
bowlerselected[8]=bowlerselected[8]-1;
}
//wickets=wickets+1;
score=score+"<ball>"+bowlercntr+"</ball>";
score=score+"<rorwoutcomeresult>"+-1+"</rorwoutcomeresult>";
[Link]=[Link]-1;
batsmanflag=1;
printScore(bowler,[Link],[Link],batsmanflag);
}
bowlercntr=bowlercntr+1;
score=score+"</score>";
return outcome;
}
//write in file
/* String workoutputfilestr = "C:\\Webserver\\[Link]";
String counterfilecntr = "C:\\Webserver\\cntrfile_cntrfile.txt";
String tempfiletmp = "C:\\Webserver\\tempfile_tmpfile.txt";
*/
int over;
//String score;
//score="";
String sequencepatternstrfile;
sequencepatternstrfile="";
int int_counter_read_read;
int_counter_read_read=0;
//read the input sequence and pattern, if not null make it as 1
int cntr_ctr;
cntr_ctr=0;
int cntrflag;
cntrflag=0;
int CurrentMatchOvericntr;
CurrentMatchOvericntr=1;
//CurrentMatchOvericntr=over;
try {
if(![Link]()){
[Link]();
}
//score=score+"</score>";
[Link](score);
[Link]();
} catch (IOException e) {
[Link]();
}
//return outcome;
int counter;
counter=0;
counter=bowler;
String bowlersequence;
//check match statistics
int overnumber[] = new int[4];//read from [Link]
//matchesplayed=[Link];
oversbowled=matchesplayed;
int i;
i=0;
//do generate order of bowlers by reading from dest file as per this
order
for(i=0;i<4;i++) {
overnumber[i]=[Link][i];//read
from properties file or its equal to matchesplayed assuming 1 over for each bowler
}
String bowlersourceinput;
bowlersourceinput="";
bowlersourceinput="bowler"+bowler+"[Link]";
if (matchesplayed>0) {
int kxcntr;
int jxcntr;
int zxcntr;
jxcntr=0;
kxcntr=0;
zxcntr=0;
kxcntr=matchesplayed*6;
kxcntr=kxcntr+1;
for(jxcntr=kxcntr;jxcntr<=kxcntr;jxcntr++) {
scoreandwickets[zxcntr]=readbowleroverfromfilegenerateover(bowler,
bowlersourceinput, oversbowled, matchesplayed);
zxcntr=zxcntr+1;
}
} else {
scoreandwickets=bowleroutcome;
}
try {
String dest;
dest="";
dest ="D:\\kirkaet\\match"+matchesplayed+"[Link]";
if(![Link]()){
[Link]();
}
String scoreoutcome;
String runsorwicketoutcome;
runsorwicketoutcome="";
scoreoutcome="<match><score>";
scoreoutcome="<bowler>"+bowler+"<bowler>";
int j;
int jcntr;
j=0;
jcntr=matchesplayed*6;
for(jcntr=j;jcntr<j;jcntr++) {
runsorwicketoutcome="<ball>"+jcntr+"</ball>";
runsorwicketoutcome="<runsorwicketoutcome>"+scoreandwickets[j]
+"</runsorwicketoutcome>";
j++;
}
scoreoutcome=scoreoutcome+runsorwicketoutcome+"<match/></score>";
[Link](scoreoutcome);
[Link]();
[Link]();
[Link]();
} catch (IOException e) {
[Link]();
}
//generate bowler sequence
//bowlersequence =
int currentgenerateMatchoverssequencecntr;
currentgenerateMatchoverssequencecntr=matchesplayed;
return scoreandwickets;
}
int scoreint_cntr_read_read;
scoreint_cntr_read_read=0;
int int_cntr_read_read;
int_cntr_read_read=0;
int cntr_read_readflag;
cntr_read_readflag=0;
int int_cntr_read_write_flag;
int_cntr_read_write_flag=0;
if (cntr_f.exists()) {
try {
StringBuilder cntrcontentBuilder = new StringBuilder();
BufferedReader br = new BufferedReader(new
FileReader(bowlercntrfilesourcenoorplayBallMatchComeon));
try {
String scntrCurrentLine = null;
while ((scntrCurrentLine = [Link]()) != null) {
[Link](scntrCurrentLine);
cntr_read_readflag=1;
}
} catch (IOException e) {
[Link]();
}
[Link]();
try {
Pattern p = [Link](regex);
Matcher m = [Link](cntr_read_read);
[Link]("cntr_read_read - " + cntr_read_read);
int x;
x=0;
if ([Link]()) {
[Link]("positionstartarray - " +
positionstartarray[x]);
x = x + 1;
int y;
y=0;
try {
Pattern pclose = [Link](regexxmlend);
Matcher mclose = [Link](cntr_read_read);
[Link]("cntr_read_read - " + cntr_read_read);
if ([Link]()) {
y = y + 1;
String ballandrunscounterpropertystring;
ballandrunscounterpropertystring="";
int k;
k=0;
k=matchesplayed; //number of overs bowled
//read the <ball> and <rorwoutcomeresult> result data into an
array
ballandrunscounterpropertystring=cntr_read_read.substring(positionendarray[k],cntr_
read_read.length());
int xcntr;
xcntr=0;
// while (xcntr<=6) {
int positionstartarrayballsandruns[] = {0,0,0,0,0,0};//read the
runs scored or wickets taken
String regexballsandruns="";
//xcntr=xcntr+1;//balls
regexballsandruns = "<rorwoutcomeresult>";
try {
if ([Link]()) {
positionstartarrayballsandruns[xcntr] =
[Link]()+1; // <counter> -- //bowler1cntr
[Link]("positionstartarrayballsandruns -"
+ positionstartarrayballsandruns[xcntr]);
[Link]("positionstartarrayballsandruns -
" + positionstartarrayballsandruns[xcntr]);
xcntr = xcntr + 1;
try {
Pattern pballsandrunsend =
[Link](regexballsandruns);
Matcher mballsandrunsend =
[Link](ballandrunscounterpropertystring);
[Link]("ballandrunscounterendpropertystring - " +
ballandrunscounterpropertystring);
if ([Link]()) {
positionendarrayarrayballsandruns[ycntr] =
[Link]()-1; // <counter> -- //bowler1cntr
[Link]("positionendarrayarrayballsandruns -" +
positionendarrayarrayballsandruns[ycntr]);
[Link]("positionendarrayarrayballsandrunss - " +
positionendarrayarrayballsandruns[ycntr]);
ycntr = ycntr + 1;
[Link]("Pattern created:
"+[Link]());
while (zcntr<1) {
runsorwicketandrunscounterproperty=[Link](posit
ionstartarrayballsandruns[zcntr],positionendarrayarrayballsandruns[zcntr]-1);
if (cntr_read_readflag==1) {
scoreint_cntr_read_read=
[Link](runsorwicketandrunscounterproperty);
}else {
scoreint_cntr_read_read=0;
}
zcntr=zcntr+1;
}
} catch (Exception e) {
[Link]();
}
return scoreint_cntr_read_read;
/**********
File cntrfilesourcenoorlightplayBallMatchfile= new
File(cntrfilesourcenoorlightplayBallMatchfilepath);
String propertyfilefilepath;
propertyfilefilepath="";
try {
propertyfilefilepath=[Link]();
} catch (IOException e) {
[Link]();
}
int int_cntr_read_read;
int_cntr_read_read=0;
int cntr_read_readflag;
cntr_read_readflag=0;
int int_cntr_read_write_flag;
int_cntr_read_write_flag=0;
if (cntrNew_f.exists()) {
try {
StringBuilder cntrcontentBuilder = new StringBuilder();
BufferedReader br = new BufferedReader(new
FileReader(cntrfilesourcenoorlightplayBallMatchfile));
try {
[Link]();
****/
String counter;
counter="";
counter=patternmatch;
String str;
str="";
try {
try {
[Link](str);
[Link]();
} catch (IOException e) {
[Link]();
} finally {
try {
if (in != null)
[Link]();
} catch (IOException ex) {
[Link]();
}
}
} catch (Exception e) {
[Link]();
}
String cntr_read_read;
cntr_read_read = str;
int cntr_read_readflag;
cntr_read_readflag=0;
int int_cntr_read_read;
int_cntr_read_read=0;
if (str=="") {
cntr_read_readflag=0;
} else {
cntr_read_readflag=1;
}
try {
Pattern p = [Link](regex);
Matcher m = [Link](cntr_read_read);
if ([Link]()) {
[Link]("positionstartarray - " +
positionstartarray);
x = x + 1;
}
} catch (PatternSyntaxException pse) {
[Link]();
}
String regexxmlend = "";
regexxmlend = "</"+ counter +">";
try {
Pattern pclose = [Link](regexxmlend);
Matcher mclose = [Link](cntr_read_read);
[Link]("cntr_read_read - " + cntr_read_read);
y = y + 1;
}
} catch (PatternSyntaxException pse) {
[Link]();
}
String counterproperty;
counterproperty="";
counterproperty=cntr_read_read.substring(positionstartarray,positionendarray-
1);
[Link]("counterproperty - "+patternmatch + "-
"+counterproperty);
if ([Link]()) {
int_cntr_read_read=-1;
}else {
int_cntr_read_read=[Link](counterproperty);
}
return int_cntr_read_read;
//propertiesfile
//Match Statistics file "D:\\kirkaet\\[Link]"
/*
* String propertyfilefilepath; propertyfilefilepath=""; try {
* propertyfilefilepath=[Link](); } catch
(IOException e)
* { [Link](); }
*/
int cntr_read_readflag;
cntr_read_readflag=0;
int incordec;
incordec=1; //1 means increment, -1 means decrement
incordec=inc;
int int_cntr_read_write_flag;
int_cntr_read_write_flag=0;
if (cntr_f.exists()) {
try {
StringBuilder cntrcontentBuilder = new StringBuilder();
BufferedReader br = new BufferedReader(new
FileReader(counterfilecntr));
try {
[Link]();
try {
Pattern p = [Link](regex);
Matcher m = [Link](cntr_read_read);
[Link]("cntr_read_read - " + cntr_read_read);
if ([Link]()) {
x = x + 1;
if ([Link]()) {
y = y + 1;
String counterproperty;
counterproperty="";
counterproperty=cntr_read_read.substring(positionstartarray,positionendarray);
if (cntr_read_readflag==1) {
int_cntr_read_read= [Link](counterproperty);
}else {
int_cntr_read_read =0;
}
int old_int_cntr_read_read;
old_int_cntr_read_read=0;
if (incordec==1) {
old_int_cntr_read_read=int_cntr_read_read;
int_cntr_read_read=int_cntr_read_read+1; //decrement
counter by 1 till its greater than 0
} else if (incordec==-1) {
old_int_cntr_read_read=int_cntr_read_read;
int_cntr_read_read=int_cntr_read_read-1; //decrement
counter by 1 till its greater than 0
}
String new_cntr_read_read;
new_cntr_read_read="";
String regexxmlcounterstr;
regexxmlcounterstr="";
regexxmlcounterstr="<"+ counter +">"+old_int_cntr_read_read+"</"+
counter +">";
String replacement;
replacement="";
replacement="<"+ counter +">"+int_cntr_read_read+"</"+ counter
+">";
new_cntr_read_read=cntr_read_read.replaceFirst(regexxmlcounterstr,
replacement);
if (cntrNew_f.createNewFile()) {
int_cntr_read_write_flag=1;
//[Link]();
}
} catch (Exception e) {
[Link]();
}
}
if (int_cntr_read_write_flag==1) {
return true;
} else {
return false;
}
}
[Link]();
[Link]();
[Link]();
} finally {
// [Link]();
// [Link]();
[Link]("the file is closed in previous block");
}
}