• Create Account

### #ActualAzaral

Posted 11 April 2013 - 04:12 PM

Use an unordered_map to store your numbers. The key would be number, the value would be how many you have of that number.

Example:

std::unordered_map< unsigned short int, unsigned short int > numbersInHand;

std::vector<unsigned short int> numbersDealt;

for(unsigned short int i = 0; i < numbersDealth.size(); i++)
{
numbersInHand[ numbersDealt[i] ]++;
}



Then it's just a matter of iterating through the map and getting the numbers from each value in it and seeing how big it is.

std::unordered_map<unsigned short int, unsigned short int>::iterator currentGroup = numbersInHand.begin();

enum HandCombinations {SinglesOnly, Pair, TwoPair, ThreeOfAKind, FullHouse, FourOfAKind} handStrength = SinglesOnly;

while( currentGroup != numbersInHand.end() )
{
switch( currentGroup->second() )

case 4:
handStrength = FourOfAKind;
break;

case 3:

if(handStrength == Pair)
{
handStrength = FullHouse;
}
else
{
handStrength = ThreeOfAKind;
}
break;

case 2:

if(handStrength == ThreeOfAKind)
{
handStrength == FullHouse;
}
else
{
handStrenght == Pair;
}
break;

currentGroup++;
}



Also, now that I think about it, you could use a map rather than an unordered map because of it keeping things in sequence.

This would make searching for straights easy.

//pseudocode
bool straightFound = false;
bool keepsearching = true;

iterator = begin;

int lowestNumber = iterator->second;
int numbersInARow = 1;
while(keepsearching)
{

if( hand.find(lowestNumber + 1) != hand.end() )
{
lowestNumber++;
numbersInARow++;
}

else
{
keepSearching = false;
}

}

if( numbersInARow == 5)
{
handStrength = straight;
}


### #3Azaral

Posted 11 April 2013 - 04:10 PM

Use an unordered_map to store your numbers. The key would be number, the value would be how many you have of that number.

Example:

std::unordered_map< unsigned short int, unsigned short int > numbersInHand;

std::vector<unsigned short int> numbersDealt;

for(unsigned short int i = 0; i < numbersDealth.size(); i++)
{

numbersInHand[ numbersDealt[i] ]++;

}



Then it's just a matter of iterating through the map and getting the numbers from each value in it and seeing how big it is.

std::unordered_map<unsigned short int, unsigned short int>::iterator currentGroup = numbersInHand.begin();

enum HandCombinations {SinglesOnly, Pair, TwoPair, ThreeOfAKind, FullHouse, FourOfAKind} handStrength = SinglesOnly;

while( currentGroup != numbersInHand.end() )
{
switch( currentGroup->second() )

case 4:
handStrength = FourOfAKind;
break;

case 3:

if(handStrength == Pair)
{
handStrength = FullHouse;
}
else
{
handStrength = ThreeOfAKind;
}
break;

case 2:

if(handStrength == ThreeOfAKind)
{
handStrength == FullHouse;
}
else
{
handStrenght == Pair;
}
break;

currentGroup++;
}



Also, now that I think about it, you could use a map rather than an unordered map because of it keeping things in sequence.

This would make searching for straights easy.

//pseudocode
bool straightFound = false;
bool keepsearching = true;

iterator = begin;

int lowestNumber = iterator->second;
int numbersInARow = 1;
while(keepsearching)
{

if( hand.find(lowestNumber + 1) != hand.end() )
{
lowestNumber++;
numbersInARow++;
}

else
{
keepSearching = false;
}

}

if( numbersInARow == 5)
{
handStrength = straight;
}


### #2Azaral

Posted 11 April 2013 - 03:48 PM

Use an unordered_map to store your numbers. The key would be number, the value would be how many you have of that number.

Example:

std::unordered_map< unsigned short int, unsigned short int > numbersInHand;

std::vector<unsigned short int> numbersDealt;

for(unsigned short int i = 0; i < numbersDealth.size(); i++)

{

numbersInHand[ numbersDealt[i] ]++;

}

Then it's just a matter of iterating through the map and getting the numbers from each value in it and seeing how big it is.

std::unordered_map<unsigned short int, unsigned short int>::iterator currentGroup = numbersInHand.begin();

enum HandCombinations {SinglesOnly, Pair, TwoPair, ThreeOfAKind, FullHouse, FourOfAKind} handStrength = SinglesOnly;

while( currentGroup != numbersInHand.end() )

{

switch( currentGroup->second() )

case 4:

handStrength = FourOfAKind;

break;

case 3:

if(handStrength == Pair)

{

handStrength = FullHouse;

}

else

{

handStrength = ThreeOfAKind;

}

break;

case 2:

if(handStrength == ThreeOfAKind)

{

handStrength == FullHouse;

}

else

{

handStrenght == Pair;

}

break;

currentGroup++;

}

Also, now that I think about it, you could use a map rather than an unordered map because of it keeping things in sequence.

This would make searching for straights easy.

//pseudocode

bool straightFound = false;

bool keepsearching = true;

iterator = begin;

int lowestNumber = iterator->second;

int numbersInARow = 1;

while(keepsearching)

{

if( hand.find(lowestNumber + 1) != hand.end() )

{

lowestNumber++;

numbersInARow++;

}

else

{

keepSearching = false;

}

}

if( numbersInARow == 5)

{

handStrength = straight;

}

### #1Azaral

Posted 11 April 2013 - 03:41 PM

Use an unordered_map to store your numbers. The key would be number, the value would be how many you have of that number.

Example:

std::unordered_map< unsigned short int, unsigned short int > numbersInHand;

std::vector<unsigned short int> numbersDealt;

for(unsigned short int i = 0; i < numbersDealth.size(); i++)

{

numbersInHand[ numbersDealt[i] ]++;

}

Then it's just a matter of iterating through the map and getting the numbers from each value in it and seeing how big it is.

std::unordered_map<unsigned short int, unsigned short int>::iterator currentGroup = numbersInHand.begin();

enum HandCombinations { Pair, ThreeOfAKind, TwoPair, FullHouse, FourOfAKind, SinglesOnly } handStrength = SinglesOnly;

while( currentGroup != numbersInHand.end() )

{

switch( currentGroup->second() )

case 4:

handStrength = FourOfAKind;

break;

case 3:

if(handStrength == Pair)

{

handStrength = FullHouse;

}

else

{

handStrength = ThreeOfAKind;

}

break;

case 2:

if(handStrength == ThreeOfAKind)

{

handStrength == FullHouse;

}

else

{

handStrenght == Pair;

}

break;

currentGroup++;

}

PARTNERS