Exemple #1
0
    public MazeNode MergeNode(MazeNode NodeToMerge)
    {
        MazeNode Union = new MazeNode(m_Position);

        Union.AddExitList(m_ExitPoints);
        Union.AddExitList(NodeToMerge.GetExitList());

        return(Union);
    }
Exemple #2
0
    private void InstantaneousMutation()
    {
        m_MutationCount++;
        bool NodesStable = true;

        Dictionary <GridPosition, MazeNode> MutatedNodes = new Dictionary <GridPosition, MazeNode>();

        for (int x = m_LeftEdge; x <= m_RightEdge; x++)
        {
            for (int y = m_TopEdge; y >= m_BottomEdge; y--)
            {
                MazeNode Node    = GetNode(x, y);
                MazeNode NewNode = new MazeNode(Node.Position);

                int BlockedNeighbors = CountBlockedNeighbors(Node);

                if (Node.ExitCount == 0)
                {
                    if (BlockedNeighbors < m_MutationBlockThreshhold)
                    {
                        NewNode.AddExitList(GridPosition.AllExits);
                        NodesStable = false;
                    }
                }
                else
                {
                    if (BlockedNeighbors <= m_MutationBlockThreshhold)
                    {
                        NewNode.AddExitList(GridPosition.AllExits);
                        NodesStable = false;
                    }
                }

                MutatedNodes.Add(Node.Position, NewNode);
            }
        }

        m_NodeList = MutatedNodes;

        // Mutation cycles are capped at 100 for sanity
        if (!NodesStable && (m_MutationCount < 100))
        {
            InstantaneousMutation();
        }
    }
Exemple #3
0
    private void GenerateRandomState()
    {
        for (int x = m_LeftEdge; x <= m_RightEdge; x++)
        {
            for (int y = m_TopEdge; y >= m_BottomEdge; y--)
            {
                MazeNode NewNode = CreateNode(x, y);

                if (Random.Range(0, 100) > m_InitialBlockChance)
                {
                    NewNode.AddExitList(GridPosition.AllExits);
                }
            }
        }
    }
Exemple #4
0
    private void SequentialMutation()
    {
        m_MutationCount++;
        bool NodesStable = true;

        for (int x = m_LeftEdge; x <= m_RightEdge; x++)
        {
            for (int y = m_TopEdge; y >= m_BottomEdge; y--)
            {
                MazeNode Node = GetNode(x, y);

                int BlockedNeighbors = CountBlockedNeighbors(Node);

                if (Node.ExitCount == 0)
                {
                    if (BlockedNeighbors < m_MutationBlockThreshhold)
                    {
                        Node.AddExitList(GridPosition.AllExits);
                        NodesStable = false;
                    }
                }
                else
                {
                    if (BlockedNeighbors > m_MutationBlockThreshhold)
                    {
                        Node.ClearExits();
                        NodesStable = false;
                    }
                }
            }
        }

        // Mutation cycles are capped at 100 for sanity
        if (!NodesStable && (m_MutationCount < 100))
        {
            SequentialMutation();
        }
    }