Per square stats utility

This commit is contained in:
Tomasz Sobczyk
2021-04-05 16:12:47 +02:00
parent 7d74185d0b
commit 570a0f6f3c

View File

@@ -11,12 +11,15 @@
#include "nnue/evaluate_nnue.h"
#include <array>
#include <string>
#include <map>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdint>
#include <sstream>
#include <iomanip>
#include <limits>
#include <mutex>
#include <optional>
@@ -74,6 +77,44 @@ namespace Learner::Stats
std::map<std::string, std::vector<std::unique_ptr<StatisticGathererFactoryBase>>> m_gatherers_by_group;
};
/*
Statistic gatherer helpers
*/
template <typename T>
struct StatPerSquare
{
StatPerSquare()
{
for (int i = 0; i < SQUARE_NB; ++i)
m_squares[i] = 0;
}
[[nodiscard]] T& operator[](Square sq)
{
return m_squares[sq];
}
[[nodiscard]] const T& operator[](Square sq) const
{
return m_squares[sq];
}
[[nodiscard]] std::string get_formatted_stats() const
{
std::stringstream ss;
for (int i = 0; i < SQUARE_NB; ++i)
{
ss << std::setw(8) << m_squares[i] << ' ';
if ((i + 1) % 8 == 0)
ss << '\n';
}
}
private:
std::array<T, SQUARE_NB> m_squares;
};
/*
Definitions for specific statistic gatherers follow:
*/