Maze solution

xiaoxiao2021-03-06  69

/ * 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 #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 0 && i <= 99)) Printf (" Error! "); Else IF (! (i> Lie && I <= Han * 10 LIE)) Printf (" " Coordinate be out of range / n "); Else IF (MAP [I / 10-1] [I% 10-1] .Elem == Black) Printf (" starting point cannot be black! / N "); Else {MAP [I / 10-1] [I% 10-1] .lem = begin; break;}} while (1) {printf ("/ n input end position (2 digits representation:"); scanf ("% D ", & i); if (! (i> lie && i <= han * 10 lie)) Printf (" Coordinate Overcoming Range / N "); ELSE IF (MAP [I / 10-1] [I% 10- 1]. Elem == Black) Printf ("starting point cannot be black! / N"); Else {MAP [I / 10-1] [I% 10-1]. Elem = end; break;} printf "/ N input is over!" ); GetChar (); system ("CLS");}}}} int main (void) {INPUTMAP (); printMap (); printf ("/ n ================ ================================================ / n "); if (MazePath ()) PrintMap (); Else Printf ("

转载请注明原文地址:https://www.9cbs.com/read-110519.html

New Post(0)