Программа поиска соединительного пути в 3-х звенной КС (режим индивидуального искания). Функциональная схема и алгоритм решения задачи, страница 2

UpDown2: TUpDown;

UpDown3: TUpDown;

StaticText3: TStaticText;

UpDown4: TUpDown;

StaticText4: TStaticText;

GroupBox1: TGroupBox;

Label4: TLabel;

Label3: TLabel;

Label2: TLabel;

Label1: TLabel;

Label5: TLabel;

Label6: TLabel;

Label7: TLabel;

Label8: TLabel;

Label9: TLabel;

Label10: TLabel;

Panel3: TPanel;

Button1: TButton;

Label11: TLabel;

StaticText5: TStaticText;

StaticText6: TStaticText;

StaticText7: TStaticText;

Panel4: TPanel;

Button2: TButton;

Label12: TLabel;

Label14: TLabel;

Label15: TLabel;

Label16: TLabel;

Label17: TLabel;

Label18: TLabel;

procedure UpDown1Click(Sender: TObject; Button: TUDBtnType);

procedure UpDown2Click(Sender: TObject; Button: TUDBtnType);

procedure UpDown3Click(Sender: TObject; Button: TUDBtnType);

procedure UpDown4Click(Sender: TObject; Button: TUDBtnType);

procedure BitBtn1Click(Sender: TObject);

procedure FormCreate(Sender: TObject);

procedure Button1Click(Sender: TObject);

procedure Button2Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

Ka,Mc,Kc: word;

implementation

{$R *.dfm}

procedure TForm1.UpDown1Click(Sender: TObject; Button: TUDBtnType);

begin            

Statictext1.Caption:=inttostr(Updown1.Position-1);

Sg1.RowCount:=Updown1.Position;

Sg1.height:=17*Updown1.Position-2;

end;

procedure TForm1.UpDown2Click(Sender: TObject; Button: TUDBtnType);

begin

Statictext2.Caption:=inttostr(Updown2.Position-1);

Sg1.ColCount:=Updown2.Position;

Sg1.Width:=17*Updown2.Position-2;

Sg2.RowCount:=Updown2.Position;

Sg2.Height:=17*Updown2.Position-2;

end;

procedure TForm1.UpDown3Click(Sender: TObject; Button: TUDBtnType);

begin

Statictext3.Caption:=inttostr(Updown3.Position-1);

Sg2.ColCount:=Updown3.Position;

Sg2.Width:=17*Updown3.Position-2;

Sg3.RowCount:=Updown3.Position;

Sg3.Height:=17*Updown3.Position-2;

end;

procedure TForm1.UpDown4Click(Sender: TObject; Button: TUDBtnType);

begin

Statictext4.Caption:=inttostr(Updown4.Position-1);

Sg3.ColCount:=Updown4.Position;

Sg3.Width:=17*Updown4.Position-2;

end;

procedure TForm1.BitBtn1Click(Sender: TObject);

var i,j:word;

begin

Panel1.Enabled:=false;

Button1.Show;

for i:=1 to Sg1.ColCount-1 do

for j:=1 to Sg1.RowCount-1 do

Sg1.Cells[i,j]:=inttostr(random(100)mod (2));

for i:=1 to Sg2.ColCount-1 do

for j:=1 to Sg2.RowCount-1 do Sg2.Cells[i,j]:=inttostr(random(100)mod (2));

for i:=1 to Sg3.ColCount-1 do

for j:=1 to Sg3.RowCount-1 do Sg3.Cells[i,j]:=inttostr(random(100)mod (2));

end;

procedure TForm1.FormCreate(Sender: TObject);

var i,j:word;

begin

for i:=1 to Sg1.RowCount do  Sg1.Cells[i,0]:=inttostr(i);

for j:=1 to Sg1.ColCount do  Sg1.Cells[0,j]:=inttostr(j);

for i:=1 to Sg2.RowCount do  Sg2.Cells[i,0]:=inttostr(i);

for j:=1 to Sg2.ColCount do  Sg2.Cells[0,j]:=inttostr(j);

for i:=1 to Sg3.RowCount do  Sg3.Cells[i,0]:=inttostr(i);

for j:=1 to Sg3.ColCount do  Sg3.Cells[0,j]:=inttostr(j);

end;

procedure TForm1.Button1Click(Sender: TObject);//формируем заявку

var i,j:word;

begin

for i:=1 to 6 do

for j:=1 to 6 do  begin

if Sg1.Cells[i,j] = 'X' then  Sg1.Cells[i,j] := '0';

if Sg2.Cells[i,j] = 'X' then  Sg2.Cells[i,j] := '0';

if Sg3.Cells[i,j] = 'X' then  Sg3.Cells[i,j] := '0';

end;

label12.Hide;

StaticText5.show;

StaticText6.show;

StaticText7.show;

label11.show;

Ka:=random(Sg1.RowCount);

if Ka=0 then Ka:=Ka+random(Sg1.RowCount-2)+1;

Mc:=random(Sg3.ColCount);

if Mc=0 then Mc:=Mc+random(Sg3.ColCount-2)+1;

Kc:=random(Sg3.RowCount);

if Kc=0 then Kc:=Kc+random(Sg3.RowCount-2)+1;

Statictext5.Caption:=inttostr(Ka);

Statictext6.Caption:=inttostr(Mc);

Statictext7.Caption:=inttostr(Kc);

Button2.Show;

end;

procedure TForm1.Button2Click(Sender: TObject);

var i:word;

begin

i:=1;

while i<=Sg1.ColCount-1 {Ma} do

begin

if  Sg1.Cells[i,Ka] = '1' then

begin

if Sg2.Cells[Kc,i] = '1' then

begin

if Sg3.Cells[Mc,Kc] = '1' then

begin

label12.Caption:='Путь найден!!!';

Sg1.Cells[i,Ka]:= 'X';

Sg2.Cells[Kc,i]:= 'X';

Sg3.Cells[Mc,Kc]:= 'X';

i:=Sg1.ColCount-1;

end;

end else label12.Caption:='Путь  НЕ найден!!!';

end;

inc(i);

end;

label12.Show;

end;

end.