Add() private method

private Add ( Card value ) : int
value Card
return int
Example #1
0
        private void FindSequentialForColor(CardsCollection cards)
        {
            CardComparer comparer = new CardComparer( );

            cards.Sort(comparer);               // we have cards sorted like A,K,Q,J,10,9,8,7

            CardsCollection foundCards = new CardsCollection();

            for (int i = 0; i < cards.Count - 1; i++)
            {
                if (IsConsequent(cards[i], cards[i + 1]))
                {
                    if (foundCards.IsEmpty)
                    {
                        foundCards.Add(cards[i]);
                    }

                    foundCards.Add(cards[i + 1]);
                }
                else
                {
                    if (!foundCards.IsEmpty)
                    {
                        AddSequentialCombination(foundCards);
                        foundCards = new CardsCollection();
                    }
                }
            }

            if (!foundCards.IsEmpty)
            {
                AddSequentialCombination(foundCards);
            }
        }
Example #2
0
        private void CheckBelotForValidColor(Player player, Card playedCard, CardsCollection foundCards)
        {
            foreach (Card card in player.Cards)
            {
                if (playedCard.CardColor == card.CardColor)
                {
                    if (playedCard.CardType == CardType.Queen && card.CardType == CardType.King)
                    {
                        foundCards.Add(playedCard);
                        foundCards.Add(card);
                    }

                    if (playedCard.CardType == CardType.King && card.CardType == CardType.Queen)
                    {
                        foundCards.Add(card);
                        foundCards.Add(playedCard);
                    }
                }
            }
        }
Example #3
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);
            }
        }
        /// <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 );
            }
        }
Example #5
0
        /// <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();
        }
Example #6
0
        /// <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();
        }
Example #7
0
        internal void Add(Player player, Card card)
        {
            _cardToPlayerMap.Add(card, player);
            _currentHand.Add(card);

            _playedCards.Add(card);
            _remainingCards.Remove(card);

            CheckForBelotCombination(player, card);

            if (_currentHand.Count < 4)              // current hand is open
            {
                _isHandClosed = false;
            }
            else             // current hand is closed
            {
                _currentHand.SetWinner(DetermineCurrentHandWinner());
                _playedHands.Add(_currentHand);
                _currentHand  = new Hand();
                _isHandClosed = true;
            }
        }
Example #8
0
        private CardsCollection InitCards()
        {
            CardsCollection cards = new CardsCollection();

            // add spades
            cards.Add(new Card(CardType.Ace, CardColor.Spades));
            cards.Add(new Card(CardType.King, CardColor.Spades));
            cards.Add(new Card(CardType.Queen, CardColor.Spades));
            cards.Add(new Card(CardType.Jack, CardColor.Spades));
            cards.Add(new Card(CardType.Ten, CardColor.Spades));
            cards.Add(new Card(CardType.Nine, CardColor.Spades));
            cards.Add(new Card(CardType.Eight, CardColor.Spades));
            cards.Add(new Card(CardType.Seven, CardColor.Spades));

            // add hearts
            cards.Add(new Card(CardType.Ace, CardColor.Hearts));
            cards.Add(new Card(CardType.King, CardColor.Hearts));
            cards.Add(new Card(CardType.Queen, CardColor.Hearts));
            cards.Add(new Card(CardType.Jack, CardColor.Hearts));
            cards.Add(new Card(CardType.Ten, CardColor.Hearts));
            cards.Add(new Card(CardType.Nine, CardColor.Hearts));
            cards.Add(new Card(CardType.Eight, CardColor.Hearts));
            cards.Add(new Card(CardType.Seven, CardColor.Hearts));

            // add diamonds
            cards.Add(new Card(CardType.Ace, CardColor.Diamonds));
            cards.Add(new Card(CardType.King, CardColor.Diamonds));
            cards.Add(new Card(CardType.Queen, CardColor.Diamonds));
            cards.Add(new Card(CardType.Jack, CardColor.Diamonds));
            cards.Add(new Card(CardType.Ten, CardColor.Diamonds));
            cards.Add(new Card(CardType.Nine, CardColor.Diamonds));
            cards.Add(new Card(CardType.Eight, CardColor.Diamonds));
            cards.Add(new Card(CardType.Seven, CardColor.Diamonds));

            // add clubs
            cards.Add(new Card(CardType.Ace, CardColor.Clubs));
            cards.Add(new Card(CardType.King, CardColor.Clubs));
            cards.Add(new Card(CardType.Queen, CardColor.Clubs));
            cards.Add(new Card(CardType.Jack, CardColor.Clubs));
            cards.Add(new Card(CardType.Ten, CardColor.Clubs));
            cards.Add(new Card(CardType.Nine, CardColor.Clubs));
            cards.Add(new Card(CardType.Eight, CardColor.Clubs));
            cards.Add(new Card(CardType.Seven, CardColor.Clubs));

            return(cards);
        }
        private void FindEquals()
        {
            #region Jacks

            CardsCollection foundJacks = new CardsCollection();
            foreach( Card card in _cards )
            {
                if( card.CardType == CardType.Jack )
                {
                    foundJacks.Add( card );
                }
            }

            if( foundJacks.Count == 4 )
            {
                _combinations.Add( new FourEqualsCombination( foundJacks, 200 ) );
            }

            #endregion

            #region Nines

            CardsCollection foundNines = new CardsCollection();
            foreach( Card card in _cards )
            {
                if( card.CardType == CardType.Nine )
                {
                    foundNines.Add( card );
                }
            }

            if( foundNines.Count == 4 )
            {
                _combinations.Add( new FourEqualsCombination( foundNines, 150 ) );
            }

            #endregion

            #region Aces

            CardsCollection foundAces = new CardsCollection();
            foreach( Card card in _cards )
            {
                if( card.CardType == CardType.Ace )
                {
                    foundAces.Add( card );
                }
            }

            if( foundAces.Count == 4 )
            {
                _combinations.Add( new FourEqualsCombination( foundAces, 100 ) );
            }

            #endregion

            #region Tens

            CardsCollection foundTens = new CardsCollection();
            foreach( Card card in _cards )
            {
                if( card.CardType == CardType.Ten )
                {
                    foundTens.Add( card );
                }
            }

            if( foundTens.Count == 4 )
            {
                _combinations.Add( new FourEqualsCombination( foundTens, 100 ) );
            }

            #endregion

            #region Kings

            CardsCollection foundKings = new CardsCollection();
            foreach( Card card in _cards )
            {
                if( card.CardType == CardType.King )
                {
                    foundKings.Add( card );
                }
            }

            if( foundKings.Count == 4 )
            {
                _combinations.Add( new FourEqualsCombination( foundKings, 100 ) );
            }

            #endregion

            #region Queens

            CardsCollection foundQueens = new CardsCollection();
            foreach( Card card in _cards )
            {
                if( card.CardType == CardType.Queen )
                {
                    foundQueens.Add( card );
                }
            }

            if( foundQueens.Count == 4 )
            {
                _combinations.Add( new FourEqualsCombination( foundQueens, 100 ) );
            }

            #endregion
        }
        private void FindSequentialForColor( CardsCollection cards )
        {
            CardComparer comparer = new CardComparer( );
            cards.Sort( comparer ); // we have cards sorted like A,K,Q,J,10,9,8,7

            CardsCollection foundCards = new CardsCollection();

            for( int i = 0; i < cards.Count-1; i++ )
            {
                if( IsConsequent( cards[i], cards[i+1] ) )
                {
                    if( foundCards.IsEmpty )
                    {
                        foundCards.Add ( cards[i] );
                    }

                    foundCards.Add ( cards[i+1] );
                }
                else
                {
                    if( !foundCards.IsEmpty )
                    {

                        AddSequentialCombination( foundCards );
                        foundCards = new CardsCollection();
                    }
                }
            }

            if( !foundCards.IsEmpty )
            {
                AddSequentialCombination( foundCards );
            }
        }
        private void FindSequential()
        {
            CardsCollection foundCards = new CardsCollection();

            #region Spades

            foreach( Card card in _cards )
            {
                if( card.CardColor == CardColor.Spades )
                {
                    foundCards.Add( card );
                }
            }

            if( foundCards.Count > 2 )
            {
                FindSequentialForColor( foundCards );
            }

            #endregion

            #region Hearts

            foundCards.Clear( );
            foreach( Card card in _cards )
            {
                if( card.CardColor == CardColor.Hearts )
                {
                    foundCards.Add( card );
                }
            }

            if( foundCards.Count > 2 )
            {
                FindSequentialForColor( foundCards );
            }

            #endregion

            #region Diamonds

            foundCards.Clear( );
            foreach( Card card in _cards )
            {
                if( card.CardColor == CardColor.Diamonds )
                {
                    foundCards.Add( card );
                }
            }

            if( foundCards.Count > 2 )
            {
                FindSequentialForColor( foundCards );
            }

            #endregion

            #region Clubs

            foundCards.Clear( );
            foreach( Card card in _cards )
            {
                if( card.CardColor == CardColor.Clubs )
                {
                    foundCards.Add( card );
                }
            }

            if( foundCards.Count > 2 )
            {
                FindSequentialForColor( foundCards );
            }

            #endregion
        }
Example #12
0
        private CardsCollection InitCards()
        {
            CardsCollection cards = new CardsCollection();

            // add spades
            cards.Add( new Card( CardType.Ace, CardColor.Spades ) );
            cards.Add( new Card( CardType.King, CardColor.Spades ) );
            cards.Add( new Card( CardType.Queen, CardColor.Spades ) );
            cards.Add( new Card( CardType.Jack, CardColor.Spades ) );
            cards.Add( new Card( CardType.Ten, CardColor.Spades ) );
            cards.Add( new Card( CardType.Nine, CardColor.Spades ) );
            cards.Add( new Card( CardType.Eight, CardColor.Spades ) );
            cards.Add( new Card( CardType.Seven, CardColor.Spades ) );

            // add hearts
            cards.Add( new Card( CardType.Ace, CardColor.Hearts ) );
            cards.Add( new Card( CardType.King, CardColor.Hearts ) );
            cards.Add( new Card( CardType.Queen, CardColor.Hearts ) );
            cards.Add( new Card( CardType.Jack, CardColor.Hearts ) );
            cards.Add( new Card( CardType.Ten, CardColor.Hearts ) );
            cards.Add( new Card( CardType.Nine, CardColor.Hearts ) );
            cards.Add( new Card( CardType.Eight, CardColor.Hearts ) );
            cards.Add( new Card( CardType.Seven, CardColor.Hearts ) );

            // add diamonds
            cards.Add( new Card( CardType.Ace, CardColor.Diamonds ) );
            cards.Add( new Card( CardType.King, CardColor.Diamonds ) );
            cards.Add( new Card( CardType.Queen, CardColor.Diamonds ) );
            cards.Add( new Card( CardType.Jack, CardColor.Diamonds ) );
            cards.Add( new Card( CardType.Ten, CardColor.Diamonds ) );
            cards.Add( new Card( CardType.Nine, CardColor.Diamonds ) );
            cards.Add( new Card( CardType.Eight, CardColor.Diamonds ) );
            cards.Add( new Card( CardType.Seven, CardColor.Diamonds ) );

            // add clubs
            cards.Add( new Card( CardType.Ace, CardColor.Clubs ) );
            cards.Add( new Card( CardType.King, CardColor.Clubs ) );
            cards.Add( new Card( CardType.Queen, CardColor.Clubs ) );
            cards.Add( new Card( CardType.Jack, CardColor.Clubs ) );
            cards.Add( new Card( CardType.Ten, CardColor.Clubs ) );
            cards.Add( new Card( CardType.Nine, CardColor.Clubs ) );
            cards.Add( new Card( CardType.Eight, CardColor.Clubs ) );
            cards.Add( new Card( CardType.Seven, CardColor.Clubs ) );

            return cards;
        }
        private void CheckBelotForValidColor( Player player, Card playedCard, CardsCollection foundCards )
        {
            foreach( Card card in player.Cards )
            {
                if( playedCard.CardColor == card.CardColor )
                {
                    if( playedCard.CardType == CardType.Queen && card.CardType == CardType.King )
                    {
                        foundCards.Add( playedCard );
                        foundCards.Add( card );
                    }

                    if(playedCard.CardType == CardType.King && card.CardType == CardType.Queen)
                    {
                        foundCards.Add( card );
                        foundCards.Add( playedCard );
                    }
                }
            }
        }
Example #14
0
        private void FindEquals()
        {
            #region Jacks

            CardsCollection foundJacks = new CardsCollection();
            foreach (Card card in _cards)
            {
                if (card.CardType == CardType.Jack)
                {
                    foundJacks.Add(card);
                }
            }

            if (foundJacks.Count == 4)
            {
                _combinations.Add(new FourEqualsCombination(foundJacks, 200));
            }

            #endregion

            #region Nines

            CardsCollection foundNines = new CardsCollection();
            foreach (Card card in _cards)
            {
                if (card.CardType == CardType.Nine)
                {
                    foundNines.Add(card);
                }
            }

            if (foundNines.Count == 4)
            {
                _combinations.Add(new FourEqualsCombination(foundNines, 150));
            }

            #endregion

            #region Aces

            CardsCollection foundAces = new CardsCollection();
            foreach (Card card in _cards)
            {
                if (card.CardType == CardType.Ace)
                {
                    foundAces.Add(card);
                }
            }

            if (foundAces.Count == 4)
            {
                _combinations.Add(new FourEqualsCombination(foundAces, 100));
            }

            #endregion

            #region Tens

            CardsCollection foundTens = new CardsCollection();
            foreach (Card card in _cards)
            {
                if (card.CardType == CardType.Ten)
                {
                    foundTens.Add(card);
                }
            }

            if (foundTens.Count == 4)
            {
                _combinations.Add(new FourEqualsCombination(foundTens, 100));
            }

            #endregion

            #region Kings

            CardsCollection foundKings = new CardsCollection();
            foreach (Card card in _cards)
            {
                if (card.CardType == CardType.King)
                {
                    foundKings.Add(card);
                }
            }

            if (foundKings.Count == 4)
            {
                _combinations.Add(new FourEqualsCombination(foundKings, 100));
            }

            #endregion

            #region Queens

            CardsCollection foundQueens = new CardsCollection();
            foreach (Card card in _cards)
            {
                if (card.CardType == CardType.Queen)
                {
                    foundQueens.Add(card);
                }
            }

            if (foundQueens.Count == 4)
            {
                _combinations.Add(new FourEqualsCombination(foundQueens, 100));
            }

            #endregion
        }
Example #15
0
        private void FindSequential()
        {
            CardsCollection foundCards = new CardsCollection();

            #region Spades

            foreach (Card card in _cards)
            {
                if (card.CardColor == CardColor.Spades)
                {
                    foundCards.Add(card);
                }
            }

            if (foundCards.Count > 2)
            {
                FindSequentialForColor(foundCards);
            }

            #endregion

            #region Hearts

            foundCards.Clear( );
            foreach (Card card in _cards)
            {
                if (card.CardColor == CardColor.Hearts)
                {
                    foundCards.Add(card);
                }
            }

            if (foundCards.Count > 2)
            {
                FindSequentialForColor(foundCards);
            }

            #endregion

            #region Diamonds

            foundCards.Clear( );
            foreach (Card card in _cards)
            {
                if (card.CardColor == CardColor.Diamonds)
                {
                    foundCards.Add(card);
                }
            }

            if (foundCards.Count > 2)
            {
                FindSequentialForColor(foundCards);
            }

            #endregion

            #region Clubs

            foundCards.Clear( );
            foreach (Card card in _cards)
            {
                if (card.CardColor == CardColor.Clubs)
                {
                    foundCards.Add(card);
                }
            }

            if (foundCards.Count > 2)
            {
                FindSequentialForColor(foundCards);
            }

            #endregion
        }