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
&& 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
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) {
}
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) {
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) {
}
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) {