remove castle side from move

This commit is contained in:
Karma Riuk 2025-02-05 14:33:59 +01:00
parent 222adbb8f0
commit a658673d2b
3 changed files with 15 additions and 15 deletions

View File

@ -203,18 +203,20 @@ Board Board::make_move(Move move) const {
// -- Handle castling (just move the rook over)
Coords c = Coords::from_index(move.source_square);
if (move.castle_side & KingSide) {
Coords rook_source{7, c.y};
int8_t old_rook = ret.squares[rook_source.to_index()];
ret.squares[rook_source.to_index()] = Piece::None;
Coords rook_dest{5, c.y};
ret.squares[rook_dest.to_index()] = old_rook;
} else if (move.castle_side & QueenSide) {
Coords rook_source{0, c.y};
int8_t old_rook = ret.squares[rook_source.to_index()];
ret.squares[rook_source.to_index()] = Piece::None;
Coords rook_dest{3, c.y};
ret.squares[rook_dest.to_index()] = old_rook;
if ((squares[move.source_square] & 0b111) == Piece::King) {
if (move.target_square - move.source_square == 2) { // king side castle
Coords rook_source{7, c.y};
int8_t old_rook = ret.squares[rook_source.to_index()];
ret.squares[rook_source.to_index()] = Piece::None;
Coords rook_dest{5, c.y};
ret.squares[rook_dest.to_index()] = old_rook;
} else if (move.target_square - move.source_square == -2) { // queen
Coords rook_source{0, c.y};
int8_t old_rook = ret.squares[rook_source.to_index()];
ret.squares[rook_source.to_index()] = Piece::None;
Coords rook_dest{3, c.y};
ret.squares[rook_dest.to_index()] = old_rook;
}
}
// -- Check for castling rights

View File

@ -12,7 +12,7 @@ struct Move {
int8_t target_square;
// bool is_capturing = false;
CastleSide castle_side = CastleSide::NeitherSide;
// CastleSide castle_side = CastleSide::NeitherSide;
bool en_passant = false;
int8_t promoting_to = Piece::None;

View File

@ -60,7 +60,6 @@ std::vector<Move> king_moves(const Board& b, const Coords xy) {
ret.push_back(Move{
xy.to_index(),
Coords{6, xy.y}.to_index(),
.castle_side = CastleSide::KingSide
});
}
@ -68,7 +67,6 @@ std::vector<Move> king_moves(const Board& b, const Coords xy) {
ret.push_back(Move{
xy.to_index(),
Coords{2, xy.y}.to_index(),
.castle_side = CastleSide::QueenSide
});
}