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


C# Bag.Count方法代码示例

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


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

示例1: RemoveUnreachableBasesAndInputs

        /// <summary>
        /// Removes from the propnet all components that are discovered through type
        /// inference to only ever be true or false, replacing them with their values
        /// appropriately. This method may remove base and input propositions that are
        /// shown to be always false (or, in the case of base propositions, those that
        /// are always true).
        /// </summary>
        /// <param name="pn"></param>
        /// <param name="basesTrueByInit">The set of base propositions that are true on the first turn of the game.</param>
        public void RemoveUnreachableBasesAndInputs(PropNet pn, HashSet<IProposition> basesTrueByInit)
        {
            //If this doesn't contain a component, that's the equivalent of Type.NEITHER
            var reachability = new Dictionary<IComponent, Type>();
            //Keep track of the number of true inputs to AND gates and false inputs to
            //OR gates.
            var numTrueInputs = new Bag<IComponent>();
            var numFalseInputs = new Bag<IComponent>();
            var toAdd = new Stack<Tuple<IComponent, TypeCode>>();

            //It's easier here if we get just the one-way version of the map
            var legalsToInputs = new Dictionary<IProposition, IProposition>();
            foreach (IProposition legalProp in pn.LegalPropositions.Values.SelectMany(v => v))
            {
                IProposition inputProp = pn.LegalInputMap[legalProp];
                if (inputProp != null)
                    legalsToInputs[legalProp] = inputProp;
            }

            //All constants have their values
            foreach (IComponent c in pn.Components) //ConcurrencyUtils.checkForInterruption();
                if (c is IConstant)
                    toAdd.Push(c.Value ? Tuple.Create(c, TypeCode.True) : Tuple.Create(c, TypeCode.False));

            //Every input can be false (we assume that no player will have just one move allowed all game)
            foreach (IProposition p in pn.InputPropositions.Values)
                toAdd.Push(Tuple.Create((IComponent)p, TypeCode.False));

            //Every base with "init" can be true, every base without "init" can be false
            foreach (IProposition baseProp in pn.BasePropositions.Values)
                toAdd.Push(basesTrueByInit.Contains(baseProp)
                    ? Tuple.Create((IComponent)baseProp, TypeCode.True)
                    : Tuple.Create((IComponent)baseProp, TypeCode.False));

            //Keep INIT, for those who use it
            IProposition initProposition = pn.InitProposition;
            toAdd.Push(Tuple.Create((IComponent)initProposition, TypeCode.Both));

            while (toAdd.Any())
            {
                //ConcurrencyUtils.checkForInterruption();
                Tuple<IComponent, TypeCode> curEntry = toAdd.Pop();
                IComponent curComp = curEntry.Item1;
                var newInputType = new Type(curEntry.Item2);
                Type oldType = reachability[curComp] ?? new Type(TypeCode.Neither);

                //We want to send only the new addition to our children,
                //for consistency in our parent-true and parent-false
                //counts.
                //Make sure we don't double-apply a type.

                var typeToAdd = new Type(TypeCode.Neither); // Any new values that we discover we can have this iteration.
                if (curComp is IProposition)
                    typeToAdd = newInputType;
                else if (curComp is ITransition)
                    typeToAdd = newInputType;
                else if (curComp is IConstant)
                    typeToAdd = newInputType;
                else if (curComp is INot)
                    typeToAdd = new Type(newInputType.Opposite());
                else if (curComp is IAnd)
                {
                    if (newInputType.HasTrue)
                    {
                        numTrueInputs.Add(curComp);
                        if (numTrueInputs.Count(n => n == curComp) == curComp.Inputs.Count)
                            typeToAdd = new Type(TypeCode.True);
                    }
                    if (newInputType.HasFalse)
                        typeToAdd = new Type(typeToAdd.With(TypeCode.False));
                }
                else if (curComp is IOr)
                {
                    if (newInputType.HasFalse)
                    {
                        numFalseInputs.Add(curComp);
                        if (numFalseInputs.Count(n => n == curComp) == curComp.Inputs.Count)
                            typeToAdd = new Type(TypeCode.False);
                    }
                    if (newInputType.HasTrue)
                        typeToAdd = new Type(typeToAdd.With(TypeCode.True));
                }
                else
                    throw new Exception("Unhandled component type " + curComp.GetType());

                if (oldType.Includes(typeToAdd)) //We don't know anything new about curComp
                    continue;

                reachability[curComp] = new Type(typeToAdd.With(oldType));
                typeToAdd = new Type(typeToAdd.Minus(oldType));
                if (typeToAdd == TypeCode.Neither)
//.........这里部分代码省略.........
开发者ID:druzil,项目名称:nggp-base,代码行数:101,代码来源:PropNetFactoryUtils.cs


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