Пример #1
0
        protected void buildGuidMap(MoronThinker thinker)
        {
            List <MoronIONode> visited, horizon;
            MoronIONode        node;

            horizon = new List <MoronIONode>();
            visited = new List <MoronIONode>();

            horizon.Add(thinker.getCurrentNode());
            guidMap = new Dictionary <String, MoronIONode>();

            while (horizon.Count > 0)
            {
                node = horizon[0];
                horizon.RemoveAt(0);
                visited.Add(node);

                guidMap[node.guid] = node;

                foreach (GraphEdge edge in node.edges)
                {
                    if (!visited.Contains((MoronIONode)edge.to))
                    {
                        horizon.Add((MoronIONode)edge.to);
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        ///		Creates and returns the root of a fresh set of nodes and edges for the given [thinker].
        /// </summary>
        public MoronIONode createResolvedGraph(MoronThinker thinker)
        {
            MoronIONode[] resolvedNodes;
            MoronIONode   node;

            resolvedNodes = new MoronIONode[nodes.Count];

            for (int i = 0; i < nodes.Count; i++)
            {
                node                  = (MoronIONode)Activator.CreateInstance(nodes[i].GetType());
                node.thinker          = thinker;
                node.guid             = nodes[i].guid;
                node.interruptsIntent = nodes[i].interruptsIntent;
                node.setJoistsTo(nodes[i]);

                resolvedNodes[i] = node;
            }

            foreach (Pair <int, int> edge in edges)
            {
                resolvedNodes[edge.key].addEdge(resolvedNodes[edge.value]);
            }

            for (int i = 0; i < resolvedNodes.Length; i++)
            {
                resolvedNodes[i].init();
            }

            return(resolvedNodes[0]);
        }