/**
 * @author Yoshihiro Fujio
 * CS239 section 2
 * PA2
 * V1 date 2007/03/11
**/
/**********************************************************************
 * BridgeHand.java
 *
 * Represents a cards hold by each player
 ********************************************************************/

    public class BridgeHand
   {
      private Card[] hand;
      private int i = 0; // array number of the current hand
   
    /***************************************************************
    * Creates a cards of player that contains 13 cards. 
    ***************************************************************/
       public BridgeHand()
      {
         hand = new Card[13];
      } // end BridgeHand
   
    /***************************************************************
    * evaluates hand
    ***************************************************************/
       public int evaluateHand()
      {
        
         int totalPoints = 0; // total points of a hand
         int club = 0; // number of cards with suit CLUB
         int diamond = 0; // number of cards with suit DIAMIOND
         int heart = 0; // number of cards with suit HEART
         int spade = 0; // number of cards with suit SPADE
      
      
         for (int ii = 0; ii < 13; ii++)
         {
         // check points of Jack, Queen, King, and Ace
            totalPoints += hand[ii].getPoints();
         
         // add a count to each counter if there is one
            if (hand[ii].suit == Suit.CLUB)
               club++;
            if (hand[ii].suit == Suit.DIAMOND)
               diamond++;
            if (hand[ii].suit ==Suit.HEART)
               heart++;
            if (hand[ii].suit == Suit.SPADE)
               spade++;
         
         }
      
      // check points for void suit, singleton, and doubleton;
			// for club
         if (club == 0)
            totalPoints += 3;
         if (club == 1)
            totalPoints += 2;
         if (club == 2)
            totalPoints += 1;
      	
			// for diamond
         if (diamond == 0)
            totalPoints += 3;
         if (diamond == 1)
            totalPoints += 2;
         if (diamond == 2)
            totalPoints += 1;
      	
			// for heart
         if (heart == 0)
            totalPoints += 3;
         if (heart == 1)
            totalPoints += 2;
         if (heart == 2)
            totalPoints += 1;
      	
			// for spade
         if (spade == 0)
            totalPoints += 3;
         if (spade == 1)
            totalPoints += 2;
         if (spade == 2)
            totalPoints += 1;
      	
         return totalPoints;
      } // end evaluateHand
   
    /***************************************************************
    * put a card of one player in a hand
    ***************************************************************/
       public void putCardInHand(Card aCard)
      {
         hand[i] = aCard;
      
         i++;
      
      } // end putCardInHand
   
   /*********************************************************
    * The string of cards in hand
    * @return The String of list of cards in hand
    ********************************************************/
       public String toString ()
      {
         String handCards = "";
      
         for (int ii = 0; ii < 13; ii++)
         {
            handCards += hand[ii] + "\n";
         }	
      
         return handCards;
      } // end toString	
   } // end class