1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-06 03:19:36 +00:00

san.cpp cleanup

Hopefully no functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2008-12-01 14:34:31 +01:00
parent d95b9189d8
commit 20390fcb3c

View file

@ -82,53 +82,40 @@ const std::string move_to_san(const Position& pos, Move m) {
san = "O-O"; san = "O-O";
else else
{ {
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 (type_of_piece(pc) == PAWN)
{
if (pos.move_is_capture(m))
san += file_to_char(square_file(move_from(m)));
}
else
{ {
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: case AMBIGUITY_NONE:
break; break;
case AMBIGUITY_FILE: case AMBIGUITY_FILE:
san += file_to_char(square_file(from)); san += file_to_char(square_file(from));
break; break;
case AMBIGUITY_RANK: case AMBIGUITY_RANK:
san += rank_to_char(square_rank(from)); san += rank_to_char(square_rank(from));
break; break;
case AMBIGUITY_BOTH: case AMBIGUITY_BOTH:
san += square_to_string(from); san += square_to_string(from);
break; break;
default: default:
assert(false); 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 += "x"; san += "x";
}
san += square_to_string(move_to(m)); san += square_to_string(move_to(m));
if (move_promotion(m)) if (move_promotion(m))
{ {
san += '='; san += '=';
san += piece_type_to_char(move_promotion(m), true); san += piece_type_to_char(move_promotion(m), true);
} }
} }
// Is the move check? We don't use pos.move_is_check(m) here, because // 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, // Position::move_is_check doesn't detect all checks (not castling moves,
// promotions and en passant captures). // promotions and en passant captures).
@ -273,32 +260,29 @@ Move move_from_san(const Position& pos, const std::string& movestr) {
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; UndoInfo u;
std::stringstream s; std::stringstream s;
std::string moveStr; std::string moveStr;
size_t length, maxLength; size_t length = 0;
size_t maxLength = 80 - startColumn;
Position p(pos);
length = 0; for (int i = 0; line[i] != MOVE_NONE; i++)
maxLength = 80 - startColumn; {
for(int i = 0; line[i] != MOVE_NONE; i++) {
moveStr = move_to_san(p, line[i]); moveStr = move_to_san(p, line[i]);
length += moveStr.length() + 1; length += moveStr.length() + 1;
if(breakLines && length > maxLength) { if (breakLines && length > maxLength)
s << "\n"; {
for(int j = 0; j < startColumn; j++) s << '\n' << std::setw(startColumn) << ' ';
s << " ";
length = moveStr.length() + 1; length = moveStr.length() + 1;
} }
s << moveStr << " "; s << moveStr << ' ';
if (line[i] == MOVE_NULL) if (line[i] == MOVE_NULL)
p.do_null_move(u); p.do_null_move(u);
else else
p.do_move(line[i], u); p.do_move(line[i], u);
} }
return s.str(); return s.str();
} }
@ -312,21 +296,21 @@ const std::string pretty_pv(const Position& pos, int time, int depth,
std::stringstream s; std::stringstream s;
// Depth // Depth
s << std::setw(2) << std::setfill(' ') << depth << " "; s << std::setw(2) << depth << " ";
// Score // Score
s << std::setw(8) << score_string(score); s << std::setw(8) << score_string(score);
// Time // Time
s << std::setw(8) << std::setfill(' ') << time_string(time) << " "; s << std::setw(8) << time_string(time) << " ";
// Nodes // Nodes
if (nodes < 1000000ULL) if (nodes < 1000000ULL)
s << std::setw(8) << std::setfill(' ') << nodes << " "; s << std::setw(8) << nodes << " ";
else if (nodes < 1000000000ULL) else if (nodes < 1000000000ULL)
s << std::setw(7) << std::setfill(' ') << nodes/1000ULL << 'k' << " "; s << std::setw(7) << nodes/1000ULL << 'k' << " ";
else else
s << std::setw(7) << std::setfill(' ') << nodes/1000000ULL << 'M' << " "; s << std::setw(7) << nodes/1000000ULL << 'M' << " ";
// PV // PV
s << line_to_san(pos, pv, 30, true); s << line_to_san(pos, pv, 30, true);
@ -379,37 +363,38 @@ namespace {
const std::string time_string(int milliseconds) { const std::string time_string(int milliseconds) {
std::stringstream s; std::stringstream s;
s << std::setfill('0');
int hours = milliseconds / (1000*60*60); int hours = milliseconds / (1000*60*60);
int minutes = (milliseconds - hours*1000*60*60) / (60*1000); int minutes = (milliseconds - hours*1000*60*60) / (1000*60);
int seconds = (milliseconds - hours*1000*60*60 - minutes*60*1000) / 1000; int seconds = (milliseconds - hours*1000*60*60 - minutes*1000*60) / 1000;
if (hours) if (hours)
s << hours << ':'; s << hours << ':';
s << std::setw(2) << std::setfill('0') << minutes << ':';
s << std::setw(2) << std::setfill('0') << seconds;
s << std::setw(2) << minutes << ':' << std::setw(2) << seconds;
return s.str(); return s.str();
} }
const std::string score_string(Value v) { const std::string score_string(Value v) {
std::stringstream s; std::stringstream s;
if(abs(v) >= VALUE_MATE - 200) { if (v >= VALUE_MATE - 200)
if(v < 0) s << "#" << (VALUE_MATE - v + 1) / 2;
else if(v <= -VALUE_MATE + 200)
s << "-#" << (VALUE_MATE + v) / 2; s << "-#" << (VALUE_MATE + v) / 2;
else else
s << "#" << (VALUE_MATE - v + 1) / 2; {
}
else {
float floatScore = float(v) / float(PawnValueMidgame); float floatScore = float(v) / float(PawnValueMidgame);
if (v >= 0) if (v >= 0)
s << '+'; s << '+';
s << std::setprecision(2) << std::fixed << floatScore; s << std::setprecision(2) << std::fixed << floatScore;
} }
return s.str(); return s.str();
} }
} }