thx!!!
void combat (vector<double>& health, double oaccuracy, double obase_damage)
{
for (int j = 1; j < health.size (); j++)
{
for (int k = 1; k < obase_damage; k++)
{
if (j - k >= 0)
health [j - k] += oaccuracy * health [j] / obase_damage;
else
health [0] += oaccuracy * health [j] / obase_damage;
}
health [j] *= 1 - oaccuracy;
health [j] += oaccuracy * health [j] / obase_damage;
}
}
void statistics (double& p, double& win, double& loss, vector<double> health, vector<double> ohealth)
{
double temp = 1 - (1 - health [0]) * (1 - ohealth [0]);
temp -= p;
if (health [0] > 0 || ohealth [0] > 0)
{
win += temp * (ohealth [0] / (ohealth [0] + health [0]));
loss += temp * (health [0] / (ohealth [0] + health [0]));
}
p += temp;
}
void create_health (vector<double>& health, double constitution)
{
for (int i = 0; i < constitution * 10; i++)
health.push_back (0);
health [health.size () - 1] = 1;
}
int main()
{
cout << "Enter both players' stats to calculate chances of winning." << endl << endl;
double attack; // Your Attack level
double strength; // Your Strength level
double defence; // Your Defence level
double constitution; // Your Constitution level
double oattack; // Opponent's Attack level
double ostrength; // Opponent's Strength level
double odefence; // Opponent's Defence level
double oconstitution; // Opponent's Constitution level
cout << "Attack: ";
cin >> attack; // Your Attack level
cout << "Strength: ";
cin >> strength; // Your Strength level
cout << "Defence: ";
cin >> defence; // Your Defence level
cout << "Constitution: ";
cin >> constitution; // Your Constitution level
cout << endl;
cout << "Opponent's Attack: ";
cin >> oattack; // Opponent's Attack level
cout << "Opponent's Strength: ";
cin >> ostrength; // Opponent's Strength level
cout << "Opponent's Defence: ";
cin >> odefence; // Opponent's Defence level
cout << "Opponent's Constitution: ";
cin >> oconstitution; // Opponent's Constitution level
cout << endl;
double effective_attack = 10 * (attack + 8 + 3); // 5/8 from standard formula, 3 from style bonus
double effective_strength = strength + 8; // ,,
double base_damage = effective_strength + 5; // ,,
double effective_defence = 10 * (defence + 8); // ,,
double oeffective_attack = 10 * (oattack + 8 + 3); // ,,
double oeffective_strength = ostrength + 8; // ,,
double obase_damage = oeffective_strength + 5; // ,,
double oeffective_defence = 10 * (odefence + 8); // ,,
double accuracy;
double oaccuracy;
if (attack < odefence)
accuracy = (effective_attack - 1) / (2 * oeffective_defence);
else
accuracy = 1 - (oeffective_defence + 1) / (2 * effective_attack);
if (oattack < defence)
oaccuracy = (oeffective_attack - 1) / (2 * effective_defence);
else
oaccuracy = 1 - (effective_defence + 1) / (2 * oeffective_attack);
cout << "Your accuracy: " << accuracy << endl;
cout << "Opponent's accuracy: " << oaccuracy << endl;
cout << endl;
vector<double> health;
vector<double> ohealth;
create_health (health, constitution);
create_health (ohealth, oconstitution);
double p = 0;
double win = 0;
double loss = 0;
for (int hit = 0; win + loss < 0.99 && hit < 1000; hit++)
{
combat (health, oaccuracy, obase_damage);
combat (ohealth, accuracy, base_damage);
statistics (p, win, loss, health, ohealth);
}
cout << "Your win chance: " << win << endl;
cout << "Opponent's win chance: " << loss << endl;
return 0;
}