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;
}