示例#1
0
        private Stack <int>[] Shuffle(Stack <int>[] a, int cMoves)
        {
            Stack <int>[] aShuffled = new Stack <int> [a.Length];
            for (int i = 0; i < a.Length; i++)
            {
                aShuffled[i] = new Stack <int>(a[i]);
            }

            for (int i = 0; i < cMoves; i++)
            {
                int iStack = RandomGenerator.Next(aShuffled.Length);
                if (aShuffled[iStack].Count == 0)
                {
                    continue;
                }
                int iTargetStack = -1;
                if (iStack == 0 || (iStack < a.Length - 1 && RandomGenerator.NextDouble() < 0.5))
                {
                    iTargetStack = iStack + 1;
                }
                else
                {
                    iTargetStack = iStack - 1;
                }

                int iBlock = aShuffled[iStack].Pop();
                aShuffled[iTargetStack].Push(iBlock);
            }
            return(aShuffled);
        }
示例#2
0
        //implements a two cycle map
        private int AssignStacksToAgents()
        {
            //first we create a cycle of all but one
            m_lAgentStacks = new List <List <int> >();
            int        iCurrentStack = 0;
            bool       bSmallAgent   = false;
            List <int> lStacks       = null;

            for (int i = 0; i < Arms - 1; i++)
            {
                double dRand = RandomGenerator.NextDouble();
                bSmallAgent = dRand < 0.0;

                int cStacks = 0;
                if (bSmallAgent)
                {
                    cStacks = RandomGenerator.Next(2) + 3;
                }
                else
                {
                    cStacks = RandomGenerator.Next(MaxStacksPerAgent / 2) + MaxStacksPerAgent / 2 + 3;
                }
                lStacks = new List <int>();
                for (int j = 0; j < cStacks; j++)
                {
                    lStacks.Add(iCurrentStack + j);
                }
                m_lAgentStacks.Add(lStacks);
                iCurrentStack += cStacks - 1;
            }
            m_lAgentStacks.Last().Add(0);
            int iConnectStack1 = RandomGenerator.Next(iCurrentStack / 2);
            int iConnectStack2 = RandomGenerator.Next(iCurrentStack / 2) + iCurrentStack / 2;


            //now we cut the cycle in half
            lStacks = new List <int>();
            lStacks.Add(iConnectStack1);
            lStacks.Add(iCurrentStack + 1);
            lStacks.Add(iConnectStack2);
            m_lAgentStacks.Add(lStacks);

            m_lPublicStacks = new List <int>();
            for (int iStack = 0; iStack < iCurrentStack + 1; iStack++)
            {
                int cReachingArms = 0;
                foreach (List <int> l in m_lAgentStacks)
                {
                    if (l.Contains(iStack))
                    {
                        cReachingArms++;
                    }
                }
                if (cReachingArms > 1)
                {
                    m_lPublicStacks.Add(iStack);
                }
            }


            return(iCurrentStack + 2);
        }