两人玩骰子,游戏规则如下:
#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;
}
#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);
}
}
如果对你有帮助,可以点击我这个回答右上方的【采纳】按钮,给我个采纳吗,谢谢