Skip to content

Commit 79fa72f

Browse files
committed
Merge pull request #89 from official-stockfish/pull_no_pretty
Prefer operator<<() to pretty() No functional change.
2 parents d309197 + 5644e14 commit 79fa72f

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

src/position.cpp

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,30 @@ CheckInfo::CheckInfo(const Position& pos) {
107107
}
108108

109109

110+
/// operator<<(Position) returns an ASCII representation of the position
111+
112+
std::ostream& operator<<(std::ostream& os, const Position& pos) {
113+
114+
os << "\n +---+---+---+---+---+---+---+---+\n";
115+
116+
for (Rank r = RANK_8; r >= RANK_1; --r)
117+
{
118+
for (File f = FILE_A; f <= FILE_H; ++f)
119+
os << " | " << PieceToChar[pos.piece_on(make_square(f, r))];
120+
121+
os << " |\n +---+---+---+---+---+---+---+---+\n";
122+
}
123+
124+
os << "\nFen: " << pos.fen() << "\nKey: " << std::hex << std::uppercase
125+
<< std::setfill('0') << std::setw(16) << pos.st->key << "\nCheckers: ";
126+
127+
for (Bitboard b = pos.checkers(); b; )
128+
os << UCI::format_square(pop_lsb(&b)) << " ";
129+
130+
return os;
131+
}
132+
133+
110134
/// Position::init() initializes at startup the various arrays used to compute
111135
/// hash keys and the piece square tables. The latter is a two-step operation:
112136
/// Firstly, the white halves of the tables are copied from PSQT[] tables.
@@ -429,32 +453,6 @@ const string Position::fen() const {
429453
}
430454

431455

432-
/// Position::pretty() returns an ASCII representation of the position
433-
434-
const string Position::pretty() const {
435-
436-
std::ostringstream ss;
437-
438-
ss << "\n +---+---+---+---+---+---+---+---+\n";
439-
440-
for (Rank r = RANK_8; r >= RANK_1; --r)
441-
{
442-
for (File f = FILE_A; f <= FILE_H; ++f)
443-
ss << " | " << PieceToChar[piece_on(make_square(f, r))];
444-
445-
ss << " |\n +---+---+---+---+---+---+---+---+\n";
446-
}
447-
448-
ss << "\nFen: " << fen() << "\nKey: " << std::hex << std::uppercase
449-
<< std::setfill('0') << std::setw(16) << st->key << "\nCheckers: ";
450-
451-
for (Bitboard b = checkers(); b; )
452-
ss << UCI::format_square(pop_lsb(&b)) << " ";
453-
454-
return ss.str();
455-
}
456-
457-
458456
/// Position::game_phase() calculates the game phase interpolating total non-pawn
459457
/// material between endgame and midgame limits.
460458

src/position.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,19 @@ const size_t StateCopySize64 = offsetof(StateInfo, key) / sizeof(uint64_t) + 1;
7373
/// when traversing the search tree.
7474

7575
class Position {
76+
77+
friend std::ostream& operator<<(std::ostream&, const Position&);
78+
7679
public:
7780
Position() {}
7881
Position(const Position& pos, Thread* t) { *this = pos; thisThread = t; }
7982
Position(const std::string& f, bool c960, Thread* t) { set(f, c960, t); }
8083
Position& operator=(const Position&);
8184
static void init();
8285

83-
// Text input/output
86+
// FEN string input/output
8487
void set(const std::string& fenStr, bool isChess960, Thread* th);
8588
const std::string fen() const;
86-
const std::string pretty() const;
8789

8890
// Position representation
8991
Bitboard pieces() const;

src/uci.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ void UCI::loop(int argc, char* argv[]) {
203203
else if (token == "setoption") setoption(is);
204204
else if (token == "flip") pos.flip();
205205
else if (token == "bench") benchmark(pos, is);
206-
else if (token == "d") sync_cout << pos.pretty() << sync_endl;
206+
else if (token == "d") sync_cout << pos << sync_endl;
207207
else if (token == "isready") sync_cout << "readyok" << sync_endl;
208208
else if (token == "eval") sync_cout << Eval::trace(pos) << sync_endl;
209209
else

0 commit comments

Comments
 (0)