c++掷色子问题求问

两人玩骰子,游戏规则如下:

  1. 两人轮流掷骰子,每次掷两个,每人最多掷 10 次。
  2. 将每人每次的分值累加计分。
  3. 当两个骰子点数都为 6 时,计 8 分;当两个点数相等且不为两个 6 时,计 7 分;当两个点数 不一样时,计其中点数较小的骰子的点数。
  4. 结束条件:当双方都掷 10 次或经过 5 次后一方累计分数多出另一方的 30%及以上。最后显 示双方分数并判定优胜者。
#include <bits/stdc++.h>
using namespace std;

int func(){
    int a,b;
    a=rand()%6+1;
    b=rand()%6+1;
    if(a==b&&a==6){
        return 8;
    }else if(a==b){
        return 7;
    }else{
        return (a<b?a:b);
    }
}
int  main(){
    int sumA,sumB,i;
    sumA=sumB=0;
    srand(time(0));

    for(i=0;i<10;i++){
        sumA+=func();
        sumB+=func();
        if(i==4){
            if(sumA>1.3*sumB){
               cout<<"A:"<<sumA<<"B:"<<sumB<<" "<<"5局A获胜"<<endl;
                return 0;
            }else if(sumB>1.3*sumA){
                cout<<"A:"<<sumA<<"B:"<<sumB<<" "<<"5局B获胜"<<endl;
                return 0;
            }
        }
    }
    if(sumA>sumB){
        cout<<"A:"<<sumA<<"B:"<<sumB<<" "<<"10局A获胜"<<endl;
    }else if(sumB>sumA){
        cout<<"A:"<<sumA<<"B:"<<sumB<<" "<<"10局B获胜"<<endl;
    }else{
        cout<<"A:"<<sumA<<"B:"<<sumB<<" "<<"平局"<<endl;

    }
    return 0;
}

img

#include "ThrowDice.h"
#include <array>

void ThrowDice::setSeed() {
    using namespace std::chrono;
    // get a seed, that seed is come from epoch time
    // use .count() to transfer [time_since_epoch()] 
    // this Type [duration] to Type [long long]
    // seed is a continuous changed value
    // so it can be as a seed and into random_number_engine to produce
    // auto == long long
    unsigned seed = system_clock::now().time_since_epoch().count();
    std::minstd_rand std_rand{ seed };

    constexpr unsigned a{ 0 };
    constexpr unsigned b{ 6 };

    std::array<unsigned, 10> diceEvent;
    for (auto& el : diceEvent)     {
        el = a + std_rand() % (b + 1);
    }

    for (const auto& el : diceEvent) {
        printf_s("%u\n", el);
    }

}

如果对你有帮助,可以点击我这个回答右上方的【采纳】按钮,给我个采纳吗,谢谢