Skip to content

Commit

Permalink
Merge pull request #89 from official-stockfish/pull_no_pretty
Browse files Browse the repository at this point in the history
Prefer operator<<() to pretty()

No functional change.
  • Loading branch information
mcostalba committed Nov 1, 2014
2 parents d309197 + 5644e14 commit 79fa72f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
50 changes: 24 additions & 26 deletions src/position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,30 @@ CheckInfo::CheckInfo(const Position& pos) {
}


/// operator<<(Position) returns an ASCII representation of the position

std::ostream& operator<<(std::ostream& os, const Position& pos) {

os << "\n +---+---+---+---+---+---+---+---+\n";

for (Rank r = RANK_8; r >= RANK_1; --r)
{
for (File f = FILE_A; f <= FILE_H; ++f)
os << " | " << PieceToChar[pos.piece_on(make_square(f, r))];

os << " |\n +---+---+---+---+---+---+---+---+\n";
}

os << "\nFen: " << pos.fen() << "\nKey: " << std::hex << std::uppercase
<< std::setfill('0') << std::setw(16) << pos.st->key << "\nCheckers: ";

for (Bitboard b = pos.checkers(); b; )
os << UCI::format_square(pop_lsb(&b)) << " ";

return os;
}


/// Position::init() initializes at startup the various arrays used to compute
/// hash keys and the piece square tables. The latter is a two-step operation:
/// Firstly, the white halves of the tables are copied from PSQT[] tables.
Expand Down Expand Up @@ -429,32 +453,6 @@ const string Position::fen() const {
}


/// Position::pretty() returns an ASCII representation of the position

const string Position::pretty() const {

std::ostringstream ss;

ss << "\n +---+---+---+---+---+---+---+---+\n";

for (Rank r = RANK_8; r >= RANK_1; --r)
{
for (File f = FILE_A; f <= FILE_H; ++f)
ss << " | " << PieceToChar[piece_on(make_square(f, r))];

ss << " |\n +---+---+---+---+---+---+---+---+\n";
}

ss << "\nFen: " << fen() << "\nKey: " << std::hex << std::uppercase
<< std::setfill('0') << std::setw(16) << st->key << "\nCheckers: ";

for (Bitboard b = checkers(); b; )
ss << UCI::format_square(pop_lsb(&b)) << " ";

return ss.str();
}


/// Position::game_phase() calculates the game phase interpolating total non-pawn
/// material between endgame and midgame limits.

Expand Down
6 changes: 4 additions & 2 deletions src/position.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,19 @@ const size_t StateCopySize64 = offsetof(StateInfo, key) / sizeof(uint64_t) + 1;
/// when traversing the search tree.

class Position {

friend std::ostream& operator<<(std::ostream&, const Position&);

public:
Position() {}
Position(const Position& pos, Thread* t) { *this = pos; thisThread = t; }
Position(const std::string& f, bool c960, Thread* t) { set(f, c960, t); }
Position& operator=(const Position&);
static void init();

// Text input/output
// FEN string input/output
void set(const std::string& fenStr, bool isChess960, Thread* th);
const std::string fen() const;
const std::string pretty() const;

// Position representation
Bitboard pieces() const;
Expand Down
2 changes: 1 addition & 1 deletion src/uci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void UCI::loop(int argc, char* argv[]) {
else if (token == "setoption") setoption(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 == "d") sync_cout << pos << sync_endl;
else if (token == "isready") sync_cout << "readyok" << sync_endl;
else if (token == "eval") sync_cout << Eval::trace(pos) << sync_endl;
else
Expand Down

2 comments on commit 79fa72f

@lucasart
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's cleaner to merge locally, rather than using GitHub's merge button. It avoids these extra merge commits, that make the commit log non linear and hard to follow.

git checkout -b new_branch
git pull https://github.com/userxyz/Stockfish.git userxyz_awesome_patch
# resolve merge conflicts and commit, if any

git checkout master
git merge --squash new_branch
git commit
# edit commit message

git branch -D new_branch

Maybe non linear history is a feature, and deemed the right way by some git experts, but for me it makes the history hard to follow.

@mcostalba
Copy link
Author

@mcostalba mcostalba commented on 79fa72f Nov 2, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.