Пример #1
0
        private int EvalutePointsOnPartnerAnnounce(Card targetCard)
        {
            // 1.2
            int       points        = 0;
            const int POINTS_TO_ADD = 10;

            foreach (KeyValuePair <Announcement, Player> kv in _allAnnounces)
            {
                Announcement announce = kv.Key;
                if (announce.Type == AnnouncementTypeEnum.Spades ||
                    announce.Type == AnnouncementTypeEnum.Hearts ||
                    announce.Type == AnnouncementTypeEnum.Diamonds ||
                    announce.Type == AnnouncementTypeEnum.Clubs)
                {
                    if (targetCard.CardColor == GetCardColor(announce.Type))
                    {
                        Player player = kv.Value;

                        if (player == _playingManager.GetPartner(this))
                        {
                            points += POINTS_TO_ADD;
                        }

                        if (player != this && player != _playingManager.GetPartner(this))
                        {
                            points -= POINTS_TO_ADD;
                        }
                    }
                }
            }

            return(points);
        }
Пример #2
0
        protected override void PlayCard(PlayingManager manager)
        {
            Card selectedCard = null;

            _playingManager = manager;

            IList <Card> validCards = GetValidCards();

            if (manager.CurrentHand.IsEmpty)               // 2.1
            {
                #region 2.1

                int  maxEvaluated     = 0;
                Card maxEvaluatedCard = null;

                foreach (Card card in validCards)
                {
                    int points = EvalutePointsOnRemaining(card);
                    points += EvalutePointsOnPartnerAnnounce(card);
                    points += EvalutePointsOnTrumpColor(card);

                    if (points > maxEvaluated)
                    {
                        maxEvaluated     = points;
                        maxEvaluatedCard = card;
                    }
                }

                if (maxEvaluatedCard != null)
                {
                    #region 2.1.1

                    if (IsCurrentMaxCardInPlayingColor(maxEvaluatedCard))
                    {
                        #region 2.1.1.1

                        selectedCard = maxEvaluatedCard;

                        #endregion
                    }
                    else
                    {
                        #region 2.1.1.2

                        int  minPlayingPoints     = 1000;                    // incorrect but big enough value;
                        Card minPlayingPointsCard = null;

                        foreach (Card card in validCards)
                        {
                            if (card.CardColor == maxEvaluatedCard.CardColor)
                            {
                                int points = CardPointEvaluator.EvaluateCard(_playingManager.CurrentAnnouncement.Type, card);
                                if (points < minPlayingPoints)
                                {
                                    minPlayingPoints     = points;
                                    minPlayingPointsCard = card;
                                }
                            }
                        }

                        selectedCard = minPlayingPointsCard;

                        #endregion
                    }

                    #endregion
                }
                else
                {
                    #region 2.1.2

                    Random rand = new Random();
                    selectedCard = validCards[rand.Next(validCards.Count)] as Card;

                    #endregion
                }

                #endregion
            }
            else             //2.2
            {
                #region 2.2

                Card currentMaxCardInPlayingColor = null;
                foreach (Card card in validCards)
                {
                    if (card.CardColor == GetPlayingColor() && IsCurrentMaxCardInPlayingColor(card))
                    {
                        currentMaxCardInPlayingColor = card;
                        break;
                    }
                }

                if (currentMaxCardInPlayingColor != null)                   // 2.2.1
                {
                    selectedCard = currentMaxCardInPlayingColor;
                }
                else                 // 2.2.2
                {
                    #region 2.2.2

                    IList <CardColor> zeroEvaluatedColors;

                    if (FindZeroEvaluatedColor(validCards, out zeroEvaluatedColors))                         // 2.2.2.1
                    {
                        #region 2.2.2.1

                        Card   biggestCardInHand = _playingManager.GetBiggestCard();
                        Player partner           = _playingManager.GetPartner(this);
                        if (IsCurrentMaxCardInPlayingColor(biggestCardInHand) &&
                            _playingManager.GetPlayerWhoPlayedCard(biggestCardInHand) == partner)                                 //2.2.2.1.1
                        {
                            #region 2.2.2.1.1

                            int  maxPlayingPoints     = -100;
                            Card maxPlayingPointsCard = null;

                            foreach (Card card in validCards)
                            {
                                foreach (CardColor color in zeroEvaluatedColors)
                                {
                                    // we are in case 2.2.2.1 so we know card evaluated to 0 points exists
                                    if (card.CardColor == color)
                                    {
                                        int points = CardPointEvaluator.EvaluateCard(_playingManager.CurrentAnnouncement.Type, card);
                                        if (points > maxPlayingPoints)
                                        {
                                            maxPlayingPoints     = points;
                                            maxPlayingPointsCard = card;
                                        }
                                    }
                                }
                            }

                            selectedCard = maxPlayingPointsCard;

                            #endregion
                        }
                        else                         // 2.2.2.1.2
                        {
                            #region 2.2.2.1.2

                            int  minPlayingPoints     = 1000;                        // incorrect but big enough value;
                            Card minPlayingPointsCard = null;

                            foreach (Card card in validCards)
                            {
                                foreach (CardColor color in zeroEvaluatedColors)
                                {
                                    // we are in case 2.2.2.1 so we know card evaluated to 0 points exists
                                    if (card.CardColor == color)
                                    {
                                        int points = CardPointEvaluator.EvaluateCard(_playingManager.CurrentAnnouncement.Type, card);
                                        if (points < minPlayingPoints)
                                        {
                                            minPlayingPoints     = points;
                                            minPlayingPointsCard = card;
                                        }
                                    }
                                }
                            }

                            selectedCard = minPlayingPointsCard;

                            #endregion
                        }


                        #endregion
                    }
                    else                     // 2.2.2.2
                    {
                        #region 2.2.2.2

                        Card   biggestCardInHand = _playingManager.GetBiggestCard();
                        Player partner           = _playingManager.GetPartner(this);
                        if (IsCurrentMaxCardInPlayingColor(biggestCardInHand) &&
                            _playingManager.GetPlayerWhoPlayedCard(biggestCardInHand) == partner)                                 //2.2.2.2.1
                        {
                            #region 2.2.2.2.1

                            int  minEvaluated     = 1000;
                            Card minEvaluatedCard = null;

                            foreach (Card card in validCards)
                            {
                                int pointsOnRemaining = EvalutePointsOnRemaining(card);
                                // we are in case 2.2.2.2 so we know card evaluated >0 exists
                                if (pointsOnRemaining < minEvaluated)
                                {
                                    minEvaluated     = pointsOnRemaining;
                                    minEvaluatedCard = card;
                                }
                            }

                            selectedCard = minEvaluatedCard;

                            #endregion
                        }
                        else                         // 2.2.2.2.2
                        {
                            #region 2.2.2.2.2

                            int  minPlayingPoints     = 1000;                        // incorrect but big enough value;
                            int  minOnRemainingPoints = 1000;
                            Card minPlayingPointsCard = null;
                            Card minOnRemainingCard   = null;

                            foreach (Card card in validCards)
                            {
                                int pointsOnRemaining = EvalutePointsOnRemaining(card);
                                pointsOnRemaining += EvalutePointsOnPartnerAnnounce(card);

                                int points = CardPointEvaluator.EvaluateCard(_playingManager.CurrentAnnouncement.Type, card);
                                if (points < minPlayingPoints)
                                {
                                    minPlayingPoints     = points;
                                    minPlayingPointsCard = card;
                                }

                                if (pointsOnRemaining <= 0 && points < minOnRemainingPoints)
                                {
                                    minOnRemainingPoints = points;
                                    minOnRemainingCard   = card;
                                }
                            }

                            if (minOnRemainingCard == null)
                            {
                                selectedCard = minPlayingPointsCard;
                            }
                            else
                            {
                                selectedCard = minOnRemainingCard;
                            }

                            #endregion
                        }


                        #endregion
                    }

                    #endregion
                }

                #endregion
            }

            Debug.Assert(selectedCard != null);

            RaiseCardPlayed(selectedCard);
        }