Example #1
0
 public void Clear()
 {
     foreach (Direction dir in DirectionUtils.Directions())
     {
         Set(dir, false);
     }
 }
Example #2
0
        static bool ClearLoopsAndCheck(Tile[,] map)
        {
            int startX = 0;
            int startY;

            for (startY = 0; startY < MAP_HEIGHT; startY++)
            {
                Tile tile = map[0, startY];
                if (tile.Type == TileType.Start)
                {
                    break;
                }
            }

            bool homeOnPath = false;

            void Search(int fromX, int fromY)
            {
                Tile tile = map.MaybeGet(fromX, fromY);

                if (tile == null || tile.OnPath)
                {
                    return;
                }

                tile.OnPath = true;
                homeOnPath  = homeOnPath || tile.Type == TileType.Home;

                foreach (Direction dir in DirectionUtils.Directions())
                {
                    if (tile.Get(dir) == true)
                    {
                        Search(fromX + dir.X(), fromY + dir.Y());
                    }
                }
            }

            Search(startX, startY);

            if (!homeOnPath)
            {
                return(false);
            }

            for (int x = 0; x < MAP_WIDTH; x++)
            {
                for (int y = 0; y < MAP_HEIGHT; y++)
                {
                    var tile = map[x, y];
                    if (!tile.OnPath)
                    {
                        tile.Clear();
                    }
                }
            }

            return(true);
        }
Example #3
0
        static void Propogate(Tile[,] map, int fromX, int fromY)
        {
            var tile = map[fromX, fromY];

            foreach (Direction dir in DirectionUtils.Directions())
            {
                bool?valueInDir = tile.Get(dir);
                if (valueInDir == null)
                {
                    continue;
                }

                (Tile neighbor, int neighborX, int neighborY) = map.ValueInDirection(fromX, fromY, dir);

                if (neighbor != null)
                {
                    if (neighbor.TryResolve(dir.Opposite(), valueInDir.Value))
                    {
                        Propogate(map, neighborX, neighborY);
                    }
                }
            }
        }
Example #4
0
 private Direction[] UnresolvedDirections() =>
 DirectionUtils.Directions()
 .Where(dir => Get(dir) == null)
 .ToArray();
Example #5
0
 public int Count(Func <bool?, bool> predicate) => DirectionUtils
 .Directions()
 .Select(dir => predicate(Get(dir)))
 .Count(hasValue => hasValue);