it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Glaurung is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Glaurung is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/// precomputes material hash keys for a few basic endgames, in order
/// to make it easy to recognize such endgames when they occur.
/// precomputes material hash keys for a few basic endgames, in order
/// to make it easy to recognize such endgames when they occur.
/// MaterialInfoTable::get_material_info() takes a position object as input,
/// computes or looks up a MaterialInfo object, and returns a pointer to it.
/// If the material configuration is not already present in the table, it
/// MaterialInfoTable::get_material_info() takes a position object as input,
/// computes or looks up a MaterialInfo object, and returns a pointer to it.
/// If the material configuration is not already present in the table, it
/// same material configuration occurs again.
MaterialInfo *MaterialInfoTable::get_material_info(const Position &pos) {
/// same material configuration occurs again.
MaterialInfo *MaterialInfoTable::get_material_info(const Position &pos) {
// have analysed this material configuration before, and we can simply
// return the information we found the last time instead of recomputing it:
if(mi->key == key)
// have analysed this material configuration before, and we can simply
// return the information we found the last time instead of recomputing it:
if(mi->key == key)
for(c = WHITE, sign = 1; c <= BLACK; c++, sign = -sign) {
// No pawns makes it difficult to win, even with a material advantage:
for(c = WHITE, sign = 1; c <= BLACK; c++, sign = -sign) {
// No pawns makes it difficult to win, even with a material advantage:
// Bishop pair:
if(pos.bishop_count(c) >= 2) {
mgValue += sign * BishopPairMidgameBonus;
egValue += sign * BishopPairEndgameBonus;
}
// Bishop pair:
if(pos.bishop_count(c) >= 2) {
mgValue += sign * BishopPairMidgameBonus;
egValue += sign * BishopPairEndgameBonus;
}
// http://mywebpages.comcast.net/danheisman/Articles/evaluation_of_material_imbalance.htm
mgValue += sign * Value(pos.knight_count(c)*(pos.pawn_count(c)-5)*16);
egValue += sign * Value(pos.knight_count(c)*(pos.pawn_count(c)-5)*16);
// http://mywebpages.comcast.net/danheisman/Articles/evaluation_of_material_imbalance.htm
mgValue += sign * Value(pos.knight_count(c)*(pos.pawn_count(c)-5)*16);
egValue += sign * Value(pos.knight_count(c)*(pos.pawn_count(c)-5)*16);