The announcement ( bidding ) in the current deal.
Inheritance: IComparable
コード例 #1
0
        /// <summary>
        /// Constructor for the class
        /// </summary>
        internal AnnouncementManager()
        {
            _announces = new List< Announcement >();
            _players = new List< Player >();

            _isBiddingFinished = false;

            _lastValidAnnouncement = new Announcement( AnnouncementTypeEnum.Pass, false, false );
        }
コード例 #2
0
        /// <summary>
        /// Constructor for the class
        /// </summary>
        internal PlayingManager( Announcement current, BelotGame game, CardsCollection _allCards )
        {
            _game = game;
            _playedHands = new List< Hand >();
            _cardToPlayerMap = new Dictionary<Card, Player>();
            _currentAnnouncement = current;
            _currentHand = new Hand();
            _isHandClosed = false;
            _cardComparer = new CardComparer( current.Type );

            _playedCards = new CardsCollection();
            _remainingCards = new CardsCollection();

            foreach( Card card in _allCards )
            {
                _remainingCards.Add( card );
            }
        }
コード例 #3
0
ファイル: Deal.cs プロジェクト: NikolayIT/BelotGameEngine
        /// <summary>
        /// Constructor for the class. Creates a new deal during the current game.
        /// </summary>
        /// <param name="game"></param>
        /// <param name="firstPlayer"></param>
        internal Deal( BelotGame game, Player firstPlayer )
        {
            this._game = game;
            this._firstPlayer = firstPlayer;

            _mapEqualCombinationToPlayer = new ListDictionary();
            _mapSequentialCombinationToPlayer = new ListDictionary();
            _mapBelotCombinationToPlayer = new ListDictionary();

            _allCards = InitCards();
            _cards = new CardsCollection();

            foreach( Card card in _allCards )
            {
                _cards.Add( card );
            }

            _currentAnnouncement = new Announcement( AnnouncementTypeEnum.Pass, false, false );

            _game.RaiseDealStarted();
        }
コード例 #4
0
 /// <summary>
 /// Raises the BiddingCompleted event
 /// </summary>
 protected void RaiseBiddingCompleted( Player winner, Announcement announce )
 {
     if( BiddingCompleted != null )
         {
             BiddingCompleted( winner, announce );
         }
 }
コード例 #5
0
ファイル: AIPlayer.cs プロジェクト: NikolayIT/BelotGameEngine
        private int GetDistance( Card card, Card maxCard, Announcement announce )
        {
            int distance = 0;
            if ( card.CardColor != maxCard.CardColor )
            {
                throw new ArgumentException( "When comparing distance between two cards, they must have same color" );
            }

            CardColor trumpColor = GetTrumpColor();

            switch ( announce.Type )
            {
                case AnnouncementTypeEnum.AllTrumps:
                    distance = GetDistanceTrumps( card, maxCard );
                    break;
                case AnnouncementTypeEnum.NoTrumps:
                    distance = GetDistanceNoTrumps( card, maxCard );
                    break;
                case AnnouncementTypeEnum.Spades:
                case AnnouncementTypeEnum.Hearts:
                case AnnouncementTypeEnum.Diamonds:
                case AnnouncementTypeEnum.Clubs:
                    if ( card.CardColor == trumpColor )
                        distance = GetDistanceTrumps( card, maxCard );
                    else
                        distance = GetDistanceNoTrumps( card, maxCard );
                    break;
            }

            return distance;
        }
コード例 #6
0
ファイル: AIPlayer.cs プロジェクト: NikolayIT/BelotGameEngine
        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;
        }
コード例 #7
0
        /// <summary>
        /// Gets a string representation of an Announcement
        /// </summary>
        private string GetAnnouncementString( Announcement announce )
        {
            string str = "";
            switch ( announce.Type )
            {
                case AnnouncementTypeEnum.AllTrumps:
                    str = StringResources.allTrumps;
                    break;
                case AnnouncementTypeEnum.NoTrumps:
                    str = StringResources.noTrumps;
                    break;
                case AnnouncementTypeEnum.Spades:
                    str = StringResources.spades;
                    break;
                case AnnouncementTypeEnum.Hearts:
                    str = StringResources.hearts;
                    break;
                case AnnouncementTypeEnum.Diamonds:
                    str = StringResources.diamonds;
                    break;
                case AnnouncementTypeEnum.Clubs:
                    str = StringResources.clubs;
                    break;
                case AnnouncementTypeEnum.Pass:
                    str = StringResources.pass;
                    break;
            }

            if ( announce.IsDoubled )
            {
                str = StringResources.doubled;
            }
            if ( announce.IsReDoubled )
            {
                str = StringResources.redoubled;
            }

            return str;
        }
コード例 #8
0
        private void CompPlayerBidded( Player player, Announcement currentAnnounce )
        {
            SetPlayerActive( null );

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

            Thread.Sleep( 1000 - Properties.Settings.Default.Speed*50 );

            this.Text = StringResources.lastBid;
            this.Text += GetAnnouncementString( currentAnnounce );
            this.Text += StringResources.saidBy;
            this.Text += player.Name;
        }
コード例 #9
0
        private void BiddingCompleted( Player winner, Announcement finalAnnounce )
        {
            this.Text = StringResources.gameOf;
            this.Text = GetAnnouncementString( finalAnnounce );
            this.Text = StringResources.saidBy;
            this.Text = winner.Name;

            _passedAnnouncesForm.AddSpaces();
        }
コード例 #10
0
 private void buttonOK_Click( object sender, System.EventArgs e )
 {
     if ( _radioAll.Checked )
         this._announce = new Announcement( AnnouncementTypeEnum.AllTrumps, false, false );
     if ( _radioNo.Checked )
         this._announce = new Announcement( AnnouncementTypeEnum.NoTrumps, false, false );
     if ( _radioSpades.Checked )
         this._announce = new Announcement( AnnouncementTypeEnum.Spades, false, false );
     if ( _radioHearts.Checked )
         this._announce = new Announcement( AnnouncementTypeEnum.Hearts, false, false );
     if ( _radioDiamonds.Checked )
         this._announce = new Announcement( AnnouncementTypeEnum.Diamonds, false, false );
     if ( _radioClubs.Checked )
         this._announce = new Announcement( AnnouncementTypeEnum.Clubs, false, false );
     if ( _radioPass.Checked )
         this._announce = new Announcement( AnnouncementTypeEnum.Pass, false, false );
     if ( _radioDouble.Checked )
         this._announce = new Announcement( _manager.GetLastValidAnnouncement().Type, true, false );
     if ( _radioReDouble.Checked )
         this._announce = new Announcement( _manager.GetLastValidAnnouncement().Type, false, true );
 }
コード例 #11
0
        /// <summary>
        /// If announcement made by this player is valid according to game rules
        /// </summary>
        public bool IsValid( Player player, Announcement announce )
        {
            if( player == null)
                throw new ArgumentNullException( "Player", "Bidding player cannot be null");

            if(	announce == null)
                throw new ArgumentNullException( "Announcement", "Announcement cannot be null");

            return IsValid( player, announce.Type, announce.IsDoubled, announce.IsReDoubled );
        }
コード例 #12
0
        /// <summary>
        /// Stores and announcement made by a player
        /// </summary>
        /// <param name="player"></param>
        /// <param name="announce"></param>
        internal void Add( Player player, Announcement announce )
        {
            if( !IsValid( player, announce ))
                throw new InvalidOperationException( "You cannot bid lower than current" );

            if( (_players.Count != 0)&&( player == (Player)_players[_players.Count - 1] ) )
                throw new InvalidOperationException( "You cannot bid twice" );

            _announces.Add( announce );
            _players.Add( player );

            if( announce.Type != AnnouncementTypeEnum.Pass )
            {
                _lastValidAnnouncement = announce;
                _lastBidder = player;
            }
            else
            {
                //4 successive passes end bidding or 3 passes after a legal bid
                if( _announces.Count > 3 )
                {
                    if( ( ( _announces[_announces.Count-1]).Type == AnnouncementTypeEnum.Pass ) &&
                        ( ( _announces[_announces.Count-2]).Type == AnnouncementTypeEnum.Pass ) &&
                        ( ( _announces[_announces.Count-3]).Type == AnnouncementTypeEnum.Pass ) &&
                        ( _lastBidder != null || (_announces[_announces.Count-4]).Type == AnnouncementTypeEnum.Pass ) )
                    {
                        this._isBiddingFinished = true;
                    }
                }
            }
        }
コード例 #13
0
ファイル: Deal.cs プロジェクト: NikolayIT/BelotGameEngine
        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();
        }