]> git.sesse.net Git - stockfish/commitdiff
Small simplifications in square.h
authorMarco Costalba <mcostalba@gmail.com>
Wed, 23 Feb 2011 08:43:47 +0000 (09:43 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Wed, 23 Feb 2011 17:41:27 +0000 (18:41 +0100)
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/endgame.cpp
src/square.h

index 348feecf70bf5e170211460a23145a55749610dd..eaa7f2e95c847a484871e920e3e7b2bed3cc8fc0 100644 (file)
@@ -402,7 +402,7 @@ ScaleFactor ScalingFunction<KBPsK>::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<KBPPKB>::apply(const Position& pos) const {
         && opposite_color_squares(ksq, wbsq)
         && (   bbsq == blockSq2
             || (pos.attacks_from<BISHOP>(blockSq2) & pos.pieces(BISHOP, weakerSide))
-            || rank_distance(r1, r2) >= 2))
+            || abs(r1 - r2) >= 2))
         return SCALE_FACTOR_ZERO;
 
     else if (   ksq == blockSq2
index 0e314b04ac809f017d42d162a8d381caad9b8d99..fe0cc9684101b669487c0d97bd81c9a783b23aca 100644 (file)
@@ -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) {