Subversion Repositories Games.Chess Giants

Rev

Rev 96 | Rev 169 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
96 pmbaty 1
/*
2
  Stockfish, a UCI chess playing engine derived from Glaurung 2.1
3
  Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
4
  Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
5
  Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
6
 
7
  Stockfish is free software: you can redistribute it and/or modify
8
  it under the terms of the GNU General Public License as published by
9
  the Free Software Foundation, either version 3 of the License, or
10
  (at your option) any later version.
11
 
12
  Stockfish is distributed in the hope that it will be useful,
13
  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
  GNU General Public License for more details.
16
 
17
  You should have received a copy of the GNU General Public License
18
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
*/
20
 
21
#include <algorithm>
22
#include <cassert>
23
#include <ostream>
24
 
25
#include "misc.h"
26
#include "search.h"
27
#include "thread.h"
28
#include "tt.h"
29
#include "uci.h"
30
#include "syzygy/tbprobe.h"
31
 
32
using std::string;
33
 
34
UCI::OptionsMap Options; // Global object
35
 
36
namespace UCI {
37
 
38
/// 'On change' actions, triggered by an option's value change
39
void on_clear_hash(const Option&) { Search::clear(); }
40
void on_hash_size(const Option& o) { TT.resize(o); }
41
void on_logger(const Option& o) { start_logger(o); }
42
void on_threads(const Option&) { Threads.read_uci_options(); }
43
void on_tb_path(const Option& o) { Tablebases::init(o); }
44
 
45
 
46
/// Our case insensitive less() function as required by UCI protocol
47
bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const {
48
 
49
  return std::lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end(),
50
         [](char c1, char c2) { return tolower(c1) < tolower(c2); });
51
}
52
 
53
 
54
/// init() initializes the UCI options to their hard-coded default values
55
 
56
void init(OptionsMap& o) {
57
 
58
  const int MaxHashMB = Is64Bit ? 1024 * 1024 : 2048;
59
 
154 pmbaty 60
  o["Debug Log File"]        << Option("", on_logger);
96 pmbaty 61
  o["Contempt"]              << Option(0, -100, 100);
62
  o["Threads"]               << Option(1, 1, 128, on_threads);
63
  o["Hash"]                  << Option(16, 1, MaxHashMB, on_hash_size);
64
  o["Clear Hash"]            << Option(on_clear_hash);
65
  o["Ponder"]                << Option(false);
66
  o["MultiPV"]               << Option(1, 1, 500);
67
  o["Skill Level"]           << Option(20, 0, 20);
68
  o["Move Overhead"]         << Option(30, 0, 5000);
69
  o["Minimum Thinking Time"] << Option(20, 0, 5000);
70
  o["Slow Mover"]            << Option(89, 10, 1000);
71
  o["nodestime"]             << Option(0, 0, 10000);
72
  o["UCI_Chess960"]          << Option(false);
73
  o["SyzygyPath"]            << Option("<empty>", on_tb_path);
74
  o["SyzygyProbeDepth"]      << Option(1, 1, 100);
75
  o["Syzygy50MoveRule"]      << Option(true);
76
  o["SyzygyProbeLimit"]      << Option(6, 0, 6);
77
}
78
 
79
 
80
/// operator<<() is used to print all the options default values in chronological
81
/// insertion order (the idx field) and in the format defined by the UCI protocol.
82
 
83
std::ostream& operator<<(std::ostream& os, const OptionsMap& om) {
84
 
85
  for (size_t idx = 0; idx < om.size(); ++idx)
86
      for (const auto& it : om)
87
          if (it.second.idx == idx)
88
          {
89
              const Option& o = it.second;
90
              os << "\noption name " << it.first << " type " << o.type;
91
 
92
              if (o.type != "button")
93
                  os << " default " << o.defaultValue;
94
 
95
              if (o.type == "spin")
96
                  os << " min " << o.min << " max " << o.max;
97
 
98
              break;
99
          }
100
 
101
  return os;
102
}
103
 
104
 
105
/// Option class constructors and conversion operators
106
 
107
Option::Option(const char* v, OnChange f) : type("string"), min(0), max(0), on_change(f)
108
{ defaultValue = currentValue = v; }
109
 
110
Option::Option(bool v, OnChange f) : type("check"), min(0), max(0), on_change(f)
111
{ defaultValue = currentValue = (v ? "true" : "false"); }
112
 
113
Option::Option(OnChange f) : type("button"), min(0), max(0), on_change(f)
114
{}
115
 
116
Option::Option(int v, int minv, int maxv, OnChange f) : type("spin"), min(minv), max(maxv), on_change(f)
117
{ defaultValue = currentValue = std::to_string(v); }
118
 
119
Option::operator int() const {
120
  assert(type == "check" || type == "spin");
121
  return (type == "spin" ? stoi(currentValue) : currentValue == "true");
122
}
123
 
124
Option::operator std::string() const {
125
  assert(type == "string");
126
  return currentValue;
127
}
128
 
129
 
130
/// operator<<() inits options and assigns idx in the correct printing order
131
 
132
void Option::operator<<(const Option& o) {
133
 
134
  static size_t insert_order = 0;
135
 
136
  *this = o;
137
  idx = insert_order++;
138
}
139
 
140
 
141
/// operator=() updates currentValue and triggers on_change() action. It's up to
142
/// the GUI to check for option's limits, but we could receive the new value from
143
/// the user by console window, so let's check the bounds anyway.
144
 
145
Option& Option::operator=(const string& v) {
146
 
147
  assert(!type.empty());
148
 
149
  if (   (type != "button" && v.empty())
150
      || (type == "check" && v != "true" && v != "false")
151
      || (type == "spin" && (stoi(v) < min || stoi(v) > max)))
152
      return *this;
153
 
154
  if (type != "button")
155
      currentValue = v;
156
 
157
  if (on_change)
158
      on_change(*this);
159
 
160
  return *this;
161
}
162
 
163
} // namespace UCI