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