unit uTest;
interface
Const
maxXData = 4;
maxYData = 4;
Type
TData = Array[0..maxXData+1, 0..maxYData+1] Of Char;
Procedure TestIt;
implementation
Const
CX: Array[0..7] Of Integer = (-1, 0, 1, 1, 1, 0, -1, -1);
CY: Array[0..7] Of Integer = (-1, -1, -1, 0, 1, 1, 1, 0);
Var
AData: TData;
function FindWord( AString: String): Boolean;
var
iX: Integer;
iY: Integer;
function WordAt(AIdx, x,y, ox,oy: Integer): Boolean;
var
i: Integer;
begin
Result := False;
if AString[AIdx] = AData[x,y] then
begin
Inc(AIdx);
if AIdx > Length(AString) then
begin
Result := TRUE;
end
else
begin
for i := 0 to 7 do
begin
if Not (((x+CX[i])=ox) And ((y+CY[i])=oy)) then //<--------- Breakpoint
begin
Result := WordAt(AIdx, x+CX[i], y+CY[i], x, y);
if Result then
Break;
end;
end;
i := 0;
end;
end
else
begin
i := 0;
end;
end;
begin
Result := FALSE;
for iX := 0 to maxXData-1 do
begin
for iY := 0 to maxYData-1 do
begin
if WordAt(1, iX+1, iY+1, 0, 0) then
begin
//Mark AString as found
end;
end;
end;
end;
Procedure TestIt;
var
iX: Integer;
iY: Integer;
begin
for iX := 0 to maxXData-1 do
begin
for iY := 0 to maxYData-1 do
begin
AData[iX, iY] := Char(Ord('A')+Random(Ord('Z')-Ord('A')+1));
end;
end;
AData[3,3] := 'T';
//
FindWord('TEST');
end;
end.