Script
Here's a solution using my Icepool Python package:
from icepool import Deck, multiset_function, Reroll
deck = Deck({
'A' : 3,
'B' : 2,
'C' : 2,
'D' : 2,
'E' : 2,
'F' : 2,
'N' : 46,
'X' : 1,
})
def all_basic(outcome, count):
return outcome <= 'F' and count == deck[outcome]
@multiset_function
def hand_pile(hand, pile):
return (
(hand & ['A', 'B', 'C', 'D', 'E', 'F']).any(),
pile >= ['X'],
pile.map_counts(all_basic).any(),
)
def final_evaluation(keep, got_x, got_all_basic):
if not keep:
return Reroll
return got_x and got_all_basic
output(hand_pile(deck.deal(7, 6)).map(final_evaluation))
(API subject to change. This script is based on Icepool v0.25.6.)
Try this script in your browser.
Result
Die with denominator 7422507311299080
Outcome |
Quantity |
Probability |
False |
7401705459513360 |
99.719746% |
True |
20801851785720 |
0.280254% |
Explanation
- Given a single card and how many of that card were drawn,
all_basic
returns 1 if that card is a basic card and all copies of that card were drawn, and 0 otherwise.
- The
multiset_function
allows us to define a function using some simple multiset operations. In this case, we jointly determine three things:
- Whether the "hand" contained any basic card. The
&
operator represents multiset intersection, and .any()
determines whether that intersection is non-empty.
- Whether the "pile" contained the X card.
- Whether the "pile" contained all copies of a basic card for
.any()
such card.
final_evaluation
describes restarting if the first condition is not met, and otherwise determines whether the other two conditions are met.
- Finally, we put it all together by dealing 7 cards to the "hand" and 6 to the "pile".
Algorithm
The algorithm uses dynamic programming and the decomposition of the hypergeometric distribution into binomials to find the distribution efficiently. If you are curious to learn more, you can read my paper here.
@inproceedings{liu2022icepool,
title={Icepool: Efficient Computation of Dice Pool Probabilities},
author={Albert Julius Liu},
booktitle={Eighteenth AAAI Conference on Artificial Intelligence and Interactive Digital Entertainment},
volume={18},
number={1},
pages={258-265},
year={2022},
month={Oct.},
eventdate={2022-10-24/2022-10-28},
venue={Pomona, California},
url={https://ojs.aaai.org/index.php/AIIDE/article/view/21971},
doi={10.1609/aiide.v18i1.21971}
}