From aa40d0a917285172e9334156fef5236b0c0e004f Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Wed, 23 Feb 2011 09:43:47 +0100 Subject: [PATCH] Small simplifications in square.h No functional change. Signed-off-by: Marco Costalba --- src/endgame.cpp | 4 ++-- src/square.h | 20 ++++++-------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/endgame.cpp b/src/endgame.cpp index 348feecf..eaa7f2e9 100644 --- a/src/endgame.cpp +++ b/src/endgame.cpp @@ -402,7 +402,7 @@ ScaleFactor ScalingFunction::apply(const Position& pos) const { Square kingSq = pos.king_square(weakerSide); if ( opposite_color_squares(queeningSq, bishopSq) - && file_distance(square_file(kingSq), pawnFile) <= 1) + && abs(square_file(kingSq) - pawnFile) <= 1) { // The bishop has the wrong color, and the defending king is on the // file of the pawn(s) or the neighboring file. Find the rank of the @@ -769,7 +769,7 @@ ScaleFactor ScalingFunction::apply(const Position& pos) const { && opposite_color_squares(ksq, wbsq) && ( bbsq == blockSq2 || (pos.attacks_from(blockSq2) & pos.pieces(BISHOP, weakerSide)) - || rank_distance(r1, r2) >= 2)) + || abs(r1 - r2) >= 2)) return SCALE_FACTOR_ZERO; else if ( ksq == blockSq2 diff --git a/src/square.h b/src/square.h index 0e314b04..fe0cc968 100644 --- a/src/square.h +++ b/src/square.h @@ -72,7 +72,7 @@ inline Square operator- (Square x, SquareDelta i) { return x - Square(i); } inline void operator-= (Square& x, SquareDelta i) { x = x - Square(i); } inline Square make_square(File f, Rank r) { - return Square(int(f) | (int(r) << 3)); + return Square((int(r) << 3) | int(f)); } inline File square_file(Square s) { @@ -104,7 +104,7 @@ inline Rank relative_rank(Color c, Square s) { } inline SquareColor square_color(Square s) { - return SquareColor((int(square_file(s)) + int(square_rank(s))) & 1); + return SquareColor(int(square_rank(s) + s) & 1); } inline bool opposite_color_squares(Square s1, Square s2) { @@ -112,20 +112,12 @@ inline bool opposite_color_squares(Square s1, Square s2) { return ((s >> 3) ^ s) & 1; } -inline int file_distance(File f1, File f2) { - return abs(int(f1) - int(f2)); -} - inline int file_distance(Square s1, Square s2) { - return file_distance(square_file(s1), square_file(s2)); -} - -inline int rank_distance(Rank r1, Rank r2) { - return abs(int(r1) - int(r2)); + return abs(square_file(s1) - square_file(s2)); } inline int rank_distance(Square s1, Square s2) { - return rank_distance(square_rank(s1), square_rank(s2)); + return abs(square_rank(s1) - square_rank(s2)); } inline int square_distance(Square s1, Square s2) { @@ -149,8 +141,8 @@ inline char rank_to_char(Rank r) { } inline const std::string square_to_string(Square s) { - return std::string(1, file_to_char(square_file(s))) - + std::string(1, rank_to_char(square_rank(s))); + char ch[] = { file_to_char(square_file(s)), rank_to_char(square_rank(s)), 0 }; + return std::string(ch); } inline bool file_is_ok(File f) { -- 2.39.2