/*Generate a random hand from the deck selected. Hand size is altered in the settings. If there are any new cards added, * populate the hand with these first, then, 1/2 chance of a card with score = 1, 1/3 chance of a card with score = 2 and * a 1/6 chance of a card with score = 3.*/ public void GetHand() { Random = new Random(); CardDatabase = new CardDB(Deck); Hand = new ObservableCollection <Card>(); var RandomNumber = 0; var CardDict = new Dictionary <int, ObservableCollection <Card> > { { 0, new ObservableCollection <Card>(CardDatabase.GetCardsWithScore(0)) }, { 1, new ObservableCollection <Card>(CardDatabase.GetCardsWithScore(1)) }, { 2, new ObservableCollection <Card>(CardDatabase.GetCardsWithScore(2)) }, { 3, new ObservableCollection <Card>(CardDatabase.GetCardsWithScore(3)) } }; HandSize = Math.Min(Settings.HandSize, CardDict[0].Count + CardDict[1].Count + CardDict[2].Count + CardDict[3].Count); int Ones = CardDict[1].Count > 0 ? 5 : 0; int Twos = CardDict[2].Count > 0 ? 3 + Ones : 0; int Three = CardDict[3].Count > 0 ? Ones > 0 ? Twos > 0 ? 1 + Twos : Ones + 1 : Twos > 0 ? Twos + 1 : 1 : 0; var OnesRange = Enumerable.Range(0, Ones); var TwosRange = Enumerable.Range(Ones, Twos); var ThreesRange = Enumerable.Range(Twos, Three); while (CardDict[0].Count > 0 && Hand.Count < HandSize) { RandomNumber = Random.Next(0, CardDict[0].Count); Hand.Add(CardDict[0][RandomNumber]); CardDict[0].RemoveAt(RandomNumber); } while (Hand.Count < HandSize) { RandomNumber = Random.Next(0, Three + 1); if (OnesRange.Contains(RandomNumber) && CardDict[1].Count > 0) { RandomNumber = Random.Next(0, CardDict[1].Count); Hand.Add(CardDict[1][RandomNumber]); CardDict[1].RemoveAt(RandomNumber); } else if (TwosRange.Contains(RandomNumber) && CardDict[2].Count > 0) { RandomNumber = Random.Next(0, CardDict[2].Count); Hand.Add(CardDict[2][RandomNumber]); CardDict[2].RemoveAt(RandomNumber); } else if (ThreesRange.Contains(RandomNumber) && CardDict[3].Count > 0) { RandomNumber = Random.Next(0, CardDict[3].Count); Hand.Add(CardDict[3][RandomNumber]); CardDict[3].RemoveAt(RandomNumber); } } }
public void GetCards() { ScheduledScore = DeckDatabase.GetScheduled(Deck); Cards = CardDatabase.GetCardsWithScore(0); if (Cards.Count < 5) { Cards = new ObservableCollection <Card>(Cards.Concat(CardDatabase.GetCardsWithScore(ScheduledScore))); } if (Cards.Count >= 5) { Cards = new ObservableCollection <Card>(Cards.Take(5)); } var x = CardDatabase.GetCards(); if (Cards.Count < HandSize) { FillDeck(); } }