quick little refactoring

This commit is contained in:
Karma Riuk 2025-02-06 18:34:54 +01:00
parent 77f77ac04e
commit b8627ace14
4 changed files with 11 additions and 11 deletions

View File

@ -117,7 +117,7 @@ std::string Board::to_fen() const {
int full_piece = squares[rank * 8 + file]; int full_piece = squares[rank * 8 + file];
char piece = p2c[full_piece & 0b111]; char piece = p2c[full_piece & 0b111];
int8_t colour = colour_at({file, rank}); Colour colour = colour_at({file, rank});
if (empty_cell_counter > 0) { if (empty_cell_counter > 0) {
ret += std::to_string(empty_cell_counter); ret += std::to_string(empty_cell_counter);
@ -181,8 +181,8 @@ Board Board::make_move(Move move) const {
ret.squares[move.source_square] = Piece::None; ret.squares[move.source_square] = Piece::None;
ret.squares[move.target_square] = this->squares[move.source_square]; ret.squares[move.target_square] = this->squares[move.source_square];
int8_t source_piece = piece_at(move.source_square); Piece source_piece = piece_at(move.source_square);
int8_t target_piece = piece_at(move.target_square); Piece target_piece = piece_at(move.target_square);
// -- Handle en passant target being eaten // -- Handle en passant target being eaten
if (en_passant_target != -1 && source_piece == Piece::Pawn if (en_passant_target != -1 && source_piece == Piece::Pawn

View File

@ -41,19 +41,19 @@ struct Board {
|| is_stalemate_for(White) || is_stalemate_for(Black); || is_stalemate_for(White) || is_stalemate_for(Black);
} }
int8_t piece_at(int8_t idx) const { Piece piece_at(int8_t idx) const {
return squares[idx] & 0b00111; return (Piece) (squares[idx] & 0b00111);
} }
int8_t piece_at(Coords xy) const { Piece piece_at(Coords xy) const {
return piece_at(xy.to_index()); return piece_at(xy.to_index());
} }
int8_t colour_at(int8_t idx) const { Colour colour_at(int8_t idx) const {
return squares[idx] & 0b11000; return (Colour) (squares[idx] & 0b11000);
} }
int8_t colour_at(Coords xy) const { Colour colour_at(Coords xy) const {
return colour_at(xy.to_index()); return colour_at(xy.to_index());
} }
}; };

View File

@ -5,7 +5,7 @@
std::vector<Move> pawn_moves(const Board& b, const Coords xy) { std::vector<Move> pawn_moves(const Board& b, const Coords xy) {
std::vector<Move> ret{}; std::vector<Move> ret{};
int8_t my_colour = b.colour_at(xy); Colour my_colour = b.colour_at(xy);
// -- Capture to the left // -- Capture to the left
if (xy.x > 0) { if (xy.x > 0) {

View File

@ -9,7 +9,7 @@ keep_only_blocking(const std::vector<Move> candidates, const Board& board) {
if (candidates.size() == 0) if (candidates.size() == 0)
return {}; return {};
int8_t my_colour = board.colour_at(candidates[0].source_square); Colour my_colour = board.colour_at(candidates[0].source_square);
std::vector<Move> ret; std::vector<Move> ret;
for (Move move : candidates) { for (Move move : candidates) {
Board board_after_move = board.make_move(move); Board board_after_move = board.make_move(move);