Commit ea86d0e9 authored by aggsol's avatar aggsol 🙉

combat tester

parent 113a95b4
= Assets
What kind of assets are required?
1. Fonts
2. Fillers
3. Covers
4. Banners/Borders?
5. Character Portraits
== Art
* [60 Terrible Character Portraits For Creative Commons Release](https://www.kickstarter.com/projects/mungo/60-terrible-character-portraits-for-creative-commo)
* http://aterribleidea.com/
* http://www.hhvferry.com/deckplans
== Dungeons
* https://campaignwiki.org/1pdc/[One Page Dungeons 2009-2018]
cmake_minimum_required(VERSION 3.8) cmake_minimum_required(VERSION 3.8)
# combat-tester
add_executable("combat-tester" combat-tester.cpp)
target_compile_features("combat-tester" PRIVATE cxx_std_14)
target_compile_definitions("combat-tester" PRIVATE _FORTIFY_SOURCE=2)
target_compile_options("combat-tester" PRIVATE
-Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Woverloaded-virtual -Wzero-as-null-pointer-constant
-pedantic -fPIE -fstack-protector-all -fno-rtti
)
# Gamebook graph creator # Gamebook graph creator
add_executable("gamebook-graph" gamebook-graph.cpp) add_executable("gamebook-graph" gamebook-graph.cpp)
target_compile_features("gamebook-graph" PRIVATE cxx_std_14) target_compile_features("gamebook-graph" PRIVATE cxx_std_14)
......
#include "CliArguments.hpp"
#include <chrono>
#include <iomanip>
#include <functional>
#include <random>
#include <string>
class Dice
{
public:
explicit Dice(int sides)
: distribution(1, sides)
{
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
generator.seed(seed);
}
int roll()
{
int value = distribution(generator);
// std::cout << "rolled=" << value << "\n";
return value;
}
private:
std::mt19937 generator;
std::uniform_int_distribution<int> distribution;
};
class Fighter
{
public:
int skill = 0;
int stamina = 0;
int id = 0;
std::string name;
};
int resolveCombat(Fighter& hero, Fighter& orc)
{
Dice dice(6);
while(hero.stamina > 0 && orc.stamina > 0)
{
int heroAttack = hero.skill + dice.roll() + dice.roll();
int orcAttack = orc.skill + dice.roll() + dice.roll();
// std::cout << "heroAttack=" << heroAttack << " orcAttack=" << orcAttack << "\n";
if(heroAttack > orcAttack)
{
orc.stamina -= 2;
}
if(heroAttack < orcAttack)
{
hero.stamina -= 2;
}
if(hero.stamina <= 0)
{
return -1;
}
if(orc.stamina <= 0)
{
return 1;
}
}
return 0;
}
int main(int argc, char* argv[])
{
int rounds = 10000;
int heroInitialSkill = 9;
int heroInitialStamina = 14;
int orcInitialSkill = 6;
int orcInitalStamina = 10;
int score = 0;
int heroWins = 0;
int heroDamaged = 0;
int heroDamageAmount = 0;
int orcWins = 0;
for(int i=0; i<rounds; ++i)
{
Fighter hero;
hero.skill = heroInitialSkill;
hero.stamina = heroInitialStamina;
Fighter orc;
orc.skill = orcInitialSkill;
orc.stamina = orcInitalStamina;
int result = resolveCombat(hero, orc);
score += result;
if(result > 0)
{
heroWins++;
}
if(result < 0)
{
orcWins++;
}
if(hero.stamina < heroInitialStamina)
{
heroDamageAmount += heroInitialStamina - hero.stamina;
heroDamaged++;
}
}
std::cout << "Rounds: " << rounds << "\n";
std::cout << "Hero Wins=" << heroWins << " Damage Ratio=" << (float)heroDamaged/rounds
<< " Avg. Damage=" << (float)heroDamageAmount/heroDamaged
<< "\n";
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