Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://yadi.sk/d/DFAM8fHp7sedfQ
- uses
- GraphABC;
- const
- Max1 = 10;
- type
- tDiskCoords = record
- X, Y, H, W : Integer;
- end;
- var
- Disks : Integer;
- var
- Coords : array [-1..+1, 1..Max1] of tDiskCoords;
- U : array [-1..+1, 0..Max1] of Integer;
- procedure coords1;
- begin
- var Y := 600;
- var H := 550 div Disks;
- var W := 100 div Disks;
- for var i := 1 to Disks do
- begin
- Y -= H;
- Coords[-1,i].X := 150; Coords[-1,i].Y := Y; Coords[-1,i].H := H-1; Coords[-1,i].W := W;
- Coords[ 0,i].X := 400; Coords[ 0,i].Y := Y; Coords[ 0,i].H := H-1; Coords[ 0,i].W := W;
- Coords[+1,i].X := 650; Coords[+1,i].Y := Y; Coords[+1,i].H := H-1; Coords[+1,i].W := W;
- end;
- end;
- procedure osnovanie;
- var
- R : Integer;
- begin
- Brush.Color := clWhite;
- Pen.Color := clWhite;
- Rectangle(0, 0, Window.Width, Window.Height);
- Pen.Color := clGray;
- Rectangle( 45, 600, 255, 610);
- Rectangle(295, 600, 505, 610);
- Rectangle(545, 600, 755, 610);
- Rectangle(146, 30, 154, 601);
- Rectangle(396, 30, 404, 601);
- Rectangle(646, 30, 654, 601);
- Pen.Color := clBlack;
- Brush.Color := clBlue;
- for var Row := 1 to Disks do
- for var Col := -1 to +1 do
- begin
- R := U[Col, Row];
- if R > 0 then
- with Coords[Col, Row] do
- Rectangle(X - R*W, Y, X + R*W, Y+H);
- end;
- end;
- procedure diskp(fromColumn, toColumn : Integer);
- begin
- U[toColumn, 0] += 1;
- U[toColumn, U[toColumn, 0]] := U[fromColumn, U[fromColumn, 0]];
- U[fromColumn, U[fromColumn, 0]] := 0;
- U[fromColumn, 0] -= 1;
- osnovanie;
- sleep(250);
- end;
- procedure hanoy(count, init, aux, fin : Integer);
- begin
- if count = 1 then
- diskp(init, fin)
- else
- begin
- hanoy(count-1, init, fin, aux);
- diskp(init, fin);
- hanoy(count-1, aux, init, fin);
- end;
- end;
- procedure poisk;
- begin
- Window.Title := 'Ханойские башни. Дисков: ' + Disks.ToString;
- coords1;
- U[-1, 0] := Disks;
- for var i := 1 to Disks do
- U[-1, i] := Disks - i + 1;
- osnovanie;
- ReadLn;
- hanoy(Disks, -1, 0, +1);
- end;
- begin
- Window.SetSize(800, 650);
- WriteLn('Введите количество дисков от 1 до ', Max1); ReadLn(Disks);
- if Not(Disks in [1..Max1]) then
- WriteLn('Кол-во дисков от 1 до 10.')
- else
- poisk;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement