示例#1
0
 private static void dfs(Node node)
 {
     Used.Add(node);
     foreach (LinkNode outLink in node.OutLinks)
     {
         if (!Used.Contains(outLink.NodeEnd))
         {
             dfs(outLink.NodeEnd);
         }
     }
 }
示例#2
0
文件: Bridge.cs 项目: pnquest/AoC2017
 private void UsePart(Link l)
 {
     _available.Remove(l);
     if (Used.Any())
     {
         l.UseSide(Used.Last().FirstFreeSide().Value);
     }
     else
     {
         l.UseSide(0);
     }
     Used.Add(l);
 }
示例#3
0
        /**
         * 获取对象实例
         **/
        public T GetObjectInstance <T>() where T : IPoolable, new()
        {
            T    Instance  = default(T);
            Type Prototype = typeof(T);

            if (!ObjectDict.ContainsKey(Prototype))
            {
                CreateObjectPool <T>(CAPACITY);
            }

            List <Object>  Used;
            Queue <Object> Objects;
            bool           Result = ObjectDict.TryGetValue(Prototype, out Objects);

            if (Result)
            {
                ObjectUsedRef.TryGetValue(Prototype, out Used);
                int UsedCount = 0;
                //int Capacity = 0;
                ObjectUsedDict.TryGetValue(Prototype, out UsedCount);
                //CapacityDict.TryGetValue(Prototype, out Capacity);

                if (Objects.Count > 0)
                {
                    //返回第一个
                    Instance = (T)Objects.Dequeue();
                    //更新使用计数
                    UsedCount++;
                    ObjectUsedDict[Prototype] = UsedCount;
                    //添加到使用中的队列
                    Used.Add(Instance);
                }
                else
                {
                    //if (UsedCount < Capacity)
                    //{
                    //创建新的实例
                    Instance = new T();
                    //更新使用计数
                    UsedCount++;
                    ObjectUsedDict[Prototype] = UsedCount;

                    //添加到使用中的队列
                    Used.Add(Instance);
                    //}
                }
            }
            return(Instance);
        }
        private void Check(int column)
        {
            from     = column;
            fromPile = FindTableau[from];
            if (fromPile.Count == 0)
            {
                // No cards.
                return;
            }

            // Configure the working tableau.
            WorkingTableau.Variation = Variation;

            // Find roots.
            Roots.Clear();
            int row = fromPile.Count;

            Roots.Add(row);
            while (row > 0)
            {
                int count = fromPile.GetRunUpAnySuit(row);
                row -= count;
                Roots.Add(row);
            }
            int runs = Roots.Count - 1;

            if (runs <= 1)
            {
                // Not at least two runs.
                return;
            }

            // Check first with no uncovering moves.
            best = -1;
            CheckOne(Move.Empty);

            Used.Clear();
            for (int i = 0; i < UncoveringMoves.Count; i++)
            {
                // Make sure the move doesn't interfere.
                Move move = UncoveringMoves[i];
                if (move.From == from || move.To == from)
                {
                    continue;
                }

                // Only need to try an uncovered card once.
                if (Used.Contains(move.From))
                {
                    continue;
                }
                Used.Add(move.From);

                // The uncovered card has to match a root to be useful.
                Card uncoveredCard = FindTableau[move.From][move.FromRow - 1];
                bool matchesRoot   = false;
                for (int j = 1; j < Roots.Count; j++)
                {
                    if (uncoveredCard.IsTargetFor(fromPile[Roots[j]]))
                    {
                        matchesRoot = true;
                        break;
                    }
                }
                if (!matchesRoot)
                {
                    continue;
                }

                // Try again to find a composite single pile move.
                move.ToRow = -1;
                CheckOne(move);
            }
        }