/// <summary> /// Compares current combination to another one /// </summary> /// <param name="combination">combination to compare to</param> /// <returns>1 if current combination is bigger, -1 if second combination is bigger, 0 if both combination are equal</returns> public override int CompareTo(object combination) { if (!(combination is SequentialCombination)) { throw new InvalidOperationException("Cannot compare SequentialCombination to an object of different type"); } int result = 0; SequentialCombination comb = combination as SequentialCombination; if (this.Points > comb.Points) { result = 1; } else if (this.Points < comb.Points) { result = -1; } else { // both combinations are sequential. See biggest card CardComparer comparer = new CardComparer( ); this.Cards.Sort(comparer); comb.Cards.Sort(comparer); result = comparer.Compare(this.Cards[0], comb.Cards[0]); } return(result); }
/// <summary> /// Compares current combination to another one /// </summary> /// <param name="combination">combination to compare to</param> /// <returns>1 if current combination is bigger, -1 if second combination is bigger, 0 if both combination are equal</returns> public override int CompareTo( object combination ) { if( !(combination is SequentialCombination) ) { throw new InvalidOperationException( "Cannot compare SequentialCombination to an object of different type" ); } int result = 0; SequentialCombination comb = combination as SequentialCombination; if( this.Points > comb.Points ) { result = 1; } else if( this.Points < comb.Points ) { result = -1; } else { // both combinations are sequential. See biggest card CardComparer comparer = new CardComparer( ); this.Cards.Sort( comparer ); comb.Cards.Sort( comparer ); result = comparer.Compare( this.Cards[0], comb.Cards[0] ); } return result; }
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); } }
/// <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 ); } }
private void DealCards(int count) { System.Random rand = new Random(DateTime.Now.Millisecond * DateTime.Now.Second); Player current = this._firstPlayer; for (int i = count; i > 0; i--) { int index = rand.Next(i); current.Cards.Add(_cards[index]); current = this._game.GetNextPlayer(current); _cards.RemoveAt(index); } CardComparer comparer = new CardComparer(this._currentAnnouncement.Type); this._game.GetPlayer(PlayerPosition.South).Cards.Sort(comparer); this._game.GetPlayer(PlayerPosition.East).Cards.Sort(comparer); this._game.GetPlayer(PlayerPosition.North).Cards.Sort(comparer); this._game.GetPlayer(PlayerPosition.West).Cards.Sort(comparer); }
private bool IsCurrentMaxCardInPlayingColor( Card targetCard ) { CardComparer comparer = new CardComparer( _playingManager.CurrentAnnouncement.Type ); bool foundBigger = false; foreach ( Card remCard in _playingManager.RemainingCards ) { if ( targetCard.CardColor == remCard.CardColor ) { if ( comparer.Compare( targetCard, remCard ) < 0 ) { foundBigger = true; break; } } } if ( !foundBigger ) { foreach ( Card remCard in _playingManager.CurrentHand ) { if ( targetCard.CardColor == remCard.CardColor ) { if ( comparer.Compare( targetCard, remCard ) < 0 ) { foundBigger = true; break; } } } } return !foundBigger; }
private Card GetCurrentMaxCardInColor( CardColor color ) { Card maxCard = null; CardComparer comparer = new CardComparer( _playingManager.CurrentAnnouncement.Type ); foreach ( Card card in _playingManager.RemainingCards ) { if ( card.CardColor == color ) { if ( maxCard == null ) { maxCard = card; } if ( comparer.Compare( maxCard, card ) < 0 ) { maxCard = card; } } } foreach ( Card card in _playingManager.CurrentHand ) { if ( card.CardColor == color ) { if ( maxCard == null ) { maxCard = card; } if ( comparer.Compare( maxCard, card ) < 0 ) { maxCard = card; } } } return maxCard; }
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 DealCards( int count ) { System.Random rand = new Random( DateTime.Now.Millisecond * DateTime.Now.Second ); Player current = this._firstPlayer; for( int i = count; i > 0; i-- ) { int index = rand.Next( i ); current.Cards.Add( _cards[index] ); current = this._game.GetNextPlayer( current ); _cards.RemoveAt( index ); } CardComparer comparer = new CardComparer( this._currentAnnouncement.Type ); this._game.GetPlayer( PlayerPosition.South ).Cards.Sort( comparer ); this._game.GetPlayer( PlayerPosition.East ).Cards.Sort( comparer ); this._game.GetPlayer( PlayerPosition.North ).Cards.Sort( comparer ); this._game.GetPlayer( PlayerPosition.West ).Cards.Sort( comparer ); }
internal void Sort(CardComparer comparer) { this.InnerList.Sort(comparer); this.InnerList.Reverse(); RaiseChanged( ); }
internal void Sort( CardComparer comparer ) { this.InnerList.Sort( comparer ); this.InnerList.Reverse(); RaiseChanged( ); }