c++ - 兰德函数,生成 3 个值的概率(对于简单的老虎机)?

标签 c++ random probability

我正在做一个简单的(终端)老虎机项目,其中终端将输出 3 个水果名称,如果它们都相同则玩家获胜。

我不知道如何设定玩家赢得该回合的概率(例如大约 40% 的概率)。截至目前,我有:

     this->slotOne = rand() % 6 + 1;              // chooses rand number for designated slot
     this->oneFruit = spinTOfruit(this->slotOne); //converts rand number to fruit name

     this->slotTwo = rand() % 6 + 1;
     this->twoFruit = spinTOfruit(this->slotTwo);

     this->slotThree = rand() % 6 + 1;
     this->threeFruit = spinTOfruit(this->slotThree);

它根据数量挑选一个“水果”,但三个插槽中的每个插槽都有 6 分之一的机会(看到有 6 个水果)。由于每个单独的插槽都有 1/6 的机会,因此总体上获胜的概率非常低。

我该如何解决这个问题以创造更好的赔率(或者甚至更好,选择赔率,在需要时改变赔率)?

我考虑过将后两次旋转更改为更少的选项(例如 rand()%2),但这会使最后两个插槽每次都选择相同的一对水果。

我项目的链接:https://github.com/tristanzickovich/slotmachine

最佳答案

作弊。

首先决定玩家是否获胜

const bool winner = ( rand() % 100 ) < 40 // 40 % odds (roughly)

然后发明一个支持你的决定的结果。

if ( winner )
{
   // Pick the one winning fruit.
   this->slotOne = this->slotTwo = this->slotThree = rand() % 6 + 1;  
}
else
{
   // Pick a failing combo.
   do
   {
        this->slotOne = rand() % 6 + 1;    
        this->slotTwo = rand() % 6 + 1;    
        this->slotThree = rand() % 6 + 1;    
   } while ( slotOne == slotTwo && slotTwo == slotThree );
}

您现在可以玩弄玩家的情绪,就像拉斯维加斯最好的游戏一样。

关于c++ - 兰德函数,生成 3 个值的概率(对于简单的老虎机)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27953386/

相关文章:

c++ - 使用函数返回数组 - C++

c++ - Mergecom 标签不按顺序 (MC_OUT_OF_ORDER_TAG) 问题

android - MersenneTwister - Android(java) 和 C (Arduino) 中的相同伪随机数

matlab - matlab中randn函数的问题

c# - XNA:需要帮助在计时器滴答声中在任何一侧产生敌人,然后让它们随机移动

matlab - 计算任何给定实体被选择的概率

python - 用 PyMC 解决反问题

c++ - 如何通过id获取线程对象?

c++ - 我的电脑不接受 s.length,但其他编译器接受

python - 贝叶斯法则——如何计算似然