Walk through the maze: Find all paths

Source: Internet
Author: User


 

/* Perform the maze: Find all paths */
/* Allroadmaze_20050128.c (recursive )*/
/* 2005-1-28 */
/* Output the result to the text file "c: \ route.txt "*/
/* First output the maze map represented by 01 */
/* Then output all feasible paths */
/* The Maze map uses 0 to indicate space 1 as the obstacle */
/* The abscissa ranges from left to right from 0 1 2 3 ...*/
/* The vertical coordinates are 0 1 2 3 from top to bottom ...*/
# Include <stdlib. h>
# Include <time. h>
# Include <math. h>
# Include <stdio. h>
# Include "conio. h"
# Define N 5
# Define M 5
# Define maxlen m * N
Int time1 = 0;
Int bg [M] [N];
Int aa [M] [N];
Struct pace {
Int dir;
Int ri;
Int rj;
} Road [MAXLEN];
FILE * fp;
Int length = 0;
Int dj [] = {1, 0,-1, 0 };
Int di [] = {0, 1, 0,-1 };
Void makebg (int, int );
Int go (int, int, int );
Int main () {/* main () start */
Int step = 20;
Int len = 10;
Int size = 20;
Int x = 0, y = 0;
Int I = 0;
Makebg (M, N );
If (fp = fopen ("c: \ route.txt", "w") = NULL ){
Printf ("Cannot open teh file! N ");
Return (-1 );
}
Outputmap ();
Go (0, 0, 0 );
Getch ();
Fclose (fp );
}
/* Main () ends */

/* Randomly generate an array representing the maze map */
Void makebg (int a, int B ){
Int I, j;
Int ran;
Int direc;
/* Initialize the maze map */
For (I = 0; I <a; I ++)
For (j = 0; j <B; j ++)
Bg [I] [j] = 1;
/* Randomly generate a maze path */
Randomize ();
I = j = 0; direc = 2;
While (1 ){
Bg [I] [j] = 0;
If (I> = M-1 & j> = N-1) break;
Ran = (int) rand () * 4;
If (ran <1 ){
If (direc! = 1 & I <A-1 ){
I ++;
Direc = 3;
}

<

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.