LCOV - code coverage report
Current view: top level - Source - skill.cpp (source / functions) Coverage Total Hit
Test: coverage Lines: 94.1 % 17 16
Test Date: 2026-03-02 16:42:41 Functions: 100.0 % 1 1

            Line data    Source code
       1              : #include "skill.hpp"
       2              : 
       3              : #include "dynamicConfig.hpp"
       4              : #include "tools.hpp"
       5              : 
       6            4 : Move Skill::pick(std::vector<MultiPVScores>& multiPVMoves) {
       7              :    const size_t    multiPV    = multiPVMoves.size();
       8            4 :    const ScoreType topScore   = multiPVMoves[0].s;
       9            4 :    const ScoreType worstScore = multiPVMoves[multiPV - 1].s;
      10            4 :    const ScoreType delta      = std::min(static_cast<ScoreType>(topScore - worstScore), absValue(P_wp));
      11            4 :    const ScoreType weakness   = 128 - DynamicConfig::level; // so from 28 (minimum) to 128 (maximum)
      12              :    ScoreType       maxScore   = matedScore(0);
      13              : 
      14            4 :    Logging::LogIt(Logging::logInfo) << "Picking suboptimal move from " << multiPV << " best move(s)";
      15              : 
      16              :    // shuffling of available moves thanks to both a deterministic value and a random one
      17            4 :    Move m = INVALIDMOVE;
      18           20 :    for (size_t i = 0; i < multiPV; ++i) {
      19            0 :       if (!isValidMove(multiPVMoves[i].m)) continue;
      20           16 :       const ScoreType currentMoveScore = multiPVMoves[i].s;
      21              :       // magic formula from Stockfish
      22           32 :       const ScoreType add = (weakness * (topScore - currentMoveScore) + randomInt<int, 1234>(0, weakness) * delta) / 128;
      23           32 :       Logging::LogIt(Logging::logInfo) << ToString(multiPVMoves[i].m) << " " << currentMoveScore << " " << add << " " << maxScore;
      24           16 :       const ScoreType score = currentMoveScore + (isMateScore(currentMoveScore) ? 0 : add);
      25           16 :       if (score >= maxScore) {
      26              :          maxScore = score;
      27           12 :          m        = multiPVMoves[i].m;
      28              :       }
      29              :    }
      30            8 :    Logging::LogIt(Logging::logInfo) << "Picked move " << ToString(m) << " " << maxScore;
      31            4 :    return m;
      32              : }
        

Generated by: LCOV version 2.0-1