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/>.
37 bool Tune::update_on_last;
38 const UCI::Option* LastOption = nullptr;
39 static std::map<std::string, int> TuneResults;
41 string Tune::next(string& names, bool pop) {
47 string token = names.substr(0, names.find(','));
50 names.erase(0, token.size() + 1);
52 std::stringstream ws(token);
53 name += (ws >> token, token); // Remove trailing whitespace
55 } while (std::count(name.begin(), name.end(), '(') - std::count(name.begin(), name.end(), ')'));
60 static void on_tune(const UCI::Option& o) {
62 if (!Tune::update_on_last || LastOption == &o)
66 static void make_option(const string& n, int v, const SetRange& r) {
68 // Do not generate option when there is nothing to tune (ie. min = max)
69 if (r(v).first == r(v).second)
72 if (TuneResults.count(n))
75 Options[n] << UCI::Option(v, r(v).first, r(v).second, on_tune);
76 LastOption = &Options[n];
78 // Print formatted parameters, ready to be copy-pasted in Fishtest
79 std::cout << n << "," << v << "," << r(v).first << "," << r(v).second << ","
80 << (r(v).second - r(v).first) / 20.0 << ","
81 << "0.0020" << std::endl;
85 void Tune::Entry<int>::init_option() {
86 make_option(name, value, range);
90 void Tune::Entry<int>::read_option() {
91 if (Options.count(name))
92 value = int(Options[name]);
96 void Tune::Entry<Value>::init_option() {
97 make_option(name, value, range);
101 void Tune::Entry<Value>::read_option() {
102 if (Options.count(name))
103 value = Value(int(Options[name]));
106 // Instead of a variable here we have a PostUpdate function: just call it
108 void Tune::Entry<Tune::PostUpdate>::init_option() {}
110 void Tune::Entry<Tune::PostUpdate>::read_option() {
114 } // namespace Stockfish
117 // Init options with tuning session results instead of default values. Useful to
118 // get correct bench signature after a tuning session or to test tuned values.
119 // Just copy fishtest tuning results in a result.txt file and extract the
122 // cat results.txt | sed 's/^param: \([^,]*\), best: \([^,]*\).*/ TuneResults["\1"] = int(round(\2));/'
124 // Then paste the output below, as the function body
127 namespace Stockfish {
129 void Tune::read_results() { /* ...insert your values here... */
132 } // namespace Stockfish