stickfosh/cpp/src/move.hpp

49 lines
1.1 KiB
C++
Raw Normal View History

2025-02-02 18:17:37 +01:00
#pragma once
2025-02-02 17:13:55 +01:00
#include "castle_side.hpp"
#include "coords.hpp"
2025-02-03 19:09:13 +01:00
#include "pieces/piece.hpp"
2025-02-02 17:13:55 +01:00
2025-02-02 16:49:24 +01:00
#include <cstdint>
#include <sstream>
2025-02-02 16:49:24 +01:00
struct Move {
2025-02-02 18:17:37 +01:00
int8_t source_square;
2025-02-02 16:49:24 +01:00
int8_t target_square;
2025-02-02 17:13:55 +01:00
bool is_capturing = false;
CastleSide castle_side = CastleSide::NeitherSide;
2025-02-02 18:17:37 +01:00
bool en_passant = false;
2025-02-03 19:09:13 +01:00
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();
}
2025-02-02 16:49:24 +01:00
};
inline std::ostream& operator<<(std::ostream& os, const Move& m) {
os << m.to_string();
return os;
}