Either way, if I put in the same amount of humans and zombies each time I get the same result. I think it might be a problem with my other code because when I change the varibles partaining to the the human/zombie strenth the results still end the same. But my friend had a similar program and his problem was with his random number generator, and I've never used mt19937 before. Here is my program. The user is supposed to input the number of zombies then skeletons, and the program is supposed to use a random number generator to decide which team wins and by how much. Help would be appreciated.
#include <iostream>
#include <random>
#include <ctime>
using namespace std;
//Human Specifications
float humanAttack = 0.8f;
float humanDamage = 10.0f;
float maxHumanHealth = 15.0f;
float currentHumanHealth = maxHumanHealth;
int humanNumber;
//Zombie Specifications
float zombieAttack = 0.5f;
float zombieDamage = 15.0f;
float maxZombieHealth = 10.0f;
float currentZombieHealth = maxZombieHealth;
int zombieNumber;
char turn = 'H';
int attackResult;
int main() {
mt19937 randomGenerator(time(NULL));
//default_random_engine randomGenerator(time(NULL));
uniform_real_distribution<float> attack(0.0f, 1.0f);
//Setting Numbers
cout << "~*~*~*~*-Humans VS Zombies-*~*~*~*~" << endl << endl;
cout << "Set the number of humans: ";
cin >> humanNumber;
cout << endl << "Set the number of zombies: ";
cin >> zombieNumber;
while ((zombieNumber >0) && (humanNumber >0)) {
//Dice Roll
attackResult = attack(randomGenerator);
//Humans Turn
if (turn == 'H') {
if (attackResult < humanAttack) {
currentZombieHealth = currentZombieHealth - humanAttack;
if (currentZombieHealth <= 0) {
zombieNumber --;
currentZombieHealth = maxZombieHealth;
}
}
turn = 'Z';
}
//Zombies Turn
else {
if (attackResult < zombieAttack) {
currentHumanHealth = currentHumanHealth - zombieAttack;
if (currentHumanHealth <= 0) {
humanNumber --;
currentHumanHealth = maxHumanHealth;
}
}
turn = 'H';
}
}
cout << endl << "[The noise of battle...]" << endl << endl << endl;
cout << "BATTLE IS OVER" << endl << endl;
if (zombieNumber > 0) {
cout << "The zombies have won the battle!" << endl;
}
else {
cout << "The humans have won the battle!" << endl;
}
cout << "There are " << humanNumber << " humans and " << zombieNumber << " zombies left alive." << endl;
return 0;
}
Aucun commentaire:
Enregistrer un commentaire