1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 00:33:09 +00:00

Use string instead of std::string

And others small code style touches.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2009-05-10 17:58:53 +01:00
parent 78eecbf6d7
commit 27619830d4
10 changed files with 85 additions and 92 deletions

View file

@ -30,12 +30,13 @@
#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",
@ -67,25 +68,25 @@ const std::string BenchmarkPositions[] = {
/// 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);
@ -107,30 +108,30 @@ void benchmark(const std::string& commandLine) {
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)
@ -138,13 +139,12 @@ void benchmark(const std::string& commandLine) {
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;
}

View file

@ -37,7 +37,6 @@ enum Color {
//// 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) {

View file

@ -29,6 +29,7 @@
#include "material.h"
using std::string;
////
//// Local definitions
@ -59,9 +60,9 @@ public:
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
{
@ -352,7 +353,7 @@ EndgameFunctions::EndgameFunctions() {
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);
@ -373,12 +374,12 @@ Key EndgameFunctions::buildKey(const std::string& keyCode) {
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));

View file

@ -81,6 +81,8 @@ static const string AppTag = "";
//// Variables
////
bool Chess960;
uint64_t dbg_cnt0 = 0;
uint64_t dbg_cnt1 = 0;

View file

@ -40,6 +40,13 @@
#define Max(x, y) (((x) < (y))? (y) : (x))
////
//// Variables
////
extern bool Chess960;
////
//// Prototypes
////

View file

@ -27,7 +27,6 @@
#include "move.h"
#include "piece.h"
#include "position.h"
#include "ucioption.h"
////

View file

@ -35,6 +35,8 @@
#include "san.h"
#include "ucioption.h"
using std::string;
////
//// Variables
@ -63,7 +65,7 @@ Position::Position(const Position& pos) {
copy(pos);
}
Position::Position(const std::string& fen) {
Position::Position(const string& fen) {
from_fen(fen);
}
@ -72,9 +74,9 @@ Position::Position(const std::string& 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();
@ -98,7 +100,7 @@ void Position::from_fen(const std::string& fen) {
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;
@ -219,10 +221,10 @@ void Position::from_fen(const std::string& fen) {
/// 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--)
@ -272,7 +274,7 @@ const std::string Position::to_fen() const {
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()
@ -284,7 +286,7 @@ void Position::print(Move m) const {
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--)

View file

@ -31,6 +31,7 @@
#include "movepick.h"
#include "san.h"
using std::string;
////
//// Local definitions
@ -51,8 +52,8 @@ namespace {
/// 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);
}
@ -64,7 +65,7 @@ namespace {
/// 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));
@ -76,7 +77,7 @@ const std::string move_to_san(const Position& pos, Move 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)";
@ -138,7 +139,7 @@ const std::string move_to_san(const Position& pos, Move m) {
/// 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());
@ -166,7 +167,7 @@ Move move_from_san(const Position& pos, const std::string& movestr) {
// 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;
@ -176,7 +177,7 @@ Move move_from_san(const Position& pos, const std::string& movestr) {
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';
@ -292,11 +293,11 @@ Move move_from_san(const Position& pos, const std::string& movestr) {
/// 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);
@ -325,8 +326,8 @@ const std::string line_to_san(const Position& pos, Move line[], int startColumn,
/// 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
@ -396,7 +397,7 @@ namespace {
}
const std::string time_string(int milliseconds) {
const string time_string(int milliseconds) {
std::stringstream s;
s << std::setfill('0');
@ -413,7 +414,7 @@ namespace {
}
const std::string score_string(Value v) {
const string score_string(Value v) {
std::stringstream s;

View file

@ -33,13 +33,7 @@
#include "thread.h"
#include "ucioption.h"
////
//// Variables
////
bool Chess960;
using std::string;
////
//// Local definitions
@ -53,11 +47,11 @@ namespace {
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;
@ -71,7 +65,7 @@ namespace {
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
@ -155,7 +149,7 @@ namespace {
// 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;
@ -168,7 +162,7 @@ namespace {
// 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())
@ -245,9 +239,7 @@ void print_uci_options() {
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)
@ -260,7 +252,7 @@ void print_uci_options() {
/// 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);
}
@ -271,7 +263,7 @@ bool get_option_value_bool(const std::string& 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);
}
@ -280,9 +272,9 @@ int get_option_value_int(const std::string& 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);
}
@ -290,28 +282,27 @@ const std::string get_option_value_string(const std::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");
}
@ -321,7 +312,7 @@ void push_button(const std::string& buttonName) {
/// 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;

View file

@ -27,27 +27,18 @@
#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)