]> git.sesse.net Git - stockfish/blobdiff - src/square.h
Introduce and use same_color_squares()
[stockfish] / src / square.h
index 66b714a13de3589cb4f0686ab47bfd24d4d53bf4..d35d72bfd5b21311f1b2be9b79d05c597016d76f 100644 (file)
@@ -139,6 +139,11 @@ inline Color square_color(Square s) {
   return Color((int(square_file(s)) + int(square_rank(s))) & 1);
 }
 
+inline bool same_color_squares(Square s1, Square s2) {
+  int s = int(s1) ^ int(s2);
+  return (((s >> 3) ^ s) & 1) == 0;
+}
+
 inline int file_distance(File f1, File f2) {
   return abs(int(f1) - int(f2));
 }
@@ -180,10 +185,8 @@ inline Square square_from_string(const std::string& str) {
 }
 
 inline const std::string square_to_string(Square s) {
-  std::string str;
-  str += file_to_char(square_file(s));
-  str += rank_to_char(square_rank(s));
-  return str;
+  return  std::string(1, file_to_char(square_file(s)))
+        + std::string(1, rank_to_char(square_rank(s)));
 }
 
 inline bool file_is_ok(File f) {