c - 魔法风云卡抽奖概率函数C语言

标签 c

我目前正在编写一个函数,它会询问您的牌组大小、您在该牌组中拥有的特定牌的副本数量、您的初始手牌大小、您调度的牌数(我们正在设置调度的牌除了抓牌,然后将重新调度的牌洗回),以及你想在哪个回合抓牌。

本质上,我将所有未抽到牌的概率相乘(然后用 1 减去该概率)得到在特定回合抽到特定牌的概率。到目前为止,我的函数如下所示:

void card_probability() {

    int total;
    int numCopies;
    int n;
    int m;
    int turn;
    double initial_draw_prob;
    double mulligan_prob;
    double draw_prob;
    double neg_probability;
    double probability;

    printf("Enter how many total cards there are in the deck: ");
    scanf("%d", &total);

    printf("Enter how many copies of the card that you are looking for are 
    in the deck: ");
    scanf("%d", &numCopies);

    printf("Enter your initial hand size: ");
    scanf("%d", &n);

    printf("Enter how many cards you are mulliganing: ");
    scanf("%d", &m);

    printf("Enter what turn you want to draw the card by: ");
    scanf("%d", &turn);

    initial_draw_prob = ((total - numCopies) / total);

    //for loop{}

    mulligan_prob = ((total - numCopies - n) / (total - n));

    //for loop{}

    draw_prob = ((total - numCopies - n - m) / (total - n - m));

    //for loop{}

    neg_probability = initial_draw_prob * mulligan_prob * draw_prob;
    probability = 1 - neg_probability


    printf("The probability of drawing at least one of the cards by turn %d 
    given you mulliganed %d cards is %lf", turn, m, probability);

}

int main(){
card_probability();

return 0;
}

我在设置这些 for 循环以使其正常工作时遇到了问题。本质上发生的是三个不同的概率部分:

1.) 第一手抽不到想要的牌的概率 (total - numCopies)/(total) 是在第一次抽取时不抽取该卡的概率。然后,例如,如果你总共抽了 7 张牌,你会继续下去并将概率相乘,直到得到 (total - numCopies - 7)/(total - 7)

2.) 调度指定数量后不抽牌的概率。

3.) 在指定回合未抽到牌的概率。

谁能帮我设置这些 for 循环?我无法获得正确的增量。我在纸上算了算,套牌大小为 10,我想要的牌有 2 张,手牌大小为 2,再调度 1 个,选择的回合为 3,我有 16.66% 的几率不抽牌 =>大约 83% 到第 3 回合抽牌。

最佳答案

那么,当您查看循环时,为什么不减少一个额外的值呢?

所以

int current_total = total;
for( int i = 0; i < opening_hand_size; i++)
{
  prob = prob * (( current_total - num_copies) / current_total) ;
  current_total--;
} 

关于c - 魔法风云卡抽奖概率函数C语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43815223/

相关文章:

Java线程概念

c - 如何为指针和三维数组动态分配内存

从完整图计算最短路径

c - 指针指向的元素的索引

c - 本程序的控制流程

c - 抛出异常 : Access violation writing location for Matlab Coder in Visual Studio

C 结构变量不反射(reflect)变化

c - 如何将两个已排序的文件合并为一个已排序的文件?

c - 在 C 中,如何检查一个字符串是否包含 2 个数字、1 个字母和 4 个数字?

c - Accept() 传递 Accept 的参数 3 使指针指向整数而不进行强制转换