Card Game Opening Hand Calculator with subgroups

card-gameshypergeometric functionprobability distributions

So I'm trying to create a Yugioh Card Game opening hand calculator in a google spreadsheet. This can also be seen as drawing balls from an urn without replacement, but every ball has multiple attributes for example it could have a color as well as stripes on it.

So basically I created a database containing every card in the deck with data attached to it such as the amount of copies in the deck (value ranging from 1 to 3; terminology: 1="1of",2="2of", 3=3of), the type of card (Starter, Extender, Brick, Handtrap, Breaker; consider this the color) and if the card is a "Hard once per turn" (short: hopt) (meaning only 1 copy of this card can be used; consider this striped/not striped).

I'm using hypergeometrical distribution to calculate the different probabilities.

HYPGEOMDIST(num_successes, num_draws, successes_in_pop, pop_size)

    num_successes - amount of cards of a certain type I want to draw
    num_draws - amount of draws in my opening hand (5)
    successes_in_pop - total number of cards belonging to a certain type
    pop_size - total deck size

The spreadsheet automatically takes the inputs from the database and calculates pop_size and succcesses_in_pop.

Then I let it calculate the probability for num_successes [1,2,3,4,5].
Adding those up accordingly gives me probability for drawing 1+ 2+ 3+ Cards for that card type as results of 4+ and 5+ are not of any interest to create more balanced hands not containing just 1 card type.

For this example I'm using a 40 card deck with 4 different 3of cards
that all belong to the Starter type and drawing 5 random cards.
They are also all considered "hard once per turn"(short: hopt).
HYPGEOMDIST(x,5,12,40)

Then the probability for drawing 2+ Starters is 0,4772 for x=[2,3,4,5]

However this does not take into account, that in Yugioh a lot of cards are "Hard once per turn"(short: hopt). That means If I draw 1 copy of a specific card which I play 3 copies the remaining 2 copies in my deck are not considered legitimate Starter cards anymore If I want to draw 2 usable starters in my opening 5. They basically have to be unique cards while still belonging to the same overall group (card type Starter).

Therefore 0,4772 cannot be the final result yet. Because as soon as I draw the first Starter card since all 4 different ones are each hopt, I lose 2 legitimate targets remaining in my deck bringing down the remaining amount of Starter cards in the deck down from 11 to 9.

Some cards are not hopt though. So then in my example lets say 1 of the 4 different cards is not hopt, meaning drawing multiples of it is a viable combination.

Then in some hands I would draw this 1 card and still have 11 legitimate targets in deck.
In others I would not draw this card and only have 9 legitimate targets left.

Thanks to the help of @HighDiceRoller I got the following solution:

hopt - short for "hard once per turn"
b - amount of different hopt 2of cards 
c - amount of different hopt 3of cards
N1 - total amount of cards of certain type
N2 - total deck count
n1 - handsize

(1 - b * HYPGEOMDIST(2,2,2,N1) - c * HYPGEOMDIST(2,2,3,N1)) * HYPGEOMDIST(2,n1,N1,N2) + 
(1 - c * HYPGEOMDIST(3,3,3,N1)) +  * HYPGEOMDIST(3,n1,N1,N2) +
HYPGEOMDIST(4,n1,N1,N2) +
HYPGEOMDIST(5,n1,N1,N2) +

HYPGEOMDIST(2,2,2,N1) describes the probability of drawing the same card played at 2 copies (2ofs) twice out of the total amount of cards of a certain type. Multiplying that with the amount of different hopt 2of cards in deck gives us the odds for drawing a 2of card twice. Repeat for drawing 3ofs.

Subtracting the sum of those 2 gives us the probability of not drawing the same card twice. Now simply multiply with the probability of drawing exactly 2 cards of the target card type and we get the the probability of not drawing any 2 of the same card while drawing exactly 2 cards of the target type.

Repeat the process for the probability of not drawing 3 of the same card while drawing exactly 3 of the target type. Then add the probability of drawing exactly 4 and 5 cards of the target type and we are done. We now got the probability of drawing 2+ cards without any duplicate draws of hopt, meaning everytime we would draw 2 cards of that type, they could be used.

Edit: I replaced all the wrong steps and calculations with the correct formulas to make it easier to follow and reproduce results and help with Part2: Calculating the probability of drawing 3+ different hopt cards.

Best Answer

Using conditional probability

HYPGEOMDIST(2,5,3,40)=0,035
HYPGEOMDIST(3,5,3,40)=0,001

Now let's calculate the conditional probability of drawing exactly 2 starters cards and those 2 beeing copies of the same card.

HYPGEOMDIST(2,5,12,40)*0,140=0,046
HYPGEOMDIST(3,5,12,40)*0,004=0,000504

The correct thing to do here is not to multiply to find the conditional probability (which isn't the correct way to find the conditional probability anyways), but find the conditional probability and multiply. Specifically, conditional on drawing $k$ total starters, the probability that they are not all the same is

1 - 4 * HYPGEOMDIST(k,k,3,12)

effectively drawing $k$ cards from a deck consisting of just the 12 starters. Then you can multiply by the probability of drawing $k$ starters from the full deck, then sum over $k$ to get the total probability, i.e.

(1 - 4 * HYPGEOMDIST(2,2,3,12)) * HYPGEOMDIST(2,5,12,40) + 
(1 - 4 * HYPGEOMDIST(3,3,3,12)) * HYPGEOMDIST(3,5,12,40) +
HYPGEOMDIST(4,5,12,40) +
HYPGEOMDIST(5,5,12,40)

Icepool

My Icepool Python probability package can compute this, including counting more than 2 starters:

from icepool import Deck

STARTERS = 'a'
HARD_STARTERS = 'bcd'

def count_starters(outcome, count):
    if outcome in STARTERS:
        return count
    elif outcome in HARD_STARTERS:
        return min(count, 1)
    else:
        return 0

deck = Deck('abcd' * 3 + 'x' * 28)
output(deck.deal(5).map_counts(function=count_starters).count())

Result:

Die with denominator 658008

Outcome Quantity Probability
0 98280 14.935989%
1 276318 41.993106%
2 218880 33.264033%
3 59220 8.999891%
4 5202 0.790568%
5 108 0.016413%

You can try this in your browser here.

Related Question