Exemplo n.º 1
0
        public override Announcement MakeAnnouncement(AnnouncementManager manager)
        {
            _allAnnounces = manager.GetAllAnnouncements();

            Announcement announce     = null;
            bool         isValidFound = false;
            int          sum          = 0;
            int          count        = 0;

            const int MIN_FOR_TRUMP     = 34;
            const int MIN_FOR_NOTRUMPS  = 34;
            const int MIN_FOR_ALLTRUMPS = 60;

            //const int POINTS_TO_ADD = 5; // add 5 or 10 points if player has 4 or 5 cards of same color

            #region Check Clubs
            if (!isValidFound)
            {
                foreach (Card card in this.Cards)
                {
                    sum += CardPointEvaluator.EvaluateCard(AnnouncementTypeEnum.Clubs, card);

                    if (card.CardColor == CardColor.Clubs)
                    {
                        count++;
                    }
                }

                if (sum > MIN_FOR_TRUMP && count > 2)
                {
                    if (AnnouncementTypeEnum.Clubs == manager.GetLastValidAnnouncement().Type)
                    {
                        announce = new Announcement(AnnouncementTypeEnum.Clubs, true, false);
                    }
                    else
                    {
                        announce = new Announcement(AnnouncementTypeEnum.Clubs, false, false);
                    }
                    isValidFound = manager.IsValid(this, announce);
                }
            }
            #endregion

            #region Check Diamonds
            sum   = 0;
            count = 0;
            if (!isValidFound)
            {
                foreach (Card card in this.Cards)
                {
                    sum += CardPointEvaluator.EvaluateCard(AnnouncementTypeEnum.Diamonds, card);

                    if (card.CardColor == CardColor.Diamonds)
                    {
                        count++;
                    }
                }

                if (sum > MIN_FOR_TRUMP && count > 2)
                {
                    if (AnnouncementTypeEnum.Diamonds == manager.GetLastValidAnnouncement().Type)
                    {
                        announce = new Announcement(AnnouncementTypeEnum.Diamonds, true, false);
                    }
                    else
                    {
                        announce = new Announcement(AnnouncementTypeEnum.Diamonds, false, false);
                    }
                    isValidFound = manager.IsValid(this, announce);
                }
            }
            #endregion

            #region Check Hearts
            sum   = 0;
            count = 0;
            if (!isValidFound)
            {
                foreach (Card card in this.Cards)
                {
                    sum += CardPointEvaluator.EvaluateCard(AnnouncementTypeEnum.Hearts, card);

                    if (card.CardColor == CardColor.Hearts)
                    {
                        count++;
                    }
                }

                if (sum > MIN_FOR_TRUMP && count > 2)
                {
                    if (AnnouncementTypeEnum.Hearts == manager.GetLastValidAnnouncement().Type)
                    {
                        announce = new Announcement(AnnouncementTypeEnum.Hearts, true, false);
                    }
                    else
                    {
                        announce = new Announcement(AnnouncementTypeEnum.Hearts, false, false);
                    }
                    isValidFound = manager.IsValid(this, announce);
                }
            }
            #endregion

            #region Check Spades
            sum   = 0;
            count = 0;
            if (!isValidFound)
            {
                foreach (Card card in this.Cards)
                {
                    sum += CardPointEvaluator.EvaluateCard(AnnouncementTypeEnum.Spades, card);

                    if (card.CardColor == CardColor.Spades)
                    {
                        count++;
                    }
                }

                if (sum > MIN_FOR_TRUMP && count > 2)
                {
                    if (AnnouncementTypeEnum.Spades == manager.GetLastValidAnnouncement().Type)
                    {
                        announce = new Announcement(AnnouncementTypeEnum.Spades, true, false);
                    }
                    else
                    {
                        announce = new Announcement(AnnouncementTypeEnum.Spades, false, false);
                    }
                    isValidFound = manager.IsValid(this, announce);
                }
            }
            #endregion

            #region Check No Trumps
            sum = 0;
            if (!isValidFound)
            {
                foreach (Card card in this.Cards)
                {
                    sum += CardPointEvaluator.EvaluateCard(AnnouncementTypeEnum.NoTrumps, card);
                }

                if (sum > MIN_FOR_NOTRUMPS)
                {
                    if (AnnouncementTypeEnum.NoTrumps == manager.GetLastValidAnnouncement().Type)
                    {
                        announce = new Announcement(AnnouncementTypeEnum.NoTrumps, true, false);
                    }
                    else
                    {
                        announce = new Announcement(AnnouncementTypeEnum.NoTrumps, false, false);
                    }
                    isValidFound = manager.IsValid(this, announce);
                }
            }
            #endregion

            #region Check All Trumps
            sum   = 0;
            count = 0;
            if (!isValidFound)
            {
                foreach (Card card in this.Cards)
                {
                    sum += CardPointEvaluator.EvaluateCard(AnnouncementTypeEnum.AllTrumps, card);
                }

                if (sum > MIN_FOR_ALLTRUMPS)
                {
                    if (AnnouncementTypeEnum.AllTrumps == manager.GetLastValidAnnouncement().Type)
                    {
                        announce = new Announcement(AnnouncementTypeEnum.AllTrumps, true, false);
                    }
                    else
                    {
                        announce = new Announcement(AnnouncementTypeEnum.AllTrumps, false, false);
                    }
                    isValidFound = manager.IsValid(this, announce);
                }
            }
            #endregion


            if (!isValidFound)
            {
                announce = new Announcement(AnnouncementTypeEnum.Pass, false, false);
            }

            RaiseAnnounceMade(announce);
            return(announce);
        }
Exemplo n.º 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);
        }