summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
d95b918)
Hopefully no functional change.
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
////
/// move_to_san() takes a position and a move as input, where it is assumed
////
/// move_to_san() takes a position and a move as input, where it is assumed
-/// that the move is a legal move from the position. The return value is
+/// 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) {
/// a string containing the move in short algebraic notation.
const std::string move_to_san(const Position& pos, Move m) {
- Square from = move_from(m);
- Square to = move_to(m);
Piece pc = pos.piece_on(move_from(m));
Piece pc = pos.piece_on(move_from(m));
-
- if (type_of_piece(pc) == PAWN)
- {
- if (pos.move_is_capture(m))
- san += file_to_char(square_file(move_from(m)));
- }
- else
+ if (type_of_piece(pc) != PAWN)
{
san += piece_type_to_char(type_of_piece(pc), true);
{
san += piece_type_to_char(type_of_piece(pc), true);
+ Square from = move_from(m);
switch (move_ambiguity(pos, m)) {
switch (move_ambiguity(pos, m)) {
case AMBIGUITY_NONE:
break;
case AMBIGUITY_NONE:
break;
case AMBIGUITY_FILE:
san += file_to_char(square_file(from));
break;
case AMBIGUITY_FILE:
san += file_to_char(square_file(from));
break;
case AMBIGUITY_RANK:
san += rank_to_char(square_rank(from));
break;
case AMBIGUITY_RANK:
san += rank_to_char(square_rank(from));
break;
case AMBIGUITY_BOTH:
san += square_to_string(from);
break;
case AMBIGUITY_BOTH:
san += square_to_string(from);
break;
default:
assert(false);
}
}
default:
assert(false);
}
}
if (pos.move_is_capture(m))
if (pos.move_is_capture(m))
+ {
+ if (type_of_piece(pc) == PAWN)
+ san += file_to_char(square_file(move_from(m)));
san += square_to_string(move_to(m));
san += square_to_string(move_to(m));
if (move_promotion(m))
{
san += '=';
san += piece_type_to_char(move_promotion(m), true);
}
}
if (move_promotion(m))
{
san += '=';
san += piece_type_to_char(move_promotion(m), true);
}
}
// Is the move check? We don't use pos.move_is_check(m) here, because
// Position::move_is_check doesn't detect all checks (not castling moves,
// promotions and en passant captures).
// Is the move check? We don't use pos.move_is_check(m) here, because
// Position::move_is_check doesn't detect all checks (not castling moves,
// promotions and en passant captures).
/// move_from_san() takes a position and a string as input, and tries to
/// move_from_san() takes a position and a string as input, and tries to
-/// interpret the string as a move in short algebraic notation. On success,
+/// interpret the string as a move in short algebraic notation. On success,
/// 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.
/// 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 m;
while ((m = mp.get_next_move()) != MOVE_NONE)
{
Move m;
while ((m = mp.get_next_move()) != MOVE_NONE)
- if(move_is_short_castle(m) && pos.pl_move_is_legal(m))
+ if (move_is_short_castle(m) && pos.pl_move_is_legal(m))
return m;
return MOVE_NONE;
return m;
return MOVE_NONE;
const std::string line_to_san(const Position& pos, Move line[], int startColumn, bool breakLines) {
const std::string line_to_san(const Position& pos, Move line[], int startColumn, bool breakLines) {
- Position p = Position(pos);
UndoInfo u;
std::stringstream s;
std::string moveStr;
UndoInfo u;
std::stringstream s;
std::string moveStr;
- size_t length, maxLength;
-
- length = 0;
- maxLength = 80 - startColumn;
-
- for(int i = 0; line[i] != MOVE_NONE; i++) {
- moveStr = move_to_san(p, line[i]);
- length += moveStr.length() + 1;
- if(breakLines && length > maxLength) {
- s << "\n";
- for(int j = 0; j < startColumn; j++)
- s << " ";
- length = moveStr.length() + 1;
- }
- s << moveStr << " ";
+ size_t length = 0;
+ size_t maxLength = 80 - startColumn;
+ Position p(pos);
- if(line[i] == MOVE_NULL)
- p.do_null_move(u);
- else
- p.do_move(line[i], u);
- }
+ for (int i = 0; line[i] != MOVE_NONE; i++)
+ {
+ moveStr = move_to_san(p, line[i]);
+ length += moveStr.length() + 1;
+ if (breakLines && length > maxLength)
+ {
+ s << '\n' << std::setw(startColumn) << ' ';
+ length = moveStr.length() + 1;
+ }
+ s << moveStr << ' ';
+ if (line[i] == MOVE_NULL)
+ p.do_null_move(u);
+ else
+ p.do_move(line[i], u);
+ }
std::stringstream s;
// Depth
std::stringstream s;
// Depth
- s << std::setw(2) << std::setfill(' ') << depth << " ";
+ s << std::setw(2) << depth << " ";
// Score
s << std::setw(8) << score_string(score);
// Time
// Score
s << std::setw(8) << score_string(score);
// Time
- s << std::setw(8) << std::setfill(' ') << time_string(time) << " ";
+ s << std::setw(8) << time_string(time) << " ";
- if(nodes < 1000000ULL)
- s << std::setw(8) << std::setfill(' ') << nodes << " ";
- else if(nodes < 1000000000ULL)
- s << std::setw(7) << std::setfill(' ') << nodes/1000ULL << 'k' << " ";
+ if (nodes < 1000000ULL)
+ s << std::setw(8) << nodes << " ";
+ else if (nodes < 1000000000ULL)
+ s << std::setw(7) << nodes/1000ULL << 'k' << " ";
- s << std::setw(7) << std::setfill(' ') << nodes/1000000ULL << 'M' << " ";
+ s << std::setw(7) << nodes/1000000ULL << 'M' << " ";
// PV
s << line_to_san(pos, pv, 30, true);
// PV
s << line_to_san(pos, pv, 30, true);
const std::string time_string(int milliseconds) {
const std::string time_string(int milliseconds) {
+ s << std::setfill('0');
- int hours = milliseconds / (1000 * 60 * 60);
- int minutes = (milliseconds - hours*1000*60*60) / (60*1000);
- int seconds = (milliseconds - hours*1000*60*60 - minutes*60*1000) / 1000;
+ int hours = milliseconds / (1000*60*60);
+ int minutes = (milliseconds - hours*1000*60*60) / (1000*60);
+ int seconds = (milliseconds - hours*1000*60*60 - minutes*1000*60) / 1000;
- if(hours)
- s << hours << ':';
- s << std::setw(2) << std::setfill('0') << minutes << ':';
- s << std::setw(2) << std::setfill('0') << seconds;
+ if (hours)
+ s << hours << ':';
+ s << std::setw(2) << minutes << ':' << std::setw(2) << seconds;
return s.str();
}
const std::string score_string(Value v) {
return s.str();
}
const std::string score_string(Value v) {
- if(abs(v) >= VALUE_MATE - 200) {
- if(v < 0)
- s << "-#" << (VALUE_MATE + v) / 2;
- else
+ if (v >= VALUE_MATE - 200)
s << "#" << (VALUE_MATE - v + 1) / 2;
s << "#" << (VALUE_MATE - v + 1) / 2;
- }
- else {
- float floatScore = float(v) / float(PawnValueMidgame);
- if(v >= 0)
- s << '+';
- s << std::setprecision(2) << std::fixed << floatScore;
+ else if(v <= -VALUE_MATE + 200)
+ s << "-#" << (VALUE_MATE + v) / 2;
+ else
+ {
+ float floatScore = float(v) / float(PawnValueMidgame);
+ if (v >= 0)
+ s << '+';
+
+ s << std::setprecision(2) << std::fixed << floatScore;