shifting auxiliary function bitcount from Tools to CardsValue

This commit is contained in:
floty
2014-06-08 17:03:53 +02:00
parent 61bdbe8e06
commit 16f3f6ceb2
4 changed files with 22 additions and 22 deletions
+16 -6
View File
@@ -255,7 +255,7 @@ int CardsValue::cardsValueShort(int cards[4])
// Royal Flush, Straight Flush, Flush
for(color_idx=0; color_idx<4; color_idx++) { // check all colors
if(Tools::bitcount(cards[color_idx])>=5) { // check if at least 5 cards of one color
if(bitcount(cards[color_idx])>=5) { // check if at least 5 cards of one color
if((cards[color_idx] & straight[0]) == straight[0]) // check for Royal Flush
return 9;
else { // check for Straight Flush
@@ -293,7 +293,7 @@ int CardsValue::cardsValueShort(int cards[4])
for(color_2_idx=color_1_idx+1; color_2_idx<3; color_2_idx++) {
for(color_3_idx=color_2_idx+1; color_3_idx<4; color_3_idx++) {
temp = cards[color_1_idx] & cards[color_2_idx] & cards[color_3_idx];
if(Tools::bitcount(temp) == 2) { // two times Three of a Kind
if(bitcount(temp) == 2) { // two times Three of a Kind
return 6; // Full House
} else {
if(temp) {
@@ -315,7 +315,7 @@ int CardsValue::cardsValueShort(int cards[4])
for(color_1_idx=0; color_1_idx<3; color_1_idx++) {
for(color_2_idx=color_1_idx+1; color_2_idx<4; color_2_idx++) {
temp = cards[color_1_idx] & cards[color_2_idx];
if(Tools::bitcount(temp) >= 2) { // at least two times Two of a Kind
if(bitcount(temp) >= 2) { // at least two times Two of a Kind
return 2; // Two Pairs
} else {
if(temp) { // search for second pair
@@ -343,7 +343,7 @@ int CardsValue::cardsValue(int cards[4], int bestHand[4])
// Royal Flush, Straight Flush, Flush
for(color_1_idx=0; color_1_idx<4; color_1_idx++) { // check all colors
if(Tools::bitcount(cards[color_1_idx])>=5) { // check if at least 5 cards of one color
if(bitcount(cards[color_1_idx])>=5) { // check if at least 5 cards of one color
if((cards[color_1_idx] & straight[0]) == straight[0]) { // check for Royal Flush
if(bestHand) bestHand[color_1_idx] = straight[0];
return 900000000; // Royal Flush
@@ -407,7 +407,7 @@ int CardsValue::cardsValue(int cards[4], int bestHand[4])
}
}
if(temp1) {
if(Tools::bitcount(temp1) == 2) {
if(bitcount(temp1) == 2) {
// two times Three of a Kind
if(bestHand) {
kickerValue1 = determineKickerValue(temp1,0,0);
@@ -459,7 +459,7 @@ int CardsValue::cardsValue(int cards[4], int bestHand[4])
}
}
if(temp1) {
if(Tools::bitcount(temp1) >= 2) { // at least two times Two of a Kind
if(bitcount(temp1) >= 2) { // at least two times Two of a Kind
kickerValue1 = determineKickerValue(temp1,0,1);
kickerValue2 = determineKickerValue(OR & ~kickerValue1.select,2,2);
if(bestHand) {
@@ -2572,6 +2572,16 @@ std::list<std::string> CardsValue::translateCardsValueCode(int cardsValueCode)
}
int CardsValue::bitcount(int in)
{
int count=0 ;
while (in) {
count++ ;
in &= (in - 1) ;
}
return count ;
}
//int** CardsValue::showdown(GameState beRoID, int** playerCards, int playerCount) {
//
+2
View File
@@ -58,6 +58,8 @@ public:
static int holeCardsToIntCode(int[2]);
static std::vector< std::vector<int> > calcCardsChance(GameState, int[2], int[5]);
static int bitcount(int in);
//static int** showdown(GameState, int**, int);
};
-11
View File
@@ -82,14 +82,3 @@ void Tools::GetRand(int minValue, int maxValue, unsigned count, int *out)
*startPtr++ = gen();
}
}
int Tools::bitcount(int in)
{
int count=0 ;
while (in) {
count++ ;
in &= (in - 1) ;
}
return count ;
}
-1
View File
@@ -38,7 +38,6 @@ public:
static void ShuffleArrayNonDeterministic(int *inout, unsigned count);
static void GetRand(int minValue, int maxValue, unsigned count, int *out);
static int bitcount(int in);
};