本文整理汇总了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();
}
示例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));
}
示例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());
}
示例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));
}
示例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);
}
示例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);
}
示例7: testDeck
public void testDeck()
{
Deck testDeck = new Deck();
testDeck.CreateDeck();
testDeck.DrawCard();
testDeck.Shuffle();
Assert.IsNotNull(testDeck);
}
示例8: Game
public Game()
{
Deck = new Deck();
Deck.Shuffle();
Finished = false;
Moves = 0;
Round = 1;
}
示例9: Deck_Shuffle_VerifyNotInOrder
public void Deck_Shuffle_VerifyNotInOrder()
{
// Arrange
var deck = new Deck();
// Act
deck.Shuffle();
}
示例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()}");
}
示例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]);
}
}
示例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>>()));
}
示例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));
}
}
示例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();
}
示例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);
}
}