A manager that observes bidding rules.
Exemplo n.º 1
0
        internal Player EnterBiddingState()
        {
            AnnouncementManager announcementManager = new AnnouncementManager( );

            Player       current = this._firstPlayer;
            Announcement announce;

            while (!announcementManager.IsBiddingFinished)
            {
                announce = current.MakeAnnouncement(announcementManager);

                announcementManager.Add(current, announce);

                _currentAnnouncement = announcementManager.GetLastValidAnnouncement();

                current = _game.GetNextPlayer(current);
            }

            _bidWinner = announcementManager.GetLastBidder();

            return(announcementManager.GetLastBidder());
        }
Exemplo n.º 2
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.º 3
0
        public override Announcement MakeAnnouncement( AnnouncementManager manager )
        {
            Announcement ret = RaiseAnnounceMaking( manager );

            return ret;
        }
Exemplo n.º 4
0
 /// <summary>
 /// Raises the AnnounceMaking event
 /// </summary>
 protected Announcement RaiseAnnounceMaking( AnnouncementManager manager )
 {
     if ( AnnounceMaking != null )
     {
         return AnnounceMaking( this, manager );
     }
     else
     {
         return null;
     }
 }
Exemplo n.º 5
0
        private Announcement HumanPlayerIsBidding( Player player, AnnouncementManager manager )
        {
            SetPlayerActive( player );
            _announceForm.Bid( player, manager );
            _announceForm.ShowDialog();
            this.Update();

            Announcement currentAnnounce = _announceForm.Announce;

            this.Text = StringResources.lastBid;
            this.Text += GetAnnouncementString( currentAnnounce );
            this.Text += StringResources.saidBy;
            this.Text += player.Name;

            bool isActive = currentAnnounce.CompareTo( _game.CurrentDeal.CurrentAnnouncement ) > 0;
            _passedAnnouncesForm.AddMessage( player.Name, GetAnnouncementString( currentAnnounce ), isActive );

            return currentAnnounce;
        }
Exemplo n.º 6
0
 public void Bid( Player player, AnnouncementManager manager )
 {
     this._manager = manager;
     this._player = player;
 }
Exemplo n.º 7
0
 /// <summary>
 /// The player makes an announcement (bidding). Player has to ask the manager if desired announcement is valid. Otherwise returning invalid announcement throws exception.
 /// </summary>
 /// <param name="manager">Manager that observes bidding rules</param>
 /// <returns>Announcement made by the player</returns>
 public abstract Announcement MakeAnnouncement(AnnouncementManager manager);
Exemplo n.º 8
0
 /// <summary>
 /// The player makes an announcement (bidding). Player has to ask the manager if desired announcement is valid. Otherwise returning invalid announcement throws exception.
 /// </summary>
 /// <param name="manager">Manager that observes bidding rules</param>
 /// <returns>Announcement made by the player</returns>
 public abstract Announcement MakeAnnouncement( AnnouncementManager manager );
Exemplo n.º 9
0
        internal Player EnterBiddingState()
        {
            AnnouncementManager announcementManager = new AnnouncementManager( );

            Player current = this._firstPlayer;
            Announcement announce;

            while( !announcementManager.IsBiddingFinished	)
            {
                announce = current.MakeAnnouncement( announcementManager );

                announcementManager.Add( current, announce );

                _currentAnnouncement = announcementManager.GetLastValidAnnouncement();

                current = _game.GetNextPlayer( current );
            }

            _bidWinner = announcementManager.GetLastBidder();

            return announcementManager.GetLastBidder();
        }