Exemplo n.º 1
0
    private (int[, ], bool[, ]) PlaceSplotch(int[,] grid, int posW, int posD, int mag)
    {
        Vector3 center   = new Vector3(posW, 0, posD);
        Vector3 position = new Vector3(0, 0, 0);

        // iterate the vicinity of the splotch center
        foreach ((int countW, int countD) in Itr.IterationRange(posW - mag - splotchRimWidth, posW + mag + splotchRimWidth,
                                                                posD - mag - splotchRimWidth, posD + mag + splotchRimWidth))
        {
            position = new Vector3(countW, 0, countD);
            // if it is on the rim
            if ((GetDistance(position, center) >= (float)mag) &&
                ((GetDistance(position, center) <= (float)mag + splotchRimWidth)))
            {
                if (grid[countW, countD] == 1) // if there is a block
                {
                    grid[countW, countD]     = (int)LibraryElements.Elements.RingRim;
                    gridLock[countW, countD] = true;
                }
            }
            else if ((GetDistance(position, center) < mag)) // if it is inside the radius
            {
                grid[countW, countD]     = 0;
                gridLock[countW, countD] = true;
            }
        }

        grid[posW, posD] = (int)LibraryElements.Elements.Obelisk;

        return(grid, gridLock);
    }
Exemplo n.º 2
0
    private bool CheckForOverlaps(bool[,] grid, int posW, int posD, int mag)
    {
        bool    result   = true;
        Vector3 center   = new Vector3(posW, 0, posD);
        Vector3 position = new Vector3(0, 0, 0);

        // iterate the vicinity of the splotch center
        foreach ((int countW, int countD) in Itr.IterationRange(posW - mag - splotchRimWidth, posW + mag + splotchRimWidth,
                                                                posD - mag - splotchRimWidth, posD + mag + splotchRimWidth))
        {
            if ((GetDistance(position, center) <= mag)) // if it is inside the radius
            {
                if (!grid[countW, countD])              // if the position is not 0, then there is already a massive index there; so the whole checked space is unavailable
                {
                    result = false;
                    break;
                }
            }
            if (!result)
            {
                break;
            }
        }

        return(result);
    }
Exemplo n.º 3
0
    public static List <(int, int)> FindPattern(ref int[,] grid, ref bool[,] gridLock, int[,] pattern)
    {
        List <(int, int)> result           = new List <(int, int)>();
        List <(int, int)> countedPositions = new List <(int, int)>();


        (int width, int depth) = Grids.Dim(grid);

        int patternWidth = pattern.GetLength(0);
        int patternDepth = pattern.GetLength(1);


        // 1.
        foreach ((int countW, int countD) in Itr.IterationRange(1, width - patternWidth, 1, depth - patternDepth))
        {
            if (countedPositions.Contains((countW, countD)) || gridLock[countW, countD])
            {
                continue;
            }
            // overlay at position
            bool match = Overlay(grid, gridLock, pattern, countW, countD, countedPositions);
            if (match)
            {
                MarkAsCounted(pattern, ref grid, ref gridLock, countW, countD, ref countedPositions);
                result.Add((countW, countD));
            }
        }

        return(result);
    }
Exemplo n.º 4
0
    internal static int[,] AddNbrs(int[,] grid, int minCount)
    {
        (int width, int depth) = Grids.Dim(grid);

        int[,] result = Copy(grid);

        int[] pos = new int[4] {
            0, 1, 0, -1
        };

        foreach ((int countW, int countD) in Itr.IterationRange(1, width - 1, 1, depth - 1))
        {
            if (result[countW, countD] == 1)
            {
                continue;
            }

            int  nbrs = 0;
            bool mark = false;
            for (int count = 0; count < 4; count += 1)
            {
                int nbrW = countW + pos[(count + 3) % 4];
                int nbrD = countD + pos[count];
                if (grid[nbrW, nbrD] != 0)
                {
                    nbrs++;
                    if (nbrs >= minCount)
                    {
                        mark = true;
                        break;
                    }
                }
            }
            if (mark)
            {
                result[countW, countD] = 1;
            }
        }

        return(result);
    }