Exemple #1
0
        private void GenerateLayout()
        {
            int                 initialD         = HilbertCurve.xy2d(n, initialHilbertTile.x, initialHilbertTile.y);
            int                 i                = initialD;
            int                 maxSteps         = n * n - 1;
            Connections         direction        = Connections.None;
            List <List <int2> > unconnectedPaths = new List <List <int2> >();
            List <int2>         currentPath      = new List <int2>();
            int2                currentTile      = new int2(initialHilbertTile.x, initialHilbertTile.y);

            currentPath.Add(Hilbert2Layout(currentTile));

            while (i < maxSteps)
            {
                int2 nextTile = HilbertCurve.d2xy(n, i + 1);

                if (IsInsideOffsetFrame(nextTile.x, nextTile.y))
                {
                    direction = GetDirection(currentTile, nextTile);

                    if (direction != Connections.None)                     // we can connect currentTile and nextTile directly.
                    {
                        int2 layoutTile = Hilbert2Layout(currentTile);
                        layoutConnections[layoutTile.x, layoutTile.y] |= direction;
                    }
                    else
                    {
                        unconnectedPaths.Add(currentPath);
                        currentPath = new List <int2>();
                    }

                    currentPath.Add(Hilbert2Layout(nextTile));
                    currentTile = nextTile;
                }

                i++;
            }

            unconnectedPaths.Add(currentPath);
            ConnectUnconnectedPaths(unconnectedPaths);
            exit = currentTile;
        }
Exemple #2
0
        private int2 FindEntrance()
        {
            int2 result = int2.zero;
            bool found  = false;
            int  i      = 0;
            int  max    = n * n - 1;

            while (!found && i <= max)
            {
                int2 candidate = HilbertCurve.d2xy(n, i);

                if (IsInsideOffsetFrame(candidate.x, candidate.y))
                {
                    result = candidate;
                    found  = true;
                }

                i++;
            }
            return(result);
        }