Badugi is a 4 card low hand poker game.
i / 13 is suit and i % 13 is rank. Cards from 0 to 51 inclusive.
Straights and flushes do not count. The best hand is A234. The worst hand is KKKK.
If you match on either a suit or rank you take out a card. Any 4 card hand beats a 3 card hand. Any 3 card hand beats a 2 card hand....
The way I approached was to start with a score of 4 and take 1 away on a match. Need to match on the or (rank or suite) as a card that matches on both is still just one card eliminated.
Would use this to mark how many hands you are ahead and behind.
Please comment on style and speed.
public static int BadugiStrength(int[] cards)
{
int score = 4;
int i = cards[0];
for(int j = 1; j <= 3; j ++)
{
if(i % 13 == cards[j] % 13 || i / 13 == cards[j] / 13)
{
score--;
break;
}
}
i = cards[1];
for (int j = 2; j <= 3; j++)
{
if (i % 13 == cards[j] % 13 || i / 13 == cards[j] / 13)
{
score--;
break;
}
}
if (cards[2] % 13 == cards[3] % 13 || cards[2] / 13 == cards[3] / 13)
{
score--;
}
return score;
}
public static int Badugi()
{
int counter = 0;
int[] hand = new int[4];
int[] scores = new int[5];
for (int i = 51; i >=3; i--)
{
hand[0] = i;
for (int j = i - 1; j >= 2; j--)
{
hand[1] = j;
for (int k = j - 1; k >= 1; k--)
{
hand[2] = k;
for (int m = k - 1; m >= 0; m--)
{
int score = BadugiStrength(hand);
scores[score]++;
counter++;
}
}
}
}
Debug.WriteLine($"4 card {scores[4]} 3 card {scores[3]} 2 card {scores[2]} 1 card {scores[1]} total {scores[4] + scores[3] + scores[2] + scores[1]} {counter}");
return counter;
}