阿龍打 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