Ejemplo n.º 1
0
        private void addSourroundingWallsToWallList(MazeCoordinate target)
        {
            MazeCoordinate[] temp = MazeCoordinate.GetHorizontalVerticalAdjacentCoordinates(target);

            for (int i = 0; i < temp.Length; i++)
            {
                if (this.CurrentMaze.IsPointInMaze(temp[i]))
                {
                    if (!VisitedList.Contains(temp[i]))
                    {
                        if (!WallsList.Contains(temp[i]))
                        {
                            WallsList.Add(temp[i]);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private bool checkIfWallDividesTwoCorridors(MazeCoordinate target)
        {
            MazeCoordinate[] temp = MazeCoordinate.GetHorizontalVerticalAdjacentCoordinates(target);

            int TargetWallAlignsWithCorridors = 0;

            foreach (MazeCoordinate c in temp)
            {
                if (this.CurrentMaze.GetMazeTypeOnPos(c) == MazeFieldType.Corridor)
                {
                    if (target.X == c.X || target.Y == c.Y)
                    {
                        TargetWallAlignsWithCorridors++;
                    }
                }
            }

            // direct connection
            if (TargetWallAlignsWithCorridors > 2)
            {
                return(true);
            }

            temp = MazeCoordinate.GetAllAdjacentCoordinates(target);

            int CorridorFieldsInCloseProximity   = 0;
            HashSet <MazeCoordinate> inProximity = new HashSet <MazeCoordinate>();

            foreach (MazeCoordinate c in temp)
            {
                if (CurrentMaze.GetMazeTypeOnPos(c) != MazeFieldType.Wall)
                {
                    CorridorFieldsInCloseProximity++;
                    inProximity.Add(c);
                }
            }
            // This value can be reduced to create more narrow sideways, maybe make it configurable ?
            if (CorridorFieldsInCloseProximity >= 3)
            {
                return(true);
            }

            if (CorridorFieldsInCloseProximity == 2)
            {
                // check if the corridors are adjacent each other then its OK.
                foreach (MazeCoordinate c in inProximity)
                {
                    var  subset      = inProximity.Where(x => x != c).AsEnumerable();
                    bool allAdjacent = subset.All(x => x.IsAdjacentTo(c));
                    if (allAdjacent)
                    {
                        return(false);
                    }
                }
                return(true);
            }

            if (TargetWallAlignsWithCorridors > 1 && CorridorFieldsInCloseProximity >= 2)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }