Exemplo n.º 1
0
        // uses Dictionary to create/track Pairs/Trips/Quads
        private void analyzePTQ()
        {
            var dict = new Dictionary <int, List <Card> >();

            // sorts Cards in Dictionary based on value
            foreach (Card c1 in availableCards)
            {
                if (dict.ContainsKey(c1.highValue))
                {
                    dict[c1.highValue].Add(c1);
                }
                else
                {
                    dict[c1.highValue] = new List <Card>()
                    {
                        c1
                    };
                }
            }

            // iterates through dictionary and creates Pairs/Trips/Quads when applicable
            foreach (KeyValuePair <int, List <Card> > kv in dict)
            {
                var tempHand = kv.Value;
                switch (tempHand.Count)
                {
                case 2:
                    var pair = new Pair(tempHand);
                    if (bestPair is null || pair.value > bestPair.value)
                    {
                        this.bestPair = pair;
                    }
                    this.pairs.Add(pair);
                    break;

                case 3:
                    var toak = new ThreeOfAKind(tempHand);
                    if (bestTrips is null || toak.value > bestTrips.value)
                    {
                        this.bestTrips = toak;
                    }
                    this.trips.Add(toak);
                    break;

                case 4:
                    if (bestQuads is null || tempHand[0].highValue > bestQuads.value)
                    {
                        this.bestQuads = new FourOfAKind(tempHand);
                    }
                    break;

                default:
                    continue;
                }
            }
        }
Exemplo n.º 2
0
        private void checkForFullHouse()
        {
            ThreeOfAKind toak = null;
            Pair         pair = null;

            foreach (Pair p in pairs)
            {
                if (pair is null || p.value > pair.value)
                {
                    pair = p;
                }
            }

            foreach (ThreeOfAKind t in trips)
            {
                if (toak is null)
                {
                    toak = t;
                }
                else if (t.value > toak.value)
                {
                    ThreeOfAKind temp = toak;
                    toak = t;

                    if (pair is null || temp.value > pair.value)
                    {
                        pair = new Pair(temp.cards.GetRange(0, 2));
                    }
                }
                else if (t.value < toak.value && (pair is null || t.value > pair.value))
                {
                    pair = new Pair(t.cards.GetRange(0, 2));
                }
            }

            if (!(toak is null) && !(pair is null))
            {
                this.bestFullHouse = new FullHouse(toak, pair);
            }
        }
Exemplo n.º 3
0
 public FullHouse(ThreeOfAKind t, Pair p) : base(t.cards.Concat(p.cards).ToList(), t.value, "B", p.value)
 {
 }