X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fbitboard.h;h=cf948afc7c9398f4b63aa56d79409d34acc7f89c;hp=c9f199eee0105c910fa7c9bc539bf113d7e4884f;hb=f35e52f030af837ed8a89eecd67a6f746ee2e897;hpb=002bf4d8dbf804ce8303e01733341a0922af2e71 diff --git a/src/bitboard.h b/src/bitboard.h index c9f199ee..cf948afc 100644 --- a/src/bitboard.h +++ b/src/bitboard.h @@ -2,7 +2,7 @@ Stockfish, a UCI chess playing engine derived from Glaurung 2.1 Copyright (C) 2004-2008 Tord Romstad (Glaurung author) Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad - Copyright (C) 2015-2017 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad + Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad Stockfish is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -126,11 +126,10 @@ inline Bitboard& operator^=(Bitboard& b, Square s) { return b ^= SquareBB[s]; } -inline bool more_than_one(Bitboard b) { +constexpr bool more_than_one(Bitboard b) { return b & (b - 1); } - /// rank_bb() and file_bb() return a bitboard representing all the squares on /// the given file or rank. @@ -153,8 +152,8 @@ inline Bitboard file_bb(Square s) { /// shift() moves a bitboard one step along direction D. Mainly for pawns -template -inline Bitboard shift(Bitboard b) { +template +constexpr Bitboard shift(Bitboard b) { return D == NORTH ? b << 8 : D == SOUTH ? b >> 8 : D == NORTH_EAST ? (b & ~FileHBB) << 9 : D == SOUTH_EAST ? (b & ~FileHBB) >> 7 : D == NORTH_WEST ? (b & ~FileABB) << 7 : D == SOUTH_WEST ? (b & ~FileABB) >> 9 @@ -162,6 +161,16 @@ inline Bitboard shift(Bitboard b) { } +/// pawn_attacks_bb() returns the pawn attacks for the given color from the +/// squares in the given bitboard. + +template +constexpr Bitboard pawn_attacks_bb(Bitboard b) { + return C == WHITE ? shift(b) | shift(b) + : shift(b) | shift(b); +} + + /// adjacent_files_bb() returns a bitboard representing all the squares on the /// adjacent files of the given one. @@ -180,9 +189,9 @@ inline Bitboard between_bb(Square s1, Square s2) { } -/// forward_ranks_bb() returns a bitboard representing all the squares on all the ranks -/// in front of the given one, from the point of view of the given color. For -/// instance, forward_ranks_bb(BLACK, SQ_D3) will return the 16 squares on ranks 1 and 2. +/// forward_ranks_bb() returns a bitboard representing the squares on all the ranks +/// in front of the given one, from the point of view of the given color. For instance, +/// forward_ranks_bb(BLACK, SQ_D3) will return the 16 squares on ranks 1 and 2. inline Bitboard forward_ranks_bb(Color c, Square s) { return ForwardRanksBB[c][rank_of(s)];