Advertisement
SmnVadik

Lab 6.5

Sep 5th, 2023
567
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 4.41 KB | None | 0 0
  1. unit Unit1;
  2.  
  3.  
  4. interface
  5.  
  6. uses
  7.     Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  8.     System.Classes, Vcl.Graphics,
  9.     Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls;
  10.  
  11. type
  12.     TForm1 = class(TForm)
  13.         PaintBox1: TPaintBox;
  14.         Timer1: TTimer;
  15.         Button1: TButton;
  16.         procedure Button1Click(Sender: TObject);
  17.         procedure Timer1Timer(Sender: TObject);
  18.     private
  19.         { Private declarations }
  20.     public
  21.         { Public declarations }
  22.     end;
  23.  
  24. var
  25.     i, j, k, l, s, z: integer;
  26.     A_x, A_y, A_nx, A_ny, A_kol: integer;
  27.     B_x, B_y, B_nx, B_ny, B_kol: integer;
  28.     R_x, R_y: integer;
  29.     str: String;
  30.     mov1: Array [1 .. 8] of integer;
  31.     mov2: Array [1 .. 8] of integer;
  32.     mov3: Array [0 .. 1000, 0 .. 1000] of integer;
  33.  
  34.     Form1: TForm1;
  35.  
  36.  
  37. implementation
  38.  
  39. {$R *.dfm}
  40.  
  41. procedure TForm1.Button1Click(Sender: TObject);
  42. begin
  43.  
  44.     for i := 1 to 4 do
  45.     begin
  46.  
  47.         for j := 1 to 4 do
  48.         begin
  49.  
  50.             PaintBox1.Canvas.Brush.Color := clBlack;
  51.             PaintBox1.Canvas.Rectangle(0 + l, 0 + k, 80 + l, 80 + k);
  52.             l := l + 80;
  53.             PaintBox1.Canvas.Brush.Color := clWhite;
  54.             PaintBox1.Canvas.Rectangle(0 + l, 0 + k, 80 + l, 80 + k);
  55.             l := l + 80;
  56.         end;
  57.         l := 0;
  58.         k := k + 80;
  59.         for j := 1 to 4 do
  60.         begin
  61.  
  62.             PaintBox1.Canvas.Brush.Color := clWhite;
  63.             PaintBox1.Canvas.Rectangle(0 + l, 0 + k, 80 + l, 80 + k);
  64.             l := l + 80;
  65.             PaintBox1.Canvas.Brush.Color := clBlack;
  66.             PaintBox1.Canvas.Rectangle(0 + l, 0 + k, 80 + l, 80 + k);
  67.             l := l + 80;
  68.         end;
  69.         l := 0;
  70.         k := k + 80;
  71.     end;
  72.  
  73.     mov1[1] := 2;
  74.     mov1[2] := 1;
  75.     mov1[3] := 2;
  76.     mov1[4] := -2;
  77.     mov1[5] := -1;
  78.     mov1[6] := -1;
  79.     mov1[7] := 1;
  80.     mov1[8] := -2;
  81.     mov2[1] := -1;
  82.     mov2[2] := -2;
  83.     mov2[3] := 1;
  84.     mov2[4] := 1;
  85.     mov2[5] := -2;
  86.     mov2[6] := 2;
  87.     mov2[7] := 2;
  88.     mov2[8] := -1;
  89.  
  90.     l := 0;
  91.     k := 1;
  92.     i := 0;
  93.     j := 1;
  94.  
  95.     A_kol := 8;
  96.     B_kol := 8;
  97.  
  98.     A_x := 40;
  99.     A_y := 40;
  100.     mov3[A_x][A_y] := 1;
  101.  
  102.     PaintBox1.Canvas.Brush.Color := clred;
  103.     PaintBox1.Canvas.Ellipse(A_x - 4, A_y - 4, A_x + 4, A_y + 4);
  104.     str := IntToStr(k);
  105.     PaintBox1.Canvas.TextOut(A_x + 6, A_y + 6, str);
  106.     PaintBox1.Canvas.Brush.Color := clWhite;
  107.  
  108.     Timer1.Enabled := True;
  109.     Button1.Enabled := False;
  110.  
  111. end;
  112.  
  113. procedure TForm1.Timer1Timer(Sender: TObject);
  114. begin
  115.     k := k + 1;
  116.     for i := 1 to 63 do
  117.     begin
  118.         for s := 1 to 8 do
  119.         begin
  120.             if (A_x + mov1[s] * 80 >= 40) and (A_y + mov2[s] * 80 >= 40) and
  121.               (A_x + mov1[s] * 80 <= 600) and (A_y + mov2[s] * 80 <= 600) and
  122.               (mov3[A_x + mov1[s] * 80][A_y + mov2[s] * 80] = 0)
  123.             then
  124.             begin
  125.                 A_kol := 0;
  126.                 A_nx := A_x + mov1[s] * 80;
  127.                 A_ny := A_y + mov2[s] * 80;
  128.  
  129.                 for z := 1 to 8 do
  130.                 begin
  131.                     if (A_nx + mov1[z] * 80 >= 40) and
  132.                       (A_ny + mov2[z] * 80 >= 40) and
  133.                       (A_nx + mov1[z] * 80 <= 600) and
  134.                       (A_ny + mov2[z] * 80 <= 600) and
  135.                       (mov3[A_nx + mov1[z] * 80][A_ny + mov2[z] * 80] = 0) then
  136.  
  137.                         A_kol := A_kol + 1;
  138.  
  139.                 end;
  140.  
  141.             end;
  142.  
  143.             if B_kol > A_kol then
  144.             begin
  145.                 B_x := A_nx;
  146.                 B_y := A_ny;
  147.                 B_kol := A_kol;
  148.             end;
  149.  
  150.         end;
  151.  
  152.         PaintBox1.Canvas.pen.Color := clred;
  153.         PaintBox1.Canvas.pen.Width := 5;
  154.         PaintBox1.Canvas.MoveTo(A_x, A_y);
  155.         PaintBox1.Canvas.LineTo(B_x, B_y);
  156.         PaintBox1.Canvas.Brush.Color := clWhite;
  157.  
  158.         A_x := B_x;
  159.         A_y := B_y;
  160.         A_nx := 0;
  161.         A_ny := 0;
  162.         A_kol := 8;
  163.         B_kol := 8;
  164.         mov3[A_x][A_y] := 1;
  165.  
  166.         PaintBox1.Canvas.Brush.Color := clred;
  167.         PaintBox1.Canvas.Ellipse(A_x - 4, A_y - 4, A_x + 4, A_y + 4);
  168.  
  169.         str := IntToStr(k);
  170.         Inc(K);
  171.         PaintBox1.Canvas.TextOut(A_x + 6, A_y + 6, str);
  172.         PaintBox1.Canvas.Brush.Color := clWhite;
  173.  
  174.     end;
  175.     j := j + 1;
  176.  
  177.     if i = 64 then
  178.     begin
  179.         Timer1.Enabled := False;
  180.     end;
  181.  
  182. end;
  183.  
  184. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement