removed the is_capturing flag of move
This commit is contained in:
parent
c55645ad73
commit
222adbb8f0
@ -220,6 +220,7 @@ Board Board::make_move(Move move) const {
|
|||||||
// -- Check for castling rights
|
// -- Check for castling rights
|
||||||
ret.w_castle_rights = w_castle_rights;
|
ret.w_castle_rights = w_castle_rights;
|
||||||
ret.b_castle_rights = b_castle_rights;
|
ret.b_castle_rights = b_castle_rights;
|
||||||
|
bool is_capturing = squares[move.target_square] != Piece::None;
|
||||||
if (white_to_play) {
|
if (white_to_play) {
|
||||||
if ((squares[move.source_square] & 0b111) == King)
|
if ((squares[move.source_square] & 0b111) == King)
|
||||||
ret.w_castle_rights = NeitherSide;
|
ret.w_castle_rights = NeitherSide;
|
||||||
@ -232,7 +233,7 @@ Board Board::make_move(Move move) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Coords target = Coords::from_index(move.target_square);
|
Coords target = Coords::from_index(move.target_square);
|
||||||
if (move.is_capturing && target.y == 7
|
if (is_capturing && target.y == 7
|
||||||
&& (squares[move.target_square] & 0b111) == Rook) {
|
&& (squares[move.target_square] & 0b111) == Rook) {
|
||||||
if (target.x == 0 && (ret.b_castle_rights & QueenSide))
|
if (target.x == 0 && (ret.b_castle_rights & QueenSide))
|
||||||
ret.b_castle_rights &= ~(QueenSide);
|
ret.b_castle_rights &= ~(QueenSide);
|
||||||
@ -251,7 +252,7 @@ Board Board::make_move(Move move) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Coords target = Coords::from_index(move.target_square);
|
Coords target = Coords::from_index(move.target_square);
|
||||||
if (move.is_capturing && target.y == 0
|
if (is_capturing && target.y == 0
|
||||||
&& (squares[move.target_square] & 0b111) == Rook) {
|
&& (squares[move.target_square] & 0b111) == Rook) {
|
||||||
if (target.x == 0 && (ret.w_castle_rights & QueenSide))
|
if (target.x == 0 && (ret.w_castle_rights & QueenSide))
|
||||||
ret.w_castle_rights &= ~(QueenSide);
|
ret.w_castle_rights &= ~(QueenSide);
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
std::string pos =
|
std::string pos =
|
||||||
"r2q1rk1/pP1p2pp/Q4n2/bbp1p3/Np6/1B3NBn/pPPP1PPP/R3K2R b KQ - 0 5";
|
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
|
||||||
// Board b = Board::setup_fen_position(pos);
|
// Board b = Board::setup_fen_position(pos);
|
||||||
perft();
|
perft(pos);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ struct Move {
|
|||||||
int8_t source_square;
|
int8_t source_square;
|
||||||
int8_t target_square;
|
int8_t target_square;
|
||||||
|
|
||||||
bool is_capturing = false;
|
// bool is_capturing = false;
|
||||||
CastleSide castle_side = CastleSide::NeitherSide;
|
CastleSide castle_side = CastleSide::NeitherSide;
|
||||||
bool en_passant = false;
|
bool en_passant = false;
|
||||||
int8_t promoting_to = Piece::None;
|
int8_t promoting_to = Piece::None;
|
||||||
|
@ -21,7 +21,6 @@ std::vector<Move> pawn_moves(const Board& b, const Coords xy) {
|
|||||||
ret.push_back(Move{
|
ret.push_back(Move{
|
||||||
xy.to_index(),
|
xy.to_index(),
|
||||||
left.to_index(),
|
left.to_index(),
|
||||||
.is_capturing = true,
|
|
||||||
.promoting_to = (int8_t) (my_colour | piece)
|
.promoting_to = (int8_t) (my_colour | piece)
|
||||||
});
|
});
|
||||||
else
|
else
|
||||||
@ -43,7 +42,6 @@ std::vector<Move> pawn_moves(const Board& b, const Coords xy) {
|
|||||||
ret.push_back(Move{
|
ret.push_back(Move{
|
||||||
xy.to_index(),
|
xy.to_index(),
|
||||||
right.to_index(),
|
right.to_index(),
|
||||||
.is_capturing = true,
|
|
||||||
.promoting_to = (int8_t) (my_colour | piece)
|
.promoting_to = (int8_t) (my_colour | piece)
|
||||||
});
|
});
|
||||||
else
|
else
|
||||||
@ -56,12 +54,8 @@ std::vector<Move> pawn_moves(const Board& b, const Coords xy) {
|
|||||||
Coords c = Coords::from_index(b.en_passant_target);
|
Coords c = Coords::from_index(b.en_passant_target);
|
||||||
int dy = my_colour == Colour::White ? 1 : -1;
|
int dy = my_colour == Colour::White ? 1 : -1;
|
||||||
if (c.y == xy.y + dy && (c.x == xy.x - 1 || c.x == xy.x + 1)) {
|
if (c.y == xy.y + dy && (c.x == xy.x - 1 || c.x == xy.x + 1)) {
|
||||||
ret.push_back(Move{
|
ret.push_back(Move{xy.to_index(), c.to_index(), .en_passant = true}
|
||||||
xy.to_index(),
|
);
|
||||||
c.to_index(),
|
|
||||||
.is_capturing = true,
|
|
||||||
.en_passant = true
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,18 +53,11 @@ legal_moves(int8_t p, const Board& b, const Coords xy, bool looking_for_check) {
|
|||||||
|
|
||||||
std::optional<Move>
|
std::optional<Move>
|
||||||
move_for_position(const Board& board, const Coords source, const Coords dest) {
|
move_for_position(const Board& board, const Coords source, const Coords dest) {
|
||||||
if (!dest.is_within_bounds())
|
if (!dest.is_within_bounds()
|
||||||
|
|| board.colour_at(source) == board.colour_at(dest))
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
int8_t piece = board.squares[dest.to_index()];
|
|
||||||
if (piece == Piece::None)
|
|
||||||
return Move{source.to_index(), dest.to_index()};
|
return Move{source.to_index(), dest.to_index()};
|
||||||
|
|
||||||
int8_t source_colour = board.colour_at(source);
|
|
||||||
int8_t dest_colour = board.colour_at(dest);
|
|
||||||
if (source_colour != dest_colour)
|
|
||||||
return Move{source.to_index(), dest.to_index(), true};
|
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Move>
|
std::vector<Move>
|
||||||
@ -74,11 +67,11 @@ look_direction(const Board& board, const Coords xy, int mult_dx, int mult_dy) {
|
|||||||
int dx = mult_dx * d;
|
int dx = mult_dx * d;
|
||||||
int dy = mult_dy * d;
|
int dy = mult_dy * d;
|
||||||
|
|
||||||
std::optional<Move> move =
|
Coords target{xy.x + dx, xy.y + dy};
|
||||||
move_for_position(board, xy, Coords{xy.x + dx, xy.y + dy});
|
std::optional<Move> move = move_for_position(board, xy, target);
|
||||||
if (move.has_value()) {
|
if (move.has_value()) {
|
||||||
ret.push_back(move.value());
|
ret.push_back(move.value());
|
||||||
if (move.value().is_capturing)
|
if (board.squares[target.to_index()] != Piece::None)
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user