阿龙打 Bob有打 查理打战斗到死,三人C++
亚伦拍摄,再鲍勃,然后查理,我们每个人的100%的几率为50%的几率有30%的几率首先尝试拍摄最佳效果的人。有人能解释为什么Aaron没有赢得任何回合?查理大概赢得了480次,鲍勃赢得了大约200次,但是它报告说,亚伦赢得了0分。阿隆应该赢得大约150 - 200次,而鲍勃比这个大一点。
这是我的代码,任何帮助将不胜感激。提前致谢。
#include<iostream>
#include<ctime>
#include<cstdlib>
#include<cmath>
using namespace std;
const double aShot = 30;
const double bShot = 50;
const double cShot = 100;
void start(bool& aAlive, bool& bAlive, bool& cAlive, int& aCount, int& bCount, int& cCount, double result){
// Aaron Shoots at Charlie
if (aShot >= result){
cAlive=false;
}
//Bob Shoots at Charlie
if (cAlive == false){
cout<<"Charlie is dead, Bob shot at Aaron"<<endl;
if (bShot >= result)
aAlive = false;
}
else if ((cAlive == true) && (bShot >= result))
cAlive = false;
//Charlie Shoots at Bob
if (cAlive == false){
cout<<"Charlie is dead"<<endl;
}
else if ((cAlive == true) && (cShot >= result))
bAlive = false;
//Aaron Shoots at Bob
if (bAlive == false){
cout<<"Bob is dead, Aaron shoots at Charlie"<<endl;
if (aShot >= result)
cAlive = false;}
else if ((bAlive == true) && (aShot >= result))
bAlive = false;
//Bob Shoots at Aaron
if (bAlive == false)
cout<<"Bob is dead"<<endl;
else if ((bAlive == true) && (bShot >= result))
aAlive = false;
//Charlie Shoots at Aaron
if (aAlive == false)
cout<<"Aaron is dead"<<endl;
else if ((aAlive == true) && (cShot >= result))
aAlive = false;
if ((aAlive == true) && (bAlive == false) && (cAlive == false))
aCount++;
if ((aAlive == false) && (bAlive == true) && (cAlive == false))
bCount++;
if ((aAlive == false) && (bAlive == false) && (cAlive == true))
cCount++;
}
int main(){
bool aAlive = true, bAlive = true, cAlive = true;
int i, aCount = 0, bCount = 0, cCount = 0;
cout<<"Welcome to the game"<<endl;
srand (time(NULL));
for (i=0; i<=1000; i++){
//Sets random number, or chance they hit their target
double result = rand() % 101;
cout<<result<<endl;
//Sets all players to alive
aAlive = true, bAlive = true, cAlive = true;
//Calling The Duel
start(aAlive, bAlive, cAlive, aCount, bCount, cCount, result);
}
cout<<"Aaron won: "<<aCount<<" times"<<endl;
cout<<"Bob won: "<<bCount<<" times"<<endl;
cout<<"Charlie won: "<<cCount<<" times"<<endl;
}
你有问题吗?更具体的东西? – shafeen
这是谜题的逻辑。每个人都会射击一次(如果他们轮到他们)。如果亚伦杀死查理,然后鲍勃射杀亚伦(无人射击)。如果亚伦未能击杀查理,那么鲍勃将射杀查理(鲍勃仍然活着)。如果鲍勃未能杀死查理,查理杀死鲍勃(查理仍然活着)。所以亚伦永远不会赢。 (如果亚伦还活着,至少还有一个人还活着)。 –
为什么亚伦在节目结束时获得0胜?我相信这是因为每个镜头都没有产生一个随机数,但我不太确定。 – Beez