X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmaterial.cpp;h=5e8f75d9cc4b6c2561fdd5b1a5bb784078be323c;hb=fad595f5b6b343708fc0b4d8ab15ab73040f84c1;hp=e19b0c9e4225f9636821a9f841793184a01a106c;hpb=f26e0fec64eed03279704e851b11c1654ea2c63c;p=stockfish diff --git a/src/material.cpp b/src/material.cpp index e19b0c9e..5e8f75d9 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -23,6 +23,7 @@ //// #include +#include #include #include @@ -72,7 +73,7 @@ namespace { // Helper templates used to detect a given material distribution template 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; } @@ -134,18 +135,18 @@ template<> const SFMap& EndgameFunctions::get() const { return maps.second; /// 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(); } + memset(entries, 0, MaterialTableSize * sizeof(MaterialInfo)); } MaterialInfoTable::~MaterialInfoTable() { @@ -181,7 +182,7 @@ Phase MaterialInfoTable::game_phase(const Position& pos) { 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 @@ -191,7 +192,8 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) { 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 @@ -254,7 +256,7 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) { else if (is_KQKRPs(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) { @@ -332,7 +334,7 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) { // Second-degree polynomial material imbalance by Tord Romstad // - // We use NO_PIECE_TYPE as a place holder for the bishop pair "extended piece", + // We use PIECE_TYPE_NONE as a place holder for the bishop pair "extended piece", // this allow us to be more flexible in defining bishop pair bonuses. for (pt1 = PIECE_TYPE_NONE; pt1 <= QUEEN; pt1++) {