mirror of
https://github.com/sockspls/badfish
synced 2025-04-29 16:23:09 +00:00
Small touches in position.h
No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
80dd90f972
commit
1a8e3f0b2e
5 changed files with 26 additions and 28 deletions
|
@ -187,7 +187,7 @@ Value Endgame<KBNK>::apply(const Position& pos) const {
|
|||
// 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 (opposite_color_squares(bishopSquare, SQ_A1))
|
||||
if (opposite_colors(bishopSquare, SQ_A1))
|
||||
{
|
||||
winnerKSq = mirror(winnerKSq);
|
||||
loserKSq = mirror(loserKSq);
|
||||
|
@ -433,7 +433,7 @@ ScaleFactor Endgame<KBPsK>::apply(const Position& pos) const {
|
|||
Square queeningSq = relative_square(strongerSide, make_square(pawnFile, RANK_8));
|
||||
Square kingSq = pos.king_square(weakerSide);
|
||||
|
||||
if ( opposite_color_squares(queeningSq, bishopSq)
|
||||
if ( opposite_colors(queeningSq, bishopSq)
|
||||
&& abs(file_of(kingSq) - pawnFile) <= 1)
|
||||
{
|
||||
// The bishop has the wrong color, and the defending king is on the
|
||||
|
@ -710,12 +710,12 @@ ScaleFactor Endgame<KBPKB>::apply(const Position& pos) const {
|
|||
// Case 1: Defending king blocks the pawn, and cannot be driven away
|
||||
if ( file_of(weakerKingSq) == file_of(pawnSq)
|
||||
&& relative_rank(strongerSide, pawnSq) < relative_rank(strongerSide, weakerKingSq)
|
||||
&& ( opposite_color_squares(weakerKingSq, strongerBishopSq)
|
||||
&& ( opposite_colors(weakerKingSq, strongerBishopSq)
|
||||
|| relative_rank(strongerSide, weakerKingSq) <= RANK_6))
|
||||
return SCALE_FACTOR_ZERO;
|
||||
|
||||
// Case 2: Opposite colored bishops
|
||||
if (opposite_color_squares(strongerBishopSq, weakerBishopSq))
|
||||
if (opposite_colors(strongerBishopSq, weakerBishopSq))
|
||||
{
|
||||
// We assume that the position is drawn in the following three situations:
|
||||
//
|
||||
|
@ -760,7 +760,7 @@ ScaleFactor Endgame<KBPPKB>::apply(const Position& pos) const {
|
|||
Square wbsq = pos.piece_list(strongerSide, BISHOP)[0];
|
||||
Square bbsq = pos.piece_list(weakerSide, BISHOP)[0];
|
||||
|
||||
if (!opposite_color_squares(wbsq, bbsq))
|
||||
if (!opposite_colors(wbsq, bbsq))
|
||||
return SCALE_FACTOR_NONE;
|
||||
|
||||
Square ksq = pos.king_square(weakerSide);
|
||||
|
@ -788,7 +788,7 @@ ScaleFactor Endgame<KBPPKB>::apply(const Position& pos) const {
|
|||
// some square in the frontmost pawn's path.
|
||||
if ( file_of(ksq) == file_of(blockSq1)
|
||||
&& relative_rank(strongerSide, ksq) >= relative_rank(strongerSide, blockSq1)
|
||||
&& opposite_color_squares(ksq, wbsq))
|
||||
&& opposite_colors(ksq, wbsq))
|
||||
return SCALE_FACTOR_ZERO;
|
||||
else
|
||||
return SCALE_FACTOR_NONE;
|
||||
|
@ -798,14 +798,14 @@ ScaleFactor Endgame<KBPPKB>::apply(const Position& pos) const {
|
|||
// 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
|
||||
&& opposite_color_squares(ksq, wbsq)
|
||||
&& opposite_colors(ksq, wbsq)
|
||||
&& ( bbsq == blockSq2
|
||||
|| (pos.attacks_from<BISHOP>(blockSq2) & pos.pieces(BISHOP, weakerSide))
|
||||
|| abs(r1 - r2) >= 2))
|
||||
return SCALE_FACTOR_ZERO;
|
||||
|
||||
else if ( ksq == blockSq2
|
||||
&& opposite_color_squares(ksq, wbsq)
|
||||
&& opposite_colors(ksq, wbsq)
|
||||
&& ( bbsq == blockSq1
|
||||
|| (pos.attacks_from<BISHOP>(blockSq1) & pos.pieces(BISHOP, weakerSide))))
|
||||
return SCALE_FACTOR_ZERO;
|
||||
|
@ -839,7 +839,7 @@ ScaleFactor Endgame<KBPKN>::apply(const Position& pos) const {
|
|||
|
||||
if ( file_of(weakerKingSq) == file_of(pawnSq)
|
||||
&& relative_rank(strongerSide, pawnSq) < relative_rank(strongerSide, weakerKingSq)
|
||||
&& ( opposite_color_squares(weakerKingSq, strongerBishopSq)
|
||||
&& ( opposite_colors(weakerKingSq, strongerBishopSq)
|
||||
|| relative_rank(strongerSide, weakerKingSq) <= RANK_6))
|
||||
return SCALE_FACTOR_ZERO;
|
||||
|
||||
|
|
|
@ -462,7 +462,7 @@ namespace {
|
|||
if (bonus && bit_is_set(ei.attackedBy[Us][PAWN], s))
|
||||
{
|
||||
if ( pos.pieces(KNIGHT, Them) == EmptyBoardBB
|
||||
&& (SquaresByColorBB[square_color(s)] & pos.pieces(BISHOP, Them)) == EmptyBoardBB)
|
||||
&& (SquaresByColorBB[color_of(s)] & pos.pieces(BISHOP, Them)) == EmptyBoardBB)
|
||||
bonus += bonus + bonus / 2;
|
||||
else
|
||||
bonus += bonus / 2;
|
||||
|
|
|
@ -342,7 +342,7 @@ void Position::print(Move move) const {
|
|||
Square sq = make_square(file, rank);
|
||||
Piece piece = piece_on(sq);
|
||||
|
||||
if (piece == PIECE_NONE && square_color(sq) == DARK)
|
||||
if (piece == PIECE_NONE && color_of(sq) == DARK)
|
||||
piece = PIECE_NONE_DARK_SQ;
|
||||
|
||||
char c = (color_of(piece_on(sq)) == BLACK ? '=' : ' ');
|
||||
|
|
|
@ -283,7 +283,7 @@ inline Piece Position::piece_on(Square s) const {
|
|||
}
|
||||
|
||||
inline bool Position::square_is_empty(Square s) const {
|
||||
return piece_on(s) == PIECE_NONE;
|
||||
return board[s] == PIECE_NONE;
|
||||
}
|
||||
|
||||
inline Color Position::side_to_move() const {
|
||||
|
@ -295,7 +295,7 @@ inline Bitboard Position::occupied_squares() const {
|
|||
}
|
||||
|
||||
inline Bitboard Position::empty_squares() const {
|
||||
return ~occupied_squares();
|
||||
return ~byTypeBB[0];
|
||||
}
|
||||
|
||||
inline Bitboard Position::pieces(Color c) const {
|
||||
|
@ -376,7 +376,7 @@ inline Bitboard Position::checkers() const {
|
|||
}
|
||||
|
||||
inline bool Position::in_check() const {
|
||||
return st->checkersBB != EmptyBoardBB;
|
||||
return st->checkersBB != 0;
|
||||
}
|
||||
|
||||
inline bool Position::pawn_is_passed(Color c, Square s) const {
|
||||
|
@ -417,9 +417,8 @@ inline Value Position::non_pawn_material(Color c) const {
|
|||
|
||||
inline bool Position::move_is_passed_pawn_push(Move m) const {
|
||||
|
||||
Color c = side_to_move();
|
||||
return piece_on(move_from(m)) == make_piece(c, PAWN)
|
||||
&& pawn_is_passed(c, move_to(m));
|
||||
return board[move_from(m)] == make_piece(sideToMove, PAWN)
|
||||
&& pawn_is_passed(sideToMove, move_to(m));
|
||||
}
|
||||
|
||||
inline int Position::startpos_ply_counter() const {
|
||||
|
@ -428,9 +427,9 @@ inline int Position::startpos_ply_counter() const {
|
|||
|
||||
inline bool Position::opposite_colored_bishops() const {
|
||||
|
||||
return piece_count(WHITE, BISHOP) == 1
|
||||
&& piece_count(BLACK, BISHOP) == 1
|
||||
&& opposite_color_squares(piece_list(WHITE, BISHOP)[0], piece_list(BLACK, BISHOP)[0]);
|
||||
return pieceCount[WHITE][BISHOP] == 1
|
||||
&& pieceCount[BLACK][BISHOP] == 1
|
||||
&& opposite_colors(pieceList[WHITE][BISHOP][0], pieceList[BLACK][BISHOP][0]);
|
||||
}
|
||||
|
||||
inline bool Position::has_pawn_on_7th(Color c) const {
|
||||
|
|
15
src/types.h
15
src/types.h
|
@ -382,11 +382,6 @@ inline Color flip(Color c) {
|
|||
return Color(c ^ 1);
|
||||
}
|
||||
|
||||
inline char piece_type_to_char(PieceType pt) {
|
||||
static const char ch[] = " PNBRQK";
|
||||
return ch[pt];
|
||||
}
|
||||
|
||||
inline Square make_square(File f, Rank r) {
|
||||
return Square((r << 3) | f);
|
||||
}
|
||||
|
@ -423,11 +418,11 @@ inline Rank relative_rank(Color c, Square s) {
|
|||
return relative_rank(c, rank_of(s));
|
||||
}
|
||||
|
||||
inline SquareColor square_color(Square s) {
|
||||
inline SquareColor color_of(Square s) {
|
||||
return SquareColor(int(rank_of(s) + s) & 1);
|
||||
}
|
||||
|
||||
inline bool opposite_color_squares(Square s1, Square s2) {
|
||||
inline bool opposite_colors(Square s1, Square s2) {
|
||||
int s = s1 ^ s2;
|
||||
return ((s >> 3) ^ s) & 1;
|
||||
}
|
||||
|
@ -444,6 +439,10 @@ inline int square_distance(Square s1, Square s2) {
|
|||
return SquareDistance[s1][s2];
|
||||
}
|
||||
|
||||
inline char piece_type_to_char(PieceType pt) {
|
||||
return " PNBRQK"[pt];
|
||||
}
|
||||
|
||||
inline char file_to_char(File f) {
|
||||
return char(f - FILE_A + int('a'));
|
||||
}
|
||||
|
@ -454,7 +453,7 @@ inline char rank_to_char(Rank r) {
|
|||
|
||||
inline const std::string square_to_string(Square s) {
|
||||
char ch[] = { file_to_char(file_of(s)), rank_to_char(rank_of(s)), 0 };
|
||||
return std::string(ch);
|
||||
return ch;
|
||||
}
|
||||
|
||||
inline Square pawn_push(Color c) {
|
||||
|
|
Loading…
Add table
Reference in a new issue