mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
Consolidate CastlingSide and CastlingRights
This is a non-functional simplification that removes CastlingSide and implements the functionality in CastlingRights (thanks to Jörg Oster for a comment on the first version of this patch). STC LLR: 2.96 (-2.94,2.94) [-3.00,1.00] Total: 53854 W: 12077 L: 12019 D: 29758 http://tests.stockfishchess.org/tests/view/5d517b940ebc5925cf107474 Closes https://github.com/official-stockfish/Stockfish/pull/2265 No functional change
This commit is contained in:
parent
a016626825
commit
3984b8f8f0
5 changed files with 26 additions and 29 deletions
|
@ -219,8 +219,8 @@ namespace {
|
||||||
template<Color Us, GenType Type>
|
template<Color Us, GenType Type>
|
||||||
ExtMove* generate_all(const Position& pos, ExtMove* moveList, Bitboard target) {
|
ExtMove* generate_all(const Position& pos, ExtMove* moveList, Bitboard target) {
|
||||||
|
|
||||||
constexpr CastlingRight OO = Us | KING_SIDE;
|
constexpr CastlingRights OO = Us & KING_SIDE;
|
||||||
constexpr CastlingRight OOO = Us | QUEEN_SIDE;
|
constexpr CastlingRights OOO = Us & QUEEN_SIDE;
|
||||||
constexpr bool Checks = Type == QUIET_CHECKS; // Reduce template instantations
|
constexpr bool Checks = Type == QUIET_CHECKS; // Reduce template instantations
|
||||||
|
|
||||||
moveList = generate_pawn_moves<Us, Type>(pos, moveList, target);
|
moveList = generate_pawn_moves<Us, Type>(pos, moveList, target);
|
||||||
|
@ -236,7 +236,7 @@ namespace {
|
||||||
while (b)
|
while (b)
|
||||||
*moveList++ = make_move(ksq, pop_lsb(&b));
|
*moveList++ = make_move(ksq, pop_lsb(&b));
|
||||||
|
|
||||||
if (Type != CAPTURES && pos.can_castle(CastlingRight(OO | OOO)))
|
if (Type != CAPTURES && pos.can_castle(CastlingRights(OO | OOO)))
|
||||||
{
|
{
|
||||||
if (!pos.castling_impeded(OO) && pos.can_castle(OO))
|
if (!pos.castling_impeded(OO) && pos.can_castle(OO))
|
||||||
*moveList++ = make<CASTLING>(ksq, pos.castling_rook_square(OO));
|
*moveList++ = make<CASTLING>(ksq, pos.castling_rook_square(OO));
|
||||||
|
|
|
@ -238,10 +238,10 @@ Score Entry::do_king_safety(const Position& pos) {
|
||||||
evaluate_shelter<Us>(pos, ksq, shelter);
|
evaluate_shelter<Us>(pos, ksq, shelter);
|
||||||
|
|
||||||
// If we can castle use the bonus after the castling if it is bigger
|
// If we can castle use the bonus after the castling if it is bigger
|
||||||
if (pos.can_castle(Us | KING_SIDE))
|
if (pos.can_castle(Us & KING_SIDE))
|
||||||
evaluate_shelter<Us>(pos, relative_square(Us, SQ_G1), shelter);
|
evaluate_shelter<Us>(pos, relative_square(Us, SQ_G1), shelter);
|
||||||
|
|
||||||
if (pos.can_castle(Us | QUEEN_SIDE))
|
if (pos.can_castle(Us & QUEEN_SIDE))
|
||||||
evaluate_shelter<Us>(pos, relative_square(Us, SQ_C1), shelter);
|
evaluate_shelter<Us>(pos, relative_square(Us, SQ_C1), shelter);
|
||||||
|
|
||||||
return shelter - make_score(0, 16 * minPawnDist);
|
return shelter - make_score(0, 16 * minPawnDist);
|
||||||
|
|
|
@ -330,16 +330,15 @@ Position& Position::set(const string& fenStr, bool isChess960, StateInfo* si, Th
|
||||||
void Position::set_castling_right(Color c, Square rfrom) {
|
void Position::set_castling_right(Color c, Square rfrom) {
|
||||||
|
|
||||||
Square kfrom = square<KING>(c);
|
Square kfrom = square<KING>(c);
|
||||||
CastlingSide cs = kfrom < rfrom ? KING_SIDE : QUEEN_SIDE;
|
CastlingRights cr = c & (kfrom < rfrom ? KING_SIDE: QUEEN_SIDE);
|
||||||
CastlingRight cr = (c | cs);
|
|
||||||
|
|
||||||
st->castlingRights |= cr;
|
st->castlingRights |= cr;
|
||||||
castlingRightsMask[kfrom] |= cr;
|
castlingRightsMask[kfrom] |= cr;
|
||||||
castlingRightsMask[rfrom] |= cr;
|
castlingRightsMask[rfrom] |= cr;
|
||||||
castlingRookSquare[cr] = rfrom;
|
castlingRookSquare[cr] = rfrom;
|
||||||
|
|
||||||
Square kto = relative_square(c, cs == KING_SIDE ? SQ_G1 : SQ_C1);
|
Square kto = relative_square(c, cr & KING_SIDE ? SQ_G1 : SQ_C1);
|
||||||
Square rto = relative_square(c, cs == KING_SIDE ? SQ_F1 : SQ_D1);
|
Square rto = relative_square(c, cr & KING_SIDE ? SQ_F1 : SQ_D1);
|
||||||
|
|
||||||
castlingPath[cr] = (between_bb(rfrom, rto) | between_bb(kfrom, kto) | rto | kto)
|
castlingPath[cr] = (between_bb(rfrom, rto) | between_bb(kfrom, kto) | rto | kto)
|
||||||
& ~(square_bb(kfrom) | rfrom);
|
& ~(square_bb(kfrom) | rfrom);
|
||||||
|
@ -1300,14 +1299,14 @@ bool Position::pos_is_ok() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Color c : { WHITE, BLACK })
|
for (Color c : { WHITE, BLACK })
|
||||||
for (CastlingSide s : {KING_SIDE, QUEEN_SIDE})
|
for (CastlingRights cr : {c & KING_SIDE, c & QUEEN_SIDE})
|
||||||
{
|
{
|
||||||
if (!can_castle(c | s))
|
if (!can_castle(cr))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ( piece_on(castlingRookSquare[c | s]) != make_piece(c, ROOK)
|
if ( piece_on(castlingRookSquare[cr]) != make_piece(c, ROOK)
|
||||||
|| castlingRightsMask[castlingRookSquare[c | s]] != (c | s)
|
|| castlingRightsMask[castlingRookSquare[cr]] != (cr)
|
||||||
|| (castlingRightsMask[square<KING>(c)] & (c | s)) != (c | s))
|
|| (castlingRightsMask[square<KING>(c)] & (cr)) != (cr))
|
||||||
assert(0 && "pos_is_ok: Castling");
|
assert(0 && "pos_is_ok: Castling");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -100,9 +100,9 @@ public:
|
||||||
|
|
||||||
// Castling
|
// Castling
|
||||||
int castling_rights(Color c) const;
|
int castling_rights(Color c) const;
|
||||||
bool can_castle(CastlingRight cr) const;
|
bool can_castle(CastlingRights cr) const;
|
||||||
bool castling_impeded(CastlingRight cr) const;
|
bool castling_impeded(CastlingRights cr) const;
|
||||||
Square castling_rook_square(CastlingRight cr) const;
|
Square castling_rook_square(CastlingRights cr) const;
|
||||||
|
|
||||||
// Checking
|
// Checking
|
||||||
Bitboard checkers() const;
|
Bitboard checkers() const;
|
||||||
|
@ -268,7 +268,7 @@ inline bool Position::is_on_semiopen_file(Color c, Square s) const {
|
||||||
return !(pieces(c, PAWN) & file_bb(s));
|
return !(pieces(c, PAWN) & file_bb(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::can_castle(CastlingRight cr) const {
|
inline bool Position::can_castle(CastlingRights cr) const {
|
||||||
return st->castlingRights & cr;
|
return st->castlingRights & cr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,11 +276,11 @@ inline int Position::castling_rights(Color c) const {
|
||||||
return st->castlingRights & (c == WHITE ? WHITE_CASTLING : BLACK_CASTLING);
|
return st->castlingRights & (c == WHITE ? WHITE_CASTLING : BLACK_CASTLING);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::castling_impeded(CastlingRight cr) const {
|
inline bool Position::castling_impeded(CastlingRights cr) const {
|
||||||
return byTypeBB[ALL_PIECES] & castlingPath[cr];
|
return byTypeBB[ALL_PIECES] & castlingPath[cr];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Square Position::castling_rook_square(CastlingRight cr) const {
|
inline Square Position::castling_rook_square(CastlingRights cr) const {
|
||||||
return castlingRookSquare[cr];
|
return castlingRookSquare[cr];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
src/types.h
12
src/types.h
|
@ -131,17 +131,15 @@ enum Color {
|
||||||
WHITE, BLACK, COLOR_NB = 2
|
WHITE, BLACK, COLOR_NB = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
enum CastlingSide {
|
enum CastlingRights {
|
||||||
KING_SIDE, QUEEN_SIDE, CASTLING_SIDE_NB = 2
|
|
||||||
};
|
|
||||||
|
|
||||||
enum CastlingRight {
|
|
||||||
NO_CASTLING,
|
NO_CASTLING,
|
||||||
WHITE_OO,
|
WHITE_OO,
|
||||||
WHITE_OOO = WHITE_OO << 1,
|
WHITE_OOO = WHITE_OO << 1,
|
||||||
BLACK_OO = WHITE_OO << 2,
|
BLACK_OO = WHITE_OO << 2,
|
||||||
BLACK_OOO = WHITE_OO << 3,
|
BLACK_OOO = WHITE_OO << 3,
|
||||||
|
|
||||||
|
KING_SIDE = WHITE_OO | BLACK_OO,
|
||||||
|
QUEEN_SIDE = WHITE_OOO | BLACK_OOO,
|
||||||
WHITE_CASTLING = WHITE_OO | WHITE_OOO,
|
WHITE_CASTLING = WHITE_OO | WHITE_OOO,
|
||||||
BLACK_CASTLING = BLACK_OO | BLACK_OOO,
|
BLACK_CASTLING = BLACK_OO | BLACK_OOO,
|
||||||
ANY_CASTLING = WHITE_CASTLING | BLACK_CASTLING,
|
ANY_CASTLING = WHITE_CASTLING | BLACK_CASTLING,
|
||||||
|
@ -363,8 +361,8 @@ constexpr Piece operator~(Piece pc) {
|
||||||
return Piece(pc ^ 8); // Swap color of piece B_KNIGHT -> W_KNIGHT
|
return Piece(pc ^ 8); // Swap color of piece B_KNIGHT -> W_KNIGHT
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr CastlingRight operator|(Color c, CastlingSide s) {
|
constexpr CastlingRights operator&(Color c, CastlingRights cr) {
|
||||||
return CastlingRight(WHITE_OO << ((s == QUEEN_SIDE) + 2 * c));
|
return CastlingRights((c == WHITE ? WHITE_CASTLING : BLACK_CASTLING) & cr);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Value mate_in(int ply) {
|
constexpr Value mate_in(int ply) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue