minor fixes

This commit is contained in:
Karma Riuk 2025-02-07 00:29:39 +01:00
parent 695cef33df
commit 0525bd565e

View File

@ -9,6 +9,7 @@
#include <algorithm> #include <algorithm>
#include <cctype> #include <cctype>
#include <map> #include <map>
#include <sstream>
#include <stdexcept> #include <stdexcept>
Board Board::setup_fen_position(std::string fen) { Board Board::setup_fen_position(std::string fen) {
@ -112,7 +113,7 @@ std::string Board::to_fen() const {
for (int rank = 7; rank >= 0; rank--) { for (int rank = 7; rank >= 0; rank--) {
int empty_cell_counter = 0; int empty_cell_counter = 0;
for (int file = 0; file < 8; file++) { for (int file = 0; file < 8; file++) {
if (squares[rank * 8 + file] == Piece::None) { if (piece_at({file, rank}) == Piece::None) {
empty_cell_counter++; empty_cell_counter++;
continue; continue;
} }
@ -302,9 +303,11 @@ int8_t Board::get_king_of(int8_t colour) const {
for (int i = 0; i < 64; i++) for (int i = 0; i < 64; i++)
if (squares[i] == (colour | Piece::King)) if (squares[i] == (colour | Piece::King))
return i; return i;
throw std::domain_error( std::stringstream ss;
"Apparently there no kings of the such color in this board" ss << "Apparently there no kings of the such color in this board: "
); << std::endl;
ss << to_fen();
throw std::domain_error(ss.str());
} }
bool Board::is_check_for(int8_t colour) const { bool Board::is_check_for(int8_t colour) const {