当前位置: 首页>>代码示例>>C#>>正文


C# HashSet.GetEnumerator方法代码示例

本文整理汇总了C#中HashSet.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# HashSet.GetEnumerator方法的具体用法?C# HashSet.GetEnumerator怎么用?C# HashSet.GetEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HashSet的用法示例。


在下文中一共展示了HashSet.GetEnumerator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddAttributes

 public TrustedHtml AddAttributes(string tag, params string[] keys)
 {
     if (string.IsNullOrEmpty(tag))
     {
         throw new System.ArgumentNullException("tag");
     }
     if (keys == null)
     {
         throw new System.ArgumentNullException("keys");
     }
     HashSet<string> hashSet = new HashSet<string>();
     for (int i = 0; i < keys.Length; i++)
     {
         string text = keys[i];
         if (string.IsNullOrEmpty(text))
         {
             throw new System.Exception("key");
         }
         hashSet.Add(text);
     }
     if (this._attributes.ContainsKey(tag))
     {
         using (HashSet<string>.Enumerator enumerator = hashSet.GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 string current = enumerator.Current;
                 this._attributes[tag].Add(current);
             }
             return this;
         }
     }
     this._attributes.Add(tag, hashSet);
     return this;
 }
开发者ID:hbulzy,项目名称:SYS,代码行数:35,代码来源:TrustedHtml.cs

示例2: TestIterators

        public void TestIterators()
        {
            List<int> myList = new List<int> { 3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5 };
              HashSet<int> mySet = new HashSet<int> { 3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5 };
              for (int i = 0; i < myList.Count; i++)
            Console.Write("{0} ", myList[i]);
              Console.WriteLine();

              IEnumerator<int> pi = mySet.GetEnumerator();
              while (pi.MoveNext())
              {
            int x = pi.Current;
            Console.Write("{0} ", x);
              }
              Console.WriteLine();

              foreach (int x in myList)
            Console.Write("{0} ", x);
              Console.WriteLine();

              MyIntList myIntList = new MyIntList { 3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5 };
              IEnumerator<int> px = myIntList.GetEnumerator(x => 0 == x % 3);
              while ( px.MoveNext())
            Console.Write("{0} ", px.Current);
              Console.WriteLine();
              // displays 3 9 6 3

              foreach(int x in myIntList)
            Console.Write("{0} ", x);
              Console.WriteLine();
              // displays 3 1 4 1 5 9 2 6 5 3 5

              Console.ReadKey();
        }
开发者ID:kambagiri,项目名称:IteratorProject,代码行数:34,代码来源:IteratorExample.cs

示例3: Main

    static void Main()
    {
        // -9,223,372,036,854,775,808 == long.MinValue
        //  9,223,372,036,854,775,807 == long.MaxValue
        // long.MinValue <= a[i] <= long.MaxValue
        // 1 <= i <= 99,999

        // Input data
        int n = int.Parse(Console.ReadLine());
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
        {
            a[i] = long.Parse(Console.ReadLine());
        }
        // Calculate
        HashSet<long> oddElementValues = new HashSet<long>();
        for (int i = 0; i < n; i++)
        {
            if (oddElementValues.Contains(a[i]))
            {
                oddElementValues.Remove(a[i]);
            }
            else
            {
                oddElementValues.Add(a[i]);
            }
        }
        HashSet<long>.Enumerator enumerator = oddElementValues.GetEnumerator();
        enumerator.MoveNext();
        // Output data
        Console.WriteLine(enumerator.Current);
    }
开发者ID:wencywww,项目名称:Visual-Studio-2012,代码行数:32,代码来源:OddNumber.cs

示例4: allClique

    public int[] allClique(string[] graphEdge)
    {
        int n = graphEdge.Length;
        int[] ret = new int[n];
        HashSet<int> c = new HashSet<int>();
        HashSet<int> s = new HashSet<int>();
        for (int i = 0; i < n; i++)
        {
            ret[i] = 0;
            c.Add(1<<i);
        }

        ret[0] = n;
        for (int k = 1; k < n; k++)
        {
            HashSet<int> cc = new HashSet<int>();
            HashSet<int>.Enumerator ee = c.GetEnumerator();
            while(ee.MoveNext())
            {
                List<int> l = new List<int>();
                int set = ee.Current;
                for (int i = 0; i < n; i++)
                {
                    if ((set & (1 << i)) == (1 << i))
                        continue;

                    bool found = true;
                    int e = set; int p = 0;
                    while (e > 0)
                    {
                        if ((e & 1) == 1)
                        {
                            if (graphEdge[p][i] == '0')
                            {
                                found = false;
                                break;
                            }
                        }
                        e = e >> 1;
                        p++;
                    }

                    if (found)
                    {
                        l.Add(i);
                    }
                }
                for (int i = 0; i < l.Count; i++)
                {
                    cc.Add(set | (1 << l[i]));
                }
            }
            ret[k] = cc.Count;

            c = cc;
        }

        return ret;
    }
开发者ID:karunasagark,项目名称:ps,代码行数:59,代码来源:GraphClique.cs

示例5: Main

    public static void Main () {
        var hs = new HashSet<string>() {
            "a",
            "b",
            "c"
        };

        foreach (var s in hs)
            Console.WriteLine(s);

        Console.WriteLine(hs.Count);

        var test = hs.GetEnumerator();
    }
开发者ID:cbsistem,项目名称:JSIL,代码行数:14,代码来源:Issue578.cs

示例6: lonelyinteger

        static int lonelyinteger(int[] a)
        {
            HashSet<int> myInts = new HashSet<int>();

            foreach (int item in a)
            {
                if (myInts.Contains(item))
                    myInts.Remove(item);

                else
                    myInts.Add(item);
            }

            IEnumerator<int> itr = myInts.GetEnumerator();
            itr.MoveNext();

            return itr.Current;
        }
开发者ID:Johnzhuo,项目名称:HackerRank,代码行数:18,代码来源:Solution.cs

示例7: ModifiedBFS

    void ModifiedBFS()
    {
        HashSet<Node> tempRoadSet = new HashSet<Node>(grid.RoadSet);
        Queue<Node> trafficQ = new Queue<Node>();
        trafficQ.Enqueue(grid.ARoadNode);

        while (tempRoadSet.Count != 0)
        {
            while (trafficQ.Count > 0)
            {
                Node current = trafficQ.Dequeue();
                if (tempRoadSet.Remove(current))
                {
                    foreach (Node n in grid.BFSGetRoadNeighbours(current))     // GetRoadNeighbors adds in/out => trafficWeight
                    {
                        if(tempRoadSet.Contains(n))
                            trafficQ.Enqueue(n);
                    }
                }
            }

            // Stranded roads
            // There maybe a chance that we take the small set. Need to improve this more.
            while (tempRoadSet.Count > 0)
            {
                HashSet<Node>.Enumerator node = tempRoadSet.GetEnumerator();
                if (node.MoveNext())
                {
                    grid.RoadSet.Remove(node.Current);     // remove stranded road
                    tempRoadSet.Remove(node.Current);
                    node.Current.IsRoad = false;
                }
            }
        }
    }
开发者ID:FIU-SCIS-Senior-Projects,项目名称:UrbanTheater,代码行数:35,代码来源:TrafficManager.cs

示例8: ExecuteCut

    /// <summary>
    /// カットを実行
    /// </summary>
    public void ExecuteCut()
    {
        int h = plateBuildMap_.GetLength(0);
        int w = plateBuildMap_.GetLength(1);

        var labelMap = new int[h,w];
        var labelLinkTbl = new Dictionary<int,int>();
        int labelSeed = 0;

        // ラベリングしていきます
        for (int yy = 0; yy < h; yy++)
        {
            if (yy == 0)
            {
                // 縦の開始の場合
                int nowLabel = labelSeed++;
                for (int xx = 0; xx < w; xx++)
                {
                    if (xx != 0)
                    {
                        if(cutting_.GetVertLineCutOp(xx-1, yy) == CuttingInfo_.CutOperations.Cut)
                        {
                            nowLabel = labelSeed++;
                        }
                    }
                    labelMap[yy, xx] = nowLabel;
                }
            }
            else
            {
                // 一つ上のブロックを起点にします
                int nowLabel = labelMap[yy-1, 0];
                for (int xx = 0; xx < w; xx++)
                {
                    if (cutting_.GetHoriLineCutOp(yy - 1, xx) == CuttingInfo_.CutOperations.None)
                    {
                        if (xx==0 || cutting_.GetVertLineCutOp(xx - 1, yy) == CuttingInfo_.CutOperations.None)
                        {
                            //上とつながる、左とつながる場合
                            if (labelMap[yy - 1, xx] != nowLabel)
                            {
                                // 上と違うラベルの場合、2つの領域が連結されます
                                labelLinkTbl[nowLabel] = labelMap[yy - 1, xx];
                            }
                        }
                        else
                        {
                            //上とつながる、左とつながら無い場合
                            nowLabel = labelMap[yy - 1, xx];
                        }
                    }
                    else
                    {
                        if (xx==0)
                        {
                            //上とつながら無い、横の起点び場合
                            nowLabel = labelSeed++;
                        }
                        else if(cutting_.GetVertLineCutOp(xx - 1, yy) == CuttingInfo_.CutOperations.None)
                        {
                            //上とつながら無い、左とつながる場合
                        }
                        else
                        {
                            //上とつながら無い、左とつながら無い場合
                            nowLabel = labelSeed++;
                        }
                    }
                    labelMap[yy, xx] = nowLabel;
                }
            }
        }
        // ラベルを振りなおします
        var labelSet = new HashSet<int>();
        for (int yy = 0; yy < h; yy++)
        {
            for (int xx = 0; xx < w; xx++)
            {
                if (labelLinkTbl.ContainsKey(labelMap[yy, xx]))
                {
                    labelMap[yy, xx] = labelLinkTbl[labelMap[yy, xx]];
                }
                labelSet.Add(labelMap[yy, xx]);
            }
        }
        // 領域が2つ以上であれば分割します
        if(labelSet.Count>1)
        {
            Debug.Log(string.Format("labelSet.Count = {0}", labelSet.Count));

            for (int zz = 0; zz < h; zz++)
            {
                for (int xx = 0; xx < w; xx++)
                {
                    if(labelMap[zz, xx] != labelSet.GetEnumerator().Current)
                    {
                        plateBuildMap_[zz, xx].TestOffsetY = -labelMap[zz, xx] * 2.8f;
//.........这里部分代码省略.........
开发者ID:RoboJam,项目名称:robojam-remote,代码行数:101,代码来源:UniPlate.cs

示例9: GetShortestPath

        public HashSet<List<Tuple<long, long>>> GetShortestPath(HashSet<Node> myIntersectNodes)
        {
            foundLeft = foundRight = false;

            //set maximum part lengths
            _MaxPartLengthLeft = _MaxPartLengthRight = (_MaxPathLength / 2);

            //if the max path length is odd add one
            if (_MaxPathLength % 2 != 0)
            {
                _MaxPartLengthLeft += 1;
                _MaxPartLengthRight += 1;
            }

            var enumerator = myIntersectNodes.GetEnumerator();

            while (enumerator.MoveNext() && _Paths.Count == 0)
            {
                //calculate parts from intersect node to end
                getShortestPathDownwards(enumerator.Current);

                ///recalculate the max part length...
                ///it could happen that the intersect node is not in the middle,
                ///so the max part length left could be less than calculated,
                ///if this happens the right part length must be adapted
                _MaxPartLengthRight = _MaxPathLength - _MaxPartLengthLeft;

                //check if max path length is odd
                if (_MaxPathLength % 2 != 0)
                {
                    _MaxPartLengthRight += 1;
                }

                //calculate parts from intersect node to start
                getShortestPathUpwards(enumerator.Current);

                //calculate full path
                if (_PathsLeft.Count > 0 && _PathsRight.Count > 0)
                {
                    //forach part from left
                    foreach (var leftPath in _PathsLeft)
                    {
                        var first = leftPath.First();

                        //foreach part from right
                        foreach (var rightPath in _PathsRight)
                            //if there starts are the same (the intersect node)
                            if (rightPath.First().Equals(first) &&
                                ((rightPath.Count + leftPath.Count - 1) <= _MaxPathLength))
                            {
                                var temp = new List<Tuple<long, long>>(rightPath);
                                temp.Reverse();
                                leftPath.RemoveAt(0);
                                temp.InsertRange(temp.Count, leftPath);

                                _Paths.Add(temp);

                                return _Paths;
                            }
                    }
                }
            }

            return null;
        }
开发者ID:anukat2015,项目名称:sones,代码行数:65,代码来源:TargetAnalyzer.cs

示例10: ParseFilenames

        /// <summary>
        /// Tries all filenames (complete path) included in the fullFileNameFile file.
        /// </summary>
        /// <param name="fullFileNameFile"></param>
        /// <returns> number of newly found filenames</returns>
        public long ParseFilenames(string fullFileNameFile)
        {
            Start();
            hashDic.CreateHelpers();
            long result = 0;
            if (File.Exists(fullFileNameFile))
            {
                Hasher warhash = new Hasher(hasherType);

                //Read the file
                FileStream fs = new FileStream(fullFileNameFile, FileMode.Open);
                StreamReader reader = new StreamReader(fs);

                HashSet<string> fileList = new HashSet<string>();

                string line;
                while ((line = reader.ReadLine()) != null)
                    fileList.Add(line.ToLower().Replace('\\', '/'));

                reader.Close();
                fs.Close();

                // strip input file from duplicates.
                File.Delete(fullFileNameFile);
                fs = new FileStream(fullFileNameFile, FileMode.Create);
                StreamWriter writer = new StreamWriter(fs);

                foreach (string file in fileList)
                    writer.WriteLine(file);

                writer.Close();
                fs.Close();

                foundNames = new Dictionary<string, bool>();

                foreach (string fn in fileList)
                {
                    foundNames[fn] = false;
                }

                //Just in case someday we want to multi thread.
                parseFileList = fileList.GetEnumerator();
                string filename;
                while ((filename = GetFileName_ParseFilenames()) != null)
                {

                    warhash.Hash(filename, 0xDEADBEEF);
                    UpdateResults found = hashDic.UpdateHash(warhash.ph, warhash.sh, filename, 0);
                    if (found == UpdateResults.NAME_UPDATED || found == UpdateResults.ARCHIVE_UPDATED)
                        result++;
                    if (found != UpdateResults.NOT_FOUND)
                        foundNames[filename] = true;
                }
                if (active)
                {
                    string outputFileRoot = Path.GetDirectoryName(fullFileNameFile) + "/" + Path.GetFileNameWithoutExtension(fullFileNameFile);
                    FileStream ofsFound = new FileStream(outputFileRoot + "-found.txt", FileMode.Create);
                    FileStream ofsNotFound = new FileStream(outputFileRoot + "-notfound.txt", FileMode.Create);
                    StreamWriter swf = new StreamWriter(ofsFound);
                    StreamWriter swnf = new StreamWriter(ofsNotFound);

                    foreach (KeyValuePair<string, Boolean> file in foundNames)
                        if (file.Value == true)
                        {
                            warhash.Hash(file.Key, 0xDEADBEEF);
                            swf.WriteLine("{0:X8}" + HashDictionary.hashSeparator
                                + "{1:X8}" + HashDictionary.hashSeparator
                                + "{2}", warhash.ph, warhash.sh, file.Key);
                        }
                        else
                        {
                            //this is a quick and dirty fix to get some more debug info
                            // to be removed in the future !!!
                            warhash.Hash(file.Key, 0xDEADBEEF);
                            //swnf.WriteLine("{0:X8}" + HashDictionary.hashSeparator
                            //    + "{1:X8}" + HashDictionary.hashSeparator
                            //    + "{2}", warhash.ph, warhash.sh, file.Key);
                            swnf.WriteLine(file.Key);
                        }

                    swnf.Close();
                    swf.Close();
                    ofsFound.Close();
                    ofsNotFound.Close();
                }
            }
            return result;
        }
开发者ID:WarEmu,项目名称:EasyMYP,代码行数:93,代码来源:HashCreator.cs

示例11: EnterSSA

		public void EnterSSA()
		{
			IRControlFlowGraph cfg = IRControlFlowGraph.Build(this);
			if (cfg == null) return;
			int originalCount = Locals.Count;
			bool[] originalAssignments = new bool[originalCount];
			int[] originalIterations = new int[originalCount];
			IRLocal tempLocal = null;

			Locals.ForEach(l => l.SSAData = new IRLocal.IRLocalSSAData(l));
			// Add new local iterations for each assignment to an original local, and keep
			// track of final iterations for each node, assigning true to indicate it was
			// assigned, false means propagated (used later)
			foreach (IRControlFlowGraphNode node in cfg.Nodes)
			{
				node.SSAFinalIterations = new Tuple<IRLocal, bool>[originalCount];
				node.SSAPhis = new IRLocal[originalCount];
				foreach (IRInstruction instruction in node.Instructions)
				{
					if (instruction.Destination == null || instruction.Destination.Type != IRLinearizedLocationType.Local) continue;
					tempLocal = Locals[instruction.Destination.Local.LocalIndex];
					if (!originalAssignments[tempLocal.Index])
					{
						originalAssignments[tempLocal.Index] = true;
						node.SSAFinalIterations[tempLocal.Index] = new Tuple<IRLocal, bool>(tempLocal, true);
						continue;
					}
					tempLocal = tempLocal.Clone(this);
					Locals.Add(tempLocal);
					tempLocal.SSAData.Iteration = ++originalIterations[tempLocal.SSAData.Original.Index];
					instruction.Destination.Local.LocalIndex = tempLocal.Index;
					node.SSAFinalIterations[tempLocal.SSAData.Original.Index] = new Tuple<IRLocal, bool>(tempLocal, true);
				}
			}

			// Any SSAFinalIterations missing from the entry node means the entry node
			// did not assign to the original local, so they can be filled in with
			// propagated original locals by, assigning false to indicate propagated
			for (int index = 0; index < originalCount; ++index)
			{
				if (cfg.Nodes[0].SSAFinalIterations[index] == null)
					cfg.Nodes[0].SSAFinalIterations[index] = new Tuple<IRLocal, bool>(Locals[index], false);
			}
			// Any SSAFinalIterations missing from any node means the node did not
			// assign to the original local, so they can be filled in with propagated
			// locals using the dominance tree, assigning false to indicate propagated
			foreach (IRControlFlowGraphNode node in cfg.Nodes)
			{
				for (int index = 0; index < originalCount; ++index)
				{
					if (node.SSAFinalIterations[index] == null)
					{
						IRControlFlowGraphNode treeNode = node.Dominator;
						while (treeNode.SSAFinalIterations[index] == null) treeNode = treeNode.Dominator;
						node.SSAFinalIterations[index] = new Tuple<IRLocal, bool>(treeNode.SSAFinalIterations[index].Item1, false);
					}
				}
			}

			// Now that all final iterations are known, we also know if the final
			// iteration for a node was assigned or propagated
			// So now we can create a phi, in the dominance frontiers of nodes which
			// have assignments to original locals
			// If the phi is the only assignment in a dominance frontier node, then
			// the phi destination becomes the final iteration for that node
			int localsBeforePhis = Locals.Count;
			BitArray phiInserted = new BitArray(cfg.Nodes.Count, false);
			BitArray localAssigned = new BitArray(cfg.Nodes.Count, false);
			HashSet<IRControlFlowGraphNode> unprocessedNodes = new HashSet<IRControlFlowGraphNode>();
			HashSet<IRControlFlowGraphNode>.Enumerator unprocessedNodesEnumerator;
			IRControlFlowGraphNode processingNode = null;
			for (int originalIndex = 0; originalIndex < originalCount; ++originalIndex)
			{
				phiInserted.SetAll(false);
				localAssigned.SetAll(false);
				foreach (IRControlFlowGraphNode node in cfg.Nodes)
				{
					if (node.SSAFinalIterations[originalIndex].Item2)
					{
						localAssigned.Set(node.Index, true);
						unprocessedNodes.Add(node);
					}
				}
				while (unprocessedNodes.Count > 0)
				{
					unprocessedNodesEnumerator = unprocessedNodes.GetEnumerator();
					unprocessedNodesEnumerator.MoveNext();
					processingNode = unprocessedNodesEnumerator.Current;
					unprocessedNodes.Remove(processingNode);
					foreach (IRControlFlowGraphNode frontierNode in processingNode.Frontiers)
					{
						if (!phiInserted[frontierNode.Index])
						{
							tempLocal = Locals[originalIndex].Clone(this);
							Locals.Add(tempLocal);
							tempLocal.SSAData.Iteration = ++originalIterations[originalIndex];
							tempLocal.SSAData.Phi = true;
							frontierNode.SSAPhis[originalIndex] = tempLocal;
							if (!frontierNode.SSAFinalIterations[originalIndex].Item2) frontierNode.SSAFinalIterations[originalIndex] = new Tuple<IRLocal, bool>(tempLocal, true);
							phiInserted.Set(frontierNode.Index, true);
//.........这里部分代码省略.........
开发者ID:carriercomm,项目名称:Proton-1,代码行数:101,代码来源:IRMethod.cs

示例12: WriteModuleAndClassRegistrationFile

 private static void WriteModuleAndClassRegistrationFile(string file, HashSet<string> nativeModules, HashSet<string> nativeClasses, HashSet<string> classesToSkip)
 {
   using (TextWriter w = (TextWriter) new StreamWriter(file))
   {
     CodeStrippingUtils.WriteStaticallyLinkedModuleRegistration(w, nativeModules, nativeClasses);
     w.WriteLine();
     w.WriteLine("void RegisterAllClasses()");
     w.WriteLine("{");
     if (nativeClasses == null)
     {
       w.WriteLine("\tvoid RegisterAllClassesGranular();");
       w.WriteLine("\tRegisterAllClassesGranular();");
     }
     else
     {
       w.WriteLine("\t//Total: {0} classes", (object) nativeClasses.Count);
       int num = 0;
       using (HashSet<string>.Enumerator enumerator = nativeClasses.GetEnumerator())
       {
         while (enumerator.MoveNext())
         {
           string current = enumerator.Current;
           w.WriteLine("\t//{0}. {1}", (object) num, (object) current);
           if (classesToSkip.Contains(current))
           {
             w.WriteLine("\t//Skipping {0}", (object) current);
           }
           else
           {
             w.WriteLine("\tvoid RegisterClass_{0}();", (object) current);
             w.WriteLine("\tRegisterClass_{0}();", (object) current);
           }
           w.WriteLine();
           ++num;
         }
       }
     }
     w.WriteLine("}");
     w.Close();
   }
 }
开发者ID:BlakeTriana,项目名称:unity-decompiled,代码行数:41,代码来源:CodeStrippingUtils.cs

示例13: CheckTermsOrder

        private void CheckTermsOrder(IndexReader r, ISet<string> allTerms, bool isTop)
        {
            TermsEnum terms = MultiFields.GetFields(r).Terms("f").Iterator(null);

            BytesRef last = new BytesRef();

            HashSet<string> seenTerms = new HashSet<string>();

            while (true)
            {
                BytesRef term = terms.Next();
                if (term == null)
                {
                    break;
                }

                Assert.IsTrue(last.CompareTo(term) < 0);
                last.CopyBytes(term);

                string s = term.Utf8ToString();
                Assert.IsTrue(allTerms.Contains(s), "term " + TermDesc(s) + " was not added to index (count=" + allTerms.Count + ")");
                seenTerms.Add(s);
            }

            if (isTop)
            {
                Assert.IsTrue(allTerms.SetEquals(seenTerms));
            }

            // Test seeking:
            IEnumerator<string> it = seenTerms.GetEnumerator();
            while (it.MoveNext())
            {
                BytesRef tr = new BytesRef(it.Current);
                Assert.AreEqual(TermsEnum.SeekStatus.FOUND, terms.SeekCeil(tr), "seek failed for term=" + TermDesc(tr.Utf8ToString()));
            }
        }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:37,代码来源:TestIndexWriterUnicode.cs

示例14: run


//.........这里部分代码省略.........
                              temp++;
                          }
                          if (temp == -1)
                          {
                              rowsToSpawn.Add(i);
                          }
                      }
                  }
                  if (rowsToSpawn.Count > 0)
                  {
                      blockedSpotFound = true;
                  }
                  else
                  {
                      doomSearchIter++;
                      if (playerID() == 0)
                      {
                          theirFirstCol--;
                      }
                      else
                      {
                          theirFirstCol++;
                      }
                  }
              }
              Console.WriteLine("Doom drop search spot done");
              if (doomSearchIter >= 7)
              {
                  doomSearchIter = 0;
              }
              int anotherIter = 0;
              while (players[playerID()].ScrapAmount >= modelVariants[(int)Unit.TERMINATOR].Cost && rowsToSpawn.Count > 0 && anotherIter < 2)
              {
                  int chooseRow = rowsToSpawn.GetEnumerator().Current;
                  players[playerID()].orbitalDrop(theirFirstCol, chooseRow, (int)Unit.TERMINATOR);
                  rowsToSpawn.Remove(chooseRow);
                  anotherIter++;
              }
              Console.WriteLine("Best spots have been tried");
              if (players[playerID()].ScrapAmount >= modelVariants[(int)Unit.TERMINATOR].Cost)
              {
                  theirFirstCol = mapWidth() - 1;
                  if (playerID() == 1)
                      theirFirstCol = 0;
                  for (int i = 0; i < mapHeight() && players[playerID()].ScrapAmount >= modelVariants[(int)Unit.TERMINATOR].Cost; i++)
                  {
                      if (!(getTile(theirFirstCol, i).TurnsUntilAssembled > 0))
                      {
                          if (!boardState.theirHangers.getValueFromSpot(theirFirstCol, i))
                          {
                              players[playerID()].orbitalDrop(theirFirstCol, i, (int)Unit.TERMINATOR);
                          }
                      }
                  }
              }
          }
          }
          else
          {
          while (rowsChecked < mapHeight())
          {
              // Not a bad row
              if (!badRows.Contains(iter))
              {
                  // enough scrap
                  if (players[playerID()].ScrapAmount >= cost)
开发者ID:austingantner,项目名称:MegaMinerAI13-Droids,代码行数:67,代码来源:AI.cs

示例15: NetworkGraph

        public NetworkGraph( int numNodePairs )
        {
            HashSet<Edge> initialEdges = new HashSet<Edge>();
            String nodeType1;
            String nodeType2;

            for (int i = 0; i < numNodePairs; i++)
            {
                String address1 = this.GenerateIPAddress();
                String address2 = this.GenerateIPAddress();

                if (uniqueAddresses.Contains(address1) || uniqueAddresses.Contains(address2))
                    continue;

                do
                {
                    nodeType1 = GenerateNodeType();
                    nodeType2 = GenerateNodeType();
                } while (!ValidateNodeConnection(nodeType1, nodeType2));

                Node x = new Node(nodeType1, address1);
                Node y = new Node(nodeType2, address2);

                Edge edge = new Edge(x, y, GenerateWeight());

                x.AddEdge(edge);
                y.AddEdge(edge);

                initialEdges.Add(edge);
                networkGraph.Add(x);
                networkGraph.Add(y);

                uniqueAddresses.Add(address1);
                uniqueAddresses.Add(address2);
            }

            using (IEnumerator<Edge> it = initialEdges.GetEnumerator())
            {

                it.MoveNext();

                Edge curEdge = it.Current;

                while (it.MoveNext())
                {
                    Edge nextEdge = it.Current;

                    Node curX = curEdge.GetX();
                    Node curY = curEdge.GetY();

                    Node nextX = nextEdge.GetX();
                    Node nextY = nextEdge.GetY();

                    if (ValidateNodeConnection(curX.GetType().ToString(), nextX.GetType().ToString()))
                    {
                        Edge newXX = new Edge(curX, nextX, GenerateWeight());

                        curX.AddEdge(newXX);
                        nextX.AddEdge(newXX);
                    }
                    else if (ValidateNodeConnection(curX.GetType().ToString(), nextY.GetType().ToString()))
                    {
                        Edge newXY = new Edge(curX, nextY, GenerateWeight());

                        curX.AddEdge(newXY);
                        nextY.AddEdge(newXY);
                    }
                    else if (ValidateNodeConnection(curY.GetType().ToString(), nextX.GetType().ToString()))
                    {
                        Edge newYX = new Edge(curY, nextX, GenerateWeight());

                        curX.AddEdge(newYX);
                        nextY.AddEdge(newYX);
                    }
                    else if (ValidateNodeConnection(curY.GetType().ToString(), nextY.GetType().ToString()))
                    {
                        Edge newYY = new Edge(curY, nextY, GenerateWeight());

                        curX.AddEdge(newYY);
                        nextY.AddEdge(newYY);
                    }
                    curEdge = nextEdge;
                }
            }
        }
开发者ID:umbarger,项目名称:RouterRIP,代码行数:85,代码来源:NetworkGraph.cs


注:本文中的HashSet.GetEnumerator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。