Advertisement
ksyshshot

Ход конём

Apr 27th, 2023
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.68 KB | Source Code | 0 0
  1. function MakeWay(Desk: ArrDesk; CurrX, CurrY: Integer): ArrDesk;
  2. var
  3.     I, J, K: Integer;
  4.     CurrNX, CurrNY, CurrCount: Integer;
  5.     PossX, PossY, PossCount: Integer;
  6. begin
  7.     PossX := 0;
  8.     PossY := 0;
  9.     CurrCount := 8;
  10.     PossCount := 8;
  11.     Desk[CurrX][CurrY] := 1;
  12.     for I := 2 to 64 do
  13.     begin
  14.         for J := 0 to 7 do
  15.         begin
  16.             if (CurrX + Possible_moves[J][0] >= 0) and (CurrX + Possible_moves[J][0] < 8) and
  17.             (CurrY + Possible_moves[J][1] >= 0) and (CurrY + Possible_moves[J][1] < 8)
  18.             and (Desk[CurrX + Possible_moves[J][0]][CurrY + Possible_moves[J][1]] = 0) then
  19.             begin
  20.                 CurrCount := 0;
  21.                 CurrNX := CurrX + Possible_moves[J][0];
  22.                 CurrNY := CurrY + Possible_moves[J][1];
  23.                 for K := 0 to 7 do
  24.                 begin
  25.                     if (CurrNX + Possible_moves[K][0] >= 0) and (CurrNX + Possible_moves[K][0] < 8) and
  26.                     (CurrNY + Possible_moves[K][1] >= 0) and (CurrNY + Possible_moves[K][1] < 8)
  27.                     and (Desk[CurrNX + Possible_moves[K][0]][CurrNY + Possible_moves[K][1]] = 0) then
  28.                     begin
  29.                         Inc(CurrCount);
  30.                     end;
  31.                 end;
  32.             end;
  33.             if PossCount > CurrCount then
  34.             begin
  35.                 PossX := CurrNX;
  36.                 PossY := CurrNY;
  37.                 PossCount := CurrCount;
  38.             end;
  39.         end;
  40.         CurrX := PossX;
  41.         CurrY := PossY;
  42.         CurrNX := 0;
  43.         CurrNY := 0;
  44.         CurrCount := 8;
  45.         PossCount := 8;
  46.         Desk[CurrX][CurrY] := I;
  47.     end;
  48.     MakeWay := Desk;
  49. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement