From 570a0f6f3c6b012e89744657e08f34e9855b1c5f Mon Sep 17 00:00:00 2001 From: Tomasz Sobczyk Date: Mon, 5 Apr 2021 16:12:47 +0200 Subject: [PATCH] Per square stats utility --- src/learn/stats.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/learn/stats.cpp b/src/learn/stats.cpp index 8efbeb6f..ce85caa0 100644 --- a/src/learn/stats.cpp +++ b/src/learn/stats.cpp @@ -11,12 +11,15 @@ #include "nnue/evaluate_nnue.h" +#include #include #include #include #include #include #include +#include +#include #include #include #include @@ -74,6 +77,44 @@ namespace Learner::Stats std::map>> m_gatherers_by_group; }; + /* + Statistic gatherer helpers + */ + + template + 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 m_squares; + }; + /* Definitions for specific statistic gatherers follow: */