It is almost alwasy the requested test and is a bit faster too.
No functional change.
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
// kbnk_mate_table() tries to drive toward corners A1 or H8,
// if we have a bishop that cannot reach the above squares we
// mirror the kings so to drive enemy toward corners A8 or H1.
// kbnk_mate_table() tries to drive toward corners A1 or H8,
// if we have a bishop that cannot reach the above squares we
// mirror the kings so to drive enemy toward corners A8 or H1.
- if (!same_color_squares(bishopSquare, SQ_A1))
+ if (opposite_color_squares(bishopSquare, SQ_A1))
{
winnerKSq = flop_square(winnerKSq);
loserKSq = flop_square(loserKSq);
{
winnerKSq = flop_square(winnerKSq);
loserKSq = flop_square(loserKSq);
Square queeningSq = relative_square(strongerSide, make_square(pawnFile, RANK_8));
Square kingSq = pos.king_square(weakerSide);
Square queeningSq = relative_square(strongerSide, make_square(pawnFile, RANK_8));
Square kingSq = pos.king_square(weakerSide);
- if ( !same_color_squares(queeningSq, bishopSq)
+ if ( opposite_color_squares(queeningSq, bishopSq)
&& file_distance(square_file(kingSq), pawnFile) <= 1)
{
// The bishop has the wrong color, and the defending king is on the
&& file_distance(square_file(kingSq), pawnFile) <= 1)
{
// The bishop has the wrong color, and the defending king is on the
// Case 1: Defending king blocks the pawn, and cannot be driven away
if ( square_file(weakerKingSq) == square_file(pawnSq)
&& relative_rank(strongerSide, pawnSq) < relative_rank(strongerSide, weakerKingSq)
// Case 1: Defending king blocks the pawn, and cannot be driven away
if ( square_file(weakerKingSq) == square_file(pawnSq)
&& relative_rank(strongerSide, pawnSq) < relative_rank(strongerSide, weakerKingSq)
- && ( !same_color_squares(weakerKingSq, strongerBishopSq)
+ && ( opposite_color_squares(weakerKingSq, strongerBishopSq)
|| relative_rank(strongerSide, weakerKingSq) <= RANK_6))
return SCALE_FACTOR_ZERO;
// Case 2: Opposite colored bishops
|| relative_rank(strongerSide, weakerKingSq) <= RANK_6))
return SCALE_FACTOR_ZERO;
// Case 2: Opposite colored bishops
- if (!same_color_squares(strongerBishopSq, weakerBishopSq))
+ if (opposite_color_squares(strongerBishopSq, weakerBishopSq))
{
// We assume that the position is drawn in the following three situations:
//
{
// We assume that the position is drawn in the following three situations:
//
Square wbsq = pos.piece_list(strongerSide, BISHOP, 0);
Square bbsq = pos.piece_list(weakerSide, BISHOP, 0);
Square wbsq = pos.piece_list(strongerSide, BISHOP, 0);
Square bbsq = pos.piece_list(weakerSide, BISHOP, 0);
- if (same_color_squares(wbsq, bbsq))
- // Not opposite-colored bishops, no scaling
+ if (!opposite_color_squares(wbsq, bbsq))
return SCALE_FACTOR_NONE;
Square ksq = pos.king_square(weakerSide);
return SCALE_FACTOR_NONE;
Square ksq = pos.king_square(weakerSide);
// some square in the frontmost pawn's path.
if ( square_file(ksq) == square_file(blockSq1)
&& relative_rank(strongerSide, ksq) >= relative_rank(strongerSide, blockSq1)
// some square in the frontmost pawn's path.
if ( square_file(ksq) == square_file(blockSq1)
&& relative_rank(strongerSide, ksq) >= relative_rank(strongerSide, blockSq1)
- && !same_color_squares(ksq, wbsq))
+ && opposite_color_squares(ksq, wbsq))
return SCALE_FACTOR_ZERO;
else
return SCALE_FACTOR_NONE;
return SCALE_FACTOR_ZERO;
else
return SCALE_FACTOR_NONE;
// in front of the frontmost pawn's path, and the square diagonally behind
// this square on the file of the other pawn.
if ( ksq == blockSq1
// in front of the frontmost pawn's path, and the square diagonally behind
// this square on the file of the other pawn.
if ( ksq == blockSq1
- && !same_color_squares(ksq, wbsq)
+ && opposite_color_squares(ksq, wbsq)
&& ( bbsq == blockSq2
|| (pos.attacks_from<BISHOP>(blockSq2) & pos.pieces(BISHOP, weakerSide))
|| rank_distance(r1, r2) >= 2))
return SCALE_FACTOR_ZERO;
else if ( ksq == blockSq2
&& ( bbsq == blockSq2
|| (pos.attacks_from<BISHOP>(blockSq2) & pos.pieces(BISHOP, weakerSide))
|| rank_distance(r1, r2) >= 2))
return SCALE_FACTOR_ZERO;
else if ( ksq == blockSq2
- && !same_color_squares(ksq, wbsq)
+ && opposite_color_squares(ksq, wbsq)
&& ( bbsq == blockSq1
|| (pos.attacks_from<BISHOP>(blockSq1) & pos.pieces(BISHOP, weakerSide))))
return SCALE_FACTOR_ZERO;
&& ( bbsq == blockSq1
|| (pos.attacks_from<BISHOP>(blockSq1) & pos.pieces(BISHOP, weakerSide))))
return SCALE_FACTOR_ZERO;
if ( square_file(weakerKingSq) == square_file(pawnSq)
&& relative_rank(strongerSide, pawnSq) < relative_rank(strongerSide, weakerKingSq)
if ( square_file(weakerKingSq) == square_file(pawnSq)
&& relative_rank(strongerSide, pawnSq) < relative_rank(strongerSide, weakerKingSq)
- && ( !same_color_squares(weakerKingSq, strongerBishopSq)
+ && ( opposite_color_squares(weakerKingSq, strongerBishopSq)
|| relative_rank(strongerSide, weakerKingSq) <= RANK_6))
return SCALE_FACTOR_ZERO;
|| relative_rank(strongerSide, weakerKingSq) <= RANK_6))
return SCALE_FACTOR_ZERO;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#if !defined(POSITION_H_INCLUDED)
#define POSITION_H_INCLUDED
#if !defined(POSITION_H_INCLUDED)
#define POSITION_H_INCLUDED
-////
-//// Includes
-////
-
#include "bitboard.h"
#include "color.h"
#include "move.h"
#include "bitboard.h"
#include "color.h"
#include "move.h"
#include "square.h"
#include "value.h"
#include "square.h"
#include "value.h"
-
-////
-//// Constants
-////
-
/// Maximum number of plies per game (220 should be enough, because the
/// maximum search depth is 100, and during position setup we reset the
/// move counter for every non-reversible move).
const int MaxGameLength = 220;
/// Maximum number of plies per game (220 should be enough, because the
/// maximum search depth is 100, and during position setup we reset the
/// move counter for every non-reversible move).
const int MaxGameLength = 220;
-
-////
-//// Types
-////
-
class Position;
/// struct checkInfo is initialized at c'tor time and keeps
class Position;
/// struct checkInfo is initialized at c'tor time and keeps
static const Value PieceValueEndgame[17];
};
static const Value PieceValueEndgame[17];
};
-
-////
-//// Inline functions
-////
-
inline int64_t Position::nodes_searched() const {
return nodes;
}
inline int64_t Position::nodes_searched() const {
return nodes;
}
inline bool Position::opposite_colored_bishops() const {
inline bool Position::opposite_colored_bishops() const {
- return piece_count(WHITE, BISHOP) == 1
- && piece_count(BLACK, BISHOP) == 1
- && !same_color_squares(piece_list(WHITE, BISHOP, 0), piece_list(BLACK, BISHOP, 0));
+ return piece_count(WHITE, BISHOP) == 1 && piece_count(BLACK, BISHOP) == 1
+ && opposite_color_squares(piece_list(WHITE, BISHOP, 0), piece_list(BLACK, BISHOP, 0));
}
inline bool Position::has_pawn_on_7th(Color c) const {
}
inline bool Position::has_pawn_on_7th(Color c) const {
return SquareColor((int(square_file(s)) + int(square_rank(s))) & 1);
}
return SquareColor((int(square_file(s)) + int(square_rank(s))) & 1);
}
-inline bool same_color_squares(Square s1, Square s2) {
+inline bool opposite_color_squares(Square s1, Square s2) {
int s = int(s1) ^ int(s2);
int s = int(s1) ^ int(s2);
- return (((s >> 3) ^ s) & 1) == 0;
+ return ((s >> 3) ^ s) & 1;
}
inline int file_distance(File f1, File f2) {
}
inline int file_distance(File f1, File f2) {