Hap*_*ppo 1 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);
Run Code Online (Sandbox Code Playgroud)
根据数字选择"水果",但三个位置中的每一个都有1/6的机会(看到有6个水果).由于每个单独的插槽有1/6的机会,总体而言,获胜的可能性非常低.
我如何解决这个问题以创造更好的赔率(甚至更好,选择赔率,在需要时改变赔率)?
我想把第二个两个旋转更改为更少的选项(例如rand()%2),但这会使最后两个插槽每次选择相同的几个水果.
作弊.
首先确定玩家是否获胜
const bool winner = ( rand() % 100 ) < 40 // 40 % odds (roughly)
Run Code Online (Sandbox Code Playgroud)
然后发明一个支持您决定的结果.
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 );
}
Run Code Online (Sandbox Code Playgroud)
你现在可以玩玩家的情绪,如拉斯维加斯最好的.