1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

code review

This commit is contained in:
Laserlicht 2024-08-03 17:55:43 +02:00
parent f0c0beb9e0
commit 9d64059496
2 changed files with 22 additions and 33 deletions

View File

@ -51,9 +51,8 @@ StatisticDataSetEntry StatisticDataSet::createEntry(const PlayerState * ps, cons
data.numberArtifacts = Statistic::getNumberOfArts(ps);
data.armyStrength = Statistic::getArmyStrength(ps, true);
data.income = Statistic::getIncome(gs, ps);
data.mapVisitedRatio = Statistic::getMapVisitedRatio(gs, ps->color);
data.obeliskVisited = Statistic::getObeliskVisited(gs, ps->team);
data.mightMagicRatio = Statistic::getMightMagicRatio(ps);
data.mapExploredRatio = Statistic::getMapExploredRatio(gs, ps->color);
data.obeliskVisitedRatio = Statistic::getObeliskVisitedRatio(gs, ps->team);
data.numMines = Statistic::getNumMines(gs, ps);
data.score = scenarioHighScores.calculate().total;
data.maxHeroLevel = Statistic::findBestHero(gs, ps->color) ? Statistic::findBestHero(gs, ps->color)->level : 0;
@ -85,9 +84,8 @@ std::string StatisticDataSet::toCsv()
ss << "NumberArtifacts" << ";";
ss << "ArmyStrength" << ";";
ss << "Income" << ";";
ss << "MapVisitedRatio" << ";";
ss << "ObeliskVisited" << ";";
ss << "MightMagicRatio" << ";";
ss << "MapExploredRatio" << ";";
ss << "ObeliskVisitedRatio" << ";";
ss << "Score" << ";";
ss << "MaxHeroLevel" << ";";
ss << "NumBattlesNeutral" << ";";
@ -116,9 +114,8 @@ std::string StatisticDataSet::toCsv()
ss << entry.numberArtifacts << ";";
ss << entry.armyStrength << ";";
ss << entry.income << ";";
ss << entry.mapVisitedRatio << ";";
ss << entry.obeliskVisited << ";";
ss << entry.mightMagicRatio << ";";
ss << entry.mapExploredRatio << ";";
ss << entry.obeliskVisitedRatio << ";";
ss << entry.score << ";";
ss << entry.maxHeroLevel << ";";
ss << entry.numBattlesNeutral << ";";
@ -225,10 +222,10 @@ int Statistic::getIncome(const CGameState * gs, const PlayerState * ps)
return totalIncome;
}
double Statistic::getMapVisitedRatio(const CGameState * gs, PlayerColor player)
float Statistic::getMapExploredRatio(const CGameState * gs, PlayerColor player)
{
double visible = 0.0;
double numTiles = 0.0;
float visible = 0.0;
float numTiles = 0.0;
for(int layer = 0; layer < (gs->map->twoLevel ? 2 : 1); layer++)
for(int y = 0; y < gs->map->height; ++y)
@ -264,9 +261,9 @@ const CGHeroInstance * Statistic::findBestHero(const CGameState * gs, const Play
return h[best];
}
std::vector<std::vector<PlayerColor>> Statistic::getRank(std::vector<TStat> stats)
std::vector<std::vector<PlayerColor>> Statistic::getRank(std::vector<std::pair<PlayerColor, si64>> stats)
{
std::sort(stats.begin(), stats.end(), [](const TStat & a, const TStat & b) { return a.second > b.second; });
std::sort(stats.begin(), stats.end(), [](const std::pair<PlayerColor, si64> & a, const std::pair<PlayerColor, si64> & b) { return a.second > b.second; });
//put first element
std::vector< std::vector<PlayerColor> > ret;
@ -301,15 +298,11 @@ int Statistic::getObeliskVisited(const CGameState * gs, const TeamID & t)
return 0;
}
double Statistic::getMightMagicRatio(const PlayerState * ps)
float Statistic::getObeliskVisitedRatio(const CGameState * gs, const TeamID & t)
{
double numMight = 0;
for(auto h : ps->heroes)
if(h->type->heroClass->affinity == CHeroClass::EClassAffinity::MIGHT)
numMight++;
return numMight / ps->heroes.size();
if(!gs->map->obeliskCount)
return 0;
return (float)getObeliskVisited(gs, t) / (float)gs->map->obeliskCount;
}
std::map<EGameResID, int> Statistic::getNumMines(const CGameState * gs, const PlayerState * ps)

View File

@ -34,9 +34,8 @@ struct DLL_LINKAGE StatisticDataSetEntry
int numberArtifacts;
si64 armyStrength;
int income;
double mapVisitedRatio;
int obeliskVisited;
double mightMagicRatio;
float mapExploredRatio;
float obeliskVisitedRatio;
std::map<EGameResID, int> numMines;
int score;
int maxHeroLevel;
@ -62,9 +61,8 @@ struct DLL_LINKAGE StatisticDataSetEntry
h & numberArtifacts;
h & armyStrength;
h & income;
h & mapVisitedRatio;
h & obeliskVisited;
h & mightMagicRatio;
h & mapExploredRatio;
h & obeliskVisitedRatio;
h & numMines;
h & score;
h & maxHeroLevel;
@ -118,16 +116,14 @@ class DLL_LINKAGE Statistic
{
static std::vector<const CGMine *> getMines(const CGameState * gs, const PlayerState * ps);
public:
using TStat = std::pair<PlayerColor, si64>;
static int getNumberOfArts(const PlayerState * ps);
static si64 getArmyStrength(const PlayerState * ps, bool withTownGarrison = false);
static int getIncome(const CGameState * gs, const PlayerState * ps);
static double getMapVisitedRatio(const CGameState * gs, PlayerColor player);
static float getMapExploredRatio(const CGameState * gs, PlayerColor player);
static const CGHeroInstance * findBestHero(const CGameState * gs, const PlayerColor & color);
static std::vector<std::vector<PlayerColor>> getRank(std::vector<TStat> stats);
static std::vector<std::vector<PlayerColor>> getRank(std::vector<std::pair<PlayerColor, si64>> stats);
static int getObeliskVisited(const CGameState * gs, const TeamID & t);
static double getMightMagicRatio(const PlayerState * ps);
static float getObeliskVisitedRatio(const CGameState * gs, const TeamID & t);
static std::map<EGameResID, int> getNumMines(const CGameState * gs, const PlayerState * ps);
};