mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-21 17:46:26 +08:00
Use a Direction enum for Square deltas
Currently the NORTH/WEST/SOUTH/EAST values are of type Square, but conceptually they are not squares but directions. This patch separates these values into a Direction enum and overloads addition and subtraction to allow adding a Square to a Direction (to get a new Square). I have also slightly trimmed the possible overloadings to improve type safety. For example, it would normally not make sense to add a Color to a Color or a Piece to a Piece, or to multiply or divide them by an integer. It would also normally not make sense to add a Square to a Square. This is a non-functional change.
This commit is contained in:
@@ -253,9 +253,9 @@ namespace {
|
||||
template<Tracing T> template<Color Us>
|
||||
void Evaluation<T>::initialize() {
|
||||
|
||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
const Square Up = (Us == WHITE ? NORTH : SOUTH);
|
||||
const Square Down = (Us == WHITE ? SOUTH : NORTH);
|
||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
const Direction Up = (Us == WHITE ? NORTH : SOUTH);
|
||||
const Direction Down = (Us == WHITE ? SOUTH : NORTH);
|
||||
const Bitboard LowRanks = (Us == WHITE ? Rank2BB | Rank3BB: Rank7BB | Rank6BB);
|
||||
|
||||
// Find our pawns on the first two ranks, and those which are blocked
|
||||
@@ -372,7 +372,7 @@ namespace {
|
||||
&& pos.is_chess960()
|
||||
&& (s == relative_square(Us, SQ_A1) || s == relative_square(Us, SQ_H1)))
|
||||
{
|
||||
Square d = pawn_push(Us) + (file_of(s) == FILE_A ? EAST : WEST);
|
||||
Direction d = pawn_push(Us) + (file_of(s) == FILE_A ? EAST : WEST);
|
||||
if (pos.piece_on(s + d) == make_piece(Us, PAWN))
|
||||
score -= !pos.empty(s + d + pawn_push(Us)) ? TrappedBishopA1H1 * 4
|
||||
: pos.piece_on(s + d + d) == make_piece(Us, PAWN) ? TrappedBishopA1H1 * 2
|
||||
@@ -422,10 +422,10 @@ namespace {
|
||||
template<Tracing T> template<Color Us>
|
||||
Score Evaluation<T>::evaluate_king() {
|
||||
|
||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
const Square Up = (Us == WHITE ? NORTH : SOUTH);
|
||||
const Bitboard Camp = (Us == WHITE ? AllSquares ^ Rank6BB ^ Rank7BB ^ Rank8BB
|
||||
: AllSquares ^ Rank1BB ^ Rank2BB ^ Rank3BB);
|
||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
const Direction Up = (Us == WHITE ? NORTH : SOUTH);
|
||||
const Bitboard Camp = (Us == WHITE ? AllSquares ^ Rank6BB ^ Rank7BB ^ Rank8BB
|
||||
: AllSquares ^ Rank1BB ^ Rank2BB ^ Rank3BB);
|
||||
|
||||
const Square ksq = pos.square<KING>(Us);
|
||||
Bitboard weak, b, b1, b2, safe, other;
|
||||
@@ -530,11 +530,11 @@ namespace {
|
||||
template<Tracing T> template<Color Us>
|
||||
Score Evaluation<T>::evaluate_threats() {
|
||||
|
||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
const Square Up = (Us == WHITE ? NORTH : SOUTH);
|
||||
const Square Left = (Us == WHITE ? NORTH_WEST : SOUTH_EAST);
|
||||
const Square Right = (Us == WHITE ? NORTH_EAST : SOUTH_WEST);
|
||||
const Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB);
|
||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
const Direction Up = (Us == WHITE ? NORTH : SOUTH);
|
||||
const Direction Left = (Us == WHITE ? NORTH_WEST : SOUTH_EAST);
|
||||
const Direction Right = (Us == WHITE ? NORTH_EAST : SOUTH_WEST);
|
||||
const Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB);
|
||||
|
||||
Bitboard b, weak, defended, stronglyProtected, safeThreats;
|
||||
Score score = SCORE_ZERO;
|
||||
@@ -636,8 +636,8 @@ namespace {
|
||||
template<Tracing T> template<Color Us>
|
||||
Score Evaluation<T>::evaluate_passed_pawns() {
|
||||
|
||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
const Square Up = (Us == WHITE ? NORTH : SOUTH);
|
||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
const Direction Up = (Us == WHITE ? NORTH : SOUTH);
|
||||
|
||||
Bitboard b, bb, squaresToQueen, defendedSquares, unsafeSquares;
|
||||
Score score = SCORE_ZERO;
|
||||
|
||||
Reference in New Issue
Block a user