Commit 2b71688c authored by aggsol's avatar aggsol

better simulations

parent ea86d0e9
......@@ -37,7 +37,7 @@ public:
std::string name;
};
int resolveCombat(Fighter& hero, Fighter& orc)
int resolveCombat(Fighter& hero, Fighter& orc, bool splitDamage)
{
Dice dice(6);
......@@ -52,10 +52,15 @@ int resolveCombat(Fighter& hero, Fighter& orc)
{
orc.stamina -= 2;
}
if(heroAttack < orcAttack)
else if(heroAttack < orcAttack)
{
hero.stamina -= 2;
}
else if(splitDamage)
{
orc.stamina -= 1;
hero.stamina -= 1;
}
if(hero.stamina <= 0)
{
......@@ -69,17 +74,9 @@ int resolveCombat(Fighter& hero, Fighter& orc)
return 0;
}
int main(int argc, char* argv[])
void runSimulation(const int heroSkill, const int heroStamina, const int orcSkill, const int orcStamina,
const int rounds, bool splitDamage)
{
int rounds = 10000;
int heroInitialSkill = 9;
int heroInitialStamina = 14;
int orcInitialSkill = 6;
int orcInitalStamina = 10;
int score = 0;
int heroWins = 0;
int heroDamaged = 0;
......@@ -89,14 +86,14 @@ int main(int argc, char* argv[])
for(int i=0; i<rounds; ++i)
{
Fighter hero;
hero.skill = heroInitialSkill;
hero.stamina = heroInitialStamina;
hero.skill = heroSkill;
hero.stamina = heroStamina;
Fighter orc;
orc.skill = orcInitialSkill;
orc.stamina = orcInitalStamina;
orc.skill = orcSkill;
orc.stamina = orcStamina;
int result = resolveCombat(hero, orc);
int result = resolveCombat(hero, orc, splitDamage);
score += result;
if(result > 0)
{
......@@ -106,16 +103,32 @@ int main(int argc, char* argv[])
{
orcWins++;
}
if(hero.stamina < heroInitialStamina)
if(hero.stamina < heroStamina)
{
heroDamageAmount += heroInitialStamina - hero.stamina;
heroDamageAmount += heroStamina - hero.stamina;
heroDamaged++;
}
}
std::cout << "Rounds: " << rounds << "\n";
std::cout << "Hero Wins=" << heroWins << " Damage Ratio=" << (float)heroDamaged/rounds
std::cout << "Hero Wins=" << (float)heroWins/rounds*100.0f << "\% Damage Ratio=" << (float)heroDamaged/rounds
<< " Avg. Damage=" << (float)heroDamageAmount/heroDamaged
<< "\n";
}
int main(int argc, char* argv[])
{
bodhi::CliArguments args(argc, argv);
auto splitDamage = args.getOpt("s", "enable-split-damage");
auto enemySkill = args.getOpt<int>("", "skill", 8);
auto enemyStamina = args.getOpt<int>("", "stamina", 8);
auto rounds = args.getOpt<int>("r", "rounds", 10000);
std::cout << "=== Weak hero Skill=8 Stamina=14 ==\n";
runSimulation(8, 14, enemySkill, enemyStamina, rounds, splitDamage);
std::cout << "=== Normal hero Skill=10 Stamina=20 ==\n";
runSimulation(10, 20, enemySkill, enemyStamina, rounds, splitDamage);
return 0;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment