1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-02 01:29:36 +00:00

Rename castling flag to castling right

This is a more conventional naming as
reported also in:

http://chessprogramming.wikispaces.com/Castling+rights

No functional change.
This commit is contained in:
Marco Costalba 2014-03-08 15:08:55 +01:00
parent 13b9e1e098
commit 1d1b7df7c6
6 changed files with 55 additions and 55 deletions

View file

@ -31,18 +31,18 @@
(mlist++)->move = make_move(to - (d), to); } (mlist++)->move = make_move(to - (d), to); }
namespace { namespace {
template<CastlingFlag Cf, bool Checks, bool Chess960> template<CastlingRight Cr, bool Checks, bool Chess960>
ExtMove* generate_castling(const Position& pos, ExtMove* mlist, Color us, const CheckInfo* ci) { ExtMove* generate_castling(const Position& pos, ExtMove* mlist, Color us, const CheckInfo* ci) {
static const bool KingSide = (Cf == WHITE_OO || Cf == BLACK_OO); static const bool KingSide = (Cr == WHITE_OO || Cr == BLACK_OO);
if (pos.castling_impeded(Cf) || !pos.can_castle(Cf)) if (pos.castling_impeded(Cr) || !pos.can_castle(Cr))
return mlist; return mlist;
// After castling, the rook and king final positions are the same in Chess960 // After castling, the rook and king final positions are the same in Chess960
// as they would be in standard chess. // as they would be in standard chess.
Square kfrom = pos.king_square(us); Square kfrom = pos.king_square(us);
Square rfrom = pos.castling_rook_square(Cf); Square rfrom = pos.castling_rook_square(Cr);
Square kto = relative_square(us, KingSide ? SQ_G1 : SQ_C1); Square kto = relative_square(us, KingSide ? SQ_G1 : SQ_C1);
Bitboard enemies = pos.pieces(~us); Bitboard enemies = pos.pieces(~us);
@ -264,13 +264,13 @@ namespace {
{ {
if (pos.is_chess960()) if (pos.is_chess960())
{ {
mlist = generate_castling<MakeCastling<Us, KING_SIDE>::flag, Checks, true>(pos, mlist, Us, ci); mlist = generate_castling<MakeCastling<Us, KING_SIDE>::right, Checks, true>(pos, mlist, Us, ci);
mlist = generate_castling<MakeCastling<Us, QUEEN_SIDE>::flag, Checks, true>(pos, mlist, Us, ci); mlist = generate_castling<MakeCastling<Us, QUEEN_SIDE>::right, Checks, true>(pos, mlist, Us, ci);
} }
else else
{ {
mlist = generate_castling<MakeCastling<Us, KING_SIDE>::flag, Checks, false>(pos, mlist, Us, ci); mlist = generate_castling<MakeCastling<Us, KING_SIDE>::right, Checks, false>(pos, mlist, Us, ci);
mlist = generate_castling<MakeCastling<Us, QUEEN_SIDE>::flag, Checks, false>(pos, mlist, Us, ci); mlist = generate_castling<MakeCastling<Us, QUEEN_SIDE>::right, Checks, false>(pos, mlist, Us, ci);
} }
} }

View file

@ -278,7 +278,7 @@ template<Color Us>
Score Entry::update_safety(const Position& pos, Square ksq) { Score Entry::update_safety(const Position& pos, Square ksq) {
kingSquares[Us] = ksq; kingSquares[Us] = ksq;
castlingFlags[Us] = pos.can_castle(Us); castlingRights[Us] = pos.can_castle(Us);
minKPdistance[Us] = 0; minKPdistance[Us] = 0;
Bitboard pawns = pos.pieces(Us, PAWN); Bitboard pawns = pos.pieces(Us, PAWN);
@ -291,10 +291,10 @@ Score Entry::update_safety(const Position& pos, Square ksq) {
Value bonus = shelter_storm<Us>(pos, ksq); Value bonus = shelter_storm<Us>(pos, ksq);
// 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(MakeCastling<Us, KING_SIDE>::flag)) if (pos.can_castle(MakeCastling<Us, KING_SIDE>::right))
bonus = std::max(bonus, shelter_storm<Us>(pos, relative_square(Us, SQ_G1))); bonus = std::max(bonus, shelter_storm<Us>(pos, relative_square(Us, SQ_G1)));
if (pos.can_castle(MakeCastling<Us, QUEEN_SIDE>::flag)) if (pos.can_castle(MakeCastling<Us, QUEEN_SIDE>::right))
bonus = std::max(bonus, shelter_storm<Us>(pos, relative_square(Us, SQ_C1))); bonus = std::max(bonus, shelter_storm<Us>(pos, relative_square(Us, SQ_C1)));
return kingSafety[Us] = make_score(bonus, -16 * minKPdistance[Us]); return kingSafety[Us] = make_score(bonus, -16 * minKPdistance[Us]);

View file

@ -48,7 +48,7 @@ struct Entry {
template<Color Us> template<Color Us>
Score king_safety(const Position& pos, Square ksq) { Score king_safety(const Position& pos, Square ksq) {
return kingSquares[Us] == ksq && castlingFlags[Us] == pos.can_castle(Us) return kingSquares[Us] == ksq && castlingRights[Us] == pos.can_castle(Us)
? kingSafety[Us] : update_safety<Us>(pos, ksq); ? kingSafety[Us] : update_safety<Us>(pos, ksq);
} }
@ -64,7 +64,7 @@ struct Entry {
Bitboard pawnAttacks[COLOR_NB]; Bitboard pawnAttacks[COLOR_NB];
Square kingSquares[COLOR_NB]; Square kingSquares[COLOR_NB];
int minKPdistance[COLOR_NB]; int minKPdistance[COLOR_NB];
int castlingFlags[COLOR_NB]; int castlingRights[COLOR_NB];
Score value; Score value;
int semiopenFiles[COLOR_NB]; int semiopenFiles[COLOR_NB];
Score kingSafety[COLOR_NB]; Score kingSafety[COLOR_NB];

View file

@ -47,7 +47,7 @@ namespace Zobrist {
Key psq[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB]; Key psq[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
Key enpassant[FILE_NB]; Key enpassant[FILE_NB];
Key castling[CASTLING_FLAG_NB]; Key castling[CASTLING_RIGHT_NB];
Key side; Key side;
Key exclusion; Key exclusion;
} }
@ -263,7 +263,7 @@ void Position::set(const string& fenStr, bool isChess960, Thread* th) {
else else
continue; continue;
set_castling_flag(c, rsq); set_castling_right(c, rsq);
} }
// 4. En passant square. Ignore if no pawn capture is possible // 4. En passant square. Ignore if no pawn capture is possible
@ -297,30 +297,30 @@ void Position::set(const string& fenStr, bool isChess960, Thread* th) {
} }
/// Position::set_castling_flag() is a helper function used to set castling /// Position::set_castling_right() is a helper function used to set castling
/// flags given the corresponding color and the rook starting square. /// rights given the corresponding color and the rook starting square.
void Position::set_castling_flag(Color c, Square rfrom) { void Position::set_castling_right(Color c, Square rfrom) {
Square kfrom = king_square(c); Square kfrom = king_square(c);
CastlingSide cs = kfrom < rfrom ? KING_SIDE : QUEEN_SIDE; CastlingSide cs = kfrom < rfrom ? KING_SIDE : QUEEN_SIDE;
CastlingFlag cf = (c | cs); CastlingRight cr = (c | cs);
st->castlingFlags |= cf; st->castlingRights |= cr;
castlingFlagsMask[kfrom] |= cf; castlingRightsMask[kfrom] |= cr;
castlingFlagsMask[rfrom] |= cf; castlingRightsMask[rfrom] |= cr;
castlingRookSquare[cf] = rfrom; castlingRookSquare[cr] = rfrom;
Square kto = relative_square(c, cs == KING_SIDE ? SQ_G1 : SQ_C1); Square kto = relative_square(c, cs == KING_SIDE ? SQ_G1 : SQ_C1);
Square rto = relative_square(c, cs == KING_SIDE ? SQ_F1 : SQ_D1); Square rto = relative_square(c, cs == KING_SIDE ? SQ_F1 : SQ_D1);
for (Square s = std::min(rfrom, rto); s <= std::max(rfrom, rto); ++s) for (Square s = std::min(rfrom, rto); s <= std::max(rfrom, rto); ++s)
if (s != kfrom && s != rfrom) if (s != kfrom && s != rfrom)
castlingPath[cf] |= s; castlingPath[cr] |= s;
for (Square s = std::min(kfrom, kto); s <= std::max(kfrom, kto); ++s) for (Square s = std::min(kfrom, kto); s <= std::max(kfrom, kto); ++s)
if (s != kfrom && s != rfrom) if (s != kfrom && s != rfrom)
castlingPath[cf] |= s; castlingPath[cr] |= s;
} }
@ -791,12 +791,12 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
st->epSquare = SQ_NONE; st->epSquare = SQ_NONE;
} }
// Update castling flags if needed // Update castling rights if needed
if (st->castlingFlags && (castlingFlagsMask[from] | castlingFlagsMask[to])) if (st->castlingRights && (castlingRightsMask[from] | castlingRightsMask[to]))
{ {
int cf = castlingFlagsMask[from] | castlingFlagsMask[to]; int cr = castlingRightsMask[from] | castlingRightsMask[to];
k ^= Zobrist::castling[st->castlingFlags & cf]; k ^= Zobrist::castling[st->castlingRights & cr];
st->castlingFlags &= ~cf; st->castlingRights &= ~cr;
} }
// Prefetch TT access as soon as we know the new hash key // Prefetch TT access as soon as we know the new hash key
@ -1128,7 +1128,7 @@ void Position::clear() {
Key Position::compute_key() const { Key Position::compute_key() const {
Key k = Zobrist::castling[st->castlingFlags]; Key k = Zobrist::castling[st->castlingRights];
for (Bitboard b = pieces(); b; ) for (Bitboard b = pieces(); b; )
{ {
@ -1396,9 +1396,9 @@ bool Position::pos_is_ok(int* failedStep) const {
if (!can_castle(c | s)) if (!can_castle(c | s))
continue; continue;
if ( (castlingFlagsMask[king_square(c)] & (c | s)) != (c | s) if ( (castlingRightsMask[king_square(c)] & (c | s)) != (c | s)
|| piece_on(castlingRookSquare[c | s]) != make_piece(c, ROOK) || piece_on(castlingRookSquare[c | s]) != make_piece(c, ROOK)
|| castlingFlagsMask[castlingRookSquare[c | s]] != (c | s)) || castlingRightsMask[castlingRookSquare[c | s]] != (c | s))
return false; return false;
} }

View file

@ -51,7 +51,7 @@ struct CheckInfo {
struct StateInfo { struct StateInfo {
Key pawnKey, materialKey; Key pawnKey, materialKey;
Value npMaterial[COLOR_NB]; Value npMaterial[COLOR_NB];
int castlingFlags, rule50, pliesFromNull; int castlingRights, rule50, pliesFromNull;
Score psq; Score psq;
Square epSquare; Square epSquare;
@ -101,9 +101,9 @@ public:
// Castling // Castling
int can_castle(Color c) const; int can_castle(Color c) const;
int can_castle(CastlingFlag f) const; int can_castle(CastlingRight cr) const;
bool castling_impeded(CastlingFlag f) const; bool castling_impeded(CastlingRight cr) const;
Square castling_rook_square(CastlingFlag f) const; Square castling_rook_square(CastlingRight cr) const;
// Checking // Checking
Bitboard checkers() const; Bitboard checkers() const;
@ -170,7 +170,7 @@ public:
private: private:
// Initialization helpers (used while setting up a position) // Initialization helpers (used while setting up a position)
void clear(); void clear();
void set_castling_flag(Color c, Square rfrom); void set_castling_right(Color c, Square rfrom);
// Helper functions // Helper functions
void do_castling(Square kfrom, Square kto, Square rfrom, Square rto); void do_castling(Square kfrom, Square kto, Square rfrom, Square rto);
@ -197,9 +197,9 @@ private:
int index[SQUARE_NB]; int index[SQUARE_NB];
// Other info // Other info
int castlingFlagsMask[SQUARE_NB]; int castlingRightsMask[SQUARE_NB];
Square castlingRookSquare[CASTLING_FLAG_NB]; Square castlingRookSquare[CASTLING_RIGHT_NB];
Bitboard castlingPath[CASTLING_FLAG_NB]; Bitboard castlingPath[CASTLING_RIGHT_NB];
StateInfo startState; StateInfo startState;
uint64_t nodes; uint64_t nodes;
int gamePly; int gamePly;
@ -273,20 +273,20 @@ inline Square Position::king_square(Color c) const {
return pieceList[c][KING][0]; return pieceList[c][KING][0];
} }
inline int Position::can_castle(CastlingFlag f) const { inline int Position::can_castle(CastlingRight cr) const {
return st->castlingFlags & f; return st->castlingRights & cr;
} }
inline int Position::can_castle(Color c) const { inline int Position::can_castle(Color c) const {
return st->castlingFlags & ((WHITE_OO | WHITE_OOO) << (2 * c)); return st->castlingRights & ((WHITE_OO | WHITE_OOO) << (2 * c));
} }
inline bool Position::castling_impeded(CastlingFlag f) const { inline bool Position::castling_impeded(CastlingRight cr) const {
return byTypeBB[ALL_PIECES] & castlingPath[f]; return byTypeBB[ALL_PIECES] & castlingPath[cr];
} }
inline Square Position::castling_rook_square(CastlingFlag f) const { inline Square Position::castling_rook_square(CastlingRight cr) const {
return castlingRookSquare[f]; return castlingRookSquare[cr];
} }
template<PieceType Pt> template<PieceType Pt>

View file

@ -124,19 +124,19 @@ enum CastlingSide {
KING_SIDE, QUEEN_SIDE, CASTLING_SIDE_NB = 2 KING_SIDE, QUEEN_SIDE, CASTLING_SIDE_NB = 2
}; };
enum CastlingFlag { // Defined as in PolyGlot book hash key enum CastlingRight { // Defined as in PolyGlot book hash key
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,
ANY_CASTLING = WHITE_OO | WHITE_OOO | BLACK_OO | BLACK_OOO, ANY_CASTLING = WHITE_OO | WHITE_OOO | BLACK_OO | BLACK_OOO,
CASTLING_FLAG_NB = 16 CASTLING_RIGHT_NB = 16
}; };
template<Color C, CastlingSide S> struct MakeCastling { template<Color C, CastlingSide S> struct MakeCastling {
static const CastlingFlag static const CastlingRight
flag = C == WHITE ? S == QUEEN_SIDE ? WHITE_OOO : WHITE_OO right = C == WHITE ? S == QUEEN_SIDE ? WHITE_OOO : WHITE_OO
: S == QUEEN_SIDE ? BLACK_OOO : BLACK_OO; : S == QUEEN_SIDE ? BLACK_OOO : BLACK_OO;
}; };
@ -341,8 +341,8 @@ inline Square operator|(File f, Rank r) {
return Square((r << 3) | f); return Square((r << 3) | f);
} }
inline CastlingFlag operator|(Color c, CastlingSide s) { inline CastlingRight operator|(Color c, CastlingSide s) {
return CastlingFlag(WHITE_OO << ((s == QUEEN_SIDE) + 2 * c)); return CastlingRight(WHITE_OO << ((s == QUEEN_SIDE) + 2 * c));
} }
inline Value mate_in(int ply) { inline Value mate_in(int ply) {