Struggling With Card Game " Pairs

Hi,

I am struggling with implementing the Poker hand ranking 2 pairs into my card game assignment. Below is the code i used to create my single pair function, but i have no idea on how to start the 2 pair function?
1
2
3
4
5
6
bool CardGame::HasSinglePair(Hand* hand)
{
	return ( ( (hand->GetCardAtPosition(0)->GetRank() == hand->GetCardAtPosition(1)->GetRank()) + (hand->GetCardAtPosition(0)->GetRank() == hand->GetCardAtPosition(2)->GetRank()) + (hand->GetCardAtPosition(0)->GetRank() == hand->GetCardAtPosition(3)->GetRank()) + (hand->GetCardAtPosition(0)->GetRank() == hand->GetCardAtPosition(4)->GetRank())) == 1 ||
			 ( (hand->GetCardAtPosition(1)->GetRank() == hand->GetCardAtPosition(0)->GetRank()) + (hand->GetCardAtPosition(1)->GetRank() == hand->GetCardAtPosition(2)->GetRank()) + (hand->GetCardAtPosition(1)->GetRank() == hand->GetCardAtPosition(3)->GetRank()) + (hand->GetCardAtPosition(1)->GetRank() == hand->GetCardAtPosition(4)->GetRank())) == 1 ||
			 ( (hand->GetCardAtPosition(2)->GetRank() == hand->GetCardAtPosition(0)->GetRank()) + (hand->GetCardAtPosition(2)->GetRank() == hand->GetCardAtPosition(1)->GetRank()) + (hand->GetCardAtPosition(2)->GetRank() == hand->GetCardAtPosition(3)->GetRank()) + (hand->GetCardAtPosition(2)->GetRank() == hand->GetCardAtPosition(4)->GetRank())) == 1 )  ;
}


i would appreciate if someone could help me with the 2 pairs hand ranking function.
if it was me, i'd get the first card and iterate over the rest of the cards til i get a pair. if i do get a pair break out with true.
if not, move the second hand of the card and iterate over the remaining cards in the hand.
repeat for all the cards.
Thank You, for the reply, another quick question, how would i do that?
This is how you do it with numbers. Apply the same method to your cards.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
#include <iostream>

int main()
{
    int arr[5] = {1,2,3,4,5}; //Two arrays of numbers. 
    int arr2[5] = {2,4,6,8,10};
    int i = 0, j = 0; //Just for the following for loops. 
    for(i = 0; i < 5; ++i) //For every element in arr. 
    {
        for(j = 0; j < 5; ++j) //For every element in arr2. 
        {
            if(arr[i] == arr2[j]) //If they are equal.
            {
                std::cout << "Match found at " << i << " " << j << "\n"; 
            }
        }
    }
    return 0;
}

Thank you for the help, much appreciated
Topic archived. No new replies allowed.