2 Stockfish, a UCI chess playing engine derived from Glaurung 2.1
3 Copyright (C) 2004-2023 The Stockfish developers (see AUTHORS file)
5 Stockfish is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 Stockfish is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
31 bool Tune::update_on_last;
32 const UCI::Option* LastOption = nullptr;
33 static std::map<std::string, int> TuneResults;
35 string Tune::next(string& names, bool pop) {
40 string token = names.substr(0, names.find(','));
43 names.erase(0, token.size() + 1);
45 std::stringstream ws(token);
46 name += (ws >> token, token); // Remove trailing whitespace
48 } while ( std::count(name.begin(), name.end(), '(')
49 - std::count(name.begin(), name.end(), ')'));
54 static void on_tune(const UCI::Option& o) {
56 if (!Tune::update_on_last || LastOption == &o)
60 static void make_option(const string& n, int v, const SetRange& r) {
62 // Do not generate option when there is nothing to tune (ie. min = max)
63 if (r(v).first == r(v).second)
66 if (TuneResults.count(n))
69 Options[n] << UCI::Option(v, r(v).first, r(v).second, on_tune);
70 LastOption = &Options[n];
72 // Print formatted parameters, ready to be copy-pasted in Fishtest
75 << r(v).first << "," << r(v).second << ","
76 << (r(v).second - r(v).first) / 20.0 << ","
81 template<> void Tune::Entry<int>::init_option() { make_option(name, value, range); }
83 template<> void Tune::Entry<int>::read_option() {
84 if (Options.count(name))
85 value = int(Options[name]);
88 template<> void Tune::Entry<Value>::init_option() { make_option(name, value, range); }
90 template<> void Tune::Entry<Value>::read_option() {
91 if (Options.count(name))
92 value = Value(int(Options[name]));
95 // Instead of a variable here we have a PostUpdate function: just call it
96 template<> void Tune::Entry<Tune::PostUpdate>::init_option() {}
97 template<> void Tune::Entry<Tune::PostUpdate>::read_option() { value(); }
99 } // namespace Stockfish
102 // Init options with tuning session results instead of default values. Useful to
103 // get correct bench signature after a tuning session or to test tuned values.
104 // Just copy fishtest tuning results in a result.txt file and extract the
107 // cat results.txt | sed 's/^param: \([^,]*\), best: \([^,]*\).*/ TuneResults["\1"] = int(round(\2));/'
109 // Then paste the output below, as the function body
113 namespace Stockfish {
115 void Tune::read_results() {
117 /* ...insert your values here... */
120 } // namespace Stockfish