{* * @(#) mazeprg1.pas - Program for solving 'maze' problem * (finding out one way in the graph from one point to another point), * the version with the use of 'goto' construction. * (c) 1994 Ivan Maidanski http://ivmai.chat.ru * Freeware program source. All rights reserved. ** * Language: Turbo Pascal * Tested with: Turbo Pascal v7.0 * Last modified: 1994-10-25 15:55:00 GMT+04:00 *} program MazeProg1; const MaxN= 20; type TNode= 0..MaxN; type TMaze= array[1..MaxN,1..MaxN] of Boolean; type TWay= array[1..MaxN] of TNode; var N: TNode; var Target: TNode; var WayEnd: TNode; var Maze: TMaze; var Way: TWay; function TestInput(Cond: Boolean): Boolean; begin Cond:=(IOResult=0) and Cond; if not Cond then WriteLn(' Incorrect data!'); TestInput:=Cond end; procedure EnterMaze; var I,J: TNode; var Ch: Char; begin for I:=1 to N do Maze[I,I]:=False; for I:=1 to Pred(N) do for J:=Succ(I) to N do repeat Write('Is there a connection between node ',I,' and ',J, ': (Yes/No) ? '); ReadLn(Ch); Ch:=UpCase(Ch); Maze[I,J]:=Ch='Y'; Maze[J,I]:=Maze[I,J] until TestInput((Ch='Y') or (Ch='N')) end; procedure Init; begin repeat Write('Enter amount of nodes: [1..',MaxN,'] '); ReadLn(N) until TestInput((N>=1) and (N<=MaxN)); repeat Write('Enter target node: [1..',N,'] '); ReadLn(Target) until TestInput((Target>=1) and (Target<=N)); EnterMaze end; procedure Run; label L1,L2,L3,L4,L5,L6; var Cur: TNode; begin WayEnd:=1; Way[WayEnd]:=1; L1: if Way[WayEnd]=Target then Exit; Cur:=1; L2: if Maze[Way[WayEnd],Cur] then goto L4; L3: if Cur=N then goto L6; Inc(Cur); goto L2; L4: Inc(WayEnd); Way[WayEnd]:=Cur; Cur:=1; L5: if Way[Cur]=Way[WayEnd] then goto L6; Inc(Cur); if Cur