public void Shuffle() { Random rng = new Random(); var shuffleCounter = rng.Next(5, 12); int n = Deck.Count; var shuffleDeck = Deck.ToList(); //shuffle between 5 and 12 times for (int i = 0; i < shuffleCounter; i++) { while (n > 1) { n--; int k = rng.Next(n + 1); GridDraftDeckData value = shuffleDeck[k]; shuffleDeck[k] = shuffleDeck[n]; shuffleDeck[n] = value; } } //after shuffling, check weights for (int i = 0; i < Deck.Count; i++) { var currentCard = shuffleDeck[i]; var value = currentCard; //if card has no weight, move on if (currentCard.Weight == 0) { continue; } int swapCardIndex = i; GridDraftDeckData swapCard = value; while (swapCard.Weight < 0 && (i - Deck.Count - 1) >= swapCard.Weight) { swapCardIndex = rng.Next(0, Deck.Count + swapCard.Weight); swapCard = shuffleDeck[swapCardIndex]; } while (swapCard.Weight > 0 && i < swapCard.Weight) { swapCardIndex = rng.Next(swapCard.Weight, Deck.Count); swapCard = shuffleDeck[swapCardIndex]; } shuffleDeck[i] = shuffleDeck[swapCardIndex]; shuffleDeck[swapCardIndex] = value; } Deck = ToDeck(shuffleDeck); CurrentCard = null; }
public void GetPreviousCard() { if (Graveyard.Count > 0) { if (CurrentCard != null) { Deck.Push(CurrentCard); } CurrentCard = Graveyard.Pop(); } }
public void DrawCard() { if (Deck.Count > 0) { if (CurrentCard != null) { Graveyard.Push(CurrentCard); } CurrentCard = Deck.Pop(); } }