Advertisement
Guest User

Texas Hold Em Hand Evaluation (C#)

a guest
Nov 6th, 2016
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 37.05 KB | None | 0 0
  1.     // evaluate this players hand
  2.     public void DoHandEval()
  3.     {
  4.         // reset hand eval
  5.         heartSum = 0;
  6.         diamondSum = 0;
  7.         clubSum = 0;
  8.         spadeSum = 0;
  9.         evalCards = new cardScript[7];
  10.         handValue = new HandValue();
  11.  
  12.         // evaluate current hand
  13.         evaluatedHand = EvaluateHand();
  14.  
  15.         // display the evaluated hand
  16.         print(this.gameObject.ToString() + " Hand: " + evaluatedHand);
  17.     }
  18.  
  19.     // stored hand evaluation variable
  20.     public Hand EvaluateHand()
  21.     {
  22.         // collect player cards and community cards and set into cards array
  23.         evalCards[0] = card1.GetComponent<cardScript>();
  24.         evalCards[1] = card2.GetComponent<cardScript>();
  25.         evalCards[2] = gm.communityCard1.GetComponent<cardScript>();
  26.         evalCards[3] = gm.communityCard2.GetComponent<cardScript>();
  27.         evalCards[4] = gm.communityCard3.GetComponent<cardScript>();
  28.         evalCards[5] = gm.communityCard4.GetComponent<cardScript>();
  29.         evalCards[6] = gm.communityCard5.GetComponent<cardScript>();
  30.  
  31.         // get the number of each suit on hand
  32.         getNumberOfSuit();
  33.  
  34.         // evaluate the hand for conditions
  35.         if (RoyalFlush())
  36.             return Hand.RoyalFlush;
  37.         else if (StraightFlush())
  38.             return Hand.StraightFlush;
  39.         else if (FourOfKind())
  40.             return Hand.FourKind;
  41.         else if (FullHouse())
  42.             return Hand.FullHouse;
  43.         else if (Flush())
  44.             return Hand.Flush;
  45.         else if (Straight())
  46.             return Hand.Straight;
  47.         else if (ThreeOfKind())
  48.             return Hand.ThreeKind;
  49.         else if (TwoPairs())
  50.             return Hand.TwoPairs;
  51.         else if (OnePair())
  52.             return Hand.OnePair;
  53.  
  54.         // if hand == nothing then hand with highest card wins
  55.         // sort the cards in order of value
  56.         evalCards = evalCards.OrderBy(x => x.myValue).ToArray();
  57.         handValue.Kicker1 = (int)evalCards[6].myValue;
  58.         handValue.Kicker2 = (int)evalCards[5].myValue;
  59.         handValue.Kicker3 = (int)evalCards[4].myValue;
  60.         handValue.Kicker4 = (int)evalCards[3].myValue;
  61.         handValue.Kicker5 = (int)evalCards[2].myValue;
  62.  
  63.         return Hand.HighCard;
  64.  
  65.     }
  66.  
  67.     // count the number of cards of each suit
  68.     private void getNumberOfSuit()
  69.     {
  70.         foreach (var element in evalCards)
  71.         {
  72.             if (element.mySuit == cardScript.suit.Heart)
  73.                 heartSum++;
  74.             else if (element.mySuit == cardScript.suit.Diamond)
  75.                 diamondSum++;
  76.             else if (element.mySuit == cardScript.suit.Club)
  77.                 clubSum++;
  78.             else if (element.mySuit == cardScript.suit.Spade)
  79.                 spadeSum++;
  80.         }
  81.     }
  82.  
  83.     // evaulate cards for a royal flush
  84.     private bool RoyalFlush()
  85.     {
  86.         // if all suits are the same
  87.         if (heartSum == 5 || diamondSum == 5 || clubSum == 5 || spadeSum == 5)
  88.         {
  89.             // make a new array to store all suit cards in flush for checking
  90.             cardScript[] suitArray = new cardScript[5];
  91.  
  92.             // sort the cards in order of suit
  93.             evalCards = evalCards.OrderBy(x => x.mySuit).ToArray();
  94.  
  95.             // if first 5 evalCards are same suit
  96.             if (evalCards[0].mySuit == evalCards[4].mySuit)
  97.             {
  98.                 // store evalCards in suitArray for checking
  99.                 suitArray[0] = evalCards[0];
  100.                 suitArray[1] = evalCards[1];
  101.                 suitArray[2] = evalCards[2];
  102.                 suitArray[3] = evalCards[3];
  103.                 suitArray[4] = evalCards[4];
  104.  
  105.                 // reorder suitArray cards in order of value
  106.                 suitArray = suitArray.OrderBy(x => x.myValue).ToArray();
  107.  
  108.                 // if evalCards == royal flush
  109.                 if (suitArray[0].myValue == cardScript.value.Ten &&
  110.                     suitArray[1].myValue == cardScript.value.Jack &&
  111.                     suitArray[2].myValue == cardScript.value.Queen &&
  112.                     suitArray[3].myValue == cardScript.value.King &&
  113.                     suitArray[4].myValue == cardScript.value.Ace)
  114.                 {
  115.                     // player with the highest value last card wins
  116.                     handValue.Total = (int)suitArray[4].myValue;
  117.  
  118.                     return true;
  119.                 }
  120.             }
  121.  
  122.             // if evalCards 2 to 6 are same suit
  123.             else if (evalCards[1].mySuit == evalCards[5].mySuit)
  124.             {
  125.                 // store evalCards in suitArray for checking
  126.                 suitArray[0] = evalCards[1];
  127.                 suitArray[1] = evalCards[2];
  128.                 suitArray[2] = evalCards[3];
  129.                 suitArray[3] = evalCards[4];
  130.                 suitArray[4] = evalCards[5];
  131.  
  132.                 // reorder suitArray cards in order of value
  133.                 suitArray = suitArray.OrderBy(x => x.myValue).ToArray();
  134.  
  135.                 // if evalCards == royal flush
  136.                 if (suitArray[0].myValue == cardScript.value.Ten &&
  137.                     suitArray[1].myValue == cardScript.value.Jack &&
  138.                     suitArray[2].myValue == cardScript.value.Queen &&
  139.                     suitArray[3].myValue == cardScript.value.King &&
  140.                     suitArray[4].myValue == cardScript.value.Ace)
  141.                 {
  142.                     // player with the highest value last card wins
  143.                     handValue.Total = (int)suitArray[4].myValue;
  144.  
  145.                     return true;
  146.                 }
  147.             }
  148.  
  149.             // if evalCards 3 to 7 are same suit
  150.             else if (evalCards[2].mySuit == evalCards[6].mySuit)
  151.             {
  152.                 // store evalCards in suitArray for checking
  153.                 suitArray[0] = evalCards[2];
  154.                 suitArray[1] = evalCards[3];
  155.                 suitArray[2] = evalCards[4];
  156.                 suitArray[3] = evalCards[5];
  157.                 suitArray[4] = evalCards[6];
  158.  
  159.                 // reorder suitArray cards in order of value
  160.                 suitArray = suitArray.OrderBy(x => x.myValue).ToArray();
  161.  
  162.                 // if evalCards == royal flush
  163.                 if (suitArray[0].myValue == cardScript.value.Ten &&
  164.                     suitArray[1].myValue == cardScript.value.Jack &&
  165.                     suitArray[2].myValue == cardScript.value.Queen &&
  166.                     suitArray[3].myValue == cardScript.value.King &&
  167.                     suitArray[4].myValue == cardScript.value.Ace)
  168.                 {
  169.                     // player with the highest value last card wins
  170.                     handValue.Total = (int)suitArray[4].myValue;
  171.  
  172.                     return true;
  173.                 }
  174.             }
  175.         }
  176.  
  177.         return false;
  178.     }
  179.  
  180.     // evaulate cards for a straight flush
  181.     private bool StraightFlush()
  182.     {
  183.         // if all suits are the same
  184.         if (heartSum == 5 || diamondSum == 5 || clubSum == 5 || spadeSum == 5)
  185.         {
  186.             // make a new array to store all suit cards in flush for checking
  187.             cardScript[] suitArray = new cardScript[5];
  188.  
  189.             // sort the cards in order of suit
  190.             evalCards = evalCards.OrderBy(x => x.mySuit).ToArray();
  191.  
  192.             // if first 5 evalCards are same suit
  193.             if (evalCards[0].mySuit == evalCards[4].mySuit)
  194.             {
  195.                 // store evalCards in suitArray for checking
  196.                 suitArray[0] = evalCards[0];
  197.                 suitArray[1] = evalCards[1];
  198.                 suitArray[2] = evalCards[2];
  199.                 suitArray[3] = evalCards[3];
  200.                 suitArray[4] = evalCards[4];
  201.  
  202.                 // reorder suitArray cards in order of value
  203.                 suitArray = suitArray.OrderBy(x => x.myValue).ToArray();
  204.  
  205.                 // if 5 consecutive valued evalCards
  206.                 if (suitArray[0].myValue + 1 == suitArray[1].myValue &&
  207.                     suitArray[1].myValue + 1 == suitArray[2].myValue &&
  208.                     suitArray[2].myValue + 1 == suitArray[3].myValue &&
  209.                     suitArray[3].myValue + 1 == suitArray[4].myValue)
  210.                 {
  211.                     // player with the highest value last card wins
  212.                     handValue.Total = (int)suitArray[4].myValue;
  213.  
  214.                     return true;
  215.                 }
  216.                 // if low Ace straight
  217.                 else if (suitArray[4].myValue - 11 == suitArray[0].myValue &&
  218.                     suitArray[0].myValue + 1 == suitArray[1].myValue &&
  219.                     suitArray[1].myValue + 1 == suitArray[2].myValue &&
  220.                     suitArray[2].myValue + 1 == suitArray[3].myValue)
  221.                 {
  222.                     // player with the highest value last card wins
  223.                     handValue.Total = (int)suitArray[3].myValue;
  224.  
  225.                     return true;
  226.                 }
  227.             }
  228.  
  229.             // if evalCards 2 to 6 are same suit
  230.             else if (evalCards[1].mySuit == evalCards[5].mySuit)
  231.             {
  232.                 // store evalCards in suitArray for checking
  233.                 suitArray[0] = evalCards[1];
  234.                 suitArray[1] = evalCards[2];
  235.                 suitArray[2] = evalCards[3];
  236.                 suitArray[3] = evalCards[4];
  237.                 suitArray[4] = evalCards[5];
  238.  
  239.                 // reorder suitArray cards in order of value
  240.                 suitArray = suitArray.OrderBy(x => x.myValue).ToArray();
  241.  
  242.                 // if 5 consecutive valued evalCards
  243.                 if (suitArray[0].myValue + 1 == suitArray[1].myValue &&
  244.                     suitArray[1].myValue + 1 == suitArray[2].myValue &&
  245.                     suitArray[2].myValue + 1 == suitArray[3].myValue &&
  246.                     suitArray[3].myValue + 1 == suitArray[4].myValue)
  247.                 {
  248.                     // player with the highest value last card wins
  249.                     handValue.Total = (int)suitArray[4].myValue;
  250.  
  251.                     return true;
  252.                 }
  253.                 // if low Ace straight
  254.                 else if (suitArray[4].myValue - 11 == suitArray[0].myValue &&
  255.                     suitArray[0].myValue + 1 == suitArray[1].myValue &&
  256.                     suitArray[1].myValue + 1 == suitArray[2].myValue &&
  257.                     suitArray[2].myValue + 1 == suitArray[3].myValue)
  258.                 {
  259.                     // player with the highest value last card wins
  260.                     handValue.Total = (int)suitArray[3].myValue;
  261.  
  262.                     return true;
  263.                 }
  264.             }
  265.  
  266.             // if evalCards 3 to 7 are same suit
  267.             else if (evalCards[2].mySuit == evalCards[6].mySuit)
  268.             {
  269.                 // store evalCards in suitArray for checking
  270.                 suitArray[0] = evalCards[2];
  271.                 suitArray[1] = evalCards[3];
  272.                 suitArray[2] = evalCards[4];
  273.                 suitArray[3] = evalCards[5];
  274.                 suitArray[4] = evalCards[6];
  275.  
  276.                 // reorder suitArray cards in order of value
  277.                 suitArray = suitArray.OrderBy(x => x.myValue).ToArray();
  278.  
  279.                 // if 5 consecutive valued evalCards
  280.                 if (suitArray[0].myValue + 1 == suitArray[1].myValue &&
  281.                     suitArray[1].myValue + 1 == suitArray[2].myValue &&
  282.                     suitArray[2].myValue + 1 == suitArray[3].myValue &&
  283.                     suitArray[3].myValue + 1 == suitArray[4].myValue)
  284.                 {
  285.                     // player with the highest value last card wins
  286.                     handValue.Total = (int)suitArray[4].myValue;
  287.  
  288.                     return true;
  289.                 }
  290.                 // if low Ace straight
  291.                 else if (suitArray[4].myValue - 11 == suitArray[0].myValue &&
  292.                     suitArray[0].myValue + 1 == suitArray[1].myValue &&
  293.                     suitArray[1].myValue + 1 == suitArray[2].myValue &&
  294.                     suitArray[2].myValue + 1 == suitArray[3].myValue)
  295.                 {
  296.                     // player with the highest value last card wins
  297.                     handValue.Total = (int)suitArray[3].myValue;
  298.  
  299.                     return true;
  300.                 }
  301.             }
  302.         }
  303.  
  304.         return false;
  305.     }
  306.  
  307.     // evaulate cards for four of a kind
  308.     private bool FourOfKind()
  309.     {
  310.  
  311.         // sort the cards in order of value
  312.         evalCards = evalCards.OrderBy(x => x.myValue).ToArray();
  313.  
  314.         // if the first card and 4th card values are identical we have 4 of a kind
  315.         if (evalCards[0].myValue == evalCards[3].myValue)
  316.         {
  317.             handValue.Total = (int)evalCards[0].myValue * 4;
  318.             handValue.Kicker1 = (int)evalCards[6].myValue;
  319.             return true;
  320.         }
  321.  
  322.         // if the second and 5th card values are identical we have 4 of a kind
  323.         else if (evalCards[1].myValue == evalCards[4].myValue)
  324.         {
  325.             handValue.Total = (int)evalCards[1].myValue * 4;
  326.             handValue.Kicker1 = (int)evalCards[6].myValue;
  327.             return true;
  328.         }
  329.  
  330.         // if the third and sixth card values are identical we have 4 of a kind
  331.         else if (evalCards[2].myValue == evalCards[5].myValue)
  332.         {
  333.             handValue.Total = (int)evalCards[2].myValue * 4;
  334.             handValue.Kicker1 = (int)evalCards[6].myValue;
  335.             return true;
  336.         }
  337.  
  338.         // if the fourth and seveth card values are identical we have 4 of a kind
  339.         else if (evalCards[3].myValue == evalCards[6].myValue)
  340.         {
  341.             handValue.Total = (int)evalCards[3].myValue * 4;
  342.             handValue.Kicker1 = (int)evalCards[2].myValue;
  343.             return true;
  344.         }
  345.  
  346.         return false;
  347.  
  348.     }
  349.  
  350.     // evaluate cards for a full house
  351.     private bool FullHouse()
  352.     {
  353.         // sort the cards in order of value
  354.         evalCards = evalCards.OrderBy(x => x.myValue).ToArray();
  355.  
  356.         // if evalCards 1 through 3 are the same
  357.         if (evalCards[0].myValue == evalCards[2].myValue)
  358.         {
  359.             // and if evalCards 4 and 5 are the same
  360.             if (evalCards[3].myValue == evalCards[4].myValue)
  361.             {
  362.                 // if 2 or more players have a full house the player with the best three of a kind wins
  363.                 handValue.Total = (int)evalCards[0].myValue * 3;
  364.  
  365.                 // 2 of or more players have the same three of a kind the best pair wins
  366.                 handValue.Kicker1 = (int)evalCards[3].myValue * 2;
  367.  
  368.                 return true;
  369.             }
  370.             // or if evalCards 5 and 6 are the same
  371.             else if (evalCards[4].myValue == evalCards[5].myValue)
  372.             {
  373.                 // if 2 or more players have a full house the player with the best three of a kind wins
  374.                 handValue.Total = (int)evalCards[0].myValue * 3;
  375.  
  376.                 // 2 of or more players have the same three of a kind the best pair wins
  377.                 handValue.Kicker1 = (int)evalCards[4].myValue * 2;
  378.                
  379.                 return true;
  380.             }
  381.             // or if evalCards 6 and 7 are the same
  382.             else if (evalCards[5].myValue == evalCards[6].myValue)
  383.             {
  384.                 // if 2 or more players have a full house the player with the best three of a kind wins
  385.                 handValue.Total = (int)evalCards[0].myValue * 3;
  386.  
  387.                 // 2 of or more players have the same three of a kind the best pair wins
  388.                 handValue.Kicker1 = (int)evalCards[5].myValue * 2;
  389.  
  390.                 return true;
  391.             }
  392.         }
  393.         // or if evalCards 2 through 4 are the same
  394.         else if (evalCards[1].myValue == evalCards[3].myValue)
  395.         {
  396.             // and evalCards 5 and 6 are the same
  397.             if (evalCards[4].myValue == evalCards[5].myValue)
  398.             {
  399.                 // if 2 or more players have a full house the player with the best three of a kind wins
  400.                 handValue.Total = (int)evalCards[1].myValue * 3;
  401.  
  402.                 // 2 of or more players have the same three of a kind the best pair wins
  403.                 handValue.Kicker1 = (int)evalCards[4].myValue * 2;
  404.  
  405.                 return true;
  406.             }
  407.             // or evalCards 6 and 7 are the same
  408.             else if (evalCards[5].myValue == evalCards[6].myValue)
  409.             {
  410.                 // if 2 or more players have a full house the player with the best three of a kind wins
  411.                 handValue.Total = (int)evalCards[1].myValue * 3;
  412.  
  413.                 // 2 of or more players have the same three of a kind the best pair wins
  414.                 handValue.Kicker1 = (int)evalCards[5].myValue * 2;
  415.  
  416.                 return true;
  417.             }
  418.         }
  419.         // or if evalCards 3 through 5 are the same
  420.         else if (evalCards[2].myValue == evalCards[4].myValue)
  421.         {
  422.             // and evalCards 6 and 7 are the same
  423.             if (evalCards[5].myValue == evalCards[6].myValue)
  424.             {
  425.                 // if 2 or more players have a full house the player with the best three of a kind wins
  426.                 handValue.Total = (int)evalCards[2].myValue * 3;
  427.  
  428.                 // 2 of or more players have the same three of a kind the best pair wins
  429.                 handValue.Kicker1 = (int)evalCards[5].myValue * 2;
  430.  
  431.                 return true;
  432.             }
  433.             // or evalCards 1 and 2 are the same
  434.             else if (evalCards[0].myValue == evalCards[1].myValue)
  435.             {
  436.                 // if 2 or more players have a full house the player with the best three of a kind wins
  437.                 handValue.Total = (int)evalCards[2].myValue * 3;
  438.  
  439.                 // 2 of or more players have the same three of a kind the best pair wins
  440.                 handValue.Kicker1 = (int)evalCards[0].myValue * 2;
  441.  
  442.                 return true;
  443.             }
  444.         }
  445.         // or if evalCards 4 through 6 are the same
  446.         else if (evalCards[3].myValue == evalCards[5].myValue)
  447.         {
  448.             // and evalCards 1 and 2 are the same
  449.             if (evalCards[0].myValue == evalCards[1].myValue)
  450.             {
  451.                 // if 2 or more players have a full house the player with the best three of a kind wins
  452.                 handValue.Total = (int)evalCards[3].myValue * 3;
  453.  
  454.                 // 2 of or more players have the same three of a kind the best pair wins
  455.                 handValue.Kicker1 = (int)evalCards[0].myValue * 2;
  456.  
  457.                 return true;
  458.             }
  459.             // or evalCards 2 and 3 are the same
  460.             else if (evalCards[1].myValue == evalCards[2].myValue)
  461.             {
  462.                 // if 2 or more players have a full house the player with the best three of a kind wins
  463.                 handValue.Total = (int)evalCards[3].myValue * 3;
  464.  
  465.                 // 2 of or more players have the same three of a kind the best pair wins
  466.                 handValue.Total = (int)evalCards[1].myValue * 2;
  467.  
  468.                 return true;
  469.             }
  470.         }
  471.         // or if evalCards 5 through 7 are the same
  472.         else if (evalCards[4].myValue == evalCards[6].myValue)
  473.         {
  474.             // amd evalCards 1 and 2 are the same
  475.             if (evalCards[0].myValue == evalCards[1].myValue)
  476.             {
  477.                 // if 2 or more players have a full house the player with the best three of a kind wins
  478.                 handValue.Total = (int)evalCards[4].myValue * 3;
  479.  
  480.                 // 2 of or more players have the same three of a kind the best pair wins
  481.                 handValue.Kicker1 = (int)evalCards[0].myValue * 2;
  482.  
  483.                 return true;
  484.             }
  485.             // or if evalCards 2 and 3 are the same
  486.             else if (evalCards[1].myValue == evalCards[2].myValue)
  487.             {
  488.                 // if 2 or more players have a full house the player with the best three of a kind wins
  489.                 handValue.Total = (int)evalCards[4].myValue * 3;
  490.  
  491.                 // 2 of or more players have the same three of a kind the best pair wins
  492.                 handValue.Kicker1 = (int)evalCards[1].myValue * 2;
  493.  
  494.                 return true;
  495.             }
  496.             // or if evalCards 3 and 4 are the same
  497.             else if (evalCards[2].myValue == evalCards[3].myValue)
  498.             {
  499.                 // if 2 or more players have a full house the player with the best three of a kind wins
  500.                 handValue.Total = (int)evalCards[4].myValue * 3;
  501.  
  502.                 // 2 of or more players have the same three of a kind the best pair wins
  503.                 handValue.Kicker1 = (int)evalCards[2].myValue * 2;
  504.  
  505.                 return true;
  506.             }
  507.         }
  508.         return false;
  509.     }
  510.  
  511.     // evaluate cards for a flush
  512.     private bool Flush()
  513.     {
  514.         // if all suits are the same
  515.         if (heartSum == 5 || diamondSum == 5 || clubSum == 5 || spadeSum == 5)
  516.         {
  517.             // make a new array to store all suit cards in flush for checking
  518.             cardScript[] suitArray = new cardScript[5];
  519.  
  520.             // sort the cards in order of suit
  521.             evalCards = evalCards.OrderBy(x => x.mySuit).ToArray();
  522.  
  523.             // if first 5 evalCards are same suit
  524.             if (evalCards[0].mySuit == evalCards[4].mySuit)
  525.             {
  526.                 // store evalCards in suitArray for checking
  527.                 suitArray[0] = evalCards[0];
  528.                 suitArray[1] = evalCards[1];
  529.                 suitArray[2] = evalCards[2];
  530.                 suitArray[3] = evalCards[3];
  531.                 suitArray[4] = evalCards[4];
  532.  
  533.                 // reorder suitArray cards in order of value
  534.                 suitArray = suitArray.OrderBy(x => x.myValue).ToArray();
  535.                
  536.                 // if flush, the player with the higher cards wins
  537.                 handValue.Total = (int)suitArray[0].myValue + (int)suitArray[1].myValue + (int)suitArray[2].myValue + (int)suitArray[3].myValue + (int)suitArray[4].myValue;
  538.  
  539.                 handValue.Kicker1 = (int)evalCards[4].myValue;
  540.                 handValue.Kicker2 = (int)evalCards[3].myValue;
  541.                 handValue.Kicker3 = (int)evalCards[2].myValue;
  542.                 handValue.Kicker4 = (int)evalCards[1].myValue;
  543.                 handValue.Kicker5 = (int)evalCards[0].myValue;
  544.  
  545.                 return true;
  546.             }
  547.  
  548.             // if evalCards 2 to 6 are same suit
  549.             else if (evalCards[1].mySuit == evalCards[5].mySuit)
  550.             {
  551.                 // store evalCards in suitArray for checking
  552.                 suitArray[0] = evalCards[1];
  553.                 suitArray[1] = evalCards[2];
  554.                 suitArray[2] = evalCards[3];
  555.                 suitArray[3] = evalCards[4];
  556.                 suitArray[4] = evalCards[5];
  557.  
  558.                 // reorder suitArray cards in order of value
  559.                 suitArray = suitArray.OrderBy(x => x.myValue).ToArray();
  560.  
  561.                 // if flush, the player with the higher cards wins
  562.                 handValue.Total = (int)suitArray[0].myValue + (int)suitArray[1].myValue + (int)suitArray[2].myValue + (int)suitArray[3].myValue + (int)suitArray[4].myValue;
  563.  
  564.                 handValue.Kicker1 = (int)evalCards[5].myValue;
  565.                 handValue.Kicker2 = (int)evalCards[4].myValue;
  566.                 handValue.Kicker3 = (int)evalCards[3].myValue;
  567.                 handValue.Kicker4 = (int)evalCards[2].myValue;
  568.                 handValue.Kicker5 = (int)evalCards[1].myValue;
  569.  
  570.                 return true;
  571.             }
  572.  
  573.             // if evalCards 3 to 7 are same suit
  574.             else if (evalCards[2].mySuit == evalCards[6].mySuit)
  575.             {
  576.                 // store evalCards in suitArray for checking
  577.                 suitArray[0] = evalCards[2];
  578.                 suitArray[1] = evalCards[3];
  579.                 suitArray[2] = evalCards[4];
  580.                 suitArray[3] = evalCards[5];
  581.                 suitArray[4] = evalCards[6];
  582.  
  583.                 // reorder suitArray cards in order of value
  584.                 suitArray = suitArray.OrderBy(x => x.myValue).ToArray();
  585.  
  586.                 // if flush, the player with the higher cards wins
  587.                 handValue.Total = (int)suitArray[0].myValue + (int)suitArray[1].myValue + (int)suitArray[2].myValue + (int)suitArray[3].myValue + (int)suitArray[4].myValue;
  588.  
  589.                 handValue.Kicker1 = (int)evalCards[6].myValue;
  590.                 handValue.Kicker2 = (int)evalCards[5].myValue;
  591.                 handValue.Kicker3 = (int)evalCards[4].myValue;
  592.                 handValue.Kicker4 = (int)evalCards[3].myValue;
  593.                 handValue.Kicker5 = (int)evalCards[2].myValue;
  594.  
  595.                 return true;
  596.             }
  597.         }
  598.  
  599.         return false;
  600.     }
  601.  
  602.     // evaluate cards for a straight
  603.     private bool Straight()
  604.     {
  605.         // sort the evalCards in order of value
  606.         evalCards = evalCards.OrderBy(x => x.myValue).ToArray();
  607.  
  608.         // if 5 consecutive valued evalCards
  609.         if (evalCards[0].myValue + 1 == evalCards[1].myValue &&
  610.             evalCards[1].myValue + 1 == evalCards[2].myValue &&
  611.             evalCards[2].myValue + 1 == evalCards[3].myValue &&
  612.             evalCards[3].myValue + 1 == evalCards[4].myValue)
  613.         {
  614.             // player with the highest value last card wins
  615.             handValue.Total = (int)evalCards[4].myValue;
  616.             return true;
  617.         }
  618.         else if (evalCards[1].myValue + 1 == evalCards[2].myValue &&
  619.             evalCards[2].myValue + 1 == evalCards[3].myValue &&
  620.             evalCards[3].myValue + 1 == evalCards[4].myValue &&
  621.             evalCards[4].myValue + 1 == evalCards[5].myValue)
  622.         {
  623.             // player with the highest value last card wins
  624.             handValue.Total = (int)evalCards[5].myValue;
  625.             return true;
  626.         }
  627.         else if (evalCards[2].myValue + 1 == evalCards[3].myValue &&
  628.             evalCards[3].myValue + 1 == evalCards[4].myValue &&
  629.             evalCards[4].myValue + 1 == evalCards[5].myValue &&
  630.             evalCards[5].myValue + 1 == evalCards[6].myValue)
  631.         {
  632.             // player with the highest value last card wins
  633.             handValue.Total = (int)evalCards[6].myValue;
  634.             return true;
  635.         }
  636.         // check for low Ace straight
  637.         else if (evalCards[6].myValue - 11 == evalCards[0].myValue &&
  638.             evalCards[0].myValue + 1 == evalCards[1].myValue &&
  639.             evalCards[1].myValue + 1 == evalCards[2].myValue &&
  640.             evalCards[2].myValue + 1 == evalCards[3].myValue)
  641.         {
  642.             // player with the highest value last card wins
  643.             handValue.Total = (int)evalCards[3].myValue;
  644.             return true;
  645.         }
  646.  
  647.         return false;
  648.     }
  649.  
  650.     // evaulate cards for three of a kind
  651.     private bool ThreeOfKind()
  652.     {
  653.         // sort the evalCards in order of value
  654.         evalCards = evalCards.OrderBy(x => x.myValue).ToArray();
  655.  
  656.         // if first 3 evalCards are the same
  657.         if (evalCards[0].myValue == evalCards[2].myValue)
  658.         {
  659.             handValue.Total = (int)evalCards[2].myValue * 3;
  660.             handValue.Kicker1 = (int)evalCards[6].myValue;
  661.             handValue.Kicker2 = (int)evalCards[5].myValue;
  662.             return true;
  663.         }
  664.         // OR 2-3-4 evalCards are the same
  665.         else if (evalCards[1].myValue == evalCards[3].myValue)
  666.         {
  667.             handValue.Total = (int)evalCards[3].myValue * 3;
  668.             handValue.Kicker1 = (int)evalCards[6].myValue;
  669.             handValue.Kicker2 = (int)evalCards[5].myValue;
  670.             return true;
  671.         }
  672.         // OR 3-4-5 are the same
  673.         else if (evalCards[2].myValue == evalCards[4].myValue)
  674.         {
  675.             handValue.Total = (int)evalCards[4].myValue * 3;
  676.             handValue.Kicker1 = (int)evalCards[6].myValue;
  677.             handValue.Kicker2 = (int)evalCards[5].myValue;
  678.             return true;
  679.         }
  680.         // OR 4-5-6 are the same
  681.         else if (evalCards[3].myValue == evalCards[5].myValue)
  682.         {
  683.             handValue.Total = (int)evalCards[5].myValue * 3;
  684.             handValue.Kicker1 = (int)evalCards[6].myValue;
  685.             handValue.Kicker2 = (int)evalCards[2].myValue;
  686.             return true;
  687.         }
  688.         // OR 5-6-7 are the same
  689.         else if (evalCards[4].myValue == evalCards[6].myValue)
  690.         {
  691.             handValue.Total = (int)evalCards[6].myValue * 3;
  692.             handValue.Kicker1 = (int)evalCards[3].myValue;
  693.             handValue.Kicker2 = (int)evalCards[2].myValue;
  694.             return true;
  695.         }
  696.  
  697.         return false;
  698.  
  699.     }
  700.  
  701.     // evaulate cards for two pairs
  702.     private bool TwoPairs()
  703.     {
  704.         // sort the evalCards in order of value
  705.         evalCards = evalCards.OrderBy(x => x.myValue).ToArray();
  706.  
  707.         // if evalCards 5,6 are same
  708.         if (evalCards[6].myValue == evalCards[5].myValue)
  709.         {
  710.             // and evalCards 3/4 are same
  711.             if (evalCards[4].myValue == evalCards[3].myValue)
  712.             {
  713.                 // determine value of highes value pair cards in hand
  714.                 handValue.Total = (int)evalCards[6].myValue * 2;
  715.  
  716.                 // determine value of second pair of cards in player hand
  717.                 handValue.Kicker1 = (int)evalCards[4].myValue * 2;
  718.  
  719.                 // determine value of remaining kicker
  720.                 handValue.Kicker2 = (int)evalCards[2].myValue;
  721.  
  722.                 return true;
  723.             }
  724.             // or evalCards 2/3 are the same
  725.             else if (evalCards[3].myValue == evalCards[2].myValue)
  726.             {
  727.                 // determine value of highes value pair cards in hand
  728.                 handValue.Total = (int)evalCards[6].myValue * 2;
  729.  
  730.                 // determine value of second pair of cards in player hand
  731.                 handValue.Kicker1 = (int)evalCards[3].myValue * 2;
  732.  
  733.                 // determine value of remaining kicker
  734.                 handValue.Kicker2 = (int)evalCards[4].myValue;
  735.  
  736.                 return true;
  737.             }
  738.             // or evalCards 1/2 are the same
  739.             else if (evalCards[2].myValue == evalCards[1].myValue)
  740.             {
  741.                 // determine value of highes value pair cards in hand
  742.                 handValue.Total = (int)evalCards[6].myValue * 2;
  743.  
  744.                 // determine value of second pair of cards in player hand
  745.                 handValue.Kicker1 = (int)evalCards[2].myValue * 2;
  746.  
  747.                 // determine value of remaining kicker
  748.                 handValue.Kicker2 = (int)evalCards[4].myValue;
  749.  
  750.                 return true;
  751.             }
  752.             // or evalCards 0/1 are the same
  753.             else if (evalCards[1].myValue == evalCards[0].myValue)
  754.             {
  755.                 // determine value of highes value pair cards in hand
  756.                 handValue.Total = (int)evalCards[6].myValue * 2;
  757.  
  758.                 // determine value of second pair of cards in player hand
  759.                 handValue.Kicker1 = (int)evalCards[1].myValue * 2;
  760.  
  761.                 // determine value of remaining kicker
  762.                 handValue.Kicker2 = (int)evalCards[4].myValue;
  763.  
  764.                 return true;
  765.             }
  766.         }
  767.         // if evalCards 4/5 are the same
  768.         else if (evalCards[5].myValue == evalCards[4].myValue)
  769.         {
  770.             // and evalCards 2/3 are the same
  771.             if (evalCards[3].myValue == evalCards[2].myValue)
  772.             {
  773.                 // determine value of highes value pair cards in hand
  774.                 handValue.Total = (int)evalCards[5].myValue * 2;
  775.  
  776.                 // determine value of second pair of cards in player hand
  777.                 handValue.Kicker1 = (int)evalCards[3].myValue * 2;
  778.  
  779.                 // determine value of remaining kicker
  780.                 handValue.Kicker2 = (int)evalCards[6].myValue;
  781.  
  782.                 return true;
  783.             }
  784.             // or evalCards 1/2 are the same
  785.             else if (evalCards[2].myValue == evalCards[1].myValue)
  786.             {
  787.                 // determine value of highes value pair cards in hand
  788.                 handValue.Total = (int)evalCards[5].myValue * 2;
  789.  
  790.                 // determine value of second pair of cards in player hand
  791.                 handValue.Kicker1 = (int)evalCards[2].myValue * 2;
  792.  
  793.                 // determine value of remaining kicker
  794.                 handValue.Kicker2 = (int)evalCards[6].myValue;
  795.  
  796.                 return true;
  797.             }
  798.             // or evalCards 0/1 are the same
  799.             else if (evalCards[1].myValue == evalCards[0].myValue)
  800.             {
  801.                 // determine value of highes value pair cards in hand
  802.                 handValue.Total = (int)evalCards[5].myValue * 2;
  803.  
  804.                 // determine value of second pair of cards in player hand
  805.                 handValue.Kicker1 = (int)evalCards[1].myValue * 2;
  806.  
  807.                 // determine value of remaining kicker
  808.                 handValue.Kicker2 = (int)evalCards[6].myValue;
  809.  
  810.                 return true;
  811.             }
  812.         }
  813.         // if cards 3/4 are the same
  814.         else if (evalCards[4].myValue == evalCards[3].myValue)
  815.         {
  816.             // and cards 1/2 are the same
  817.             if (evalCards[2].myValue == evalCards[1].myValue)
  818.             {
  819.                 // determine value of highes value pair cards in hand
  820.                 handValue.Total = (int)evalCards[4].myValue * 2;
  821.  
  822.                 // determine value of second pair of cards in player hand
  823.                 handValue.Kicker1 = (int)evalCards[2].myValue * 2;
  824.  
  825.                 // determine value of remaining kicker
  826.                 handValue.Kicker2 = (int)evalCards[6].myValue;
  827.  
  828.                 return true;
  829.             }
  830.             // or cards 0/1 are the same
  831.             else if (evalCards[1].myValue == evalCards[0].myValue)
  832.             {
  833.                 // determine value of highes value pair cards in hand
  834.                 handValue.Total = (int)evalCards[4].myValue * 2;
  835.  
  836.                 // determine value of second pair of cards in player hand
  837.                 handValue.Kicker1 = (int)evalCards[1].myValue * 2;
  838.  
  839.                 // determine value of remaining kicker
  840.                 handValue.Kicker2 = (int)evalCards[6].myValue;
  841.  
  842.                 return true;
  843.             }
  844.         }
  845.         // if cards 2/3 are the same
  846.         else if (evalCards[3].myValue == evalCards[2].myValue)
  847.         {
  848.             // and cards 0/1 are the same
  849.             if (evalCards[1].myValue == evalCards[0].myValue)
  850.             {
  851.                 // determine value of highes value pair cards in hand
  852.                 handValue.Total = (int)evalCards[3].myValue * 2;
  853.  
  854.                 // determine value of second pair of cards in player hand
  855.                 handValue.Kicker1 = (int)evalCards[1].myValue * 2;
  856.  
  857.                 // determine value of remaining kicker
  858.                 handValue.Kicker2 = (int)evalCards[6].myValue;
  859.  
  860.                 return true;
  861.             }
  862.         }
  863.  
  864.         return false;
  865.     }
  866.  
  867.     // evaulate cards for one pair
  868.     private bool OnePair()
  869.     {
  870.         // sort the evalCards in order of value
  871.         evalCards = evalCards.OrderBy(x => x.myValue).ToArray();
  872.  
  873.         // if 1/2 are same
  874.         if (evalCards[0].myValue == evalCards[1].myValue)
  875.         {
  876.             handValue.Total = (int)evalCards[1].myValue * 2;
  877.             handValue.Kicker1 = (int)evalCards[6].myValue;
  878.             handValue.Kicker2 = (int)evalCards[5].myValue;
  879.             handValue.Kicker3 = (int)evalCards[4].myValue;
  880.             return true;
  881.         }
  882.         // if 2/3 are same
  883.         else if (evalCards[1].myValue == evalCards[2].myValue)
  884.         {
  885.             handValue.Total = (int)evalCards[2].myValue * 2;
  886.             handValue.Kicker1 = (int)evalCards[6].myValue;
  887.             handValue.Kicker2 = (int)evalCards[5].myValue;
  888.             handValue.Kicker3 = (int)evalCards[4].myValue;
  889.             return true;
  890.         }
  891.         // if 3/4 are same
  892.         else if (evalCards[2].myValue == evalCards[3].myValue)
  893.         {
  894.             handValue.Total = (int)evalCards[3].myValue * 2;
  895.             handValue.Kicker1 = (int)evalCards[6].myValue;
  896.             handValue.Kicker2 = (int)evalCards[5].myValue;
  897.             handValue.Kicker3 = (int)evalCards[4].myValue;
  898.             return true;
  899.         }
  900.         // if 4/5 are same
  901.         else if (evalCards[3].myValue == evalCards[4].myValue)
  902.         {
  903.             handValue.Total = (int)evalCards[4].myValue * 2;
  904.             handValue.Kicker1 = (int)evalCards[6].myValue;
  905.             handValue.Kicker2 = (int)evalCards[5].myValue;
  906.             handValue.Kicker3 = (int)evalCards[2].myValue;
  907.             return true;
  908.         }
  909.         // if 5/6 are same
  910.         else if (evalCards[4].myValue == evalCards[5].myValue)
  911.         {
  912.             handValue.Total = (int)evalCards[5].myValue * 2;
  913.             handValue.Kicker1 = (int)evalCards[6].myValue;
  914.             handValue.Kicker2 = (int)evalCards[3].myValue;
  915.             handValue.Kicker3 = (int)evalCards[2].myValue;
  916.             return true;
  917.         }
  918.         // if 6/7 are same
  919.         else if (evalCards[5].myValue == evalCards[6].myValue)
  920.         {
  921.             handValue.Total = (int)evalCards[6].myValue * 2;
  922.             handValue.Kicker1 = (int)evalCards[4].myValue;
  923.             handValue.Kicker2 = (int)evalCards[3].myValue;
  924.             handValue.Kicker3 = (int)evalCards[2].myValue;
  925.             return true;
  926.         }
  927.  
  928.         return false;
  929.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement