public Player(Socket s, string n, int c)
 {
     mySocket = s;
     name = n;
     chips = c;
     status = "New Player!";
     card1 = null;
     card2 = null;
     betSoFar = 0;
     isFolded = true;
     hasActed = false;
     inPot = 0;
     displayCards = false;
     leftGame = false;
 }
 public bool setUpNewGame(Card a, Card b)
 {
     inPot = 0;
     betSoFar = 0;
     displayCards = false;
     if (chips == 0)
     {
         card1 = null;
         card2 = null;
         isFolded = true;
         hasActed = true;
         status = "Out of Chips";
         return false;
     }
     isFolded = false;
     hasActed = false;
     card1 = a;
     card2 = b;
     status = string.Empty;
     return true;
 }
 public Hand(Card[] c)
 {
     int pair = 0;
     int consec = 0;
     int suit = 15;
     cards = new Card[5];
     int[] valueCounts = new int[13];
     for (int i = 0; i < 5; i++)
     {
         suit = suit & (1 << c[i].suit);
         valueCounts[c[i].value]++;
         for (int j = 0; j < i; j++)
         {
             if (c[i].value == c[j].value) pair++;
             if (Math.Abs(c[i].value - c[j].value) == 1)
             {
                 if (c[i].value == 12 || c[j].value == 12)
                 {
                     consec++;
                 }
                 else
                 {
                     consec += 2;
                 }
             }
             if (Math.Abs(c[i].value - c[j].value) == 12) consec++;
         }
     }
     int cix = 0;
     if (pair == 1)
     {
         handType = "One Pair";
         testVals = new int[5];
         testVals[0] = 1;
         for (int i = 12; i >= 0; i--)
         {
             if (valueCounts[i] == 2)
             {
                 testVals[1] = i;
                 for (int n = 0; n < 5; n++)
                 {
                     if (c[n].value == i)
                     {
                         cards[cix] = c[n];
                         cix++;
                     }
                 }
                 break;
             }
         }
         int j = 2;
         for (int i = 12; i >= 0; i--)
         {
             if (valueCounts[i] == 1)
             {
                 testVals[j] = i;
                 for (int n = 0; n < 5; n++)
                 {
                     if (c[n].value == i)
                     {
                         cards[cix] = c[n];
                         cix++;
                     }
                 }
                 j++;
             }
         }
     }
     else if (pair == 2)
     {
         handType = "Two Pair";
         testVals = new int[4];
         testVals[0] = 2;
         int j = 1;
         for (int i = 12; i >= 0; i--)
         {
             if (valueCounts[i] == 2)
             {
                 testVals[j] = i;
                 for (int n = 0; n < 5; n++)
                 {
                     if (c[n].value == i)
                     {
                         cards[cix] = c[n];
                         cix++;
                     }
                 }
                 j++;
             }
         }
         for (int i = 12; i >= 0; i--)
         {
             if (valueCounts[i] == 1)
             {
                 testVals[j] = i;
                 for (int n = 0; n < 5; n++)
                 {
                     if (c[n].value == i)
                     {
                         cards[cix] = c[n];
                         cix++;
                     }
                 }
                 j++;
             }
         }
     }
     else if (pair == 3)
     {
         handType = "Three of a Kind";
         testVals = new int[4];
         testVals[0] = 3;
         for (int i = 12; i >= 0; i--)
         {
             if (valueCounts[i] == 3)
             {
                 testVals[1] = i;
                 for (int n = 0; n < 5; n++)
                 {
                     if (c[n].value == i)
                     {
                         cards[cix] = c[n];
                         cix++;
                     }
                 }
                 break;
             }
         }
         int j = 2;
         for (int i = 12; i >= 0; i--)
         {
             if (valueCounts[i] == 1)
             {
                 testVals[j] = i;
                 for (int n = 0; n < 5; n++)
                 {
                     if (c[n].value == i)
                     {
                         cards[cix] = c[n];
                         cix++;
                     }
                 }
                 j++;
             }
         }
     }
     else if (pair == 4)
     {
         handType = "Full House";
         testVals = new int[3];
         testVals[0] = 6;
         for (int i = 12; i >= 0; i--)
         {
             if (valueCounts[i] == 3)
             {
                 testVals[1] = i;
                 for (int n = 0; n < 5; n++)
                 {
                     if (c[n].value == i)
                     {
                         cards[cix] = c[n];
                         cix++;
                     }
                 }
                 break;
             }
         }
         for (int i = 12; i >= 0; i--)
         {
             if (valueCounts[i] == 2)
             {
                 testVals[2] = i;
                 for (int n = 0; n < 5; n++)
                 {
                     if (c[n].value == i)
                     {
                         cards[cix] = c[n];
                         cix++;
                     }
                 }
                 break;
             }
         }
     }
     else if (pair == 6)
     {
         handType = "Four of a Kind";
         testVals = new int[3];
         testVals[0] = 7;
         for (int i = 12; i >= 0; i--)
         {
             if (valueCounts[i] == 4)
             {
                 testVals[1] = i;
                 for (int n = 0; n < 5; n++)
                 {
                     if (c[n].value == i)
                     {
                         cards[cix] = c[n];
                         cix++;
                     }
                 }
                 break;
             }
         }
         for (int i = 12; i >= 0; i--)
         {
             if (valueCounts[i] == 1)
             {
                 testVals[2] = i;
                 for (int n = 0; n < 5; n++)
                 {
                     if (c[n].value == i)
                     {
                         cards[cix] = c[n];
                         cix++;
                     }
                 }
                 break;
             }
         }
     }
     else if (consec >= 7 && suit != 0)
     {
         handType = "Straight Flush";
         testVals = new int[2];
         testVals[0] = 8;
         for (int i = 12; i >= 0; i--)
         {
             if (valueCounts[i] == 1)
             {
                 testVals[1] = i;
                 for (int n = 0; n < 5; n++)
                 {
                     if (c[n].value == i)
                     {
                         cards[cix] = c[n];
                         cix++;
                     }
                 }
                 if (i == 12 && testVals[11] == 0) testVals[1] = 5;
             }
         }
     }
     else if (consec >= 7)
     {
         handType = "Straight";
         testVals = new int[2];
         testVals[0] = 4;
         for (int i = 12; i >= 0; i--)
         {
             if (valueCounts[i] == 1)
             {
                 testVals[1] = i;
                 for (int n = 0; n < 5; n++)
                 {
                     if (c[n].value == i)
                     {
                         cards[cix] = c[n];
                         cix++;
                     }
                 }
                 if (i == 12 && valueCounts[11] == 0) testVals[1] = 5;
             }
         }
     }
     else if (suit != 0)
     {
         handType = "Flush";
         testVals = new int[6];
         testVals[0] = 5;
         int j = 1;
         for (int i = 12; i >= 0; i--)
         {
             if (valueCounts[i] == 1)
             {
                 testVals[j] = i;
                 for (int n = 0; n < 5; n++)
                 {
                     if (c[n].value == i)
                     {
                         cards[cix] = c[n];
                         cix++;
                     }
                 }
                 j++;
             }
         }
     }
     else
     {
         handType = "High Card";
         testVals = new int[6];
         testVals[0] = 0;
         int j = 1;
         for (int i = 12; i >= 0; i--)
         {
             if (valueCounts[i] == 1)
             {
                 testVals[j] = i;
                 for (int n = 0; n < 5; n++)
                 {
                     if (c[n].value == i)
                     {
                         cards[cix] = c[n];
                         cix++;
                     }
                 }
                 j++;
             }
         }
     }
 }
 public Hand getBestHand(Card[] c)
 {
     Hand bestHand = null;
     Card[] allCards = new Card[7];
     allCards[0] = card1;
     allCards[1] = card2;
     for(int i = 0; i < 5; i ++)
     {
         allCards[i + 2] = c[i];
     }
     for (int i = 0; i < 7; i++)
     {
         for (int j = 0; j < i; j++)
         {
             Card[] handCards = new Card[5];
             int ix = 0;
             for (int k = 0; k < 7; k++)
             {
                 if (k != i && k != j)
                 {
                     handCards[ix] = allCards[k];
                     ix++;
                 }
             }
             Hand newHand = new Hand(handCards);
             if (bestHand == null || newHand.isBetter(bestHand) > 0)
             {
                 bestHand = newHand;
             }
         }
     }
     return bestHand;
 }