And others small code style touches.
No functional change.
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
#include "thread.h"
#include "ucioption.h"
+using namespace std;
////
//// Variables
////
-const std::string BenchmarkPositions[] = {
+const string BenchmarkPositions[] = {
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
"r4rk1/1b2qppp/p1n1p3/1p6/1b1PN3/3BRN2/PP3PPP/R2Q2K1 b - - 7 16",
"4r1k1/ppq3pp/3b4/2pP4/2Q1p3/4B1P1/PP5P/R5K1 b - - 0 20",
/// format (default are the BenchmarkPositions defined above).
/// The analysis is written to a file named bench.txt.
-void benchmark(const std::string& commandLine) {
+void benchmark(const string& commandLine) {
- std::istringstream csVal(commandLine);
- std::istringstream csStr(commandLine);
- std::string ttSize, threads, fileName, limitType;
+ istringstream csVal(commandLine);
+ istringstream csStr(commandLine);
+ string ttSize, threads, fileName, limitType;
int val, secsPerPos, maxDepth, maxNodes;
csStr >> ttSize;
csVal >> val;
if (val < 4 || val > 1024)
{
- std::cerr << "The hash table size must be between 4 and 1024" << std::endl;
+ cerr << "The hash table size must be between 4 and 1024" << endl;
Application::exit_with_failure();
}
csStr >> threads;
csVal >> val;
if (val < 1 || val > THREAD_MAX)
{
- std::cerr << "The number of threads must be between 1 and " << THREAD_MAX << std::endl;
+ cerr << "The number of threads must be between 1 and " << THREAD_MAX << endl;
Application::exit_with_failure();
}
set_option_value("Hash", ttSize);
else
maxNodes = val;
- std::vector<std::string> positions;
+ vector<string> positions;
if (fileName != "default")
{
- std::ifstream fenFile(fileName.c_str());
+ ifstream fenFile(fileName.c_str());
if (!fenFile.is_open())
{
- std::cerr << "Unable to open positions file " << fileName << std::endl;
+ cerr << "Unable to open positions file " << fileName << endl;
Application::exit_with_failure();
}
- std::string pos;
+ string pos;
while (fenFile.good())
{
- std::getline(fenFile, pos);
+ getline(fenFile, pos);
if (!pos.empty())
positions.push_back(pos);
}
fenFile.close();
} else
for (int i = 0; i < 16; i++)
- positions.push_back(std::string(BenchmarkPositions[i]));
+ positions.push_back(string(BenchmarkPositions[i]));
int startTime = get_system_time();
- std::vector<std::string>::iterator it;
+ vector<string>::iterator it;
int cnt = 1;
int64_t totalNodes = 0;
for (it = positions.begin(); it != positions.end(); ++it, ++cnt)
Move moves[1] = {MOVE_NONE};
int dummy[2] = {0, 0};
Position pos(*it);
- std::cout << "\nProcessing position " << cnt << '/' << positions.size() << std::endl << std::endl;
+ cout << "\nProcessing position " << cnt << '/' << positions.size() << endl << endl;
if (!think(pos, true, false, 0, dummy, dummy, 0, maxDepth, maxNodes, secsPerPos, moves))
break;
totalNodes += nodes_searched();
}
- std::cout << "\nProcessing time (ms) " << get_system_time() - startTime << std::endl
- << "Nodes searched " << totalNodes << std::endl
- << "Press any key to exit" << std::endl;
- std::cin >> fileName;
+ cout << "\nProcessing time (ms) " << get_system_time() - startTime
+ << "\nNodes searched " << totalNodes << "\nPress any key to exit" << endl;
+ cin >> fileName;
}
//// Inline functions
////
-inline Color operator+ (Color c, int i) { return Color(int(c) + i); }
inline void operator++ (Color &c, int) { c = Color(int(c) + 1); }
inline Color opposite_color(Color c) {
#include "material.h"
+using std::string;
////
//// Local definitions
EndgameScalingFunctionBase* getESF(Key key, Color* c) const;
private:
- void add(const std::string& keyCode, EndgameEvaluationFunctionBase* f);
- void add(const std::string& keyCode, Color c, EndgameScalingFunctionBase* f);
- Key buildKey(const std::string& keyCode);
+ void add(const string& keyCode, EndgameEvaluationFunctionBase* f);
+ void add(const string& keyCode, Color c, EndgameScalingFunctionBase* f);
+ Key buildKey(const string& keyCode);
struct ScalingInfo
{
add("KRPKRPP", BLACK, &ScaleKRPKRPP);
}
-Key EndgameFunctions::buildKey(const std::string& keyCode) {
+Key EndgameFunctions::buildKey(const string& keyCode) {
assert(keyCode.length() > 0 && keyCode[0] == 'K');
assert(keyCode.length() < 8);
return Position(s.str()).get_material_key();
}
-void EndgameFunctions::add(const std::string& keyCode, EndgameEvaluationFunctionBase* f) {
+void EndgameFunctions::add(const string& keyCode, EndgameEvaluationFunctionBase* f) {
EEFmap.insert(std::pair<Key, EndgameEvaluationFunctionBase*>(buildKey(keyCode), f));
}
-void EndgameFunctions::add(const std::string& keyCode, Color c, EndgameScalingFunctionBase* f) {
+void EndgameFunctions::add(const string& keyCode, Color c, EndgameScalingFunctionBase* f) {
ScalingInfo s = {c, f};
ESFmap.insert(std::pair<Key, ScalingInfo>(buildKey(keyCode), s));
//// Variables
////
+bool Chess960;
+
uint64_t dbg_cnt0 = 0;
uint64_t dbg_cnt1 = 0;
#define Max(x, y) (((x) < (y))? (y) : (x))
+////
+//// Variables
+////
+
+extern bool Chess960;
+
+
////
//// Prototypes
////
#include "move.h"
#include "piece.h"
#include "position.h"
-#include "ucioption.h"
////
#include "san.h"
#include "ucioption.h"
+using std::string;
+
////
//// Variables
copy(pos);
}
-Position::Position(const std::string& fen) {
+Position::Position(const string& fen) {
from_fen(fen);
}
/// string. This function is not very robust - make sure that input FENs are
/// correct (this is assumed to be the responsibility of the GUI).
-void Position::from_fen(const std::string& fen) {
+void Position::from_fen(const string& fen) {
- static const std::string pieceLetters = "KQRBNPkqrbnp";
+ static const string pieceLetters = "KQRBNPkqrbnp";
static const Piece pieces[] = { WK, WQ, WR, WB, WN, WP, BK, BQ, BR, BB, BN, BP };
clear();
continue;
}
size_t idx = pieceLetters.find(fen[i]);
- if (idx == std::string::npos)
+ if (idx == string::npos)
{
std::cout << "Error in FEN at character " << i << std::endl;
return;
/// Position::to_fen() converts the position object to a FEN string. This is
/// probably only useful for debugging.
-const std::string Position::to_fen() const {
+const string Position::to_fen() const {
- static const std::string pieceLetters = " PNBRQK pnbrqk";
- std::string fen;
+ static const string pieceLetters = " PNBRQK pnbrqk";
+ string fen;
int skip;
for (Rank rank = RANK_8; rank >= RANK_1; rank--)
void Position::print(Move m) const {
- static const std::string pieceLetters = " PNBRQK PNBRQK .";
+ static const string pieceLetters = " PNBRQK PNBRQK .";
// Check for reentrancy, as example when called from inside
// MovePicker that is used also here in move_to_san()
std::cout << std::endl;
if (m != MOVE_NONE)
{
- std::string col = (color_of_piece_on(move_from(m)) == BLACK ? ".." : "");
+ string col = (color_of_piece_on(move_from(m)) == BLACK ? ".." : "");
std::cout << "Move is: " << col << move_to_san(*this, m) << std::endl;
}
for (Rank rank = RANK_8; rank >= RANK_1; rank--)
#include "movepick.h"
#include "san.h"
+using std::string;
////
//// Local definitions
/// Functions
Ambiguity move_ambiguity(const Position& pos, Move m);
- const std::string time_string(int milliseconds);
- const std::string score_string(Value v);
+ const string time_string(int milliseconds);
+ const string score_string(Value v);
}
/// that the move is a legal move from the position. The return value is
/// a string containing the move in short algebraic notation.
-const std::string move_to_san(const Position& pos, Move m) {
+const string move_to_san(const Position& pos, Move m) {
assert(pos.is_ok());
assert(move_is_ok(m));
to = move_to(m);
pt = type_of_piece(pos.piece_on(move_from(m)));
- std::string san = "";
+ string san = "";
if (m == MOVE_NONE)
return "(none)";
/// the move is returned. On failure (i.e. if the string is unparsable, or
/// if the move is illegal or ambiguous), MOVE_NONE is returned.
-Move move_from_san(const Position& pos, const std::string& movestr) {
+Move move_from_san(const Position& pos, const string& movestr) {
assert(pos.is_ok());
// Normal moves. We use a simple FSM to parse the san string.
enum { START, TO_FILE, TO_RANK, PROMOTION_OR_CHECK, PROMOTION, CHECK, END };
- static const std::string pieceLetters = "KQRBN";
+ static const string pieceLetters = "KQRBN";
PieceType pt = NO_PIECE_TYPE, promotion = NO_PIECE_TYPE;
File fromFile = FILE_NONE, toFile = FILE_NONE;
Rank fromRank = RANK_NONE, toRank = RANK_NONE;
for (size_t i = 0; i < movestr.length(); i++)
{
char type, c = movestr[i];
- if (pieceLetters.find(c) != std::string::npos)
+ if (pieceLetters.find(c) != string::npos)
type = 'P';
else if (c >= 'a' && c <= 'h')
type = 'F';
/// length of 80 characters. After a line break, 'startColumn' spaces are
/// inserted at the beginning of the new line.
-const std::string line_to_san(const Position& pos, Move line[], int startColumn, bool breakLines) {
+const string line_to_san(const Position& pos, Move line[], int startColumn, bool breakLines) {
StateInfo st;
std::stringstream s;
- std::string moveStr;
+ string moveStr;
size_t length = 0;
size_t maxLength = 80 - startColumn;
Position p(pos);
/// It is used to write search information to the log file (which is created
/// when the UCI parameter "Use Search Log" is "true").
-const std::string pretty_pv(const Position& pos, int time, int depth,
- uint64_t nodes, Value score, Move pv[]) {
+const string pretty_pv(const Position& pos, int time, int depth,
+ uint64_t nodes, Value score, Move pv[]) {
std::stringstream s;
// Depth
}
- const std::string time_string(int milliseconds) {
+ const string time_string(int milliseconds) {
std::stringstream s;
s << std::setfill('0');
}
- const std::string score_string(Value v) {
+ const string score_string(Value v) {
std::stringstream s;
#include "thread.h"
#include "ucioption.h"
-
-////
-//// Variables
-////
-
-bool Chess960;
-
+using std::string;
////
//// Local definitions
enum OptionType { SPIN, COMBO, CHECK, STRING, BUTTON };
- typedef std::vector<std::string> ComboValues;
+ typedef std::vector<string> ComboValues;
struct Option {
- std::string name, defaultValue, currentValue;
+ string name, defaultValue, currentValue;
OptionType type;
size_t idx;
int minValue, maxValue;
bool operator<(const Option& o) const { return this->idx < o.idx; }
};
- typedef std::map<std::string, Option> Options;
+ typedef std::map<string, Option> Options;
///
/// Constants
// stringify converts a value of type T to a std::string
template<typename T>
- std::string stringify(const T& v) {
+ string stringify(const T& v) {
std::ostringstream ss;
ss << v;
// type changes a template seems a proper solution.
template<typename T>
- T get_option_value(const std::string& optionName) {
+ T get_option_value(const string& optionName) {
T ret = T();
if (options.find(optionName) == options.end())
std::cout << " default " << it->defaultValue;
if (it->type == SPIN)
- std::cout << " min " << it->minValue
- << " max " << it->maxValue;
-
+ std::cout << " min " << it->minValue << " max " << it->maxValue;
else if (it->type == COMBO)
for (ComboValues::const_iterator itc = it->comboValues.begin();
itc != it->comboValues.end(); ++itc)
/// get_option_value_bool() returns the current value of a UCI parameter of
/// type "check".
-bool get_option_value_bool(const std::string& optionName) {
+bool get_option_value_bool(const string& optionName) {
return get_option_value<bool>(optionName);
}
/// it could also be used with a "combo" parameter, where all the available
/// values are integers.
-int get_option_value_int(const std::string& optionName) {
+int get_option_value_int(const string& optionName) {
return get_option_value<int>(optionName);
}
/// get_option_value_string() returns the current value of a UCI parameter as
/// a string. It is used with parameters of type "combo" and "string".
-const std::string get_option_value_string(const std::string& optionName) {
+string get_option_value_string(const string& optionName) {
- return get_option_value<std::string>(optionName);
+ return get_option_value<string>(optionName);
}
/// the function does not check that the new value is legal for the given
/// parameter: This is assumed to be the responsibility of the GUI.
-void set_option_value(const std::string& optionName,
- const std::string& newValue) {
+void set_option_value(const string& name, const string& value) {
// UCI protocol uses "true" and "false" instead of "1" and "0", so convert
- // newValue according to standard C++ convention before to store it.
- std::string v(newValue);
+ // value according to standard C++ convention before to store it.
+ string v(value);
if (v == "true")
v = "1";
else if (v == "false")
v = "0";
- if (options.find(optionName) != options.end())
- options[optionName].currentValue = v;
+ if (options.find(name) != options.end())
+ options[name].currentValue = v;
else
- std::cout << "No such option: " << optionName << std::endl;
+ std::cout << "No such option: " << name << std::endl;
}
/// push_button() is used to tell the engine that a UCI parameter of type
/// "button" has been selected:
-void push_button(const std::string& buttonName) {
+void push_button(const string& buttonName) {
set_option_value(buttonName, "true");
}
/// been selected since the last time the function was called, in this case
/// it also resets the button.
-bool button_was_pressed(const std::string& buttonName) {
+bool button_was_pressed(const string& buttonName) {
if (!get_option_value<bool>(buttonName))
return false;
#include <string>
-
-////
-//// Variables
-////
-
-extern bool Chess960;
-
-
////
//// Prototypes
////
extern void init_uci_options();
extern void print_uci_options();
-extern bool get_option_value_bool(const std::string &optionName);
-extern int get_option_value_int(const std::string &optionName);
-extern const std::string get_option_value_string(const std::string &optionName);
-extern bool button_was_pressed(const std::string &buttonName);
-extern void set_option_value(const std::string &optionName,
- const std::string &newValue);
-extern void push_button(const std::string &buttonName);
+extern bool get_option_value_bool(const std::string& optionName);
+extern int get_option_value_int(const std::string& optionName);
+extern std::string get_option_value_string(const std::string& optionName);
+extern bool button_was_pressed(const std::string& buttonName);
+extern void set_option_value(const std::string& optionName,const std::string& newValue);
+extern void push_button(const std::string& buttonName);
#endif // !defined(UCIOPTION_H_INCLUDED)