Added more char constants for TPipeMaze

This commit is contained in:
Stefan Müller 2023-12-11 15:22:54 +01:00 committed by Stefan Müller
parent d1ae6d0404
commit cbce1ce794
1 changed files with 13 additions and 9 deletions

View File

@ -26,6 +26,10 @@ uses
const
CStartChar = 'S';
CLeftChar = 'l';
CRightChar = 'r';
CPathChar = '#';
CFloodFillChar = '%';
type
TPointArray = array of TPoint;
@ -221,8 +225,8 @@ end;
procedure TPipeMaze.CountEnclosureInside;
begin
if not TryCountEnclosureSide('l', FPart2) then
TryCountEnclosureSide('r', FPart2);
if not TryCountEnclosureSide(CLeftChar, FPart2) then
TryCountEnclosureSide(CRightChar, FPart2);
end;
function TPipeMaze.TryCountEnclosureSide(const AChar: Char; out OCount: Int64): Boolean;
@ -247,7 +251,7 @@ begin
if GetEnclosureMapChar(position) = AChar then
begin
stack.Push(position);
SetEnclosureMapChar(position, '%');
SetEnclosureMapChar(position, CFloodFillChar);
Inc(OCount);
end;
@ -262,10 +266,10 @@ begin
// Checks the neighboring position.
neighbor := position + direction;
c := GetEnclosureMapChar(neighbor);
if (c <> '%') and (c <> '#') then
if (c <> CFloodFillChar) and (c <> CPathChar) then
begin
stack.Push(neighbor);
SetEnclosureMapChar(neighbor, '%');
SetEnclosureMapChar(neighbor, CFloodFillChar);
Inc(OCount);
end;
end else
@ -290,19 +294,19 @@ var
c: Char;
i: Integer;
begin
SetEnclosureMapChar(APosition, '#');
SetEnclosureMapChar(APosition, CPathChar);
side := AStepMapping.LeftSide;
c := 'l';
c := CLeftChar;
for i := 1 to 2 do
begin
for offset in side do
begin
sidePosition := APosition + offset;
if CheckMapBounds(sidePosition) and (GetEnclosureMapChar(sidePosition) <> '#') then
if CheckMapBounds(sidePosition) and (GetEnclosureMapChar(sidePosition) <> CPathChar) then
SetEnclosureMapChar(sidePosition, c);
end;
side := AStepMapping.RightSide;
c := 'r';
c := CRightChar;
end;
end;