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


C# Deck.Shuffle方法代码示例

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


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

示例1: Main

        static void Main(string[] args)
        {
            Deck deck1 = new Deck();
            Deck deck2 = new Deck();

            int step = 0;
            bool flag = false;
            while (!flag)
            {
                deck2.Shuffle();
                for (int j = 0; j < 52; j++)
                {
                    if (deck1[j].ShortName == deck2[j].ShortName) flag = true;
                }
                step++;
            }

            for (int j = 0; j < 52; j++)
            {
                Console.WriteLine(String.Format("{0} \t{2}\t {1}", deck1[j].ShortName, deck2[j].ShortName, (deck1[j].ShortName == deck2[j].ShortName)?"-----":"     "));
            }
            Console.WriteLine(step);

            Console.ReadLine();
        }
开发者ID:Verdungo,项目名称:SNet,代码行数:25,代码来源:Program.cs

示例2: Deck_Should_Be_Without_Duplicates_After_Shuffle

        public void Deck_Should_Be_Without_Duplicates_After_Shuffle()
        {
            var deck = new Deck();
            var shuffledDeck = deck.Shuffle(deck.DeckBuilder());

            Assert.IsTrue(deck.IsDeckValid(shuffledDeck));
        }
开发者ID:bryagd,项目名称:CardDojo,代码行数:7,代码来源:CardShuffle.cs

示例3: Deck_Shuffle_Test

        public void Deck_Shuffle_Test()
        {
            // Arrange
            var position = 0;
            var newPosition = 0;
            var deck = new Deck();
            var positions = deck.Cards.ToDictionary(c => c, c => position++);

            // Act
            deck.Shuffle();

            foreach (var card in deck.Cards)
            {
                Console.WriteLine(card);
            }

            var positionChangeCount = deck.Cards.Select(c => positions[c] == newPosition++ ? 0 : 1).Sum();

            // Assert
            Assert.IsTrue(positionChangeCount > 52 * .9);
            Assert.AreEqual(52, deck.Cards.Count);
            Assert.AreEqual(52, deck.Cards.Distinct().Count());
            Assert.AreEqual(52, deck.Cards.Select(c => c.ToString()).Distinct().Count());
            Assert.AreEqual(52, deck.Cards.Select(c => c.GetHashCode()).Distinct().Count());
        }
开发者ID:makalainspire,项目名称:Programming,代码行数:25,代码来源:DeckTest.cs

示例4: Shuffle_atDifferentTimes_produceDifferentOrders

        public void Shuffle_atDifferentTimes_produceDifferentOrders()
        {
            // arrange:
            SerialNumber number = new SerialNumber();
            IDeck deck = new Deck(number);
            DateTime time = DateTime.Now;

            // act:
            deck.Shuffle(time);
            Card[] afterFirstShuffle = deck.ToArray();
            deck.Shuffle(time + new TimeSpan(100)); // just to be sure :-D
            Card[] afterSecondShuffle = deck.ToArray();

            // assert:
            Assert.IsFalse(afterFirstShuffle.SequenceEqual(afterSecondShuffle));
        }
开发者ID:Shamar,项目名称:FunnyHacks,代码行数:16,代码来源:DeckQA.cs

示例5: WhenADeckIsShuffled_TheCardsAreNotInExactlyTheSameOrderAsBefore

        public void WhenADeckIsShuffled_TheCardsAreNotInExactlyTheSameOrderAsBefore()
        {
            var deck = new Deck();
            var expectedCardString = string.Empty;

            // Add Cards to Deck
            for (var i = 1; i <= 9; i++)
            {
                var card = deck.Push(new Cards.Number(i, CardColour.Blue));
                expectedCardString += string.Format("{0}{1}", card.Colour, card.Value);
            }

            // Shuffle the Deck
            deck.Shuffle();

            // Remove Cards from Deck
            var cards = new List<ICard>();
            while (deck.NumberOfCardsInDeck > 0)
            {
                cards.Add(deck.Pop());
            }

            // Build Compare Strings in reverse order because the Deck is a Stack (LIFO).  (I understand due to the way shuffling occurs that in theory the decks could be identical in some universe)
            var actualCardString = string.Empty;
            for (var i = cards.Count - 1; i >= 0; i--)
            {
                actualCardString += string.Format("{0}{1}", cards[i].Colour, cards[i].Value);
            }

            Assert.AreNotEqual(actualCardString, expectedCardString);
        }
开发者ID:robisoft,项目名称:Uno,代码行数:31,代码来源:DeckTests.cs

示例6: Awake

    void Awake()
    {
        Deck deck1 = new Deck();
        deck1.Shuffle();
        Card card1 = deck1.TakeCard();
        Card[] hand1 = new Card[5];
        hand1Size = hand1.Length;  // atribui o numero de cartas na mao

        for (i = 0; i < hand1.Length; i++)
        {
            hand1[i] = deck1.TakeCard();
        }

        //hand1[] = deck1.TakeCards(3);

        //IEnumerable < Card > = deck1.TakeCards();
        //Card mao1[] = deck1.TakeCards();

        //Debug.Log( card1.Suit.ToString() + card1.CardNumber.ToString() );
        for (i = 0; i < hand1.Length; i++)
        {
            Debug.Log(hand1[i].Suit.ToString() + hand1[i].CardNumber.ToString());
        }

        Debug.Log("tamanho da mao: " + hand1Size);
    }
开发者ID:daltonbr,项目名称:truco,代码行数:26,代码来源:DeckManager.cs

示例7: testDeck

 public void testDeck()
 {
     Deck testDeck = new Deck();
     testDeck.CreateDeck();
     testDeck.DrawCard();
     testDeck.Shuffle();
     Assert.IsNotNull(testDeck);
 }
开发者ID:BryantN,项目名称:Sorry,代码行数:8,代码来源:DeckTest.cs

示例8: Game

 public Game()
 {
     Deck = new Deck();
     Deck.Shuffle();
     Finished = false;
     Moves = 0;
     Round = 1;
 }
开发者ID:lovlka,项目名称:cornball-silverlight,代码行数:8,代码来源:Game.cs

示例9: Deck_Shuffle_VerifyNotInOrder

        public void Deck_Shuffle_VerifyNotInOrder()
        {
            // Arrange
            var deck = new Deck();

            // Act
            deck.Shuffle();
        }
开发者ID:wbish,项目名称:wirk,代码行数:8,代码来源:DeckUnitTests.cs

示例10: TestDeck

 public static void TestDeck()
 {
     Console.ForegroundColor = ConsoleColor.Cyan;
     var d = new Deck();
     d.Shuffle();
     for (var i = 0; i < 52; i += 4)
         Console.WriteLine($"{i + 1}: {d.Pop()}   {i + 2}: {d.Pop()}   {i + 3}: {d.Pop()}   {i + 4}: {d.Pop()}");
 }
开发者ID:Anders-H,项目名称:GenericPokerFormationChecker,代码行数:8,代码来源:Program.cs

示例11: Shuffle_withTheSameTimeOnTheSameDeck_isIdempotent

        public void Shuffle_withTheSameTimeOnTheSameDeck_isIdempotent()
        {
            // arrange:
            SerialNumber number = new SerialNumber();
            IDeck deck = new Deck(number);
            DateTime time = DateTime.Now;

            // act:
            deck.Shuffle(time);
            Card[] afterFirstShuffle = deck.ToArray();
            deck.Shuffle(time);
            Card[] afterSecondShuffle = deck.ToArray();

            // assert:
            for(int i = 0; i < deck.Count(); ++i)
            {
                Assert.AreSame(afterFirstShuffle[i], afterSecondShuffle[i]);
            }
        }
开发者ID:Shamar,项目名称:FunnyHacks,代码行数:19,代码来源:DeckQA.cs

示例12: Shuffle_ShouldShuffleSuccessfully

        public void Shuffle_ShouldShuffleSuccessfully()
        {
            var shuffleMock = OpositeOrderShufflerMock();
            var initCards = RandomStandartCards();
            var deck = new Deck<StandartCard>(shuffleMock.Object, initCards);

            deck.Shuffle();

            shuffleMock.Verify(x => x.Shuffle(It.IsAny<List<StandartCard>>()));
        }
开发者ID:benasradzevicius9404,项目名称:opp-poker,代码行数:10,代码来源:StandartDeckTests.cs

示例13: RunManyMaxAverageDecisions

        public void RunManyMaxAverageDecisions()
        {
            var decision = new MaxAverageDecision();
            var deck = new Deck();

            foreach (var index in Enumerable.Range(0, 1000))
            {
                deck.Shuffle();
                decision.DetermineCardsToThrow(deck.Take(6));
            }
        }
开发者ID:jacerhea,项目名称:Skunked,代码行数:11,代码来源:MaxAverageDecisionPerformanceTest.cs

示例14: Game

 public Game(Player Master, List<Player> Learners, Random Random)
 {
     _Random = Random;
     _Deck = new Deck();
     _Deck.Shuffle(_Random);
     _Return = new Deck(true);
     _Master = Master;
     _Learners = Learners;
     _MasterHand = new Hand(10, _Deck);
     foreach(Player L in _Learners) _LearnerHands.Add(new Hand(10, _Deck));
     _DownCard = _Deck.Draw();
 }
开发者ID:lawrencewade,项目名称:cs440,代码行数:12,代码来源:Game.cs

示例15: TestSort

 public void TestSort()
 {
     var trials = 100; // Arbitrary number
     var newDeck = new Deck();
     var deck = new Deck();
     for (int i = 0; i < trials; i++)
     {
         deck.Shuffle();
         Assert.AreNotEqual(newDeck, deck);
         deck.Sort();
         Assert.AreEqual<Deck>(newDeck, deck);
     }
 }
开发者ID:lguthrie,项目名称:CodingExercise,代码行数:13,代码来源:UnitTests.cs


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