Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- POSSIBLE_MOVES: Array[0..7] of array[0..1] of integer = ((-1, -2), (-2, -1), (-2, 1), (-1, 2), (1, 2), (2, 1), (2, -1), (1, -2));
- type
- ArrDesk = Array[0..7] of Array[0..7] of Integer;
- var
- FullDesk: ArrDesk;
- function CanStep(X, Y: Integer): Boolean;
- begin
- if (X >= 0) and (Y >= 0) and (X < DIMENSION) and (Y < DIMENSION) then
- CanStep := true
- else
- CanStep := false;
- end;
- function IsCorrectMove(X, Y: Integer): Boolean;
- begin
- if (CanStep(X, Y)) then
- if (FullDesk[X][Y] = 0) then
- IsCorrectMove := true;
- IsCorrectMove := false;
- end;
- procedure InitializeArrDesk(var Desk: ArrDesk);
- var
- I, J: Integer;
- begin
- for I := 0 to High(Desk) do
- for J := 0 to High(Desk) do
- Desk[I][J] := 0;
- end;
- function FindMoves(X, Y, Counter: Integer): Boolean;
- var
- I, NextX, NextY: Integer;
- CanContinue: Boolean;
- begin
- FullDesk[X][Y] := Counter;
- if (Counter > (DIMENSION * DIMENSION - 1)) then
- FindMoves := true;
- for I := 0 to (DIMENSION - 1) do
- begin
- NextX := X + POSSIBLE_MOVES[I][0];
- NextY := Y + POSSIBLE_MOVES[I][1];
- CanContinue := IsCorrectMove(NextX, NextY);
- if (CanContinue) then
- if (FindMoves(NextX, NextY, (Counter + 1))) then
- FindMoves := true;
- end;
- FullDesk[X][Y] := 0;
- Dec(Counter);
- FindMoves := false;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement