/ * Name: Maze Solving Author: Avalon Date: 04-10-04 22:00 Description: "stack.h" is my generic stack. The entire program is based on a two-dimensional structural group. * /
#include "stack.h" #include
/ * Line, column * / # define han 10 # define lie 10 / ** / typedef enum {black = -1, / * represents black block (not easy) * / white = 1, / * white block (Can pass ) * / Begin = -2, / * Start point * / End = 2, / * End point * / error = -3, / * is not available * / ok = 3 / * through the detection * /} ELEM;
Typedef struct map {/ * maze map * / elem ELEM; / * Representation status * / int x; int y; / * Structure coordinate * /} Map; map map [han] [lie];
Bool nextpath (int * x, int * y) {/ * Go to the next path (modifying the structure) If you can return true * / if (Map [* x] [* y] .x! = 0) {/ * * / If (Map [* x-1] [* y] .lem == white || map [* x-1] [* y] .elex == begin || map [* x-1] [* y] .Elem == End) {(* x) -; return true;}} f (map [* x] [* y] .x! = han-1) {/ * under * / if (Map [ * x 1] [* y] .lem == white || map [* x 1] [* y] .elex == begin || map [* x 1] [* y] .lem == end {(* X) ; return true;}} f (map [* x] [* y] .y! = 0) {/ * left * / if (map [* x] [* Y-1] .Elem == white || map [* x] [* Y-1] .Elem == begin || map [* x] [* Y-1] .Elem == End) {(* y) -; Return true;}}}} (MAP [* x] [* y] .y! = lie-1) {/ * right * / if (map [* x] [* y 1] .lem == White || MAP [* x] [* y 1] .lem == begin || map [* x] [* y 1] .elem == End) {(* y) ; return true;}}} / * **** ft !!!!!!!!! **** / RETURN FALSE;} BOOL MAZEPATH (Void) {/ * To ensure the correctness of structure data ~ If the maze exists from the starting point to the terminal, Then ask a store in the stack and return to True * / StackHandle S; Struct Map Temp; INT I, J; Void PrintMap (Void); / ** / s = initstack (SIZEOF (Struct Map)); / * Structure to initialize stack * / for (i = 0; i Void PrintMap (Void) / ** / {/ * map printout * / INT I, J; Printf ("Start Output (O is white, X is black, B is the start position, E is end position: / N "); getchar (); for (i = 0; i Void InputMap / ** / {Char INPUT; INT I, J; Printf ("Maze a total of% D line% D column, start input: / n", han, lie); for (i = 0; i