GetTeamPlayer() private method

private GetTeamPlayer ( Player currentPlayer ) : Player
currentPlayer Player
return Player
Esempio n. 1
0
        private Player FindBiggestEqualCombinationHolder( )
        {
            CardCombination biggest = null;
            CardCombination second  = null;

            Player biggestPlayer = null;
            Player secondPlayer  = null;

            foreach (DictionaryEntry de in _mapEqualCombinationToPlayer)
            {
                CardCombination current = de.Key as CardCombination;

                if (biggest != null)
                {
                    if (current.CompareTo(biggest) > 1)
                    {
                        biggest       = current;
                        biggestPlayer = de.Value as Player;
                    }
                    else if (current.CompareTo(biggest) == 0)
                    {
                        second       = current;
                        secondPlayer = de.Value as Player;
                    }
                }
                else
                {
                    biggest       = current;
                    biggestPlayer = de.Value as Player;
                }
            }

            if (biggest != null && second != null)
            {
                if (biggestPlayer == secondPlayer || biggestPlayer == _game.GetTeamPlayer(secondPlayer))
                {
                    return(biggestPlayer);
                }
            }
            else if (biggest != null)
            {
                return(biggestPlayer);
            }

            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// If card played by this player is valid according to game rules
        /// </summary>
        public bool IsValid(Player player, Card card)
        {
            if (player == null)
            {
                throw new ArgumentNullException("Player", "Player cannot be null");
            }

            if (card == null)
            {
                throw new ArgumentNullException("Card", "Played card cannot be null");
            }

            CardColor wantedColor;
            Card      biggestCard;

            // if player plays first card in hand he can play any card
            if (_currentHand.IsEmpty)
            {
                return(true);
            }
            else
            {
                wantedColor = GetPlayingColor(_currentHand);
                biggestCard = GetBiggestCard(_currentHand);
            }


            if (_currentAnnouncement.Type == AnnouncementTypeEnum.AllTrumps)
            {
                #region Game of all trumps
                if (card.CardColor == wantedColor)
                {
                    if (IsBigger(card, biggestCard))
                    {
                        // card is biggest for now in wanted color
                        return(true);
                    }
                    else
                    {
                        // card is not biggest but player has no bigger one
                        return(!HasBigger(biggestCard, player.Cards, wantedColor));
                    }
                }
                else if (!HasPlayingColor(wantedColor, player.Cards))
                {
                    // if player does not have currently wanted color he can play any card
                    return(true);
                }
                #endregion
            }
            else if (_currentAnnouncement.Type == AnnouncementTypeEnum.NoTrumps)
            {
                #region Game of no trumps
                if (card.CardColor == wantedColor)
                {
                    //player may play any card in wanted color
                    return(true);
                }
                else
                {
                    // player does not have currently wanted color he can play any card
                    return(!HasPlayingColor(wantedColor, player.Cards));
                }
                #endregion
            }
            else
            {
                #region Game of color trumps
                CardColor trumpColor = GetTrumpColor( );

                if (card.CardColor == wantedColor)
                {
                    if (trumpColor == wantedColor)
                    {
                        if (IsBigger(card, biggestCard))
                        {
                            // card is biggest for now
                            return(true);
                        }
                        else
                        {
                            // card is not biggest but player has no bigger one
                            return(!HasBigger(biggestCard, player.Cards, wantedColor));
                        }
                    }
                    else
                    {
                        // card is not trump and may not be bigger
                        return(true);
                    }
                }
                else
                {
                    if (HasPlayingColor(wantedColor, player.Cards))
                    {
                        // player has cards in wanted color but plays from different one
                        return(false);
                    }
                    else
                    {
                        if (trumpColor == wantedColor)
                        {
                            // if player does not have currently wanted color or trump color he can play any card
                            return(true);
                        }
                        else
                        {
                            biggestCard = GetBiggestCard(_currentHand, trumpColor);

                            Player biggestCardOwner = _cardToPlayerMap[biggestCard] as Player;

                            if (biggestCardOwner == _game.GetTeamPlayer(player))
                            {
                                //if hand is held by partner player may not give trump
                                return(true);
                            }
                            else
                            {
                                // player must give bigger trump
                                if (!HasPlayingColor(trumpColor, player.Cards))
                                {
                                    // player does not have trumps
                                    return(true);
                                }
                                else
                                {
                                    if (biggestCard.CardColor != trumpColor)
                                    {
                                        // biggest card for now is not a trump
                                        // so player must play a trump
                                        return(card.CardColor == trumpColor);
                                    }
                                    else
                                    {
                                        if (IsBigger(card, biggestCard))
                                        {
                                            // card is biggest for now
                                            return(true);
                                        }
                                        else
                                        {
                                            // card is not biggest but player has no bigger one
                                            return(!HasBigger(biggestCard, player.Cards, trumpColor));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                #endregion
            }

            return(false);
        }