Collection of cards.
Inheritance: System.Collections.ReadOnlyCollectionBase
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 CheckForBelotCombination(Player player, Card playedCard)
        {
            CardsCollection foundCards = new CardsCollection();
            CardColor       trumpColor = GetTrumpColor( );

            if (_currentAnnouncement.Type == AnnouncementTypeEnum.AllTrumps)
            {
                if (_currentHand.IsEmpty)
                {
                    CheckBelotForValidColor(player, playedCard, foundCards);
                }
                else
                {
                    if (playedCard.CardColor == GetPlayingColor(_currentHand))
                    {
                        CheckBelotForValidColor(player, playedCard, foundCards);
                    }
                }
            }
            else if (_currentAnnouncement.Type != AnnouncementTypeEnum.NoTrumps && playedCard.CardColor == trumpColor)
            {
                CheckBelotForValidColor(player, playedCard, foundCards);
            }

            if (foundCards.Count != 0)
            {
                BelotFound(player, new BelotCombination(foundCards, 20));
            }
        }
        /// <summary>
        /// Constructor of the class
        /// </summary>
        public CombinationFinder( CardsCollection cards )
        {
            _combinations = new List< CardCombination >();
            _cards = cards;
            FindEquals();

            if( _combinations.Count == 0 )
            {
                FindSequential();
            }
        }
Example #4
0
 private bool HasPlayingColor(CardColor color, CardsCollection cards)
 {
     foreach (Card card in cards)
     {
         if (card.CardColor == color)
         {
             return(true);
         }
     }
     return(false);
 }
Example #5
0
        /// <summary>
        /// Constructor of the class
        /// </summary>
        public CombinationFinder(CardsCollection cards)
        {
            _combinations = new List <CardCombination>();
            _cards        = cards;
            FindEquals();

            if (_combinations.Count == 0)
            {
                FindSequential();
            }
        }
 private void AddSequentialCombination( CardsCollection cards )
 {
     if( cards.Count == 3 )
     {
         this._combinations.Add( new SequentialCombination ( cards, 20 ) );
     }
     if( cards.Count == 4 )
     {
         this._combinations.Add( new SequentialCombination ( cards, 50 ) );
     }
     if( cards.Count >= 5 )
     {
         this._combinations.Add( new SequentialCombination ( cards, 100 ) );
     }
 }
Example #7
0
 private void AddSequentialCombination(CardsCollection cards)
 {
     if (cards.Count == 3)
     {
         this._combinations.Add(new SequentialCombination(cards, 20));
     }
     if (cards.Count == 4)
     {
         this._combinations.Add(new SequentialCombination(cards, 50));
     }
     if (cards.Count >= 5)
     {
         this._combinations.Add(new SequentialCombination(cards, 100));
     }
 }
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);
        }
Example #9
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 #11
0
        private bool HasBigger(Card biggestCard, CardsCollection cards, CardColor wantedColor)
        {
            bool hasBigger = false;

            foreach (Card card in cards)
            {
                if (card.CardColor == wantedColor)
                {
                    if (_cardComparer.Compare(card, biggestCard) > 0)
                    {
                        hasBigger = true;
                        break;
                    }
                }
            }

            return(hasBigger);
        }
Example #12
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 #13
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 #14
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 #15
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
        }
 /// <summary>
 /// Creates an equal combination of cards
 /// </summary>
 /// <param name="cards">cards that the combination consists of</param>
 /// <param name="points">point evaluation of the combination</param>
 public FourEqualsCombination(CardsCollection cards, int points) : base(cards, points)
 {
 }
        private void CheckForBelotCombination( Player player, Card playedCard )
        {
            CardsCollection foundCards = new CardsCollection();
            CardColor trumpColor = GetTrumpColor( );

            if( _currentAnnouncement.Type == AnnouncementTypeEnum.AllTrumps )
            {
                if( _currentHand.IsEmpty )
                {
                    CheckBelotForValidColor( player, playedCard, foundCards );
                }
                else
                {
                    if( playedCard.CardColor == GetPlayingColor( _currentHand ) )
                    {
                        CheckBelotForValidColor( player, playedCard, foundCards );
                    }
                }
            }
            else if( _currentAnnouncement.Type != AnnouncementTypeEnum.NoTrumps && playedCard.CardColor == trumpColor )
            {
                CheckBelotForValidColor( player, playedCard, foundCards );
            }

            if( foundCards.Count != 0 )
            {
                BelotFound( player, new BelotCombination( foundCards, 20) );
            }
        }
        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 #19
0
 private void DrawCards( Player player, CardsCollection cards )
 {
     switch ( player.Position )
     {
         case PlayerPosition.South:
             _panelSouth.Cards = cards;
             break;
         case PlayerPosition.East:
             _panelEast.Cards = cards;
             break;
         case PlayerPosition.North:
             _panelNorth.Cards = cards;
             break;
         case PlayerPosition.West:
             _panelWest.Cards = cards;
             break;
         default:
             _panelSouth.Cards = cards;
             break;
     }
 }
Example #20
0
 /// <summary>
 /// Creates a sequential combination of cards
 /// </summary>
 /// <param name="cards">cards that the combination consists of</param>
 /// <param name="points">point evaluation of the combination</param>
 public SequentialCombination(CardsCollection cards, int points) : base(cards, points)
 {
 }
        private bool HasBigger( Card biggestCard, CardsCollection cards, CardColor wantedColor )
        {
            bool hasBigger = false;
            foreach( Card card in cards )
            {
                if( card.CardColor == wantedColor )
                {
                    if( _cardComparer.Compare( card, biggestCard ) > 0 )
                    {
                        hasBigger = true;
                        break;
                    }
                }
            }

            return hasBigger;
        }
        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 bool HasPlayingColor( CardColor color, CardsCollection cards )
 {
     foreach( Card card in cards )
     {
         if( card.CardColor == color )
             return true;
     }
     return false;
 }
        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
        }
 /// <summary>
 /// Creates a sequential combination of cards
 /// </summary>
 /// <param name="cards">cards that the combination consists of</param>
 /// <param name="points">point evaluation of the combination</param>
 public SequentialCombination( CardsCollection cards, int points )
     : base(cards, points)
 {
 }
Example #27
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
        }
Example #28
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;
        }
Example #29
0
 /// <summary>
 /// Constructor for the class.
 /// </summary>
 protected Player( )
 {
     this._cards = new CardsCollection();
     this._cards.Changed += new Belot.CardsCollection.CardsCollectionChangedHandler( RaiseCardsChanged );
 }
Example #30
0
 /// <summary>
 /// Constructor for the class.
 /// </summary>
 protected Player( )
 {
     this._cards          = new CardsCollection();
     this._cards.Changed += new Belot.CardsCollection.CardsCollectionChangedHandler(RaiseCardsChanged);
 }
 /// <summary>
 /// Constructor of the class
 /// </summary>
 protected CardCombination( CardsCollection cards, int points )
 {
     _cards = cards;
     _points = points;
 }
 /// <summary>
 /// Creates an equal combination of cards
 /// </summary>
 /// <param name="cards">cards that the combination consists of</param>
 /// <param name="points">point evaluation of the combination</param>
 public FourEqualsCombination( CardsCollection cards, int points )
     : base(cards, points)
 {
 }
 /// <summary>
 /// Constructor of the class
 /// </summary>
 protected CardCombination(CardsCollection cards, int points)
 {
     _cards  = cards;
     _points = points;
 }