Uses CRT; Const N=20; M=20; DIVISOR = 1.7; EMPTY_CELL = 0; WRONG_WAY = 1; WAY = 2; Colors:Array[EMPTY_CELL..WAY] Of Byte = (Green,Yellow,Red); Var Maze:Array[0..N-1,0..M-1] Of Byte; Procedure GenerateMaze; Var i,j:Integer; x,y:Integer; Begin For i:=0 To N-1 Do For j:=0 To M-1 Do Maze[i,j]:=EMPTY_CELL; x:=0; y:=0; While (x < N-1) Or (y < M-1) Do Begin Maze[x,y]:=WAY; If (Random>0.5) Then If x < N-1 Then Inc(x) Else Inc(y) Else If y < M-1 Then Inc(y) Else Inc(x) End; Maze[x,y]:=WAY; For i:=1 To Round(N*M/DIVISOR) Do Begin x:=Random(N); y:=Random(M); If (Maze[x,y]=EMPTY_CELL) Then Maze[x,y]:=WRONG_WAY End End; Procedure DrawMaze; Var i,j:Integer; Begin ClrScr; For i:=0 To N-1 Do Begin For j:=0 To M-1 Do Begin TextBackground(Colors[Maze[i,j]]); Write(' ') End; WriteLn End End; Begin Randomize; GenerateMaze; DrawMaze; ReadKey End.