import java.util.Random;

/*******************************************************************
 Name: Trevor Spalt
 Date: March 12, 2007
 Section: 2
 Lab: PA2
/*******************************************************************
 * This class is to make a bridge hand consisting of 13 card object.
 * The hand is filled by the dealing of the dealer (driver) which is
 * carried out by the putCardInHand method. This method also evaluates
 * the points of the hand and returns the string value of the entire
 * 13 card hand
 */
   public class BridgeHand
   {  
		private Card hand[] = new Card[13];
		
		// use this counter to increment the card index in which the card
		// is being placed
		private int counter;
		
		// Created a variable to hold the points
		private int pointHolder;
		
		/*******************************************************************
		* The constructor only initializes the counter, which incriments the
		* put card in hand method, and initializes the value for pointHolder.
 		*******************************************************************/
		public BridgeHand()
		{
			counter = 0;
			pointHolder = 0;
		}
		
		/*******************************************************************
		* evaluateHand() finds the total point value of the hand. First it
		* calls upon the rank class to get the point value of a given rank.
		* Then it takes a look at the number of cards with the same suit and
		* gives out points based on that value.
		*
		* @return pointHolder - This is the total value of the hand
 		*******************************************************************/
		public int evaluateHand()
		{
			// Create a variable to hold the number of each of the suits
			int spade, heart, diamond, club;
			spade = 0;
			heart = 0;
			diamond = 0;
			club = 0;
			
			// First calculate the points earned by the face value of the cards
			for(int look = 0; look < 13; look++)
			{
				pointHolder += hand[look].getPoints();
			}
			
			// This for loop adds one every time one of the suits is present
			// which will allow me to calculate the total number of suits in 
			// the hand.
			for(int look = 0; look < 13; look++)
			{
				if(hand[look].getSuit() == Suit.SPADE)
				{
					spade++;
				}
				else if(hand[look].getSuit() == Suit.HEART)
				{
					heart++;
				}
				else if(hand[look].getSuit() == Suit.CLUB)
				{
					club++;
				}
				else
				{
					diamond++;
				}	
			}// end for

			// Add points if any suits have a total of less then 1 2 or 3
			if(spade == 0 || diamond == 0 || club == 0 || heart == 0)
				pointHolder += 3;
			else if(spade == 1 || diamond == 1 || club == 1 || heart == 1)
				pointHolder += 2;
			else if(spade == 2 || diamond == 2 || club == 2 || heart == 2)
				pointHolder += 1;
			
			return pointHolder;
		}
		
		/*******************************************************************
		* This method takes a card from the dealer and adds it to the 13 
		* card hand.
		*
		* @param aCard - this is a card from the dealer
 		*******************************************************************/
		public void putCardInHand(Card aCard)
		{
			hand[counter] = aCard;
			
			// Forgot to increment the array at first.
			counter++;
		}
		
		/*******************************************************************
		* toString() prints out all the cards in the hand line by line. This
		* will make it easier for the user to see each card that they have.
		*
		* @return - returns all the values of the hand
 		*******************************************************************/
		public String toString()
		{
			return hand[0] + "\n" + hand[1] + "\n" + hand[2] + "\n" + hand[3] +
					 "\n" + hand[4] + "\n" + hand[5] + "\n" + hand[6] + "\n" + hand[7] +
				 	 "\n" + hand[8] + "\n" + hand[9] + "\n" + hand[10] + "\n" + hand[11] +
					 "\n" + hand[12];
		}//end toString
	}// end Deck Class