private void dealClick(object sender, RoutedEventArgs e)
        {
            try
            {
                pack = new Pack();

                for (int handNum = 0; handNum < NumHands; handNum++)
                {
                    hands[handNum] = new Hand();
                    for (int numCards = 0; numCards < Hand.HandSize; numCards++)
                    {
                        PlayingCard cardDealt = pack.DealCardFromPack();
                        hands[handNum].AddCardToHand(cardDealt);
                    }
                }
                north.Text = hands[0].ToString();
                south.Text = hands[0].ToString();
                east.Text = hands[0].ToString();
                west.Text = hands[0].ToString();
            }
            catch (Exception ex)
            {
                MessageDialog msg = new MessageDialog(ex.Message, "Error");
                msg.ShowAsync();
            }
        }
示例#2
0
        /// <summary>
        /// checks tha current Hand for the higher card
        /// </summary>
        /// <param name="card">card to check againts </param>
        /// <param name="h">Current hand of the player</param>
        /// <returns></returns>
        public static bool checkHandForHigherCard(SpadesCard card,Hand h)
        {
            if (card.Suit == CardSuit.Spades && card.Rank == CardRank.Ace) return false;

            foreach (SpadesCard c in h.CardPile)
            {

                if (hasSuit(card.Suit, h))
                {
                    if (c.Suit == card.Suit)
                    {
                        // same suit found
                        if (c.Rank == CardRank.Ace) return true;
                        else if (c.Rank > card.Rank) return true;

                    }
                    // check for spades also
                }
                else
                {
                    if (card.Suit != CardSuit.Spades)
                    {
                        if (c.Suit == CardSuit.Spades) return true; // if spades he has high card
                    }

                }

            }

            return false;
        }
        public bool IsStraight(Hand hand)
        {
            if (hand.Cards.Distinct(rankComparer).Count() != CardsInHandCount)
            {
                return false;
            }
            else
            {
                var cardValues = hand.Cards.Select((x) =>
                {
                    if (x.Rank != Rank.Ace)
                    {
                        return this.GetRankValue(x.Rank);
                    }
                    else
                    {
                        bool higherAce = hand.Cards.Any(y => y.Rank == Rank.King);
                        return this.GetRankValue(x.Rank, higherAce);
                    }
                })
                    .OrderBy(x => x)
                    .ToArray();

                for (int i = 1; i < CardsInHandCount; i++)
                {
                    if (cardValues[i] - 1 != cardValues[i - 1])
                    {
                        return false;
                    }
                }

                return true;
            }
        }
示例#4
0
        private void dealClick(object sender, RoutedEventArgs e)
        {
            try
            {
                pack = new Pack();

                for (int handNum = 0; handNum < NumHands; handNum++)
                {
                    hands[handNum] = new Hand();
                    for (int numCards = 0; numCards < Hand.HandSize; numCards++)
                    {
                        PlayingCard cardDealt = pack.DealCardFromPack();
                        hands[handNum].AddCardToHand(cardDealt);
                    }
                }

                north.Text = hands[0].ToString();
                south.Text = hands[1].ToString();
                east.Text = hands[2].ToString();
                west.Text = hands[3].ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
示例#5
0
 /// <summary>
 /// checks the hand if it has the passed suit or not
 /// </summary>
 /// <param name="suit">Suit of the card to check.</param>
 /// <param name="hand">Hand of the player to check in.</param>
 /// <returns></returns>
 public static bool hasSuit(CardSuit suit, Hand hand)
 {
     foreach (SpadesCard card in hand.CardPile)
     {
         if (Card.SuitFromCardIndex(card.CardIndex) == suit) return true;
     }
     return false;
 }
示例#6
0
        internal Round(HeartsGame game)
        {
            myGame = game;
            myTakenCards = new Hand[game.NumberPlayers];

            for (int i = 0; i < game.NumberPlayers; i++) {
                myTakenCards[i] = new Hand();
            }
        }
示例#7
0
 public void HandExtender_AceToJackIsTenPoints()
 {
     Hand hand = new Hand(new List<ICard>() {
         new Card(SuiteColor.Hearts, CardValue.Jack),
         new Card(SuiteColor.Hearts, CardValue.Queen),
         new Card(SuiteColor.Hearts, CardValue.King),
         new Card(SuiteColor.Hearts, CardValue.Ace),
     });
     Assert.AreEqual(10, hand.Points());
 }
示例#8
0
        public void HandToString()
        {
            Deck deck = new Deck();
            deck.Shuffle(123456);
            IHand[] hands = deck.Deal(13, 1);

            Hand h = new Hand(hands[0]);

            Debug.WriteLine(h.ToString());
        }
 public override void Check(CheckerHelper helper, Hand hand)
 {
     if (helper.IsFlush(hand))
     {
         Console.WriteLine("Flush!");
     }
     else
     {
         this.SuccessiveCombinationChecker.Check(helper, hand);
     }
 }
示例#10
0
        public void TestMethod2()
        {
            Hand hand = new Hand(new List<ICard>() { new Card(SuiteColor.Clubs, CardValue.Five) });

            var list = hand.Clubs.ToList();
            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(new Card(SuiteColor.Clubs, CardValue.Five), list[0]);
            Assert.IsFalse(hand.Diamonds.Any());
            Assert.IsFalse(hand.Hearts.Any());
            Assert.IsFalse(hand.Spades.Any());
        }
 public override void Check(CheckerHelper helper, Hand hand)
 {
     if (helper.HasNOfAKind(hand, 2) && helper.HasNRankGroups(hand, 3))
     {
         Console.WriteLine("Two pairs!");
     }
     else
     {
         this.SuccessiveCombinationChecker.Check(helper, hand);
     }
 }
示例#12
0
 public bool IsValidHand(Hand hand)
 {
     if (hand.Cards.Distinct(fullComparer).Count() != CardsInHandCount)
     {
         return false;
     }
     else
     {
         return true;
     }
 }
示例#13
0
        public void HandToString()
        {
            Deck deck = new Deck();
            deck.Shuffle(123456);
            IHand[] hands = deck.Deal(13, 1);

            Hand h = new Hand(hands[0]);

            Assert.AreEqual(10, h.Points());
            Assert.AreEqual(2, h.ExtraPoints());
        }
 public override void Check(CheckerHelper helper, Hand hand)
 {
     if (helper.HasNOfAKind(hand, 3) && helper.HasNOfAKind(hand, 2))
     {
         Console.WriteLine("Full house!");
     }
     else
     {
         this.SuccessiveCombinationChecker.Check(helper, hand);
     }
 }
 public override void Check(CheckerHelper helper, Hand hand)
 {
     if (helper.HasNOfAKind(hand, 4))
     {
         Console.WriteLine("Four of a kind!");
     }
     else
     {
         this.SuccessiveCombinationChecker.Check(helper, hand);
     }
 }
        public override void Check(CheckerHelper helper, Hand hand)
        {
            if (!helper.IsValidHand(hand))
            {
                Console.WriteLine("Invalid hand.");
                return;
            }

            if (helper.IsFlush(hand) && helper.IsStraight(hand))
            {
                Console.WriteLine("Straight flush!");
            }
            else
            {
                this.SuccessiveCombinationChecker.Check(helper, hand);
            }
        }
示例#17
0
文件: Deck.cs 项目: andrewphoy/Hearts
        public Hand[] Deal(int numPlayers)
        {
            Hand[] hands = new Hand[numPlayers];

            for (int i = 0; i < numPlayers; i++) {
                hands[i] = new Hand();
            }

            while (myCards.Count >= numPlayers) {
                for (int j = 0; j < numPlayers; j++) {
                    hands[j].Add(myCards[0]);
                    myCards.RemoveAt(0);
                }
            }

            // at this point we might still have cards left in the deck, that is fine
            // it is left to the calling program to distribute those cards

            return hands;
        }
示例#18
0
        private int RankBelow(CardSuit cardSuit, Hand hand, CardRank rank)
        {
            int cardCount = 0;
            foreach (SpadesCard card in hand.CardPile)
            {
                if (card.Suit == cardSuit)
                {
                    if (card.Rank < rank || card.Rank != CardRank.Ace)
                    {
                        cardCount++;
                    }
                }
            }

            return cardCount;
        }
示例#19
0
        private int RankAbove(CardSuit cardSuit, Hand hand, CardRank rank)
        {
            int cardCount = 1;

            foreach (SpadesCard card in hand.CardPile)
            {
                if (card.Suit == cardSuit)
                {
                    if (card.Rank >= rank || card.Rank == CardRank.Ace)
                    {
                        cardCount++;
                    }
                }
            }

            return cardCount;
        }
示例#20
0
 private int NumberOfCardInSuit(CardSuit suit, Hand Hand)
 {
     int count = 0;
     foreach (SpadesCard card in Hand.CardPile)
     {
         if (card.Suit == suit)
         {
             count++;
         }
     }
     return count;
 }
示例#21
0
 private bool HasCard(CardSuit suit, CardRank rank, Hand hand)
 {
     foreach (SpadesCard card in hand.CardPile)
     {
         if (card.Rank == rank && card.Suit == suit)
         {
             return true;
         }
     }
     return false;
 }
示例#22
0
 public bool HasNRankGroups(Hand hand, int n)
 {
     return hand.Cards.GroupBy(x => x.Rank).Count() == n;
 }
示例#23
0
        public bool startRound(int round)
        {
            CardUtility.ShufflePile(gameDeck);
            Hand[] hand = new Hand[4];

            int counter = 0;
            for (int j = 0; j < 4; j++)
            {
                hand[j] = new Hand();

                for (int i = counter; i < counter + 13; i++)
                {
                    hand[j].AddCard((SpadesCard)gameDeck.CardPile[i]);
                }

                counter = counter + 13;
                CardUtility.SortBySuit(hand[j]);

            }

            // initialize 4 players hand
            for (int k = 0; k < 4; k++)
            {
                SpadesPlayer[k].Hand = hand[k];
            }

            return true;
        }
示例#24
0
 public void HandExtender_JackIsOnePoints()
 {
     Hand hand = new Hand(new List<ICard>() { new Card(SuiteColor.Hearts, CardValue.Jack) });
     Assert.AreEqual(1, hand.Points());
 }
示例#25
0
 public void HandExtender_EmptyHandGives12ExtraPoints()
 {
     Hand hand = new Hand();
     Assert.AreEqual(12, hand.ExtraPoints());
 }
示例#26
0
 public bool HasNOfAKind(Hand hand, int n)
 {
     return hand.Cards.GroupBy(x => x.Rank).Any(x => x.Count() == n);
 }
示例#27
0
 public void HandExtender_KingIsThreePoints()
 {
     Hand hand = new Hand(new List<ICard>() { new Card(SuiteColor.Hearts, CardValue.King) });
     Assert.AreEqual(3, hand.Points());
 }
示例#28
0
 public void HandExtender_QueenIsTwoPoints()
 {
     Hand hand = new Hand(new List<ICard>() { new Card(SuiteColor.Hearts, CardValue.Queen) });
     Assert.AreEqual(2, hand.Points());
 }
示例#29
0
 public void HandExtender_AceIsFourPoints()
 {
     Hand hand = new Hand(new List<ICard>() { new Card(SuiteColor.Hearts, CardValue.Ace) });
     Assert.AreEqual(1, hand.Count);
     Assert.AreEqual(4, hand.Points());
 }
示例#30
0
 public bool IsFlush(Hand hand)
 {
     return hand.Cards.Distinct(suitComparer).Count() == 1;
 }