////
#include <cassert>
+#include <cstring>
#include <sstream>
#include <map>
// Helper templates used to detect a given material distribution
template<Color Us> bool is_KXK(const Position& pos) {
const Color Them = (Us == WHITE ? BLACK : WHITE);
- return pos.non_pawn_material(Them) == Value(0)
+ return pos.non_pawn_material(Them) == VALUE_ZERO
&& pos.piece_count(Them, PAWN) == 0
&& pos.non_pawn_material(Us) >= RookValueMidgame;
}
/// MaterialInfoTable c'tor and d'tor, called once by each thread
-MaterialInfoTable::MaterialInfoTable(unsigned int numOfEntries) {
+MaterialInfoTable::MaterialInfoTable() {
- size = numOfEntries;
- entries = new MaterialInfo[size];
+ entries = new MaterialInfo[MaterialTableSize];
funcs = new EndgameFunctions();
if (!entries || !funcs)
{
- cerr << "Failed to allocate " << numOfEntries * sizeof(MaterialInfo)
+ cerr << "Failed to allocate " << MaterialTableSize * sizeof(MaterialInfo)
<< " bytes for material hash table." << endl;
Application::exit_with_failure();
}
MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
Key key = pos.get_material_key();
- unsigned index = unsigned(key & (size - 1));
+ unsigned index = unsigned(key & (MaterialTableSize - 1));
MaterialInfo* mi = entries + index;
// If mi->key matches the position's material hash key, it means that we
return mi;
// Clear the MaterialInfo object, and set its key
- mi->clear();
+ memset(mi, 0, sizeof(MaterialInfo));
+ mi->factor[WHITE] = mi->factor[BLACK] = uint8_t(SCALE_FACTOR_NORMAL);
mi->key = key;
// Store game phase
else if (is_KQKRPs<BLACK>(pos))
mi->scalingFunction[BLACK] = &ScaleKQKRPs[BLACK];
- if (pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK) == Value(0))
+ if (pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK) == VALUE_ZERO)
{
if (pos.piece_count(BLACK, PAWN) == 0)
{