示例#1
0
        public void Test_Random()
        {
            int REPETITIONS = 100;

#if DEBUG
            REPETITIONS = 8;
#endif

            int seed = (int)DateTime.Now.Ticks;
            Console.WriteLine("Random seed {0}", seed);
            Random rand = new Random(seed);
            _cardRng = new SequenceRng(seed);
            _cardRng.SetSequence(StdDeck.Descriptor.FullDeckIndexes);
            for (int r = 0; r < REPETITIONS; ++r)
            {
                _enumCount = r % 7;
                int sharedCount = rand.Next(0, StdDeck.Descriptor.Size + 1 - _enumCount);
                int deadCount   = rand.Next(0, StdDeck.Descriptor.Size + 1 - sharedCount - _enumCount);

                _cardRng.Shuffle(sharedCount + deadCount);
                int rc = 0;

                _shared = new CardSet();
                for (int i = 0; i < sharedCount; ++i)
                {
                    _shared |= StdDeck.Descriptor.CardSets[_cardRng.Sequence[rc++]];
                }

                _dead = new CardSet();
                for (int i = 0; i < deadCount; ++i)
                {
                    _dead |= StdDeck.Descriptor.CardSets[_cardRng.Sequence[rc++]];
                }
                Debug.Assert(rc == sharedCount + deadCount);
                Debug.Assert(!_shared.IsIntersectingWith(_dead));

                //Console.WriteLine("B: {0:x16} D:{1:x16}", board, dead);
                _combinationsCount = 0;
                _lastCs            = 0;
                CardEnum.Combin(StdDeck.Descriptor, _enumCount, _shared, _dead, VerifyCombination);
                Assert.AreEqual(EnumAlgos.CountCombin(StdDeck.Descriptor.Size - sharedCount - deadCount, _enumCount), _combinationsCount);

                _combinationsCount1 = 0;
                _lastCs1            = 0;
                CardEnum.Combin(StdDeck.Descriptor, _enumCount, _shared, _dead, VerifyCombinationParam, _combinationsCount);
                Assert.AreEqual(EnumAlgos.CountCombin(StdDeck.Descriptor.Size - sharedCount - deadCount, _enumCount), _combinationsCount1);

                _combinationsCount1 = 0;
                _lastCs1            = 0;
                int[] cards = new int[_enumCount + sharedCount].Fill(-1);
                StdDeck.Descriptor.GetIndexesAscending(_shared).ToArray().CopyTo(cards, 0);
                int[] deadIdx = StdDeck.Descriptor.GetIndexesAscending(_shared | _dead).ToArray();

                CardEnum.Combin(StdDeck.Descriptor, _enumCount, cards, sharedCount, deadIdx, deadIdx.Length, VerifyCombinationParam, _combinationsCount);
                Assert.AreEqual(EnumAlgos.CountCombin(StdDeck.Descriptor.Size - sharedCount - deadCount, _enumCount), _combinationsCount1);
            }
            Console.WriteLine("{0} repetitions done.", REPETITIONS);
        }
示例#2
0
        public void Test_Shuffle()
        {
            // Make sure that shuffling from some start does not overwrite the beginning of the sequence
            int []      sequence = new int[10].Fill(i => i);
            SequenceRng sr       = new SequenceRng();

            for (int start = 0; start <= sequence.Length; start++)
            {
                sr.SetSequence(sequence);
                sr.Shuffle(start, sequence.Length - start);
                for (int i = 0; i < start; ++i)
                {
                    Assert.AreEqual(i, sr.Sequence[i]);
                }
            }
        }
示例#3
0
        public void Test_SameSeed()
        {
            int[] sequence = (new int[256]).Fill(i => i);

            int         seed = 123;
            SequenceRng rng1;
            SequenceRng rng2;

            // Case 1
            rng1 = new SequenceRng(seed);
            rng2 = new SequenceRng(seed);
            rng1.SetSequence(sequence);
            rng2.SetSequence(sequence);
            rng1.Shuffle();
            rng2.Shuffle();
            Assert.AreEqual(rng1.Sequence, rng2.Sequence);

            // Case 2
            rng1 = new SequenceRng(seed, sequence);
            rng2 = new SequenceRng(seed, sequence);
            rng1.Shuffle();
            rng2.Shuffle();
            Assert.AreEqual(rng1.Sequence, rng2.Sequence);

            // Case 3
            rng1 = new SequenceRng(new Random(seed));
            rng2 = new SequenceRng(new Random(seed));
            rng1.SetSequence(sequence);
            rng2.SetSequence(sequence);
            rng1.Shuffle();
            rng2.Shuffle();
            Assert.AreEqual(rng1.Sequence, rng2.Sequence);

            // Case 4
            rng1 = new SequenceRng(new Random(seed), sequence);
            rng2 = new SequenceRng(new Random(seed), sequence);
            rng1.Shuffle();
            rng2.Shuffle();
            Assert.AreEqual(rng1.Sequence, rng2.Sequence);
        }
示例#4
0
        static public void InitHe(Algo algo, int bucketsCount, bool shuffle)
        {
            algo.Buckets = new Bucket[bucketsCount].Fill(i => new Bucket());

            SequenceRng shuffler = new SequenceRng();

            shuffler.SetSequence(169);
            if (shuffle)
            {
                shuffler.Shuffle();
            }

            double handsInBucket = HePocket.Count / bucketsCount;

            for (int p = 0; p < HePocket.Count; ++p)
            {
                int b = (int)(p / handsInBucket);
                if (b >= bucketsCount)
                {
                    b = bucketsCount - 1;
                }
                algo.Buckets[b].Cards.Add(shuffler.Sequence[p]);
            }
        }