Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int i,j, end;
- FILE*fp;
- fp=fopen("totalmaze.txt","r+");
- for(i = 0;i<120;i++){
- for(j=0;j<22;j++){
- fscanf(fp,"%d",&maze[i][j]);
- }
- }
- int xstart,ystart,xend,yend,mazenumber;
- printf("This program will solve array maze 1 through 6.n");
- printf("Which maze would you like to solve? Enter a number 1 through 6.n");
- scanf("%d",&mazenumber);
- printf("Please enter the starting position.n");
- printf("row? (maze 1 = row 0, maze 2 = row 0, maze 3 = row 0, maze 4 = row 0, maze 5 = row 0, maze 6 = row 2 )n");
- scanf("%d",&xstart);
- printf("column? (maze 1 = column 9, maze 2 = column 9, maze 3 = column 2, maze 4 = column 2, maze 5 = column 2, maze 6 = column 0 )n");
- scanf("%d",&ystart);
- printf("Please enter the ending position.n");
- printf("row? (maze 1 = row 19, maze 2 = row 15, maze 3 = row 7, maze 4 = row 7, maze 5 = row 19, maze 6 = row 19)n");
- scanf("%d",&xend);
- printf("column? (maze 1 = column 12, maze 2 = column 21, maze 3 = column 21, maze 4 = column 21, maze 5 = column 16, maze 6 = column 16)n");
- scanf("%d",¥d);
- printf("nn");
- int x =0;
- if(mazenumber==1){
- i =0;
- end = 19;
- }
- if(mazenumber==2){
- i = 20;
- end = 39;
- }
- if(mazenumber==3){
- i = 40;
- end = 59;
- }
- if(mazenumber==4){
- i = 60;
- end = 79;
- }
- if(mazenumber==5){
- i = 80;
- end = 99;
- }
- if(mazenumber==6){
- i = 100;
- end = 119;
- }
- for(i; i <= end; i++)
- {
- for(j=0; j < 22; j++)
- {
- solution[x][j] = maze[i][j];
- }
- x++;
- }
- int a,b;
- for(a = 0; a < 20; a++)
- {
- for(b = 0; b < 22; b++)
- {
- printf("%d ", solution[a][b]);
- }
- printf("n");
- }
- if (solvemaze(xstart, ystart, xend, yend))
- printsolution();
- else
- printf("No solution was found. Mario has died.n");
- return 0;
- int xpos = xstart;
- int ypos = ystart;
- int prevX;
- int prevY;
- int tempX = xpos;
- int tempY = ypos;
- solution[xpos][ypos] = 1;
- while((xpos != xend) && (ypos != yend))
- {
- //down
- if((maze[tempX++][ypos]!=5) && (tempX != r))
- {
- solution[tempX][ypos] = 1;
- prevX = xpos;
- prevY = ypos;
- xpos++;
- printsolution();
- printf("nn");
- printf("nn");
- tempX = xpos;
- tempY = ypos;
- continue;
- }
- //right
- else if((maze[xpos][tempY++]!=5)&& (tempY != c))
- {
- solution[xpos][tempY]=1;
- prevX = xpos;
- prevY = ypos;
- ypos++;
- printsolution();
- printf("nn");
- printf("nn");
- tempX = xpos;
- tempY = ypos;
- continue;
- }
- //left
- else if((maze[xpos][tempY--]!=5) && (tempY != -1))
- {
- solution[xpos][tempY]=1;
- prevX = xpos;
- prevY = ypos;
- ypos--;
- printsolution();
- printf("nn");
- printf("nn");
- tempX = xpos;
- tempY = ypos;
- continue;
- }
- //up
- else if((maze[tempX--][ypos]!=5) && (tempX != -1))
- {
- solution[tempX][ypos]=1;
- prevX = xpos;
- prevY = ypos;
- xpos--;
- printsolution();
- tempX = xpos;
- tempY = ypos;
- printf("nn");
- printf("nn");
- continue;
- }
- else
- {
- solution[xpos][ypos] = 5;
- xpos = prevX;
- ypos = prevY;
- }
- }
- if((xpos == xend) && (ypos == yend))
- {
- printf("Mario had been rescued!n");
- return 1;
- }
- else
- return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement