made move str better (includes promotion)

This commit is contained in:
Karma Riuk 2025-02-04 21:51:14 +01:00
parent 609d5f8c98
commit 151a50fba9

View File

@ -5,6 +5,7 @@
#include "pieces/piece.hpp"
#include <cstdint>
#include <sstream>
struct Move {
int8_t source_square;
@ -14,10 +15,34 @@ struct Move {
CastleSide castle_side = CastleSide::NeitherSide;
bool en_passant = false;
int8_t promoting_to = Piece::None;
std::string to_string() const {
std::stringstream ss;
ss << Coords::from_index(source_square)
<< Coords::from_index(target_square);
if (promoting_to != Piece::None) {
switch (promoting_to & 0b00111) {
case Queen:
ss << 'q';
break;
case Bishop:
ss << 'b';
break;
case Knigt:
ss << 'n';
break;
case Rook:
ss << 'r';
break;
default:
break;
}
}
return ss.str();
}
};
inline std::ostream& operator<<(std::ostream& os, const Move& m) {
os << Coords::from_index(m.source_square)
<< Coords::from_index(m.target_square);
os << m.to_string();
return os;
}