//look for royal flush, removing pair using recursion public static bool isRoyalFlush(Hand hand) { hand.sortByRank(); Hand simplifiedhand1, simplifiedhand2; //to be set the same as hand - cards are removed from this hand to evaluate straights separately without the interference of pairs or three-of-a-kind for (int i = 0; i <= hand.Count() - 2; i++) { if (hand[i] == hand[i + 1]) { simplifiedhand1 = new Hand(hand); simplifiedhand1.Remove(i); simplifiedhand2 = new Hand(hand); simplifiedhand2.Remove(i + 1); if (HandCombination.isRoyalFlush(simplifiedhand1)) { return(true); } if (HandCombination.isRoyalFlush(simplifiedhand2)) { return(true); } } } int currentsuit = hand.getCard(0).getSuit(); if (hand.getCard(0).getRank() == 14 && hand.getCard(1).getRank() == 13 && hand.getCard(2).getRank() == 12 && hand.getCard(3).getRank() == 11 && hand.getCard(4).getRank() == 10 && hand.getCard(1).getSuit() == currentsuit && hand.getCard(2).getSuit() == currentsuit && hand.getCard(3).getSuit() == currentsuit && hand.getCard(4).getSuit() == currentsuit) { return(true); } else { return(false); } }
//get royal flush using recursion public static Hand getRoyalFlush(Hand hand) { hand.sortByRank(); Hand straightflush = new Hand(HandCombination.getStraightFlush(hand)); straightflush.setValue(10); if (straightflush.getCard(0).getRank() == 14) { return(straightflush); } else { straightflush.Clear(); return(straightflush); } }
//use recursion to get rid of pairs, then evaluate straight flush public static bool isStraightFlush(Hand hand) { hand.sortByRank(); Hand simplifiedhand1, simplifiedhand2; //to be set the same as hand - cards are removed from this hand to evaluate straights separately without the interference of pairs or three-of-a-kind for (int i = 0; i <= hand.Count() - 2; i++) { if (hand.getCard(i) == hand.getCard(i + 1)) { simplifiedhand1 = new Hand(hand); simplifiedhand1.Remove(i); simplifiedhand2 = new Hand(hand); simplifiedhand2.Remove(i + 1); if (HandCombination.isStraightFlush(simplifiedhand1)) { return(true); } if (HandCombination.isStraightFlush(simplifiedhand2)) { return(true); } } } for (int i = 0; i <= hand.Count() - 5; i++) { int currentrank = hand.getCard(i).getRank(), currentsuit = hand.getCard(i).getSuit(); if (currentrank == hand.getCard(i + 1).getRank() + 1 && currentrank == hand.getCard(i + 2).getRank() + 2 && currentrank == hand.getCard(i + 3).getRank() + 3 && currentrank == hand.getCard(i + 4).getRank() + 4 && currentsuit == hand.getCard(i + 1).getSuit() && currentsuit == hand.getCard(i + 2).getSuit() && currentsuit == hand.getCard(i + 3).getSuit() && currentsuit == hand.getCard(i + 4).getSuit()) { return(true); } } for (int i = 0; i <= hand.Count() - 4; i++) { int currentrank = hand.getCard(i).getRank(), currentsuit = hand.getCard(i).getSuit(); if (currentrank == 5 && hand.getCard(i + 1).getRank() == 4 && hand.getCard(i + 2).getRank() == 3 && hand.getCard(i + 3).getRank() == 2 && hand.getCard(0).getRank() == 14 && currentsuit == hand.getCard(i + 1).getSuit() && currentsuit == hand.getCard(i + 2).getSuit() && currentsuit == hand.getCard(i + 3).getSuit() && currentsuit == hand.getCard(0).getSuit()) { return(true); } } return(false); }
public string ComputerMove() { Hand temp1 = HandCombination.getBestHand(player); Hand temp2 = HandCombination.getBestHand(computer); if ((temp1 > temp2) && (temp2 < temp1)) { playerWin(); return("Player Win"); } else if ((temp2 > temp1) && (temp1 < temp2)) { computerWin(); return("Computer Win"); } else { drawWin(); return("Draw"); } }