1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 08:43:09 +00:00

Assorted trivial cleanups 4/2019

No functional change.
This commit is contained in:
Marco Costalba 2019-03-31 12:02:19 +02:00
parent 5c4002aa82
commit 4e72e2a964
14 changed files with 43 additions and 46 deletions

View file

@ -27,7 +27,8 @@
namespace {
// There are 24 possible pawn squares: the first 4 files and ranks from 2 to 7
// There are 24 possible pawn squares: files A to D and ranks from 2 to 7.
// Positions with the pawn on files E to H will be mirrored before probing.
constexpr unsigned MAX_INDEX = 2*24*64*64; // stm * psq * wksq * bksq = 196608
// Each uint32_t stores results of 32 positions, one per bit

View file

@ -18,8 +18,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <bitset>
#include <algorithm>
#include <bitset>
#include "bitboard.h"
#include "misc.h"
@ -27,16 +27,10 @@
uint8_t PopCnt16[1 << 16];
uint8_t SquareDistance[SQUARE_NB][SQUARE_NB];
Bitboard SquareBB[SQUARE_NB];
Bitboard LineBB[SQUARE_NB][SQUARE_NB];
Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
Bitboard PawnAttacks[COLOR_NB][SQUARE_NB];
Bitboard SquareBB[SQUARE_NB];
Bitboard KingFlank[FILE_NB] = {
QueenSide ^ FileDBB, QueenSide, QueenSide,
CenterFiles, CenterFiles,
KingSide, KingSide, KingSide ^ FileEBB
};
Magic RookMagics[SQUARE_NB];
Magic BishopMagics[SQUARE_NB];

View file

@ -65,14 +65,19 @@ constexpr Bitboard CenterFiles = FileCBB | FileDBB | FileEBB | FileFBB;
constexpr Bitboard KingSide = FileEBB | FileFBB | FileGBB | FileHBB;
constexpr Bitboard Center = (FileDBB | FileEBB) & (Rank4BB | Rank5BB);
constexpr Bitboard KingFlank[FILE_NB] = {
QueenSide ^ FileDBB, QueenSide, QueenSide,
CenterFiles, CenterFiles,
KingSide, KingSide, KingSide ^ FileEBB
};
extern uint8_t PopCnt16[1 << 16];
extern uint8_t SquareDistance[SQUARE_NB][SQUARE_NB];
extern Bitboard SquareBB[SQUARE_NB];
extern Bitboard LineBB[SQUARE_NB][SQUARE_NB];
extern Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
extern Bitboard PawnAttacks[COLOR_NB][SQUARE_NB];
extern Bitboard KingFlank[FILE_NB];
extern Bitboard SquareBB[SQUARE_NB];
/// Magic holds all magic bitboards relevant data for a single square
@ -148,6 +153,7 @@ inline Bitboard file_bb(Square s) {
template<Direction D>
constexpr Bitboard shift(Bitboard b) {
return D == NORTH ? b << 8 : D == SOUTH ? b >> 8
: D == NORTH+NORTH? b <<16 : D == SOUTH+SOUTH? b >>16
: D == EAST ? (b & ~FileHBB) << 1 : D == WEST ? (b & ~FileABB) >> 1
: D == NORTH_EAST ? (b & ~FileHBB) << 9 : D == NORTH_WEST ? (b & ~FileABB) << 7
: D == SOUTH_EAST ? (b & ~FileHBB) >> 7 : D == SOUTH_WEST ? (b & ~FileABB) >> 9
@ -370,8 +376,8 @@ inline Square pop_lsb(Bitboard* b) {
}
/// frontmost_sq() and backmost_sq() return the square corresponding to the
/// most/least advanced bit relative to the given color.
/// frontmost_sq() and backmost_sq() return the most/least advanced square in
/// the given bitboard relative to the given color.
inline Square frontmost_sq(Color c, Bitboard b) { return c == WHITE ? msb(b) : lsb(b); }
inline Square backmost_sq(Color c, Bitboard b) { return c == WHITE ? lsb(b) : msb(b); }

View file

@ -18,6 +18,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <algorithm>
#include <cassert>
#include <cstring> // For std::memset
#include <iomanip>
@ -186,9 +187,8 @@ namespace {
// is also calculated is ALL_PIECES.
Bitboard attackedBy[COLOR_NB][PIECE_TYPE_NB];
// attackedBy2[color] are the squares attacked by 2 pieces of a given color,
// possibly via x-ray or by one pawn and one piece. Diagonal x-ray through
// pawn or squares attacked by 2 pawns are not explicitly added.
// attackedBy2[color] are the squares attacked by at least 2 units of a given
// color, including x-rays. But diagonal x-rays through pawns are not computed.
Bitboard attackedBy2[COLOR_NB];
// kingRing[color] are the squares adjacent to the king, plus (only for a
@ -241,8 +241,7 @@ namespace {
attackedBy[Us][KING] = pos.attacks_from<KING>(ksq);
attackedBy[Us][PAWN] = pe->pawn_attacks(Us);
attackedBy[Us][ALL_PIECES] = attackedBy[Us][KING] | attackedBy[Us][PAWN];
attackedBy2[Us] = (attackedBy[Us][KING] & attackedBy[Us][PAWN])
| dblAttackByPawn;
attackedBy2[Us] = dblAttackByPawn | (attackedBy[Us][KING] & attackedBy[Us][PAWN]);
// Init our king safety tables
kingRing[Us] = attackedBy[Us][KING];
@ -309,11 +308,11 @@ namespace {
bb = OutpostRanks & ~pe->pawn_attacks_span(Them);
if (bb & s)
score += Outpost * (Pt == KNIGHT ? 4 : 2)
* (1 + bool(attackedBy[Us][PAWN] & s));
* ((attackedBy[Us][PAWN] & s) ? 2 : 1);
else if (bb &= b & ~pos.pieces(Us))
score += Outpost * (Pt == KNIGHT ? 2 : 1)
* (1 + bool(attackedBy[Us][PAWN] & bb));
* ((attackedBy[Us][PAWN] & bb) ? 2 : 1);
// Knight and Bishop bonus for being right behind a pawn
if (shift<Down>(pos.pieces(PAWN)) & s)
@ -358,8 +357,8 @@ namespace {
score += RookOnPawn * popcount(pos.pieces(Them, PAWN) & PseudoAttacks[ROOK][s]);
// Bonus for rook on an open or semi-open file
if (pos.semiopen_file(Us, file_of(s)))
score += RookOnFile[bool(pos.semiopen_file(Them, file_of(s)))];
if (pos.is_semiopen_file(Us, file_of(s)))
score += RookOnFile[bool(pos.is_semiopen_file(Them, file_of(s)))];
// Penalty when trapped by the king, even more if the king cannot castle
else if (mob <= 3)
@ -672,7 +671,7 @@ namespace {
bonus += make_score(k * w, k * w);
}
} // rank > RANK_3
} // r > RANK_3
// Scale down bonus for candidate passers which need more than one
// pawn push to become passed, or have a pawn in front of them.
@ -717,7 +716,7 @@ namespace {
// Find all squares which are at most three squares behind some friendly pawn
Bitboard behind = pos.pieces(Us, PAWN);
behind |= shift<Down>(behind);
behind |= shift<Down>(shift<Down>(behind));
behind |= shift<Down+Down>(behind);
int bonus = popcount(safe) + popcount(behind & safe);
int weight = pos.count<ALL_PIECES>(Us)
@ -777,8 +776,7 @@ namespace {
if (sf == SCALE_FACTOR_NORMAL)
{
if ( pos.opposite_bishops()
&& pos.non_pawn_material(WHITE) == BishopValueMg
&& pos.non_pawn_material(BLACK) == BishopValueMg)
&& pos.non_pawn_material() == 2 * BishopValueMg)
sf = 16 + 4 * pe->passed_count();
else
sf = std::min(40 + (pos.opposite_bishops() ? 2 : 7) * pos.count<PAWN>(strongSide), sf);

View file

@ -210,12 +210,6 @@ void prefetch(void* addr) {
#endif
void prefetch2(void* addr) {
prefetch(addr);
prefetch((uint8_t*)addr + 64);
}
namespace WinProcGroup {
#ifndef _WIN32

View file

@ -31,7 +31,6 @@
const std::string engine_info(bool to_uci = false);
void prefetch(void* addr);
void prefetch2(void* addr);
void start_logger(const std::string& fname);
void dbg_hit_on(bool b);

View file

@ -18,6 +18,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <algorithm>
#include <cassert>
#include "bitboard.h"
@ -175,14 +176,14 @@ Value Entry::evaluate_shelter(const Position& pos, Square ksq) {
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
constexpr Direction Down = (Us == WHITE ? SOUTH : NORTH);
constexpr Bitboard BlockRanks = (Us == WHITE ? Rank1BB | Rank2BB : Rank8BB | Rank7BB);
constexpr Bitboard BlockSquares = (Rank1BB | Rank2BB | Rank7BB | Rank8BB)
& (FileABB | FileHBB);
Bitboard b = pos.pieces(PAWN) & ~forward_ranks_bb(Them, ksq);
Bitboard ourPawns = b & pos.pieces(Us);
Bitboard theirPawns = b & pos.pieces(Them);
Value safety = (shift<Down>(theirPawns) & (FileABB | FileHBB) & BlockRanks & ksq) ?
Value(374) : Value(5);
Value safety = (shift<Down>(theirPawns) & BlockSquares & ksq) ? Value(374) : Value(5);
File center = clamp(file_of(ksq), FILE_B, FILE_G);
for (File f = File(center - 1); f <= File(center + 1); ++f)

View file

@ -38,7 +38,7 @@ struct Entry {
Bitboard passed_pawns(Color c) const { return passedPawns[c]; }
Bitboard pawn_attacks_span(Color c) const { return pawnAttacksSpan[c]; }
int weak_unopposed(Color c) const { return weakUnopposed[c]; }
int passed_count() const { return popcount(passedPawns[WHITE] | passedPawns[BLACK]); };
int passed_count() const { return popcount(passedPawns[WHITE] | passedPawns[BLACK]); }
template<Color Us>
Score king_safety(const Position& pos) {

View file

@ -18,6 +18,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <algorithm>
#include <cassert>
#include <cstddef> // For offsetof()
#include <cstring> // For std::memset, std::memcmp
@ -859,7 +860,6 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
// Update pawn hash key and prefetch access to pawnsTable
st->pawnKey ^= Zobrist::psq[pc][from] ^ Zobrist::psq[pc][to];
prefetch2(thisThread->pawnsTable[st->pawnKey]);
// Reset rule 50 draw counter
st->rule50 = 0;

View file

@ -95,7 +95,7 @@ public:
template<PieceType Pt> int count() const;
template<PieceType Pt> const Square* squares(Color c) const;
template<PieceType Pt> Square square(Color c) const;
int semiopen_file(Color c, File f) const;
bool is_semiopen_file(Color c, File f) const;
// Castling
int castling_rights(Color c) const;
@ -262,7 +262,7 @@ inline Square Position::ep_square() const {
return st->epSquare;
}
inline int Position::semiopen_file(Color c, File f) const {
inline bool Position::is_semiopen_file(Color c, File f) const {
return !(pieces(c, PAWN) & file_bb(f));
}
@ -321,7 +321,7 @@ inline bool Position::pawn_passed(Color c, Square s) const {
inline bool Position::advanced_pawn_push(Move m) const {
return type_of(moved_piece(m)) == PAWN
&& relative_rank(sideToMove, from_sq(m)) > RANK_4;
&& relative_rank(sideToMove, to_sq(m)) > RANK_5;
}
inline int Position::pawns_on_same_color_squares(Color c, Square s) const {

View file

@ -18,6 +18,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring> // For std::memset
@ -1201,8 +1202,8 @@ moves_loop: // When in check, search starts from here
}
// qsearch() is the quiescence search function, which is called by the main
// search function with depth zero, or recursively with depth less than ONE_PLY.
// qsearch() is the quiescence search function, which is called by the main search
// function with zero depth, or recursively with further decreasing depth per call.
template <NodeType NT>
Value qsearch(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth) {

View file

@ -20,6 +20,7 @@
#include <cassert>
#include <algorithm> // For std::count
#include "movegen.h"
#include "search.h"
#include "thread.h"

View file

@ -18,6 +18,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <algorithm>
#include <cfloat>
#include <cmath>

View file

@ -18,6 +18,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <algorithm>
#include <cassert>
#include <ostream>
#include <sstream>