summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
116234d)
Let the caller to decide where to redirect (cout or cerr) the
ASCII representation of the position. Rename the function to
reflect this.
Renamed also from_fen() and to_fen() to set() and fen() respectively.
No functional change.
fens.assign(Defaults, Defaults + 16);
else if (fenFile == "current")
fens.assign(Defaults, Defaults + 16);
else if (fenFile == "current")
- fens.push_back(current.to_fen());
+ fens.push_back(current.fen());
-/// Position::from_fen() initializes the position object with the given 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).
+/// Position::set() initializes the position object with the given 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 string& fenStr, bool isChess960, Thread* th) {
+void Position::set(const string& fenStr, bool isChess960, Thread* th) {
/*
A FEN string defines a particular position using only the ASCII character set.
/*
A FEN string defines a particular position using only the ASCII character set.
char col, row, token;
size_t p;
Square sq = SQ_A8;
char col, row, token;
size_t p;
Square sq = SQ_A8;
- std::istringstream fen(fenStr);
+ std::istringstream ss(fenStr);
- while ((fen >> token) && !isspace(token))
+ while ((ss >> token) && !isspace(token))
{
if (isdigit(token))
sq += Square(token - '0'); // Advance the given number of files
{
if (isdigit(token))
sq += Square(token - '0'); // Advance the given number of files
sideToMove = (token == 'w' ? WHITE : BLACK);
sideToMove = (token == 'w' ? WHITE : BLACK);
// 3. Castling availability. Compatible with 3 standards: Normal FEN standard,
// Shredder-FEN that uses the letters of the columns on which the rooks began
// the game instead of KQkq and also X-FEN standard that, in case of Chess960,
// if an inner rook is associated with the castling right, the castling tag is
// replaced by the file letter of the involved rook, as for the Shredder-FEN.
// 3. Castling availability. Compatible with 3 standards: Normal FEN standard,
// Shredder-FEN that uses the letters of the columns on which the rooks began
// the game instead of KQkq and also X-FEN standard that, in case of Chess960,
// if an inner rook is associated with the castling right, the castling tag is
// replaced by the file letter of the involved rook, as for the Shredder-FEN.
- while ((fen >> token) && !isspace(token))
+ while ((ss >> token) && !isspace(token))
{
Square rsq;
Color c = islower(token) ? BLACK : WHITE;
{
Square rsq;
Color c = islower(token) ? BLACK : WHITE;
}
// 4. En passant square. Ignore if no pawn capture is possible
}
// 4. En passant square. Ignore if no pawn capture is possible
- if ( ((fen >> col) && (col >= 'a' && col <= 'h'))
- && ((fen >> row) && (row == '3' || row == '6')))
+ if ( ((ss >> col) && (col >= 'a' && col <= 'h'))
+ && ((ss >> row) && (row == '3' || row == '6')))
{
st->epSquare = File(col - 'a') | Rank(row - '1');
{
st->epSquare = File(col - 'a') | Rank(row - '1');
}
// 5-6. Halfmove clock and fullmove number
}
// 5-6. Halfmove clock and fullmove number
- fen >> std::skipws >> st->rule50 >> startPosPly;
+ ss >> std::skipws >> st->rule50 >> startPosPly;
// Convert from fullmove starting from 1 to ply starting from 0,
// handle also common incorrect FEN with fullmove = 0.
// Convert from fullmove starting from 1 to ply starting from 0,
// handle also common incorrect FEN with fullmove = 0.
-/// Position::to_fen() returns a FEN representation of the position. In case
+/// Position::fen() returns a FEN representation of the position. In case
/// of Chess960 the Shredder-FEN notation is used. Mainly a debugging function.
/// of Chess960 the Shredder-FEN notation is used. Mainly a debugging function.
-const string Position::to_fen() const {
+const string Position::fen() const {
- std::ostringstream fen;
- fen << PieceToChar[piece_on(sq)];
+ ss << PieceToChar[piece_on(sq)];
- fen << (sideToMove == WHITE ? " w " : " b ");
+ ss << (sideToMove == WHITE ? " w " : " b ");
if (can_castle(WHITE_OO))
if (can_castle(WHITE_OO))
- fen << (chess960 ? char(toupper(file_to_char(file_of(castle_rook_square(WHITE, KING_SIDE))))) : 'K');
+ ss << (chess960 ? char(toupper(file_to_char(file_of(castle_rook_square(WHITE, KING_SIDE))))) : 'K');
if (can_castle(WHITE_OOO))
if (can_castle(WHITE_OOO))
- fen << (chess960 ? char(toupper(file_to_char(file_of(castle_rook_square(WHITE, QUEEN_SIDE))))) : 'Q');
+ ss << (chess960 ? char(toupper(file_to_char(file_of(castle_rook_square(WHITE, QUEEN_SIDE))))) : 'Q');
if (can_castle(BLACK_OO))
if (can_castle(BLACK_OO))
- fen << (chess960 ? file_to_char(file_of(castle_rook_square(BLACK, KING_SIDE))) : 'k');
+ ss << (chess960 ? file_to_char(file_of(castle_rook_square(BLACK, KING_SIDE))) : 'k');
if (can_castle(BLACK_OOO))
if (can_castle(BLACK_OOO))
- fen << (chess960 ? file_to_char(file_of(castle_rook_square(BLACK, QUEEN_SIDE))) : 'q');
+ ss << (chess960 ? file_to_char(file_of(castle_rook_square(BLACK, QUEEN_SIDE))) : 'q');
if (st->castleRights == CASTLES_NONE)
if (st->castleRights == CASTLES_NONE)
- fen << (ep_square() == SQ_NONE ? " - " : " " + square_to_string(ep_square()) + " ")
+ ss << (ep_square() == SQ_NONE ? " - " : " " + square_to_string(ep_square()) + " ")
<< st->rule50 << " " << 1 + (startPosPly - int(sideToMove == BLACK)) / 2;
<< st->rule50 << " " << 1 + (startPosPly - int(sideToMove == BLACK)) / 2;
-/// Position::print() prints an ASCII representation of the position to
-/// the standard output. If a move is given then also the san is printed.
+/// Position::pretty() returns an ASCII representation of the position to be
+/// printed to the standard output together with the move's san notation.
-void Position::print(Move move) const {
+const string Position::pretty(Move move) const {
const string dottedLine = "\n+---+---+---+---+---+---+---+---+";
const string twoRows = dottedLine + "\n| | . | | . | | . | | . |"
const string dottedLine = "\n+---+---+---+---+---+---+---+---+";
const string twoRows = dottedLine + "\n| | . | | . | | . | | . |"
string brd = twoRows + twoRows + twoRows + twoRows + dottedLine;
string brd = twoRows + twoRows + twoRows + twoRows + dottedLine;
- cout << "\nMove is: " << (sideToMove == BLACK ? ".." : "")
- << move_to_san(*const_cast<Position*>(this), move);
+ ss << "\nMove is: " << (sideToMove == BLACK ? ".." : "")
+ << move_to_san(*const_cast<Position*>(this), move);
for (Square sq = SQ_A1; sq <= SQ_H8; sq++)
if (piece_on(sq) != NO_PIECE)
brd[513 - 68*rank_of(sq) + 4*file_of(sq)] = PieceToChar[piece_on(sq)];
for (Square sq = SQ_A1; sq <= SQ_H8; sq++)
if (piece_on(sq) != NO_PIECE)
brd[513 - 68*rank_of(sq) + 4*file_of(sq)] = PieceToChar[piece_on(sq)];
- cout << brd << "\nFen is: " << to_fen() << "\nKey is: " << st->key << sync_endl;
+ ss << brd << "\nFen is: " << fen() << "\nKey is: " << st->key;
+ return ss.str();
public:
Position() {}
Position(const Position& p, Thread* t) { *this = p; thisThread = t; }
public:
Position() {}
Position(const Position& p, Thread* t) { *this = p; thisThread = t; }
- Position(const std::string& f, bool c960, Thread* t) { from_fen(f, c960, t); }
+ Position(const std::string& f, bool c960, Thread* t) { set(f, c960, t); }
Position& operator=(const Position&);
// Text input/output
Position& operator=(const Position&);
// Text input/output
- void from_fen(const std::string& fen, bool isChess960, Thread* th);
- const std::string to_fen() const;
- void print(Move m = MOVE_NONE) const;
+ void set(const std::string& fen, bool isChess960, Thread* th);
+ const std::string fen() const;
+ const std::string pretty(Move m = MOVE_NONE) const;
// Position representation
Bitboard pieces() const;
// Position representation
Bitboard pieces() const;
if (Options["Use Search Log"])
{
Log log(Options["Search Log Filename"]);
if (Options["Use Search Log"])
{
Log log(Options["Search Log Filename"]);
- log << "\nSearching: " << RootPos.to_fen()
+ log << "\nSearching: " << RootPos.fen()
<< "\ninfinite: " << Limits.infinite
<< " ponder: " << Limits.ponder
<< " time: " << Limits.time[RootColor]
<< "\ninfinite: " << Limits.infinite
<< " ponder: " << Limits.ponder
<< " time: " << Limits.time[RootColor]
else if (token == "go") go(pos, is);
else if (token == "position") set_position(pos, is);
else if (token == "setoption") set_option(is);
else if (token == "go") go(pos, is);
else if (token == "position") set_position(pos, is);
else if (token == "setoption") set_option(is);
- else if (token == "d") pos.print();
else if (token == "flip") pos.flip();
else if (token == "bench") benchmark(pos, is);
else if (token == "flip") pos.flip();
else if (token == "bench") benchmark(pos, is);
+ else if (token == "d") sync_cout << pos.pretty() << sync_endl;
else if (token == "isready") sync_cout << "readyok" << sync_endl;
else if (token == "eval") sync_cout << Eval::trace(pos) << sync_endl;
else
else if (token == "isready") sync_cout << "readyok" << sync_endl;
else if (token == "eval") sync_cout << Eval::trace(pos) << sync_endl;
else
- pos.from_fen(fen, Options["UCI_Chess960"], Threads.main_thread());
+ pos.set(fen, Options["UCI_Chess960"], Threads.main_thread());
SetupStates = Search::StateStackPtr(new std::stack<StateInfo>());
// Parse move list (if any)
SetupStates = Search::StateStackPtr(new std::stack<StateInfo>());
// Parse move list (if any)