the number of cockroach's move you want: ");scanf("%d",&iteration);clrscr();boundaryrow=sizerow;boundarycol=sizecol;for(a=-1;a<=sizerow;a++){for(b=-1;b<=sizecol;b++){if(a==jbug&&b==ibug)tile[a][b]='S';else if(a<0||b<0||a>=boundarycol||b>=boundaryrow)tile[a][b]='Q';elsetile[a][b]=' ';}}do{move++;clrscr();imove[0]=ibug-1;imove[1]=ibug;imove[2]=ibug+1;imove[3]=ibug+1;imove[4]=ibug+1;imove[5]=ibug;imove[6]=ibug-1;imove[7]=ibug-1;jmove[0]=jbug+1;jmove[1]=jbug+1;jmove[2]=jbug+1;jmove[3]=jbug;jmove[4]=jbug-1;jmove[5]=jbug-1;jmove[6]=jbug-1;jmove[7]=jbug;randomize();k=rand()%8;if(jmove[k]<0||jmove[k]>=boundarycol||imove[k]<0||imove[k]>=boundaryrow||jmove[k]>boundaryrow||imove[k]>boundarycol){randomize();ibug=rand()%boundarycol+1;jbug=rand()%boundaryrow+1;}else{jbug=jmove[k];ibug=imove[k];tile[jbug][ibug]='C';legal++;}count[jbug][ibug]++;for(a=-1;a<=boundaryrow;a++){for(b=-1;b<=boundarycol;b++) {if(tile[a][b]=='C'){delay(30);printf("%c",tile[a][b]);tile[a][b]='*';delay(15);}else if(tile[a][b]=='*')printf("%c",tile[a][b]); else if(a<0||b<0||a>=boundaryrow||b>=boundarycol){tile[a][b]='Q';printf("%c",tile[a][b]);}elseprintf("%c",tile[a][b]);}printf("\n");}printf("\n\nLegal moves count = %d ",legal);printf("\nCockcroach's move count = %d\n\n",move);delay(500);}while(move<iteration);printf("\nPress any key to continue... ");getch();clrscr();for(a=0;a<sizerow;a++){for(b=0;b<sizecol;b++){printf("Tile[%d][%d] got %d steps.\n",a,b,count[a][b]);delay(200);}}getche();}/*end of the program*/
the number of cockroach's move you want: ");scanf("%d",&iteration);clrscr();boundaryrow=sizerow;boundarycol=sizecol;for(a=-1;a<=sizerow;a++){for(b=-1;b<=sizecol;b++){if(a==jbug&&b==ibug)tile[a][b]='S';else if(a<0||b<0||a>=boundarycol||b>=boundaryrow)tile[a][b]='Q';elsetile[a][b]=' ';}}do{move++;clrscr();imove[0]=ibug-1;imove[1]=ibug;imove[2]=ibug+1;imove[3]=ibug+1;imove[4]=ibug+1;imove[5]=ibug;imove[6]=ibug-1;imove[7]=ibug-1;jmove[0]=jbug+1;jmove[1]=jbug+1;jmove[2]=jbug+1;jmove[3]=jbug;jmove[4]=jbug-1;jmove[5]=jbug-1;jmove[6]=jbug-1;jmove[7]=jbug;randomize();k=rand()%8;if(jmove[k]<0||jmove[k]>=boundarycol||imove[k]<0||imove[k]>=boundaryrow||jmove[k]>boundaryrow||imove[k]>boundarycol){randomize();ibug=rand()%boundarycol+1;jbug=rand()%boundaryrow+1;}else{jbug=jmove[k];ibug=imove[k];tile[jbug][ibug]='C';legal++;}count[jbug][ibug]++;for(a=-1;a<=boundaryrow;a++){for(b=-1;b<=boundarycol;b++) {if(tile[a][b]=='C'){delay(30);printf("%c",tile[a][b]);tile[a][b]='*';delay(15);}else if(tile[a][b]=='*')printf("%c",tile[a][b]); else if(a<0||b<0||a>=boundaryrow||b>=boundarycol){tile[a][b]='Q';printf("%c",tile[a][b]);}elseprintf("%c",tile[a][b]);}printf("\n");}printf("\n\nLegal moves count = %d ",legal);printf("\nCockcroach's move count = %d\n\n",move);delay(500);}while(move<iteration);printf("\nPress any key to continue... ");getch();clrscr();for(a=0;a<sizerow;a++){for(b=0;b<sizecol;b++){printf("Tile[%d][%d] got %d steps.\n",a,b,count[a][b]);delay(200);}}getche();}/*end of the program*/