Program Voln; Uses Crt; var f:text; S:array[1..23] of string[79]; s_s:array[1..23,1..79] of string[1]; map:array[1..23,1..79] of byte; i,j:integer; XS, YS, XE, YE : integer; X, Y : word; MapM : array [1..23, 1..79] of Byte; Moves : Byte; MovesX : array [1..1817] of Byte; MovesY : array [1..1817] of Byte; Procedure Next(Var x, y : word); Begin If (X <79) and (MapM[y, x] - MapM[y, x+1] = 1) then Begin X := X + 1; Exit; End; If (X >1) and (MapM[y, x] - MapM[y, x-1] = 1) then Begin X := X - 1; Exit; End; If (Y <23) and (MapM[y, x] - MapM[y+1, x] = 1) then Begin Y := Y + 1; Exit; End; If (Y >1) and (MapM[y, x] - MapM[y-1, x] = 1) then Begin Y := Y - 1; Exit; End; End; Begin clrscr; assign(f,'w.dat'); reset(f); for i:=1 to 23 do readln(f,S[i]); close(f); for i:=1 to 23 do for j:=1 to 79 do s_s[i,j]:=S[i,j]; for i:=1 to 23 do begin for j:=1 to 79 do write(s_s[i,j]); writeln; end; readln; for i:=1 to 23 do for j:=1 to 79 do begin if s_s[i,j]='*' then map[i,j]:=1; if s_s[i,j]=' ' then map[i,j]:=0; end; for i:=1 to 23 do begin for j:=1 to 79 do write(map[i,j]); writeln; end; readln; WriteLn('Please enter X and Y of the start: '); Read(XS, YS); WriteLn('Please enter X and Y of the end: '); Read(XE, YE); If (Map[yS, xS] = 1) or (Map[yE, xE] = 1) then Begin WriteLn('Проверьте точки входа/выхода'); ReadLn; Halt; End; MapM[yS, xS] := 1; I := 1; Repeat I := I + 1; For Y := 1 to 23 do For X := 1 to 79 do If MapM[y, x] = I - 1 then Begin If (Y <23) and (MapM[y+1, x] = 0) and (Map[y+1, x] = 0) Then MapM[y+1, x] := I; If (Y >1) and (MapM[y-1, x] = 0) and (Map[y-1, x] = 0) Then MapM[y-1, x] := I; If (X <79) and (MapM[y, x+1] = 0) and (Map[y, x+1] = 0) Then MapM[y, x+1] := I; If (X >1) and (MapM[y, x-1] = 0) and (Map[y, x-1] = 0) Then MapM[y, x-1] := I; End; If I = 1817 then Begin WriteLn('Вы не сможете попасть из входа в выход'); ReadLn; Halt; End; Until MapM[yE, xE] >0; Moves := I - 1; X := XE; Y := YE; I := Moves; Map[yE, xE] := 4; Repeat MovesX[I] := X; MovesY[I] := Y; Next(y, x); Map[y, x] := 3; I := I - 1; Until (X = XS) and (Y = YS); Map[yS, xS] := 2; For I := 1 to Moves do WriteLn('X = ', MovesX[I],', Y = ', MovesY[I]); readln; WriteLn('Total: ', Moves, ' moves'); ReadLn; { For Y := 1 to 23 do Begin For X := 1 to 79 do begin if (map[y,x] > 1) then s_s[y,x]:='.'; write(s_S[y,x]); end; WriteLn; End;} for y:=1 to 23 do begin for x:=1 to 79 do write(map[y,x]); writeln; end; ReadLn; End.