Anonymous Anonymous - 2 months ago
507 0

No description

C#

Node Graph Problem

for (int i = 0; i < myTerritory.Count; i++)
            {
                myTerritory[i].myVisited = false;
            }
            for (int i = 0; i < myPossibleExpansions.Count; i++)
            {
                myPossibleExpansions[i].myVisited = false;
            }

            myPossibleExpansions.Clear();
            Queue<Node> territory = new Queue<Node>();
            for (int i = 0; i < myTerritory.Count; i++)
            {
                territory.Enqueue(myTerritory[i]);
            }
            Node currentNode = myTerritory[0];
            while (currentNode != null)
            {
                for (int j = 0; j < currentNode.myEdges.Count; j++)
                {
                    Node neighbour = currentNode.myEdges[j].GetOtherNode(this);
                    if (myOwner == neighbour.myOwner)
                    {
                        continue;
                    }
                    if (neighbour.myVisited == false)
                    {
                        neighbour.myVisited = true;
                        if (neighbour.myTypeOfNode != TypeOfNode.HQ)
                        {
                            myPossibleExpansions.Add(neighbour);
                        }                           
                    }
                }
                if (territory.Count > 0)
                {
                    currentNode = territory.Dequeue();
                }
                else
                    currentNode = null;
            }