mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-25 11:36:51 +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:
@@ -94,10 +94,10 @@ namespace {
|
||||
template<Color Us>
|
||||
Score evaluate(const Position& pos, Pawns::Entry* e) {
|
||||
|
||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
const Square Up = (Us == WHITE ? NORTH : SOUTH);
|
||||
const Square Right = (Us == WHITE ? NORTH_EAST : SOUTH_WEST);
|
||||
const Square Left = (Us == WHITE ? NORTH_WEST : SOUTH_EAST);
|
||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
const Direction Up = (Us == WHITE ? NORTH : SOUTH);
|
||||
const Direction Right = (Us == WHITE ? NORTH_EAST : SOUTH_WEST);
|
||||
const Direction Left = (Us == WHITE ? NORTH_WEST : SOUTH_EAST);
|
||||
|
||||
Bitboard b, neighbours, stoppers, doubled, supported, phalanx;
|
||||
Bitboard lever, leverPush;
|
||||
@@ -254,7 +254,7 @@ Value Entry::shelter_storm(const Position& pos, Square ksq) {
|
||||
Value safety = MaxSafetyBonus;
|
||||
File center = std::max(FILE_B, std::min(FILE_G, file_of(ksq)));
|
||||
|
||||
for (File f = center - File(1); f <= center + File(1); ++f)
|
||||
for (File f = File(center - 1); f <= File(center + 1); ++f)
|
||||
{
|
||||
b = ourPawns & file_bb(f);
|
||||
Rank rkUs = b ? relative_rank(Us, backmost_sq(Us, b)) : RANK_1;
|
||||
@@ -262,7 +262,7 @@ Value Entry::shelter_storm(const Position& pos, Square ksq) {
|
||||
b = theirPawns & file_bb(f);
|
||||
Rank rkThem = b ? relative_rank(Us, frontmost_sq(Them, b)) : RANK_1;
|
||||
|
||||
int d = std::min(f, FILE_H - f);
|
||||
int d = std::min(f, ~f);
|
||||
safety -= ShelterWeakness[f == file_of(ksq)][d][rkUs]
|
||||
+ StormDanger
|
||||
[f == file_of(ksq) && rkThem == relative_rank(Us, ksq) + 1 ? BlockedByKing :
|
||||
|
||||
Reference in New Issue
Block a user