コード例 #1
0
        public void InitializeAirflowNodes()
        {
            nodes.Clear();

            AirflowNode armoryNode = new AirflowNode(armory, new string[3] {
                supplyDepot, tankFactory, departmentStore
            });
            AirflowNode deptStoreNode = new AirflowNode(departmentStore, new string[3] {
                armory, infirmary, dragonCommand
            });
            AirflowNode dragonCommandNode = new AirflowNode(dragonCommand, new string[3] {
                supplyDepot, departmentStore, infirmary
            });
            AirflowNode supplyDepotNode = new AirflowNode(supplyDepot, new string[3] {
                dragonCommand, armory, tankFactory
            });
            AirflowNode infirmaryNode = new AirflowNode(infirmary, new string[3] {
                departmentStore, tankFactory, dragonCommand
            });
            AirflowNode tankFactoryNode = new AirflowNode(tankFactory, new string[3] {
                infirmary, supplyDepot, armory
            });

            nodes.Add(armoryNode);
            nodes.Add(deptStoreNode);
            nodes.Add(dragonCommandNode);
            nodes.Add(supplyDepotNode);
            nodes.Add(infirmaryNode);
            nodes.Add(tankFactoryNode);
        }
コード例 #2
0
        public List <AirflowNode> CalculatePath()
        {
            bool solved       = false;
            int  currentIndex = 1;

            while (!solved)
            {
                AirflowNode nextNode = GetNextNode(path[currentIndex - 1]);
                if (nextNode != null)
                {
                    path.Add(nextNode);
                    currentIndex++;
                }
                else
                {
                    path.RemoveAt(currentIndex - 1);
                    currentIndex--;
                }

                if (path.Count > 5)
                {
                    if (path[5].Name.Equals(endPoint.Name))
                    {
                        solved = true;
                    }
                    else
                    {
                        path.RemoveAt(5);
                    }
                }
            }

            return(path);
        }
コード例 #3
0
        /*
         * public AirflowNode GetNextNode(AirflowNode currentNode)
         * {
         *  String nextNodeName = currentNode.GetNextNodeName();
         *  AirflowNode foundNode = Array.Find<AirflowNode>(path, s => s != null && s.Name.Equals(nextNodeName));
         *
         *  if((nextNodeName.Equals(endPoint.Name) && path.Count<AirflowNode>() < 5)
         || foundNode != null)
         || {
         ||     nextNodeName = currentNode.GetNextNodeName();
         || }
         ||
         || AirflowNode nextNode = null;
         ||
         || foreach(AirflowNode node in nodes)
         || {
         ||     if(node.Name.Equals(nextNodeName))
         ||     {
         ||         nextNode = node;
         ||         break;
         ||     }
         || }
         ||
         || return nextNode;
         ||}
         */

        public AirflowNode GetNextNode(AirflowNode currentNode)
        {
            String      nextNodeName = currentNode.GetNextNodeName();
            AirflowNode foundNode    = new AirflowNode();

            while (foundNode != null)
            {
                try
                {
                    foundNode = path.Find(s => s != null && s.Name.Equals(nextNodeName));
                    if (foundNode != null ||
                        ((nextNodeName.Equals(endPoint.Name) && path.Count <AirflowNode>() < 5)))
                    {
                        nextNodeName = currentNode.GetNextNodeName();
                        foundNode    = new AirflowNode();
                    }
                }
                catch (Exception e)
                { }
            }

            AirflowNode nextNode = null;

            if (nextNodeName != null)
            {
                foreach (AirflowNode node in nodes)
                {
                    if (node.Name.Equals(nextNodeName))
                    {
                        nextNode = node;
                        break;
                    }
                }
            }

            return(nextNode);
        }
コード例 #4
0
 public void InitializePuzzle(AirflowNode startNode, AirflowNode endNode)
 {
     path.Add(startNode);
     endPoint = endNode;
 }