i-move(2) = 0 j-move(2)= 1 i-move(3) = 1 j-move(3) = 1 i-move(4) = 1 j-move(4) =
ID: 3612004 • Letter: I
Question
i-move(2) = 0 j-move(2)= 1
i-move(3) = 1 j-move(3) = 1
i-move(4) = 1 j-move(4) = 0
i-move(5) = 1 j-move(5)= -1
i-move(6) = 0 j-move(6) = -1
i-move(7) =-1 j-move(7) = -1
i-move(8) =-1 j-move(8)= 0
A random walk to one of the eight given squares issimulated by generating a random value for k lying between 1 and 8.The bug can not move up the wall so those coordinates which leadbeyond a wall must be ignored and a new random combination formed.Each time a square is touched, the count for that square isincremented. Thus, a non-zero entry in the array shows the numberof times the bug has landed on the corresponding square. When everysquare has been touched at least once, the simulation iscomplete.
You should include an iteration limit, that is, a maximumnumber of squares that the bug may enter during the experiment.This assures that your program will not get “hung” inan infinite loop. A maximum of 50,000 iteration is appropriate forthis simulation.
Explanation / Answer
please rate - thanks you never answered my message, but I figured it out #include #include #include #include bool done(int[][20]); void draw(int[][20],int,int); void getmove(int *,int *); int main() { int i,j,ii,jj,count=0; int floor[40][20]={0}; srand(time(NULL)); i=rand()%40; j=rand()%20; floor[i][j]++; printf("Floor with bug starting "); draw(floor,i,j); for(count=1;count=0&&*i+imove[irand]=0&&*j+jmove[jrand]Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.