closes https://github.com/official-stockfish/Stockfish/pull/2532
Bench:
4869669
#include <vector>
#include <bitset>
#include <vector>
#include <bitset>
#ifndef ENDGAME_H_INCLUDED
#define ENDGAME_H_INCLUDED
#ifndef ENDGAME_H_INCLUDED
#define ENDGAME_H_INCLUDED
-#include <unordered_map>
#include <memory>
#include <string>
#include <type_traits>
#include <memory>
#include <string>
#include <type_traits>
+#include <unordered_map>
#include <utility>
#include "position.h"
#include <utility>
#include "position.h"
}
// Bonus for restricting their piece moves
}
// Bonus for restricting their piece moves
- // Greater bonus when landing square is occupied
b = attackedBy[Them][ALL_PIECES]
& ~stronglyProtected
& attackedBy[Us][ALL_PIECES];
b = attackedBy[Them][ALL_PIECES]
& ~stronglyProtected
& attackedBy[Us][ALL_PIECES];
- 43 * almostUnwinnable
-110 ;
- 43 * almostUnwinnable
-110 ;
- // Give more importance to non-material score
Value mg = mg_value(score);
Value eg = eg_value(score);
Value mg = mg_value(score);
Value eg = eg_value(score);
#include <iostream>
#include "bitboard.h"
#include <iostream>
#include "bitboard.h"
#include "position.h"
#include "search.h"
#include "thread.h"
#include "tt.h"
#include "uci.h"
#include "position.h"
#include "search.h"
#include "thread.h"
#include "tt.h"
#include "uci.h"
#include "syzygy/tbprobe.h"
namespace PSQT {
#include "syzygy/tbprobe.h"
namespace PSQT {
/// With c++17 some of this functionality can be simplified.
#if defined(__linux__) && !defined(__ANDROID__)
/// With c++17 some of this functionality can be simplified.
#if defined(__linux__) && !defined(__ANDROID__)
-void* aligned_ttmem_alloc(size_t allocSize, void** mem) {
+void* aligned_ttmem_alloc(size_t allocSize, void*& mem) {
constexpr size_t alignment = 2 * 1024 * 1024; // assumed 2MB page sizes
size_t size = ((allocSize + alignment - 1) / alignment) * alignment; // multiple of alignment
constexpr size_t alignment = 2 * 1024 * 1024; // assumed 2MB page sizes
size_t size = ((allocSize + alignment - 1) / alignment) * alignment; // multiple of alignment
- *mem = aligned_alloc(alignment, size);
- madvise(*mem, allocSize, MADV_HUGEPAGE);
- return *mem;
+ mem = aligned_alloc(alignment, size);
+ madvise(mem, allocSize, MADV_HUGEPAGE);
+ return mem;
-void* aligned_ttmem_alloc(size_t allocSize, void** mem) {
+void* aligned_ttmem_alloc(size_t allocSize, void*& mem) {
constexpr size_t alignment = 64; // assumed cache line size
size_t size = allocSize + alignment - 1; // allocate some extra space
constexpr size_t alignment = 64; // assumed cache line size
size_t size = allocSize + alignment - 1; // allocate some extra space
- *mem = malloc(size);
- void* ret = reinterpret_cast<void*>((uintptr_t(*mem) + alignment - 1) & ~uintptr_t(alignment - 1));
+ mem = malloc(size);
+ void* ret = reinterpret_cast<void*>((uintptr_t(mem) + alignment - 1) & ~uintptr_t(alignment - 1));
const std::string compiler_info();
void prefetch(void* addr);
void start_logger(const std::string& fname);
const std::string compiler_info();
void prefetch(void* addr);
void start_logger(const std::string& fname);
-void* aligned_ttmem_alloc(size_t size, void** mem);
+void* aligned_ttmem_alloc(size_t size, void*& mem);
void dbg_hit_on(bool b);
void dbg_hit_on(bool c, bool b);
void dbg_hit_on(bool b);
void dbg_hit_on(bool c, bool b);
template<Color Us, GenType Type>
ExtMove* generate_pawn_moves(const Position& pos, ExtMove* moveList, Bitboard target) {
template<Color Us, GenType Type>
ExtMove* generate_pawn_moves(const Position& pos, ExtMove* moveList, Bitboard target) {
- // Compute some compile time parameters relative to the white side
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
constexpr Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB);
constexpr Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB);
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
constexpr Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB);
constexpr Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB);
Square to = to_sq(m);
// Is there a direct check?
Square to = to_sq(m);
// Is there a direct check?
- if (st->checkSquares[type_of(piece_on(from))] & to)
+ if (check_squares(type_of(piece_on(from))) & to)
return true;
// Is there a discovered check?
return true;
// Is there a discovered check?
- if ( (st->blockersForKing[~sideToMove] & from)
+ if ( (blockers_for_king(~sideToMove) & from)
&& !aligned(from, to, square<KING>(~sideToMove)))
return true;
&& !aligned(from, to, square<KING>(~sideToMove)))
return true;
/// Thread::bestMoveCount(Move move) return best move counter for the given root move
/// Thread::bestMoveCount(Move move) return best move counter for the given root move
-int Thread::best_move_count(Move move) {
+int Thread::best_move_count(Move move) const {
auto rm = std::find(rootMoves.begin() + pvIdx,
rootMoves.begin() + pvLast, move);
auto rm = std::find(rootMoves.begin() + pvIdx,
rootMoves.begin() + pvLast, move);
captureHistory.fill(0);
for (bool inCheck : { false, true })
captureHistory.fill(0);
for (bool inCheck : { false, true })
- for (StatsType c : { NoCaptures, Captures })
- for (auto& to : continuationHistory[inCheck][c])
- for (auto& h : to)
- h->fill(0);
-
- for (bool inCheck : { false, true })
- for (StatsType c : { NoCaptures, Captures })
- continuationHistory[inCheck][c][NO_PIECE][0]->fill(Search::CounterMovePruneThreshold - 1);
+ for (StatsType c : { NoCaptures, Captures })
+ {
+ for (auto& to : continuationHistory[inCheck][c])
+ for (auto& h : to)
+ h->fill(0);
+ continuationHistory[inCheck][c][NO_PIECE][0]->fill(Search::CounterMovePruneThreshold - 1);
+ }
}
/// Thread::start_searching() wakes up the thread that will start the search
}
/// Thread::start_searching() wakes up the thread that will start the search
void idle_loop();
void start_searching();
void wait_for_search_finished();
void idle_loop();
void start_searching();
void wait_for_search_finished();
- int best_move_count(Move move);
+ int best_move_count(Move move) const;
Pawns::Table pawnsTable;
Material::Table materialTable;
Pawns::Table pawnsTable;
Material::Table materialTable;
free(mem);
clusterCount = mbSize * 1024 * 1024 / sizeof(Cluster);
free(mem);
clusterCount = mbSize * 1024 * 1024 / sizeof(Cluster);
- table = static_cast<Cluster*>(aligned_ttmem_alloc(clusterCount * sizeof(Cluster), &mem));
+ table = static_cast<Cluster*>(aligned_ttmem_alloc(clusterCount * sizeof(Cluster), mem));
if (!mem)
{
std::cerr << "Failed to allocate " << mbSize
if (!mem)
{
std::cerr << "Failed to allocate " << mbSize