public void shuffle(CardDeck deck) { CardDeck tempDeck = new CardDeck(); tempDeck.assign(deck); deck.clear(); Random rnd = new Random(); int randomIndex; while (tempDeck.Count > 0) { randomIndex = rnd.Next(tempDeck.Count); AbstractCard card = tempDeck.getCardAt(randomIndex); deck.addCard(card); tempDeck.removeCardAt(randomIndex); } }
public void shuffle(CardDeck deck) { if (deck != null && deck.Count > 1) { if (this.reverseFrom > this.reverseTo) { int temp = this.reverseFrom; this.reverseFrom = this.reverseTo; this.reverseTo = temp; } if (this.reverseFrom < 0) { this.reverseFrom = 0; } if (this.reverseTo > deck.Count - 1) { this.reverseTo = deck.Count - 1; } if (this.reverseFrom != this.reverseTo) { CardDeck tempDeck = new CardDeck(); tempDeck.assign(deck); deck.clear(); for (int i = 0; i < this.reverseFrom; i++) { deck.addCard(tempDeck.getCardAt(i)); } for (int i = this.reverseTo; i >= this.reverseFrom; i--) { deck.addCard(tempDeck.getCardAt(i)); } for (int i = this.reverseTo + 1; i < tempDeck.Count; i++) { deck.addCard(tempDeck.getCardAt(i)); } } } }
public void shuffle(CardDeck deck) { for (int i = 0; i < deck.Count; i++) { AbstractCard card = deck.getCardAt(i); if (!((card.faceSide is CardSide) && (card.backSide is BackSide))) { return; } } CardDeck tempDeck = new CardDeck(); tempDeck.assign(deck); deck.clear(); for (CardValue v = CardValue.Ace; v <= CardValue.King; v++) { for (int i = 0; i < tempDeck.Count; i++) { AbstractCard card = tempDeck.getCardAt(i); AbstractSide cside = card.faceSide; if (cside is CardSide) { CardSide side = (CardSide) cside; if ((side.cardValue == v) && (side.suit == Suit.Hearts)) { deck.addCard(card); } } } } for (CardValue v = CardValue.Ace; v <= CardValue.King; v++) { for (int i = 0; i < tempDeck.Count; i++) { AbstractCard card = tempDeck.getCardAt(i); AbstractSide cside = card.faceSide; if (cside is CardSide) { CardSide side = (CardSide) cside; if ((side.cardValue == v) && (side.suit == Suit.Clubs)) { deck.addCard(card); } } } } for (CardValue v = CardValue.King; v >= CardValue.Ace; v--) { for (int i = 0; i < tempDeck.Count; i++) { AbstractCard card = tempDeck.getCardAt(i); AbstractSide cside = card.faceSide; if (cside is CardSide) { CardSide side = (CardSide) cside; if ((side.cardValue == v) && (side.suit == Suit.Diamonds)) { deck.addCard(card); } } } } for (CardValue v = CardValue.King; v >= CardValue.Ace; v--) { for (int i = 0; i < tempDeck.Count; i++) { AbstractCard card = tempDeck.getCardAt(i); AbstractSide cside = card.faceSide; if (cside is CardSide) { CardSide side = (CardSide) cside; if ((side.cardValue == v) && (side.suit == Suit.Spades)) { deck.addCard(card); } } } } }