2024.4.25更新*1
#include<bits/stdc++.h>
#include<Windows.h>
using namespace std;
bool gun[] = {0,0,0,0,0,0};
unordered_map<int,int>mp;
int start;
int check(int val){
if(mp[start]){
start = (start+1)%6;
if(val == 1) return 1;
else if(val == 0) return 0;
}else if(val == 1){
start = (start+1)%6;
return 2;
}else {
start = (start+1)%6;
return 3;
}
}
int computer(int x){
double func = (double)x/6;
int min = 0,max = 10;
random_device seed;
ranlux48 engine(seed());
uniform_int_distribution<> distrib(min, max);
while(1){
Sleep(750);
int ok;
int rands = distrib(engine);
if(rands*x >= 5){
ok = check(1);
}else ok = check(0);
if(ok == 0){// 0自己,1对方
cout << "电脑决定把枪指向自己"<<endl;
Sleep(750);
cout << "砰!!!电脑把自己嘎了!"<<endl;
return 0;
}
else if(ok == 1) {
cout << "电脑决定把枪指向你"<<endl;
Sleep(750);
cout << "砰!!!电脑把你嘎了!"<<endl;
return 1;
}else if(ok == 2){
cout << "电脑决定把枪指向你"<<endl;
Sleep(750);
cout << "嘎吱,没有子弹射出来。"<<endl;
return 2;
}
cout << "电脑决定把枪指向自己"<<endl;
Sleep(750);
cout << "嘎吱,没有子弹射出来。"<<endl;
}
}
int player(){
cout << "你要朝谁开枪?1:朝电脑开枪,2:朝自己开枪"<<endl;
int ans;
while(1){
cin >> ans;
int ok;
if(ans == 1){
ok = check(1);
}else {
ok = check(0);
}
if(ok == 0){
cout << "砰!!!你把自己嘎了!"<<endl;
return 0;
}
else if(ok == 1) {
cout << "砰!!!恭喜!你把电脑嘎了!"<<endl;
return 1;
}
cout << "嘎吱,没有子弹射出来。"<<endl;
if(ok == 2){
return 2;
}
}
}
signed main(){
while(1){
int n,m,noe = 6,fir;
cout << "规则:可以在枪里放若干子弹,选择谁先手,如果在你的回合,你决定向自己开枪,如果你没事的话仍然是你的回合。"<<endl;
cout << "放几个子弹?"<<endl;
cin >> n;
cout << "谁先手?"<<endl;
cin >> fir;
m = n;
int min = 0,max = 5;
random_device seed;
ranlux48 engine(seed());
uniform_int_distribution<> distrib(min, max);
start = distrib(engine);
while(n--){
int random = distrib(engine);
if(mp[random]) {
n++;
continue;
}
gun[random] = 1;
mp[random]++;
}
if(fir == 0){
while(1){
int ok = computer(m);
if(ok == 0){
cout << "您赢了,您是最后赢家!!!"<<endl;
break;
}else if(ok == 1){
cout << "很遗憾,电脑不喜欢和失败者玩游戏!"<<endl;
break;
}
int okk = player();
if(okk == 0){
cout << "很遗憾,电脑不喜欢和失败者玩游戏!"<<endl;
break;
}else if(okk == 1){
cout << "您赢了,您是最后赢家!!!"<<endl;
break;
}
}
}
else{
while(1){
int okk = player();
if(okk == 0){
cout << "很遗憾,电脑不喜欢和失败者玩游戏!"<<endl;
break;
}else if(okk == 1){
cout << "您赢了,您是最后赢家!!!"<<endl;
break;
}
int ok = computer(m);
if(ok == 0){
cout << "您赢了,您是最后赢家!!!"<<endl;
break;
}else if(ok == 1){
cout << "很遗憾,电脑不喜欢和失败者玩游戏!"<<endl;
break;
}
}
}
}
}