{$A-,B-,D-,E-,F-,G-,I-,L-,N-,O-,P-,Q-,R-,S-,T-,V-,X+,Y-}
{$M 16384,0,655360}
uses Crt, Aut, Graph;
const
  PExit : boolean = false;
var
  i, j : word;
  s : string;
begin
  FillChar (MapRef^, SizeOf (Map), 0);
  FillChar (MapAct^, SizeOf (Map), 0);
  for i := 40 to 60 do
    for j:= 40 to 60 do
      MapRef^[i,j] := true;
  MapAct^ := MapRef^;
  Step := 0;
  RStep := 0;
  repeat
    DirectVideo := false;
    ClearDevice;
    GoToXY (1, 1);
    TextAttr := $0E;
    WriteLn ('_BOG&CO v1.01 (c) 1995');
    WriteLn;
    TextAttr := $0F;
    Write ('Enter redraw step: '); ReadLn (RS);
    if IOResult <> 0 then RS := 0;
    WriteLn;
    WriteLn ('Select method:'); WriteLn;
    WriteLn ('1. Parity (ç¥â­®áâì)');
    WriteLn ('2. Go west');
    WriteLn ('3. Go north');
    WriteLn ('4. Go east');
    WriteLn ('5. Go south');
    WriteLn ('6. Anneal (¯®¢¥àå­®áâ­®¥ ­ âï¦¥­¨¥)');
    WriteLn ('7. „¨ääã§¨ï, ¯®«®á ');
    WriteLn ('8. „¨ääã§¨ï, ª¢ ¤à â');
    WriteLn ('9. „¨ääã§¨ï, ¯®«®á , ãáª®à¥­­ë©');
    WriteLn ('0. „¨ääã§¨ï, ª¢ ¤à â, ãáª®à¥­­ë©');


    repeat
      PExit := true;
      ClearKbBuf;
      case ReadKey of
        '1': CurrentMethod := ParityMethod;
        '2': CurrentMethod := GoWestMethod;
        '3': CurrentMethod := GoNorthMethod;
        '4': CurrentMethod := GoEastMethod;
        '5': CurrentMethod := GoSouthMethod;
        '6':
          begin
            CurrentMethod := AnnealMethod;
            FillChar (MapRef^, SizeOf (Map), 0);
            FillChar (MapAct^, SizeOf (Map), 0);
            Step := 0;
            while Step < Round (MaxV*MaxH*0.675) do
              begin
                MapRef^[1+Random (MaxH-1),1+Random (MaxV-1)] := true;
                Inc (Step);
              end;
            MapAct^ := MapRef^;
            Step := 0;
          end;

        '7': begin Dif (0); Halt end;
        '8': begin Dif (1); Halt end;
        '9': begin Dif2 (0); Halt end;
        '0': begin Dif2 (1); Halt end;
        else PExit := false;
      end;
      ClearKbBuf;
    until PExit;
    ClearDevice;
    DrawBuffer;
    ReadKey;
    ClearKbBuf;
    repeat
      Create;
      if RStep >= RS then
        begin
          DisableRescan;
          DrawBuffer;
          EnableRescan;
          RStep := 0;
          Sound (800); Delay (2); NoSound;
        end;
      Sound (400); Delay (2); NoSound;
      if KeyPressed then
        begin
          ClearKbbuf;
          if ReadKey = #27 then Break;
        end;
      Move (MapAct^, MapRef^, SizeOf (Map));
      Inc (Step);
      Inc (RStep);
      SetFillStyle (1, Blue);
      SetColor (Blue);
      Bar (0, 0, 80, 9);
      Str (Step:4, s);
      s := 'Step: ' + s;
      SetColor (15);
      OutTextXY (0,0,s);
    until false;
    ClearKbBuf;
    if ReadKey = #27
      then PExit := true
      else PExit := false;
    ClearKbBuf;
  until PExit;
  ClearKbBuf;
end.
