# I'd like some help with Badugi absolute strength calculator

Those who playes Badugi know the basic rules:

• You have 4 cards.
• The more distinct cards both in suit and number, the better hand it is.
• Among the same number of distinct cards, the worse bust (being Ace the lower card) is winner (this means: KQJT of different suits are better than A23, KQJ all ofsuit better than A2, and KQ better than A; The best hand is A234 and the worse hand is K, from KKKK).

My question could be answered in two different ways:

1. Could someone lead me to an opensource calculator for Badugi? The calculator should satisfy the need of, given a random hand of 4 cards from a 52-card deck, determine the % of winning, losing, tying (in the theoretical scenario that I kept that hand until the showdown).

2. Could someone help me with the math to make this calculator by myself?

If chosing alternative 2, this is what I currently have, And I'll state what part do I need help with:

Population

You have `52c4 (52*51*50*49 / 4*3*2*1)` possible hands to keep for the showdown.

Reference system

Initially, the hands are ranked from A to K. I will assume A is 0 and K 12 for this calculations to be clean.

4 fully distinct cards

The best scenario here is A234 offsuit. We could say this is a bust, except that we also need different suits. For a specific cards arrangement, you have 24 (4!) combinations of different suits for the busted cards. The upper-value busts for a given WXYZ combinations of cards (assuming it is sorted W > X > Y > Z) is:

`(12-Z)C4 + (12-Y)C3 + (12-X)C2 + (12-W)`

You get, there, the amount of hands of the same type (4-distinct / badugi) that are beaten by the current hand.

The full population for badugi hands is `13C4 * 4!`. So your current badugi is beaten by other badugis like this:

`4! * (13C4 - ((12-Z)C4 + (12-Y)C3 + (12-X)C2 + (12-W)) - (1))`.

Now I have, given your WXYZ:

• # of badugi hands that beat my WXYZ.
• # of badugi hands that tie my WXYZ.
• By subtraction: # of badugi hands that lose to my WXYZ.
• Total population of badugi (full-distinct WXYZ cards) hands.

So far If your only chance was to draw badugis and no other hands, calculating your hand strength is taking the first expression and dividing by `13C4 / 4!`. This is just so you can understand what I need. However, since it is not the whole case, I will proceed with the remaining hands.

1 fully-distinct cards

I know nobody in their sane mind would reach the showdown with this hand unless having a really good reason, but let's calculate this as well.

If you have just 1 card it is because:

1. You have 4 of a kind.
2. You have a flush.

Then you always take the lowest hand. If your final value is K, Q, or J, is because you have KKKK, QQQQ, or JJJJ. For 10 and lower, you could be having TTTT or KQJT. From there, cases from having flush (like KQJT) appear.

So if you have 1 card, there are many cases you can tie with:

`1 + 4 * (amount of flushes with greater cards but same lower card)`

The last part can be calculated like `(12-Z)C3` because that is the amount of combinations of cards greater than Z, which make you complete an infamous flush that do not improve the value of Z. The remaining `1` is for getting a 4-oak (ZZZZ).

What hands can beat me?

• "4 of a kinds" of a lower value: `Z`.
• "Flushes" featuring a lower card: I simply calculate `4 * [(13C4) - (12-Z)C3 - (12-Z)C4]`, where we can understand `4 * (all flushes in a suit - all flushes withe same lower card - all flushes with greater lower card)`.

So the amount of hands that beat me is: `Z + 4 * [(13C4) - (12-Z)C3 - (12-Z)C4]`

As I said before, the last subterm `(12-Z)C4` is the amount of flushes featuring a lower card greater than Z. Example: If I have a flush with lower card 8, I will beat flushes: KQJ9 KQT9 KJT9 QJT9 KQJT (8 is normalized to 7, and 5C4 is 5).

Let's see what I have right now:

• # of hands that beat my WXYZ (second calculation).
• # of badugi hands that tie my WXYZ (first calculation in this section).
• By subtraction: # of badugi hands that lose to my WXYZ.
• Total population of these hands: `13 + 13C4 * 4`. The first term is the amount of 4oaks. The second the amount of flushes.

Could you help me stating the 4 sub-answers for the cases of 2-cards and 3-cards?

I ran a brute force analysis and this is what I think I found

`````` 17160   6.34%  4 card
123552  45.64%  3 card
112476  41.55%  2 card
17537   6.48%  1 card
270725 100.00%
``````

I think there was a mistake and the correct answer is
4 card 25740 3 card 135564 2 card 94497 1 card 14924 total 270725

Not hard to just run em all
The total matches combin(52; 4)

Need to do some work as some 4 will beat some 5 ... but this is the framework.

On 6 you could still have 3 live as one card could be both a rank and suite duplicate.

``````Rank count + suit count
8      7      6     5   4 3 2      t      t
17160 113256 112632 27209 468 0 0 270725 270725

public static int Bengasi()
{
int counter = 0;
int[] split = new int[9];
HashSet<int> rank = new HashSet<int>();
HashSet<int> suit = new HashSet<int>();
int rankPlusSuit;
for (int i = 51; i >= 3; i--)
{
for (int j = i - 1; j >= 2; j--)
{
for (int k = j - 1; k >= 1; k--)
{
for (int m = k - 1; m >= 0; m--)
{
rank.Clear();
suit.Clear();
rankPlusSuit = rank.Count + suit.Count;
split[rankPlusSuit]++;
counter++;
}
}
}
}
Debug.WriteLine(\$"{split[8]} {split[7]} {split[6]} {split[5]} {split[4]} {split[3]}  {split[8] + split[7] + split[6] + split[5] + split[4] + split[3]} {counter}");
return counter;
}
``````

Here is the strength code

``````public static int BengasiStrength(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;
}
``````