两人玩骰子,游戏规则如下:
- 两人轮流掷骰子,每次掷两个,每人最多掷 10 次。
- 将每人每次的分值累加计分。
- 当两个骰子点数都为 6 时,计 8 分;当两个点数相等且不为两个 6 时,计 7 分;当两个点数 不一样时,计其中点数较小的骰子的点数。
- 结束条件:当双方都掷 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;
}